Zabbix高可用实验模板(附拓扑)
2022年6月18日

Master的配置:
[root@www abc]# wget http://mirror.webtatic.com/yum/el7/epel-release.rpm  //下载epel-release
[root@www abc]# wget http://mirror.webtatic.com/yum/el7/webtatic-release.rpm //下载webtatic-release
[root@www abc]# rpm -ivh epel-release.rpm webtatic-release.rpm //安装
[root@www abc]# yum install mod_php72w php72w-cli.x86_64 php72w-common.x86_64 php72w-gd.x86_64 php72w-mbstring.x86_64 php72w-mysqlnd.x86_64 php72w-pdo.x86_64 php72w-fpm.x86_64 php72w-bcmath php72w-xmlwriter php72w-xmlreader php72w-ldap -y //安装php
[root@www mointer]# wget https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm//下载zabbix
[root@www mointer]# rpm -ivh zabbix-release-5.0-1.el7.noarch.rpm //安装

[root@www yum.repos.d]# yum install zabbix-server-mysql-5.0.19 zabbix-agent zabbix-web -y //安装zabbix相关
[root@localhost ~]# cp -r /usr/share/zabbix/* /var/www/html/

替换php配置
[root@localhost ~]sed -i ‘s#^post_max_size = 8M#post_max_size = 16M#g’ /etc/php.ini
[root@localhost ~]sed -i ‘s#^max_execution_time = 30#max_execution_time = 300#g’ /etc/php.ini
[root@localhost ~]sed -i ‘s#^max_input_time = 60#max_input_time = 300#g’ /etc/php.ini
[root@localhost ~]sed -i ‘883a date.timezone = Asia/shanghai’ /etc/php.ini
开机自启相关应用
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# systemctl enable zabbix-server
[root@localhost ~]# systemctl enable zabbix-agent2
安装zabbix-server/修改配置文件中的db密码。
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
DBHost=10.12.0.233
DBPassword=pass123
[root@localhost ~]# yum install keepalived sshpass -y
万事俱备,克隆服务器当slaved。
[root@localhost ~]# cd /etc/keepalived/
[root@localhost keepalived]# mv keepalived.conf keepalived.conf.bk
[root@localhost keepalived]# vim keepalived.conf
[root@localhost keepalived]# cat keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL 29
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 111
}
virtual_ipaddress {
10.12.0.235
}
notify_master /opt/to_master.sh
}
[root@localhost keepalived]# cat /opt/to_master.sh
#!/bin/bash
sshpass -p root ssh -o StrictHostKeyChecking=no root@10.12.0.232 “systemctl stop zabbix-server”
systemctl restart zabbix-server
[root@localhost keepalived]# chmod +x /opt/to_master.sh

Slaved配置:
[root@localhost ~]#  cd /etc/keepalived/
[root@localhost keepalived]# mv keepalived.conf keepalived.conf.bk
[root@localhost keepalived]# vim keepalived.conf
[root@localhost keepalived]# cat keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL 31
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 111
}
virtual_ipaddress {
10.12.0.235
}
notify_master /opt/to_master.sh
}
~
~                                 
[root@localhost keepalived]# cat /opt/to_master.sh
#!/bin/bash
sshpass -p root ssh -o StrictHostKeyChecking=no root@10.12.0.231 “systemctl stop zabbix-server”
systemctl restart zabbix-server
[root@localhost keepalived]# chmod +x /opt/to_master.sh
启动keeplived 并观察vip是否飘

database的配置:
[root@localhost ~]# wget https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm –no-check-certificate
[root@localhost ~]# rpm -ivh zabbix-release-5.0-1.el7.noarch.rpm
[root@localhost ~]# rpm -ivh zabbix-release-5.0-1.el7.noarch.rpm
[root@www yum.repos.d]# mysql -uroot -p  //登录数据库,并配置数据库
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all on Zabbix.* to Zabbix@’10.12.0.%’ identified by ‘pass123’;
[root@www yum.repos.d]# zcat /usr/share/doc/zabbix-server-mysql-5.0.6/create.sql.gz | mysql -uzabbix -p’pass123′ zabbix //导入初始架构和数据,系统将提示您输入新创建的密码。
记得去master验证下是否可以远程访问