zabbix高可用架构(三十二)
zabbix高可用
1.zabbix高可用方案
高可用最常用的方案就是服务+keepalived,但是zabbix-server不能再两台机器上同时启动,因为配置了高可用后,我们对外提供的访问地址一定是keepalive的vip地址,vip只会把请求转发到master节点,但是slave节点上的zabbix-server会因为长期收不到监控信息,从而乱报警
因此我们最终的思路就是写一个脚本,分布运行在master和slave上,谁是master谁就启动zabbix-server,否则就关闭zabbix-server
2.环境规划
ip地址 | 主机名 | 服务 |
---|---|---|
192.168.81.210 | zabbix-server | zabbix-server+keepalive+agent+mysql |
192.168.81.70 | zabbix-server | zabbix-server+keepalive+agent |
192.168.81.245 | zabbix-agent | zabbix-agent |
3.部署zabbix-server
3.1.zabbix-server配置
1.获取zabbix4.0镜像源
[root@zabbix-server ~]# wget http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
2.安装镜像源
[root@zabbix-server ~]# rpm -ivh zabbix-release-4.0-1.el7.noarch.rpm
安装完成后/etc/yum.repos.d/会多出来镜像文件
[root@zabbix-server ~]# ls /etc/yum.repos.d/
zabbix.repo
3.修改镜像文件base地址为清华园
[root@zabbix-server ~]# vim /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://mirror.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
4.开启yum缓存方便以后复用
[root@zabbix-server ~]# vim /etc/yum.conf
keepcache=1
5.安装zabbix4.0软件
[root@zabbix-server ~]# yum -y install zabbix-server-mysql zabbix-web-mysql --downloaddir=/root
6.修改zabbix server配置文件
[root@zabbix-server ~]# vim /etc/zabbix/zabbix_server.conf
DBHost=192.168.81.210
DBName=zabbix
DBUser=zabbix
DBPassword=123456
7.启动zabbix-server
[root@zabbix-server ~]# systemctl start zabbix-server.service
[root@zabbix-server ~]# systemctl enable zabbix-server.service
8.设置时区
[root@zabbix-server ~]# vim /etc/httpd/conf.d/zabbix.conf
<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 max_input_vars 10000
php_value always_populate_raw_post_data -1
php_value date.timezone Asia/Shanghai
</IfModule>
2.重启httpd
[root@zabbix-server ~]# systemctl start httpd
[root@zabbix-server ~]# systemctl enable httpd
3.2.zabbix-server2配置
1.获取zabbix4.0镜像源
[root@zabbix-server2 ~]# wget http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
2.安装镜像源
[root@zabbix-server2 ~]# rpm -ivh zabbix-release-4.0-1.el7.noarch.rpm
安装完成后/etc/yum.repos.d/会多出来镜像文件
[root@zabbix-server2 ~]# ls /etc/yum.repos.d/
zabbix.repo
3.修改镜像文件base地址为清华园
[root@zabbix-server2 ~]# vim /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://mirror.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
4.开启yum缓存方便以后复用
[root@zabbix-server2 ~]# vim /etc/yum.conf
keepcache=1
5.安装zabbix4.0软件
[root@zabbix-server2 ~]# yum -y install zabbix-server-mysql zabbix-web-mysql --downloaddir=/root
6.修改zabbix server配置文件
[root@zabbix-server2 ~]# vim /etc/zabbix/zabbix_server.conf
DBHost=192.168.81.210
DBName=zabbix
DBUser=zabbix
DBPassword=123456
7.启动zabbix-server
[root@zabbix-server2 ~]# systemctl start zabbix-server.service
[root@zabbix-server2 ~]# systemctl enable zabbix-server.service
8.设置时区
[root@zabbix-server2 ~]# vim /etc/httpd/conf.d/zabbix.conf
<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 max_input_vars 10000
php_value always_populate_raw_post_data -1
php_value date.timezone Asia/Shanghai
</IfModule>
9.重启httpd
[root@zabbix-server2 ~]# systemctl start httpd
[root@zabbix-server2 ~]# systemctl enable httpd
3.3.数据库配置
1.安装mysql
[root@zabbix-server ~]# yum -y install mariadb-server
2.启动数据库
[root@zabbix-server ~]# systemctl start mariadb.service
[root@zabbix-server ~]# systemctl enable mariadb.service
3.mysql安全配置,回车、n、一路y
[root@zabbix-server ~]# mysql_secure_installation
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Set root password? [Y/n] n
... skipping.
Remove anonymous users? [Y/n] y
... Success!
Disallow root login remotely? [Y/n] y
... Success!
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] y
... Success!
4.创建数据库并授权
[root@zabbix-server ~]# mysql
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@'%' identified by '123456';
授权root用户远程登录并使用Navicat去查看数据库
MariaDB [(none)]> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
5.导入zabbix SQL
[root@zabbix-server ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.24/create.sql.gz | mysql -uroot -p123456 zabbix
扩展:zcat可以看到压缩包中的文件内容,但是必须压缩包中只有一个文件
3.4.页面安装zabbix
两台zabbix都操作
访问:https://192.168.81.70/zabbix/setup.php
检查环境
数据库选择192.168.81.210
默认即可
3.5.登陆zabbix
由于192.168.81.210上的zabbix是一开始部署的因此上面的数据会和210一致
4.部署高可用
4.1.安装配置keepalived
将两台都配成BACKUP,优先级不同,让其自动选举
keepalive01配置
1.安装
[root@zabbix-server ~]# yum -y install keepalived
2.配置keepalived
[root@zabbix-server ~]# vim /etc/keepalived/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 1111
}
virtual_ipaddress {
192.168.81.222
}
notify_master /opt/to_master.sh
}
3.启动keepalived
[root@zabbix-server ~]# systemctl start keepalived
[root@zabbix-server ~]# systemctl enable keepalived
keepalive02配置
1.安装
[root@zabbix-server2 ~]# yum -y install keepalived
2.配置keepalived
[root@zabbix-server2 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL 30
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.81.222
}
notify_master /opt/to_master.sh
}
3.启动keepalived
[root@zabbix-server2 ~]# systemctl start keepalived
[root@zabbix-server2 ~]# systemctl enable keepalived
4.2.查看keepalived vip地址
由于192.168.81.210上的优先级比较高,因此vip在192.168.81.210上
[root@zabbix-server ~]# ip addr | grep ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 192.168.81.210/24 brd 192.168.81.255 scope global ens33
inet 192.168.81.222/32 scope global ens33
4.3.编写keepalived主备切换关闭zabbix-server的脚本
我们可以使用sshpass命令指定密码去关掉已经挂掉的主机的zabbix-server服务
192.168.81.210脚本内容
[root@zabbix-server ~]# vim /opt/to_master.sh
#!/bin/bash
sshpass -p redhat ssh -o StrictHostKeyChecking=no root@192.168.81.70 "systemctl stop zabbix-server"
systemctl restart zabbix-server
[root@zabbix-server ~]# chmod a+x /opt/to_master.sh
192.168.81.70脚本内容
[root@zabbix-server2 ~]# vim /opt/to_master.sh
#!/bin/bash
sshpass -p redhat ssh -o StrictHostKeyChecking=no root@192.168.81.210 "systemctl stop zabbix-server"
systemctl restart zabbix-server
[root@zabbix-serve2 ~]# chmod a+x /opt/to_master.sh
4.4.模拟192.168.81.210主服务挂掉
将192.168.81.210keepalived停掉,严重vip是否漂移且zabbix-server会不会停掉
192.168.81.210操作
[root@zabbix-server ~]# systemctl stop keepalived
192.168.81.70查看是否获得vim
已经获得vip
[root@zabbix-server2 ~]# ip addr |grep ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 192.168.81.70/24 brd 192.168.81.255 scope global ens33
inet 192.168.81.222/32 scope global ens33
192.168.81.210查看是否关掉zabbix-server服务
[root@zabbix-server ~]# netstat -lnpt | grep zabbix-server
5.添加zabbix监控主机
5.1.zabbix-server设置出口ip
因为我们做的是高可用,一个网卡有多个ip,因此我们要指定vip为出口ip,否则无法向zabbix-agent发送数据
两台zabbix-server都需要配置,配置完重启zabbix-server
[root@zabbix-server ~]# vim /etc/zabbix/zabbix_server.conf
SourceIP=192.168.81.222
[root@zabbix-server2 ~]# vim /etc/zabbix/zabbix_server.conf
SourceIP=192.168.81.222
5.2.安装配置agent
在客户端安装zabbix-agent
[root@192_168_81_245 ~]# yum -y instakk zabbix-agent
[root@192_168_81_245 ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.81.222
ServerActive=192.168.81.222
[root@192_168_81_245 ~]# systemctl restart zabbix-agent
5.3.添加监控主机
访问:http://192.168.81.222/zabbix
添加主机
链接模板
添加成功
文章来源: jiangxl.blog.csdn.net,作者:Jiangxl~,版权归原作者所有,如需转载,请联系作者。
原文链接:jiangxl.blog.csdn.net/article/details/116163213
- 点赞
- 收藏
- 关注作者
评论(0)