在CentOS7上安装最新的Zabbix5.0 LTS
首先
由于最近很少使用Zabbix,并且它已经进化并更新为最新版本5.0 LTS,因此我决定在CentOS7上安装它。
环境
CentOS7.8已经在初始安装状态下准备好了。
# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
大体需要的东西
・Zabbix服务器
・Zabbix代理
・MySQL >>> MariaDB
・PHP
一起来吧
1. 安装MariaDB
在Zabbix安装过程中,PHP会自动准备好,所以只需要准备数据库即可。
# yum install mariadb mariadb-server
# systemctl start mariadb
# systemctl status mariadb
2. MariaDB的初始设置
只需使用mysql_secure_installation进行初始设置,先仅设置root密码即可。
# 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
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
... 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] n
... skipping.
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!
只要安装以下内容,MariaDB的数据库设置应该就没有问题了。
# vi /etc/my.cnf.d/server.cnf
[mysqld]
character-set-server = utf8
collation-server = utf8_bin
innodb_file_per_table
character-set-server: 默认字符编码用于创建数据库时
collation-server: 默认字符编码用于访问MySQL时的输出
innodb_file_per_table: 将InnoDB的每个表的数据和索引分别管理为独立的文件
※如果您是从前开始使用MySQL的人,我认为您会明白,之前由于InnoDB的每个数据都保存在ibdata1中导致容量膨胀的问题,现在这个问题终于得到解决了!!(据说MySQL 5.6.6及以后的版本默认打开这个选项)
・最后重新启动MariaDB
# systemctl restart mariadb
3. 安装Zabbix
我們將參考官方網站上的資訊繼續進行。
3-1. 注册存储库
我使用的是CentOS7,已经注册以下的软件源。请根据您自己的环境进行适配。
# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# yum clean all
3-2. 安装zabbix服务器和代理
# yum install zabbix-server-mysql zabbix-agent
3-3. 安装SCL存储库
按照官方网站上的步骤进行操作,也进行SCL的安装。
SCL(Software Collections)是与Red Hat Enterprise Linux(RHEL)的生命周期分开的一种方式,
它提供了一种安装稳定的最新软件版本的方法,类似于Red Hat Software Collections。
由于zabbix-web-mysql和apache需要额外安装SCL,所以我们在这里安装它。(总之就是WEB界面部分吧!)
# yum install centos-release-scl
3-4. 编辑仓库
在这里按照官方步骤启用前端代码库可能一开始没有问题。
# vi /etc/yum.repos.d/zabbix.repo
[zabbix-frontend]
...
enabled=1
...
3-5. 安装前端包裹件。
即使没有安装Apache或PHP,它们也会在这里通过依赖关系自动安装。
顺便提一下,根据最新的5.0版本,PHP的最低要求貌似是7.2。
# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl
4. Zabbix的设置
创建用于Zabbix的数据库
# mysql -uroot -p
mysqlのパスワード
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by 'password ← 必要に応じて変えてね!';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> quit;
4-2. 将模式和数据导入到Zabbix所用的数据库。
# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
4-2で設定したzabbix用のDBのパスワードを求められます
4-3. Zabbix服务器配置设置
# vi /etc/zabbix/zabbix_server.conf
DBPassword=password ← zabbix用のDBのパスワード
将php的默认时区设置为日本。
# vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
; php_value[date.timezone] = Europe/Riga ← コメントアウトのままでOK
php_value[date.timezone] = Asia/Tokyo ← 追加しよう
4-5. 启用重新启动和自动启动。
# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm mariadb
必须打开防火墙!
请在启用 SELinux 的情况下进行。
# firewall-cmd --add-service=https --zone=public --permanent
# firewall-cmd --add-service=http --zone=public --permanent
# firewall-cmd --add-port=10050/tcp --zone=public --permanent
# firewall-cmd --add-port=10051/tcp --zone=public --permanent
# firewall-cmd --reload
【笔记】
Zabbix服务器 → Zabbix代理 10050
Zabbix代理 → Zabbix服务器 10051
5. 来吧,让我们来访问一下吧!!!!

6. 登录
默认
用户:管理员
密码:zabbix

由于SELinux的影响,Zabbix服务器的状态变为“未运行”,需要解决这个问题。
・查询Zabbix相关的许可规则组定义。
# getsebool -a|grep zabbix
httpd_can_connect_zabbix --> off
zabbix_can_network --> off
zabbix_run_sudo --> off
httpd_can_connect_zabbix:允许httpd使用CGI、PHP等脚本访问Zabbix服务器
zabbix_can_network:允许Zabbix服务器访问其他网络
zabbix_run_sudo:允许通过Zabbix服务器运行sudo命令。
・不需要通过Zabbix服务器授予sudo使用权限进行命令执行,因此只需将其他权限打开。
# setsebool -P httpd_can_connect_zabbix on
# setsebool -P zabbix_can_network on
・SELinux仍然十分固执。
仅仅做到这一点是不够的。在这种状态下,即使重新启动Zabbix服务器也会出现错误,因此需要进一步调整。
对付这种SELinux问题,可以使用audit2allow。
audit2allow命令会读取日志并显示拒绝的原因和解决方案。
(尝试读取/var/log/audit/audit.log)
从这里开始重复。
※在我的环境中已经执行了三次。
# grep zabbix_server /var/log/audit/audit.log | audit2allow
#============= zabbix_t ==============
allow zabbix_t zabbix_var_run_t:sock_file create;
# grep zabbix_server /var/log/audit/audit.log | audit2allow -M zabbix-policy
******************** IMPORTANT ***********************
To make this policy package active, execute:
semodule -i zabbix-policy.pp
# semodule -i zabbix-policy.pp
# systemctl restart zabbix-server
# systemctl status zabbix-server
重复结束
在我的环境中,最终显示了以下三个选项。
# grep zabbix_server /var/log/audit/audit.log | audit2allow
#============= zabbix_t ==============
#!!!! This avc is allowed in the current policy
allow zabbix_t self:unix_stream_socket connectto;
#!!!! This avc is allowed in the current policy
allow zabbix_t zabbix_var_run_t:sock_file unlink;
allow zabbix_t zabbix_var_run_t:sock_file create;

对日本语的本土化


出现的错误只是SELinux的部分。
细节上需要调优MariaDB的内存以及Zabbix的进程数量等,但总体来说已经完成到能够运行的状态了。