Rockylinux9或Centos8安装zabbix6.0

野蔷薇的呼吸 / 2023-07-11 / 原文

zabbix6.0服务端不再支持Centos7的yum安装,Centos8已停止维护,rockylinux是RHEL的下游免费发行版。
1.安装rockylinux9:阿里云下载地址

#关闭防火墙和 selinux 并重启
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
systemctl disable --now firewalld

#查看firewall服务状态
systemctl status firewalld

2.替换rockylinux9的交大源或者阿里源:

sed -e 's|^mirrorlist=|#mirrorlist=|g' \
    -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.sjtug.sjtu.edu.cn/rocky|g' \
    -i.bak \
    /etc/yum.repos.d/[Rr]ocky*.repo
dnf makecache

sed -e 's|^mirrorlist=|#mirrorlist=|g' \
    -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
    -i.bak \
    /etc/yum.repos.d/[Rr]ocky*.repo
dnf makecache

3.按照zabbix官方文档安装6.0:
a. Install Zabbix repository,Proceed with installing zabbix repository.

# rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/9/x86_64/zabbix-release-6.4-1.el9.noarch.rpm
# dnf clean all

b. 安装Zabbix server,Web前端,agent

# dnf install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent

c. 创建初始数据库
Make sure you have database server up and running.
本文以Mysql为例

#安装数据库,启动数据库,并开机自启
yum install mariadb-server -y
systemctl enable --now mariadb
#初始化 mariadb 并配置 root 密码
mysql_secure_installation 

#直接回车,空
是否设置密码:y
输入设置密码:
再次输入密码:
是否移除anonymous用户:y
是否不允许root远程登录:n
是否移除test数据库:y
是否更新:y

在数据库主机上运行以下代码。(mysql 用户名 zabbix,密码23#替换password并牢记)

# mysql -uroot -p
password
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> set global log_bin_trust_function_creators = 1;
mysql> quit;

导入初始架构和数据,系统将提示您输入新创建的密码。

# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix

Disable log_bin_trust_function_creators option after importing database schema.

# mysql -uroot -p
password
mysql> set global log_bin_trust_function_creators = 0;

d. 为Zabbix server配置数据库(前文的password)
编辑配置文件 /etc/zabbix/zabbix_server.conf

DBPassword=password

e. 启动Zabbix server和agent进程
启动Zabbix server和agent进程,并为它们设置开机自启:

# systemctl restart zabbix-server zabbix-agent httpd php-fpm
# systemctl enable zabbix-server zabbix-agent httpd php-fpm

f. Open Zabbix UI web page
The default URL for Zabbix UI when using Apache web server is http://host/zabbix
配置页面中文语言灰色:

yum install langpacks-zh_CN.noarch

安装完成后刷新即可选择中文。

4.配置后登录:zabbix默认账户Admin密码zabbix

一些小问题:
a.图形界面中文乱码
确认字体路径

#cat /usr/share/zabbix/include/defines.inc.php |grep ZBX_FONTPATH
define('ZBX_FONTPATH',				realpath('assets/fonts')); // where to search for font (GD > 2.0.18)

进入对应目录,该文件为软链接,指向/etc/alternatives/zabbix-web-font

#cd /usr/share/zabbix/assets/fonts
# ll
total 0
lrwxrwxrwx. 1 root root 33 Jul 10 23:45 graphfont.ttf -> /etc/alternatives/zabbix-web-font

zabbix-web-font也是软链接,指向字体文件/usr/share/fonts/dejavu-sans-fonts/DejaVuSans.ttf

 cd /etc/alternatives
# ll
total 0
lrwxrwxrwx. 1 root root 49 Jul 10 23:45 zabbix-web-font -> /usr/share/fonts/dejavu-sans-fonts/DejaVuSans.ttf

进入真正的字体文件目录/usr/share/fonts/dejavu-sans-fonts/、上传C:\Windows\Fonts中的simkai.ttf,备份、替换。

#cd /usr/share/fonts/dejavu-sans-fonts
#mv DejaVuSans.ttf DejaVuSans.ttf.bak
#mv simkai.ttf DejaVuSans.ttf

替换后刷新页面即可。