zabbix3.0 on CentOS7

#目的
Centos7にZabbix3.0をインストールする

#環境
* AWS(検証用なので低スペックタイプを使用)
    * EC2:t2.nano
        * gp2:8GB
    * RDS:db.t2.micro
        * gp2:30GB>理論値で90IOPS
* CentOS Linux release 7.2.1511 (Core)
* zabbix-server-mysql-3.0.1-1.el7.x86_64


#設定
##CentOS
```bash
$ sudo localectl set-locale LANG=ja_JP.utf8
$ localectl status
   System Locale: LANG=ja_JP.utf8
       VC Keymap: us
      X11 Layout: us
```

```bash
$ timedatectl list-timezones | grep Tokyo
Asia/Tokyo
$ sudo timedatectl set-timezone Asia/Tokyo
$ timedatectl status
```

```bash
$ hostnamectl set-hostname <hostname>
```

```bash
$ sudo useradd <user>
$ sudo passwd <user>
$ sudo usermod -G wheel <user>
$ cat /etc/group
(snip)
wheel:x:10:centos,<user>
(snip)
```

```bash
$ sudo visudo
(snip)
## Allows people in group wheel to run all commands
%wheel   ALL=(ALL)       ALL
(snip)
```

```bash:/etc/login.defs
(snip)
#Only wheelgroup can login
SU_WHEEL_ONLY        yes
(snip)
```

```bash:/etc/pam.d/su
#アンコメントしてgroup=wheelを記述

#%PAM-1.0
auth            sufficient      pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient      pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth            required        pam_wheel.so use_uid group=wheel
auth            substack        system-auth
auth            include         postlogin
account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet
account         include         system-auth
password        include         system-auth
session         include         system-auth
session         include         postlogin
session         optional        pam_xauth.so
```

***
##zabbix3.0
###MySQL Repositories

* mariadbは使用しないのでアンインストール

```bash
$ sudo yum list installed | grep maria
mariadb-libs.x86_64                        1:5.5.47-1.el7_2            @updates
$ sudo yum remove mariadb-libs.x86_64
```

* [MySQL Repositoriesを登録](https://dev.mysql.com/downloads/repo/)

```bash
$ wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
$ sudo rpm -Uvh mysql57-community-release-el7-7.noarch.rpm
$ sudo yum install mysql-community-client
```

###RDS
* サーバにアタッチするバラメータグループのパラメータ編集でログ取得出来るようにフラグ1を立てる
    * slow_query_log
    * general_log

* zabbixフロントエンドの日本語文字化け対策として明示的にutf8とする
    * character_set_database
    * character_set_server

* 確認

```mysql
mysql> show variables like 'character_set%';
+--------------------------+-------------------------------------------+
| Variable_name            | Value                                     |
+--------------------------+-------------------------------------------+
| character_set_client     | utf8                                      |
| character_set_connection | utf8                                      |
| character_set_database   | utf8                                      |
| character_set_filesystem | binary                                    |
| character_set_results    | utf8                                      |
| character_set_server     | utf8                                      |
| character_set_system     | utf8                                      |
| character_sets_dir       | /rdsdbbin/mysql-5.7.10.R1/share/charsets/ |
+--------------------------+-------------------------------------------+
8 rows in set (0.10 sec)

mysql> 
```

###zabbix-server
* リポジトリ登録してインストール

```bash
$ sudo rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
$ sudo yum install zabbix-server-mysql zabbix-web-mysql zabbix-web-japanese zabbix-agent zabbix-get
```

* 初期スキーマとデータをインポート（2系とはやり方が少し違う）

```bash
$ cd /usr/share/doc/zabbix-server-mysql-3.0.1
$ zcat create.sql.gz | mysql -h <rds-endpoint> <db> -u <user> -p
```

* zabbix-server.conf(dbname,dbuserはデフォルトのzabbixにしてあるので変更なし)

```bash:/etc/zabbix/zabbix_server.conf
82a83,84
> DBHost=<rds-endpoint>
> 
115a118,119
> 
> DBPassword=<rds-password>
```

* ここで定義されている値を/etc/php.iniに適用する

```bash:/etc/httpd/conf.d/zabbix.conf
(snip)
<Directory "/usr/share/zabbix">
    Options FollowSymLinks
    AllowOverride None
    Require all granted

    <IfModule mod_php5.c>
        php_value max_execution_time 300
        php_value memory_limit 128M
        php_value post_max_size 16M
        php_value upload_max_filesize 2M
        php_value max_input_time 300
        php_value always_populate_raw_post_data -1
        # php_value date.timezone Europe/Riga
    </IfModule>
</Directory>
(snip)
```

```bash:/etc/php.ini
384c384
< max_execution_time = 30
---
> max_execution_time = 300
394c394
< max_input_time = 30
---
> max_input_time = 300
698c698
< ; always_populate_raw_post_data = On
---
> always_populate_raw_post_data = -1
878c878
< ; date.timezone = Europe/Riga
---
> date.timezone = Asia/Tokyo
```

* zabbix-agent.conf

```bash:/etc/zabbix/zabbix_agentd.conf
96a97
>
104a106,107
> ListenPort=10050
>
147c150
< Hostname=Zabbix server
---
> #Hostname=Zabbix server
155c158
< # HostnameItem=system.hostname
---
> HostnameItem=system.hostname
```

* Apache

```bash:/var/www
$ sudo ln -s /usr/share/zabbix zabbix
```

```bash:/etc/httpd/conf/httpd.conf
119c119
< DocumentRoot "/var/www/html"
---
> DocumentRoot "/var/www/zabbix"
125c125
<     AllowOverride None
---
>     AllowOverride All
131c131
< <Directory "/var/www/html">
---
> <Directory "/var/www/zabbix">
144c144
<     Options Indexes FollowSymLinks
---
>     Options FollowSymLinks
151c151
<     AllowOverride None
---
>     AllowOverride All
```


* フロントエンド

```bash
$ sudo systemctl enable httpd.service && sudo systemctl enable zabbix-server.service && sudo systemctl enable zabbix-agent.service
$ sudo systemctl start httpd && sudo systemctl start zabbix-server && sudo systemctl start zabbix-agent
```

![zbx3.0_1.png](https://qiita-image-store.s3.amazonaws.com/0/58788/3a91879a-1db7-76a2-5d12-6be63eb5f11a.png)

![zbx3.0_2.png](https://qiita-image-store.s3.amazonaws.com/0/58788/255f5197-80fb-918b-7a58-26496bafe425.png)

![zbx3.0_3.png](https://qiita-image-store.s3.amazonaws.com/0/58788/88dcc19a-4ae6-9ec7-0e0c-4051e56b5a51.png)

![zbx3.0_4.png](https://qiita-image-store.s3.amazonaws.com/0/58788/99ec1dcc-aa74-36e8-c6c3-360821d1ce4f.png)

![zbx3.0_5.png](https://qiita-image-store.s3.amazonaws.com/0/58788/82544d1e-2f99-b6d3-ffc8-7b975c9111fa.png)

![zbx3.0_6.png](https://qiita-image-store.s3.amazonaws.com/0/58788/0ceae5cd-ddbc-e35e-452a-fbac59ef5776.png)

![zbx3.0_7.png](https://qiita-image-store.s3.amazonaws.com/0/58788/f079cae6-8085-b21e-8c2b-86692dd1c465.png)

![zbx3.0_8.png](https://qiita-image-store.s3.amazonaws.com/0/58788/5883b71f-256c-40ff-cef7-f47240788109.png)