在CentOS 7上安装Zabbix 3.0
总结安装CentOS7和Zabbix3.0的步骤。
环境AWS
CentOS Linux 7 x86_64 HVM
AWS
CentOS Linux 7 x86_64 HVM (云计算服务)
准备之后
更改主机名称在中国,可以使用hostnamectl来更改主机名,也可以使用/etc/hostname。
# hostnamectl set-hostname zabbix-test01
# 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
修改时区↓起始值
# 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
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
确认设置是否反映(时区应该设置为日本时间)
# 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,将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
# 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
# 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
# reboot
# 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_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的数据库和用户
密码设为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数据注入到数据库中。
# zcat /usr/share/doc/zabbix-server-mysql-3.0.14/create.sql.gz | mysql -uzabbix zabbix -p
Enter password: <==パスワード入力
# <==特に何も表示はない
将DB的信息写入Zabbix的配置文件。
# echo "DBHost=localhost" >> /etc/zabbix/zabbix_server.conf
# echo "DBPassword=zabbixzabbix" >> /etc/zabbix/zabbix_server.conf
# zcat /usr/share/doc/zabbix-server-mysql-3.0.14/create.sql.gz | mysql -uzabbix zabbix -p
Enter password: <==パスワード入力
# <==特に何も表示はない
# 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.
# 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.
这只是一个粗略的说明,总之,导入已经完成。
接下来我会写一些关于在浏览器上的初始设置之类的内容。。。