PHPUnit

品質の良いプロダクトコードを書くことができるようになる。

use PHPUnit\Framework\TestCase;

classs HogeTest extends TestCase
{
	public function testHoge()
	{
		$stack = [];
		$this->assertEquals(0, count($stack));
	}
}

単体テストとは?

単体テスト(ユニットテストと呼ばれることもあります)は、プログラムを構成する比較的小さな単位(ユニット)が個々の機能を正しく果たしているかどうかを検証するテスト

通常、関数やメソッドが単体テストの単位(ユニット)となります。 プログラムが全体として正しく動作しているかを検証する結合テストは、開発の比較的後の段階でQAチームなどによって行なわれることが多いのとは対照的に、単体テストは、コード作成時などの早い段階で開発者によって実施されることが多いのが特徴

コードの内容をよく理解している開発者によって、コード作成と同時か直後に(または、『テスト駆動型開発』Test Driven Development:TDD と呼ばれる開発手法ではコードの作成よりも前に)テストケースが作成されるため、妥当性の高いテストケースを資産として残すことができ、後の拡張開発や改修時にも再利用できる

/etc/zabbix/zabbix_server.conf

/etc/zabbix/zabbix_server.conf

編集していきます。

DBName=zabbix
DBUser=zabbix
DBPassword=zabbixpassword
DBSocket=/var/lib/mysql/mysql.sock

mysql.sockって何? /var/lib/mysqlにmysqlで作成したdatabase一覧がありますね。

zabbix serverを起動

[vagrant@localhost zabbix]$ sudo service zabbix-server start
Starting Zabbix server: [ OK ]

うお!

あ、これやってなかった。
yum install -y zabbix-web zabbix-web-mysql zabbix-web-japanese

