测试环境准备
# 准备3台服务器,安装rocky 9 系统
[root@zbx-ha-db ~]# cat /etc/os-release
NAME="Rocky Linux"
VERSION="9.4 (Blue Onyx)"
# 服务器名称和IP地址规划
zbx-ha1 (10.180.10.241)
zbx-ha2 (10.180.10.242)
zbx-ha-db (10.180.10.243)
virtual IP (VIP) (10.180.10.250)
# 测试环境在每台服务器上关闭防火墙,禁用selinux
systemctl disable firewalld
systemctl stop firewalld
vim /etc/selinux/config
SELINUX=disabled
shutdown -r now
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
建立数据库
# 指定需要安装的mariadb版本,dnf包管理工具默认安装的是11.40.02,启动zabbix会报错,MariaDB database version Must not be higher than (11.03.xx),需要去zabbix配置中setting AllowUnsupportedDBVersions=1,并且不保证没问题。
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | bash -s -- --mariadb-server-version="mariadb-10.6"
chmod +x mariadb_repo_setup
./mariadb_repo_setup --mariadb-server-version="mariadb-10.6"
dnf install mariadb-server mariadb-backup
systemctl enable mariadb
systemctl start mariadb
mariadb-secure-installation
第一个:Enter current password for root (enter for none):
要求输入正确的原root密码,因为我们是新装,没有密码,所以直接回车
第二个:Switch to unix_socket authentication [Y/n]
是否切换到unix_socket 权限验证,因为这个验证不需要密码不安全,所以输入n,回车
第三个:Change the root password? [Y/n]
是否修改root密码,参考其他文章说跟系统有联系所以不建议修改,输入n回车
第四个:Remove anonymous users? [Y/n]
删除匿名用户,y
第五个:Disallow root login remotely? [Y/n]
禁止root远程登录,y
第六个:Remove test database and access to it? [Y/n]
删除测试库,y
第7个:Reload privilege tables now? [Y/n]
刷新授权表,使设置立即生效,y
mariadb -u root -p
create database zabbix character set utf8mb4 collate utf8mb4_bin;
create user zabbix@'10.180.10.241' identified by '123456';
create user zabbix@'10.180.10.242' identified by '123456';
create user zabbix@'10.180.10.250' identified by '123456';
grant all privileges on zabbix.* to 'zabbix'@'10.180.10.241' identified by '123456';
grant all privileges on zabbix.* to 'zabbix'@'10.180.10.242' identified by '123456';
grant all privileges on zabbix.* to 'zabbix'@'10.180.10.250' identified by '123456';
set global log_bin_trust_function_creators = 1;
quit
# 当把 zabbix database schema 导入到新创建的zabbix数据库中后再次禁用log_bin_trust_function_creators
mysql -u root -p
set global log_bin_trust_function_creators = 0;
quit
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
安装zabbix服务器集群节点一
rpm -Uvh https://repo.zabbix.com/zabbix/7.0/rocky/9/x86_64/zabbix-release-7.0-4.el9.noarch.rpm
dnf clean all
dnf install zabbix-server-mysql zabbix-selinux-policy
# 启用zabbix HA
vim /etc/zabbix/zabbix_server.conf
DBHost=10.180.10.243
DBPassword=123456
HANodeName=zbx-ha1
NodeAddress=10.180.10.241
systemctl enable zabbix-server
systemctl start zabbix-server
# 把 zabbix database schema 导入到后端的zabbix数据库
dnf install zabbix-sql-scripts MariaDB-client
zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mariadb -h 10.180.10.243 --default-character-set=utf8mb4 -u zabbix -p zabbix
# 设置带有HA的nginx (为了确保前端也可以HA,将使用Keepalived设置它们)
dnf install -y keepalived
cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
vim /etc/keepalived/keepalived.conf
# 清除所有内容
:%d
# 添加如下内容
vrrp_track_process chk_nginx {
process nginx
weight 10
}
vrrp_instance ZBX_1 {
state MASTER
interface ens32
virtual_router_id 51
priority 244
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
track_process {
chk_nginx
}
virtual_ipaddress {
10.180.10.250/24
}
}
dnf install nginx zabbix-web-mysql zabbix-nginx-conf
vim /etc/nginx/conf.d/zabbix.conf
listen 80;
server_name 10.180.10.250;
systemctl enable nginx keepalived
systemctl start nginx keepalived
# 查看系统默认已有的语言包
localectl list-locales
# 查看当前生效的语言包
localectl
# 筛选出需要的中文语言包
dnf list |grep glibc-langpack|grep zh
# 安装中文语言包
dnf install glibc-langpack-zh.x86_64
# 修改当前生效语言包为中文zh_CN.UTF-8
localectl set-locale LANG="zh_CN.UTF-8"
# 重启zabbix server相关服务
systemctl restart zabbix-server nginx
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
安装zabbix服务器集群节点二
rpm -Uvh https://repo.zabbix.com/zabbix/7.0/rocky/9/x86_64/zabbix-release-7.0-4.el9.noarch.rpm
dnf clean all
dnf install zabbix-server-mysql zabbix-selinux-policy
vim /etc/zabbix/zabbix_server.conf
DBHost=10.180.10.243
DBPassword=123456
HANodeName=zbx-ha2
NodeAddress=10.180.10.242
systemctl enable zabbix-server
systemctl start zabbix-server
dnf install -y keepalived
cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
vim /etc/keepalived/keepalived.conf
# 清除所有内容
:%d
# 添加如下内容
vrrp_track_process chk_nginx {
process nginx
weight 10
}
vrrp_instance ZBX_1 {
state BACKUP
interface ens32
virtual_router_id 51
priority 243
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
track_process {
chk_nginx
}
virtual_ipaddress {
10.180.10.250/24
}
}
dnf install nginx zabbix-web-mysql zabbix-nginx-conf
vim /etc/nginx/conf.d/zabbix.conf
listen 80;
server_name 10.180.10.250;
systemctl enable nginx keepalived
systemctl start nginx keepalived
dnf install glibc-langpack-zh.x86_64
localectl set-locale LANG="zh_CN.UTF-8"
systemctl restart zabbix-server nginx
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
配置zabbix前端
导航到vip地址( http://10.180.10.250/)
对于第一个节点,将zabbix服务器名称设置为zbx-ha1,并选择时区,然后点击下一步和完成
完成后在第一个节点中执行以下操作
再次导航到vip地址( http://10.180.10.250/),填写相同的配置向导,将zabbix服务器名设置为zbx-ha2,完成向导后再次启用zbx-ha1的前端
登录zabbix管理控制台,查看带有HA信息的Zabbix服务器系统信息,默认凭据为 Username:Admin Password:zabbix
将语言改为中文
熟悉相关界面后我们将开始测试相关功能。