CentOS7にZabbix Server 4.0 インストール
環境
- OS: CentOS Linux release 7.6.1810 (Core)
- ImageId: ami-045f38c93733dd48d
- InstanceType: t2.micro
- SELinux: disabled
- install: MariaDB10.3, httpd2.4, php7.3, wget1.1, Zabbix4.0
手順
OS確認
$ sudo more /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
ロケール変更
$ localectl
System Locale: LANG=en_US.UTF-8
VC Keymap: us
X11 Layout: us
$ localectl list-locales | grep -i ja_JP.utf8
ja_JP.utf8
$ sudo localectl set-locale LANG=ja_JP.utf8
$ sudo localectl set-keymap jp106
$ localectl
System Locale: LANG=ja_JP.utf8
VC Keymap: jp106
X11 Layout: jp
X11 Model: jp106
X11 Options: terminate:ctrl_alt_bksp
Timezone変更
$ timedatectl status
Local time: Tue 2018-06-26 05:37:04 UTC
Universal time: Tue 2018-06-26 05:37:04 UTC
RTC time: Tue 2018-06-26 05:37:03
Time zone: UTC (UTC, +0000)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
$ sudo timedatectl set-timezone Asia/Tokyo
$ timedatectl status
Local time: Tue 2018-06-26 14:38:43 JST
Universal time: Tue 2018-06-26 05:38:43 UTC
RTC time: Tue 2018-06-26 05:38:42
Time zone: Asia/Tokyo (JST, +0900)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
ホスト名変更
$ uname -n
ip-172-16-0-4.ap-northeast-1.compute.internal
$ sudo hostnamectl set-hostname zabbix
$ uname -n
zabbix
SELinux無効化
$ sudo getenforce
Enforcing
$ sudo sed -i.bak "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
$ diff /etc/selinux/config*
7c7
< SELINUX=disabled
---
> SELINUX=enforcing
$ sudo shutdown -r now
モジュール最新化
$ sudo yum update -y
$ sudo shutdown -r now
リポジトリ登録
$ sudo yum install http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm -y
$ sudo yum install epel-release -y
$ sudo yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm -y
$ curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
$ yum repolist enabled
$ ls -l /etc/yum.repos.d/
ZabbixServer,mariadbインストール
$ sudo yum --enablerepo=remi-php73 install zabbix-server-mysql zabbix-web-mysql zabbix-web-japanese zabbix-agent mariadb-server -y
$ sudo yum install zabbix-server-mysql zabbix-web-mysql zabbix-web-japanese zabbix-agent mariadb-server -y
mariadb設定
$ systemctl status mariadb.service
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: inactive (dead)
$ sudo systemctl start mariadb.service
$ systemctl status mariadb.service
● mariadb.service - MariaDB 10.3.15 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
mqmigrated-from-my.cnf-settings.conf
Active: active (running) since Tue 2019-06-11 14:33:02 JST; 4s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Process: 18399 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 18355 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
Process: 18353 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Main PID: 18367 (mysqld)
Status: "Taking your SQL requests now..."
CGroup: /system.slice/mariadb.service
mq18367 /usr/sbin/mysqld
Jun 11 14:33:02 ip-172-16-7-175.ap-northeast-1.compute.internal mysqld[18367]: 2019-06-11 14:33:02 0 [Note] InnoDB: 10.3.15 started; ...d 21
Jun 11 14:33:02 ip-172-16-7-175.ap-northeast-1.compute.internal mysqld[18367]: 2019-06-11 14:33:02 0 [Note] InnoDB: Loading buffer po...pool
Jun 11 14:33:02 ip-172-16-7-175.ap-northeast-1.compute.internal mysqld[18367]: 2019-06-11 14:33:02 0 [Note] InnoDB: Buffer pool(s) lo...3:02
Jun 11 14:33:02 ip-172-16-7-175.ap-northeast-1.compute.internal mysqld[18367]: 2019-06-11 14:33:02 0 [Note] Plugin 'FEEDBACK' is disabled.
Jun 11 14:33:02 ip-172-16-7-175.ap-northeast-1.compute.internal mysqld[18367]: 2019-06-11 14:33:02 0 [Note] Server socket created on ...::'.
Jun 11 14:33:02 ip-172-16-7-175.ap-northeast-1.compute.internal mysqld[18367]: 2019-06-11 14:33:02 0 [Note] Reading of all Master_inf...eded
Jun 11 14:33:02 ip-172-16-7-175.ap-northeast-1.compute.internal mysqld[18367]: 2019-06-11 14:33:02 0 [Note] Added new Master_info '' ...able
Jun 11 14:33:02 ip-172-16-7-175.ap-northeast-1.compute.internal mysqld[18367]: 2019-06-11 14:33:02 0 [Note] /usr/sbin/mysqld: ready f...ons.
Jun 11 14:33:02 ip-172-16-7-175.ap-northeast-1.compute.internal mysqld[18367]: Version: '10.3.15-MariaDB' socket: '/var/lib/mysql/my...rver
Jun 11 14:33:02 ip-172-16-7-175.ap-northeast-1.compute.internal systemd[1]: Started MariaDB 10.3.15 database server.
Hint: Some lines were ellipsized, use -l to show in full.
$ sudo systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
$ sudo cp -p /etc/my.cnf.d/server.cnf /etc/my.cnf.d/server.cnf.bak
$ sudo vi /etc/my.cnf.d/server.cnf
$ diff /etc/my.cnf.d/server.cnf*
13,16d12
< character-set-server = utf8
< collation-server = utf8_bin
< skip-character-set-client-handshake
< innodb_file_per_table
$ sudo systemctl restart mariadb.service
$ systemctl status mariadb.service
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2018-06-26 17:12:33 JST; 15s ago
Process: 12771 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 12739 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 12770 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─12770 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─12980 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin -...
Jun 26 17:12:31 mon systemd[1]: Starting MariaDB database server...
Jun 26 17:12:31 mon mariadb-prepare-db-dir[12739]: Database MariaDB is probably initialized in /var/lib/mysql ...one.
Jun 26 17:12:31 mon mysqld_safe[12770]: 180626 17:12:31 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Jun 26 17:12:32 mon mysqld_safe[12770]: 180626 17:12:32 mysqld_safe Starting mysqld daemon with databases fro...mysql
Jun 26 17:12:33 mon systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
$ mysql -uroot -e 'show variables like "%char%"'
+--------------------------+----------------------------+
| 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 | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
$ sudo 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): <Enter押下>
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
New password: zabbix
Re-enter new password: zabbix
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
... 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
... 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
- 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!
$ sudo mysql -uroot -pzabbix
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
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;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix' ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
$ sudo zcat /usr/share/doc/zabbix-server-mysql-4.0.9/create.sql.gz | mysql -uroot -pzabbix zabbix
ZabbixServer設定
$ sudo sed -i.bak 's/# DBPassword=/DBPassword=zabbix/g' /etc/zabbix/zabbix_server.conf
$ sudo diff /etc/zabbix/zabbix_server.conf*
115c115
< DBPassword=zabbix
---
> # DBPassword=
$ sudo systemctl start zabbix-server
$ sudo systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
PHP設定
$ sudo sed -i.bak 's/\;date\.timezone\ \=/date\.timezone\ \=\ Asia\/Tokyo/g' /etc/php.ini
$ sudo sed -i "s/^post_max_size.*$/post\_max\_size\ \=\ 16M/g" /etc/php.ini
$ sudo sed -i "s/^max_execution_time.*$/max\_execution\_time\ \=\ 300/g" /etc/php.ini
$ sudo sed -i "s/^max_input_time.*$/max\_input\_time\ \=\ 300/g" /etc/php.ini
$ sudo sed -i "s/^upload_max_filesize.*$/upload\_max\_filesize\ \=\ 4M/g" /etc/php.ini
$ sudo diff /etc/php.ini*
384c384
< max_execution_time = 300
---
> max_execution_time = 30
394c394
< max_input_time = 300
---
> max_input_time = 60
672c672
< post_max_size = 16M
---
> post_max_size = 8M
800c800
< upload_max_filesize = 4M
---
> upload_max_filesize = 2M
878c878
< date.timezone = Asia/Tokyo
---
> ;date.timezone =
$ sudo systemctl restart httpd
$ systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2018-06-26 17:40:53 JST; 8s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 13148 (httpd)
Status: "Processing requests..."
CGroup: /system.slice/httpd.service
├─13148 /usr/sbin/httpd -DFOREGROUND
├─13150 /usr/sbin/httpd -DFOREGROUND
├─13151 /usr/sbin/httpd -DFOREGROUND
├─13152 /usr/sbin/httpd -DFOREGROUND
├─13153 /usr/sbin/httpd -DFOREGROUND
└─13154 /usr/sbin/httpd -DFOREGROUND
Jun 26 17:40:53 mon systemd[1]: Starting The Apache HTTP Server...
Jun 26 17:40:53 mon httpd[13148]: AH00558: httpd: Could not reliably determine the server's fully qualified ...essage
Jun 26 17:40:53 mon systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
$ sudo systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.