vi td-agent.conf

設定ファイル
sourceディレクティブ。入力方法を決める

<source>
  type forward
</source>

matchディレクティブ。マッチした入力への処理を決める

<match index.html>
  type file
  path /var/log/fluent/access1
</match>

[vagrant@localhost td-agent]$ sudo /etc/init.d/td-agent status
td-agent is running [ OK ]

fluentdを使おう

vagrant@vagrant-ubuntu-trusty-64:~$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
vagrant@vagrant-ubuntu-trusty-64:~$ gem -v
1.8.23
vagrant@vagrant-ubuntu-trusty-64:~$ gem update –system
ERROR: While executing gem … (RuntimeError)
gem update –system is disabled on Debian, because it will overwrite the content of the rubygems Debian package, and might break your Debian system in subtle ways. The Debian-supported way to update rubygems is through apt-get, using Debian official repositories.
If you really know what you are doing, you can still update rubygems by setting the REALLY_GEM_UPDATE_SYSTEM environment variable, but please remember that this is completely unsupported by Debian.
vagrant@vagrant-ubuntu-trusty-64:~$ gem list

*** LOCAL GEMS ***

curl -L https://toolbelt.treasuredata.com/sh/install-amazon1-td-agent3.sh | sh

[vagrant@localhost td-agent]$ ls
plugin td-agent.conf

CodeIgniter

PHPを用いて動的Webサイトを構築するために利用するオープンソースのWebアプリケーションフレームワーク

コード量が少ない(どこでどんな処理をしているのかの見通しもいい)
動作が速い(これまた、レイヤーの薄さがあっての効果です)

稼働中のコンテナに入る
docker-compose exec hoge_app bash

stop
docker-compose stop

docker-compose rm -v
docker-compose build –no-cache
docker rm ‘docker ps -a -q’

docker volume rm $(docker volume ls -qf dangling=true)

docker images -a

docker rmi ‘docker images -aq’
docker rmi -f ‘docker images -aq’

docker image prune

docker rmi $(docker images | awk ‘/^/ {print $3}’)

docker cp file.rc continername:/host/dir/

docker cp continer_name:/var/www/html/ /User/meta/hoge

docker composeのインストール

vagrant@vagrant-ubuntu-trusty-64:~/wordpress/dataonly$ sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 617 0 617 0 0 374 0 –:–:– 0:00:01 –:–:– 374
100 8648k 100 8648k 0 0 205k 0 0:00:42 0:00:42 –:–:– 303k
vagrant@vagrant-ubuntu-trusty-64:~/wordpress/dataonly$ sudo chmod +x /usr/local/bin/docker-compose

vagrant@vagrant-ubuntu-trusty-64:~/wordpress/dataonly$ sudo docker-compose ps
Name Command State Ports
————————————————————————————
dataonly_dbserver_1 docker-entrypoint.sh mysqld Up 3306/tcp, 33060/tcp
dataonly_webserver_1 docker-entrypoint.sh apach … Exit 1

Docker compose とは、複数のコンテナから成るサービスを構築・実行する手順を自動的にし、管理を容易にする機能

dockerでnginx

dockerのimageからnginxをpullする

vagrant@vagrant-ubuntu-trusty-64:~$ sudo docker run -d -p 8080:80 –name webserver ngiUnable to find image ‘nginx:latest’ locally
latest: Pulling from library/nginx
802b00ed6f79: Pull complete
c16436dbc224: Pull complete
683eac851b28: Pull complete
Digest: sha256:e8ab8d42e0c34c104ac60b43ba60b19af08e19a0e6d50396bdfd4cef0347ba83
Status: Downloaded newer image for nginx:latest
f8a67eabff58916d0afb8029ad64d050410d39e4ac2f64af7f2875829c010030

dockerとは

Dockerは軽量な仮想マシンを簡単に構築することができ、インフラを含めたアプリ全体をまるまる、コンテナという箱に閉じ込めることができる

– OS依存がなく、導入が容易
– 案件ごとに異なる環境を構築できるため、特定のPC依存を回避
– ミドルウェア導入や新インフラ環境のテストが各自のPCで可能
– 言語やツールのバージョンアップテストが容易
– チームメンバー全員が各自のPCでデバッグ可能になる

