keepalived实现zabbix高可用

1. 环境规划

image.png

2. 初始环境准备

2.1 初始环境图示

image.png

2.2 初始环境搭建

zabbix-web01:


#安装数据库(10.0.0.8)
 yum install mariadb-server.x86_64 -y
 systemctl start mariadb.service
 systemctl enable mariadb.service
 
#建议执行下  mysql_secure_installation

#为zabbix创库授权
MariaDB [(none)]>  create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on zabbix.* to zabbix@'10.0.0.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit

#zabbix-agnet安装
yum install zabbix-agent -y

zabbix-server01

# 1. 安装php 第三方源
yum install epel-release.noarch -y
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# 2. 安装 nginx、php7.2 和所需 php 扩展模块
yum install nginx  php72w-cli php72w-fpm php72w-common php72w-mysqlnd php72w-mbstring  php72w-gd php72w-bcmath php72w-ldap php72w-xml -y​
# 3. 修改php-fpm的配置(修改运行用户和组 修改为nginx)
vim  /etc/php-fpm.d/www.conf
# 4. 修改nginx的配置(来自于 /etc/nginx/nginx.conf.default)
vim  /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;
    root   /html;
    location / {
        index  index.php index.html index.htm;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME  /html$fastcgi_script_name;
        include        fastcgi_params;
        }

# 5. 启动nginx和php-fpm
systemctl start php-fpm
systemctl enable php-fpm
systemctl start nginx
systemctl enable nginx
# 6. 安装 zabbix-web
cd /opt/
#下载源码包
wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.5.tar.gz
tar xf zabbix-5.0.4.tar.gz
mkdir /html
#拷贝zabbix-web到站点目录
cp -a zabbix-5.0.5/ui/* /html
#修改站点目录属主和属组
chown -R nginx:nginx /html
# 7.  浏览器访问10.0.0.71
#解决web页面500 ERROR
mkdir /var/lib/php/session
chown -R nginx:nginx /var/lib/php/session​
#修改php配置消除警告
vim /etc/php.ini
post_max_size = 8M
修改为
post_max_size = 16M
​
max_execution_time = 30
修改为
max_execution_time = 300
​
max_input_time = 60
修改为
max_input_time = 300
​
;date.timezone =
去掉注释,并修改为
date.timezone = Asia/Shanghai
​
#重启php-fpm,并刷新浏览器
systemctl restart php-fpm.service
​
# 8. 安装 zabbix-server
rpm -ivh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum install zabbix-server-mysql -y
#导入zabbix初始数据文件
scp -rp /usr/share/doc/zabbix-server-mysql-*/create.sql.gz root10.0.0.8:~
# 10.0.0.8上导入表结构
[root@zabbix-agnet ~]# zcat create.sql.gz |mysql -uzabbix -p123456 zabbix
#修改zabbix-server配置
vim /etc/zabbix/zabbix_server.conf
#配置下数据库的连接信息
DBHost=10.0.0.8
DBName=zabbix
DBUser=zabbix
DBPassword=123456
#启动 zabbix-server
systemctl start zabbix-server.service
systemctl enable zabbix-server.service
#打开浏览器,继续安装

准备一台zabbix-server02 与zabbixserver01环境一致

# 由zabbix-server71克隆而来的72
# 10.0.0.72
systemctl stop zabbix-server.service 
systemctl stop nginx
systemctl stop php-fpm
systemctl stop mariadb

安装keepalived

#zabbix-server01\zabbix-server02

yum install keepalived -y 

#zabbix-server01
cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
    router_id LVS_DEVEL 71
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.70
    }
    notify_master /opt/to_master.sh   # 如果切换为master就执行该脚本
}

vi /opt/to_master.sh
i#!/bin/bash
ssh -o StrictHostKeyChecking=no root@10.0.0.72 "systemctl stop zabbix-server.service"
systemctl start zabbix-server.service

# zabbix-server02
cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
    router_id LVS_DEVEL 72
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.70
    }
    notify_master /opt/to_master.sh
}

vi /opt/to_master.sh
i#!/bin/bash
ssh -o StrictHostKeyChecking=no root@10.0.0.71 "systemctl stop zabbix-server.service"
systemctl start zabbix-server.service



# 然后配置zabbix-agnet
Server=10.0.0.70
ServerActive=10.0.0.70

# 配置zabbix-server用虚拟地址10.0.0.70来取值 否则就用自己的ip取值了 zabbix-agent不会给的
SourceIP=10.0.0.70
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。