CentOS7にZabbix3.0をインストールする

CentOS7にZabbix3.0をインストールまでの手順まとめ

#環境
AWS
CentOS Linux 7 x86_64 HVM


#下準備

##ホスト名変更
hostnamectlで変更する、`/etc/hostname`でもok

```
# hostnamectl set-hostname zabbix-test01
```

ホスト名が書き込まれているか確認(一応)

```
[root@ip-10-0-0-186 ~]# cat /etc/hostname 
zabbix-test01
```

再起動または停止→起動するたびに
cloudinitがホスト名をip-[プライベートIP]に戻してしまうので
ホスト名を静的にする

```
# echo "preserve_hostname: true" >> /etc/cloud/cloud.cfg
```



##Timezone変更

↓初期値

```
# timedatectl 
      Local time: Mon 2018-02-05 13:57:17 UTC
  Universal time: Mon 2018-02-05 13:57:17 UTC
        RTC time: Mon 2018-02-05 13:57:16
       Time zone: UTC (UTC, +0000)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
```

日本時間にする

```
# timedatectl set-timezone Asia/Tokyo
```

設定反映されたか確認(Time zoneの値が日本時間になってるはず)

```
# timedatectl 
      Local time: Mon 2018-02-05 22:57:29 JST
  Universal time: Mon 2018-02-05 13:57:29 UTC
        RTC time: Mon 2018-02-05 13:57:28
       Time zone: Asia/Tokyo (JST, +0900)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
```

こんな感じに表示される

```
# date
Mon Feb  5 23:02:11 JST 2018
```

##SELinux無効化
Apacheを使うためにdisabledにする
SELINUX=disabledと記述

```
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
```

##パッケージ更新
とりあえず最新のパッケージに更新、ついでにbashの補完機能もインストール

```
# yum update -y && yum install bash-completion -y
```

#再起動
ホスト名とSELinuxの設定を反映させるため再起動

```
# reboot 
```

#Zabbix3.0のインストール
```
# yum install http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-
3.0-1.el7.noarch.rpm -y
```

必要なパッケージ一式インストール

```
# yum install -y httpd php mariadb mariadb-server zabbix-server-mysql zabbix-web-mysql zabbix-web-japanese
```

#MariaDB初期設定

```
# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y <==y
New password: <==新しいパスワードを入力
Re-enter new password: <==もう一度パスワードを入力
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y <==anonymousユーザの削除するかどうか
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y <==リモートでのrootログインを許可するかどうか
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y <==データベース「test」を削除するかどうか
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y <==設定を反映するかどうか
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
```

##Zabbix用のデータベース作成
Zabbix用のデータベースとユーザを作成する
パスワードは`zabbixzabbix`とする

```
# mysql -u root -p
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbixzabbix';
MariaDB [(none)]> select user,host from mysql.user; <==作成したユーザがあるか確認(zabbix | localhost )がある行
quit;
```

入出力例

```
# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbixzabbix';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user   | host      |
+--------+-----------+
| root   | 127.0.0.1 |
| root   | ::1       |
| root   | localhost |
| zabbix | localhost |
+--------+-----------+
4 rows in set (0.00 sec)

MariaDB [(none)]> quit;
```

##SQLをDBに流し込む

```
# zcat /usr/share/doc/zabbix-server-mysql-3.0.14/create.sql.gz | mysql -uzabbix zabbix -p
Enter password: <==パスワード入力
# <==特に何も表示はない
```

##Zabbixの設定ファイルにDBの情報を書き込む

```
# echo "DBHost=localhost" >> /etc/zabbix/zabbix_server.conf 
# echo "DBPassword=zabbixzabbix" >> /etc/zabbix/zabbix_server.conf 
```

apacheの設定編集
`/etc/httpd/conf.d/zabbix.conf`に
`php_value date.timezone Asia/Tokyo`
を追加

```
# cat /etc/httpd/conf.d/zabbix.conf 
#
# Zabbix monitoring system php web frontend
#

Alias /zabbix /usr/share/zabbix

<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
        php_value date.timezone Asia/Tokyo
    </IfModule>
</Directory>

<Directory "/usr/share/zabbix/conf">
    Require all denied
</Directory>

<Directory "/usr/share/zabbix/app">
    Require all denied
</Directory>

<Directory "/usr/share/zabbix/include">
    Require all denied
</Directory>

<Directory "/usr/share/zabbix/local">
    Require all denied
</Directory>
```

#各サービス起動

```
# systemctl start zabbix-server.service
# systemctl start mariadb.service 
# systemctl start zabbix-server.service 
```

#各サービス自動起動

```
# systemctl enable httpd.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
# systemctl enable mariadb.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
# systemctl enable zabbix-server.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/sy
stemd/system/zabbix-server.service.
```

雑な説明ですが、とりあえず導入完了です。
次はブラウザでの初期設定とか書きます。。。