vagrant@vagrant-ubuntu-trusty-64:~$ sudo docker info
Containers: 10
Running: 3
Paused: 0
Stopped: 7
Images: 9
Server Version: 18.06.1-ce
Storage Driver: devicemapper
Pool Name: docker-8:1-263323-pool
Pool Blocksize: 65.54kB
Base Device Size: 10.74GB
Backing Filesystem: ext4
Udev Sync Supported: true
Data file: /dev/loop0
Metadata file: /dev/loop1
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Data Space Used: 690.4MB
Data Space Total: 107.4GB
Data Space Available: 39.73GB
Metadata Space Used: 1.466MB
Metadata Space Total: 2.147GB
Metadata Space Available: 2.146GB
Thin Pool Minimum Free Space: 10.74GB
Deferred Removal Enabled: false
Deferred Deletion Enabled: false
Deferred Deleted Device Count: 0
Library Version: 1.02.77 (2012-10-15)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
apparmor
Kernel Version: 3.13.0-100-generic
Operating System: Ubuntu 14.04.5 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 489.9MiB
Name: vagrant-ubuntu-trusty-64
ID: CLZ5:A6GJ:OEWU:E76Y:ZUKL:LGLE:UOUK:I4FC:6TWQ:OHYZ:FJTK:F3CG
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Username: ddddocker
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

docker basic

vagrant@vagrant-ubuntu-trusty-64:~$ docker attach –sig-proxy=false 345
WARNING: Error loading config file: /home/vagrant/.docker/config.json: stat /home/vagrant/.docker/config.json: permission denied
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.38/containers/345/json: dial unix /var/run/docker.sock: connect: permission denied
vagrant@vagrant-ubuntu-trusty-64:~$ sudo docker attach –sig-proxy=false 345

total used free shared buff/cache available
Mem: 501708 164064 44344 428 293300 316495
Swap: 0 0 0

total used free shared buff/cache available
Mem: 501708 164064 44344 428 293300 316499
Swap: 0 0 0

コンテナの中に入る
vagrant@vagrant-ubuntu-trusty-64:~$ sudo docker run -i -t centos /bin/bash
[root@8f60db713564 /]#

mysqlをwindows10に入れる

C:\mysql-56\bin>mysqld –install mysq56
Service successfully installed.

C:\mysql-56\bin>mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.41 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>

きた。
eclipseでどうしても必要だと思ったが、半日かかった。

ec2でperlを動かそう

/var/www/cgi-bin

[ec2-user@ cgi-bin]$ ls
hello.cgi
[ec2-user@ cgi-bin]$ sudo chmod +x hello.cgi

#!/usr/bin/perl --
print "Content-type: text/html \n\n";
print "Hello";

きた

mysql
mysql> create database perldb;
Query OK, 1 row affected (0.02 sec)

mysql> use perldb;
Database changed
mysql> create table t1(
-> a int,
-> b varchar(10)
-> );
Query OK, 0 rows affected (0.04 sec)

mysql> insert into t1 values(1, ‘asakura’),(2, ‘adachi’),(3, ‘kobayakawa’);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from t1;
+——+————+
| a | b |
+——+————+
| 1 | asakura |
| 2 | adachi |
| 3 | kobayakawa |
+——+————+
3 rows in set (0.01 sec)

$ perl hoge.pl
Can’t locate DBI.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at hoge.pl line 4.
BEGIN failed–compilation aborted at hoge.pl line 4.

sudo yum -y install perl-DBI perl-DBD-MySQL

きた!OKKKKKKKKKKKKKKKK

次はservlet mysqlだ。ここわなー

perlでmysqlからselectする(cgi編)

#!/usr/bin/perl --

use strict;
use DBI;

our $DB_NAME = "perldb";
our $DB_USER = "hoge";
our $DB_PASS = "hogehoge";
our $DB_HOST = "localhost";
our $DB_PORT = "3306";

my $dbh = DBI->connect("dbi:mysql:dbname=$DB_NAME;host=$DB_HOST;port=$DB_PORT","$DB_USER","$DB_PASS") or die "$!\n Error: failed to connect to DB.\n";
my $sth = $dbh->prepare("SELECT * FROM t1;");
$sth->execute();

print "Content-Type: text/html; charset=Shift_JIS\n\n";
while (my $ary_ref = $sth->fetchrow_arrayref) {
  print "<p>$ary_ref->[0], $ary_ref->[1]</p>\n";
}

$sth->finish;
$dbh->discconect;

なんや、OKだ。

次は、このままec2にperlを載せたい。