こうか?
[vagrant@localhost src]$ cd /usr/share/doc/zabbix-web-3.0.22
[vagrant@localhost zabbix-web-3.0.22]$ cp httpd24-example.conf /etc/httpd/conf.d/zabbix.conf
cp: cannot create regular file `/etc/httpd/conf.d/zabbix.conf’: 許可がありません
[vagrant@localhost zabbix-web-3.0.22]$ sudo httpd24-example.conf /etc/httpd/conf.d/zabbix.conf
sudo: httpd24-example.conf: コマンドが見つかりません
[vagrant@localhost zabbix-web-3.0.22]$ sudo cp httpd24-example.conf /etc/httpd/conf.d/zabbix.conf

Internal Server Error
なぜ?

zabbixを入れていこう

まず、mysqlにログインして、databaseを作ります。

mysql> create database zabbix character set utf8;
Query OK, 1 row affected (0.03 sec)

zabbix, zabbix-server, zabbix-server-mysqlを入れる
yum install -y zabbix zabbix-server zabbix-server-mysql

パッケージ zabbix は利用できません。
パッケージ zabbix-server-pgsql-3.0.22-1.el6.x86_64 はインストール済みか最新バージョンです
パッケージ zabbix-server-mysql-3.0.22-1.el6.x86_64 はインストール済みか最新バージョンです
何もしません

??

zabix-agentをinstall

cd /usr/share/doc

[vagrant@localhost doc]$ cd zabbix-server-mysql-3.0.22
[vagrant@localhost zabbix-server-mysql-3.0.22]$ ls
AUTHORS COPYING ChangeLog NEWS README create.sql.gz

これ、あってんのか??

cat でsql文を読み込ませて、mysqlを実行

cat create.sql | mysq -u root -p zabbix

まじか、これ?
mysql> use zabbix
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+—————————-+
| Tables_in_zabbix |
+—————————-+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| groups |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| httpstep |
| httpstepitem |
| httptest |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| item_application_prototype |
| item_condition |
| item_discovery |
| items |
| items_applications |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| mappings |
| media |
| media_type |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opinventory |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| rights |
| screen_user |
| screen_usrgrp |
| screens |
| screens_items |
| scripts |
| service_alarms |
| services |
| services_links |
| services_times |
| sessions |
| slides |
| slideshow_user |
| slideshow_usrgrp |
| slideshows |
| sysmap_element_url |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| timeperiods |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemaps |
+—————————-+
113 rows in set (0.00 sec)

zabbixを使おう

zabbixとは?
>Zabbixとは、サーバー、ネットワーク、アプリケーションを集中監視するためのオープンソースの統合監視ソフトウェアです。統合監視に必要な監視、障害検知、通知機能を備えています。多数のプラットフォームに対応したZabbixエージェントとSNMPに対応しているため、システム全体をZabbixひとつで監視することが可能です。

zabbix-agent.x86_64 : Zabbix Agent
zabbix-get.x86_64 : Zabbix Get
zabbix-java-gateway.x86_64 : Zabbix java gateway
zabbix-proxy-mysql.x86_64 : Zabbix proxy for MySQL or MariaDB database
zabbix-proxy-pgsql.x86_64 : Zabbix proxy for PostgreSQL database
zabbix-proxy-sqlite3.x86_64 : Zabbix proxy for SQLite3 database
zabbix-release.noarch : Zabbix repository configuration
zabbix-sender.x86_64 : Zabbix Sender
zabbix-server-mysql.x86_64 : Zabbix server for MySQL or MariaDB database
zabbix-server-pgsql.x86_64 : Zabbix server for PostgresSQL database
zabbix-web.noarch : Zabbix web frontend common package
zabbix-web-mysql.noarch : Zabbix web frontend for MySQL
zabbix-web-pgsql.noarch : Zabbix web frontend for PostgreSQL
zabbix-web-japanese.noarch : Japanese font settings for frontend

さくら共有サーバーにansibleで命令

以下のように書く
-e ‘ansible_python_interpreter=/usr/local/bin/python’

インベントリファイルにip, username, passを書くと、

# ansible all -i hosts -m ping -e 'ansible_python_interpreter=/usr/local/bin/python'
xx.xxx.xxx.xxx | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
xx.xxx.xxx.xxx | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

うおおおおおおおおおおおおおおおおおおおおおおおおおおお
まじかーーーーーーーーーーーーーーーーー

ansible.cfg

[defaults]
hostfile = ./hosts

# ansible all -m ping -e ‘ansible_python_interpreter=/usr/local/bin/python’
[DEPRECATION WARNING]: [defaults]hostfile option, The key is misleading as it
can also be a list of hosts, a directory or a list of paths , use [defaults]
inventory=/path/to/file|dir instead. This feature will be removed in version
2.8. Deprecation warnings can be disabled by setting deprecation_warnings=False
in ansible.cfg.
xx.xxx.xxx.xxx | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
xx.xxx.xxx.xxx | SUCCESS => {
“changed”: false,
“ping”: “pong”
}

インベントリファイルにuser passを書いていく

[sakura1]

[sakura2]

[sakura1:vars]
ansible_ssh_port=22
ansible_ssh_user=
ansible_ssh_pass=
ansible_sudo_pass=

[sakura2:vars]
ansible_ssh_port=22
ansible_ssh_user=
ansible_ssh_pass=
ansible_sudo_pass=

[root@ ansible]# ansible all -i hosts -m ping
| FAILED! => {
“changed”: false,
“module_stderr”: “Shared connection to xxx.xx.xx.xx closed.\r\n”,
“module_stdout”: “/usr/bin/python: not found\r\n”,
“msg”: “MODULE FAILURE”,
“rc”: 127
}
xx.xxx.xxx.xx | FAILED! => {
“changed”: false,
“module_stderr”: “Shared connection to xx.xxx.xxx.xx closed.\r\n”,
“module_stdout”: “/usr/bin/python: not found\r\n”,
“msg”: “MODULE FAILURE”,
“rc”: 127
}

ん? python2.7が入っていない?
[root@localhost ~]# yum -y install centos-release-scl-rh
[root@localhost ~]# yum -y install python27

[root@ ansible]# scl enable python27 bash
[root@ ansible]# python –version
Python 2.7.13

ansible all -i hosts -m ping -e ‘ansible_python_interpreter=/opt/rh/python27/root/usr/bin/python2.7’

アアアアアアアアアアアアア、
remote hostにはいっていないとか。。

Ansibleの設定を加えていこう

var/local/ansible
vi .ssh/config

Host sakura1
  HostName 182.xx.xx.xx
Host sakura2
  HostName 49.xxx.xxx.xxx

公開鍵を作成する
# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /var/local/ansible/.ssh/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/local/ansible/.ssh/id_rsa.
Your public key has been saved in /var/local/ansible/.ssh/id_rsa.pub.
The key fingerprint is:
c8:43:16:c5:69:5e:ad:d9:bb:0c:0e:22:7e:06:9a:46 root@hoge.vs.sakura.ne.jp
The key’s randomart image is:
+–[ RSA 2048]—-+
| .o.. . |
| .+ . . |
| oo . + |
| + .. o . |
| + S . |
| E o … . . |
| . + o . o o . |
| + . o . o |
| . o |
+—————–+

# ssh-copy-id sakura1
あれ? なんかうまくいかない。

# ansible all -i hosts -m ping
The authenticity of host ‘hoge’ can’t be established.
RSA key fingerprint is 0c:3.
Are you sure you want to continue connecting (yes/no)? The authenticity of host ‘1hoge)’ can’t be established.
RSA key fingerprint is 1f:3c:fa.
Are you sure you want to continue connecting (yes/no)? yes
hoge | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: Warning: Permanently added ‘hoge’ (RSA) to the list of known hosts.\r\nPermission denied (publickey,password).\r\n”,
“unreachable”: true
}

Please type ‘yes’ or ‘no’: yes
hoge | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: Warning: Permanently added ‘1hoge’ (RSA) to the list of known hosts.\r\nPermission denied (publickey,password).\r\n”,
“unreachable”: true
}

やはりRSA接続が上手くいっていない
インベントリファイルにパスワードを書く方法を模索か

vpsでansibleを動かす準備をしよう

1.さくら共有サーバー2つ分のipアドレスを取得
2.vpsにanshibleをインストール
3.vpsからさくら共有サーバーにping ponコマンドを実行し、ansibleが動くことを確認
4.vpsからファイルを転送して、アクセスする

まずはここまでやりたい。1は終了。
ansibleのplaybookをどこで実行するか?var/wwwwはapacheが動いているので、/var/localにansibleフォルダを作るのが無難か。

ansibleをインストールします。
# sudo yum -y install ansible

ansibleが入りました。config fileはetcに入ってますね。いいのか?
[root@hoge ansible]# ansible –version
ansible 2.6.4
config file = /etc/ansible/ansible.cfg
configured module search path = [u’/root/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python2.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]