文章目录
- 1. server高可用-默认HA
- 2. 访问高可用
1. server高可用-默认HA
1.部署zabbix单节点后,配置添加HANodeName和NodeAddress即为HA架构
2.zabbix1故障后切换zabbix2使用
3.浏览器访问主机1,使用主机1php前端连接mysql后zabbix2提供后台服务
---------------------------------------------------------
HA 集群状态:
active 正常
standby 待机
unavailable 不可用
stopped 停用
# 查看HA状态
zabbix_server -R ha_status
# 切换细节
主节点和备节点每5秒更新一次上次访问时间。每个备节点监控主节点的最后一次访问时间。
如果主节点的最后一次访问时间超过了“故障转移延迟”秒,备用节点将自己切换为主节点,
并将“unavailable”状态分配给先前的主节点。
# 修改切换时间(10s-15min)
zabbix_server -R ha_set_failover_delay=5m
命令查看HA状态:
单节点配置HA:
两节点完成HA配置:
切换,手动停1节点:
切换,手动停1节点,2节点日志显示standby切换为active:
2. 访问高可用
php:
# cp /etc/opt/remi/php74/php-fpm.d/www.conf \
/etc/opt/remi/php74/php-fpm.d/www.conf.bk
# sed -i 's/user = apache/user = nginx/' \
/etc/opt/remi/php74/php-fpm.d/www.conf
# sed -i 's/group = apache/group = nginx/' \
/etc/opt/remi/php74/php-fpm.d/www.conf
# cat /etc/opt/remi/php74/php-fpm.d/www.conf|grep nginx|grep -v "^;"
# sed -i 's/127\.0\.0\.1:9000/192\.168\.20\.61:9000/' \
/etc/opt/remi/php74/php-fpm.d/www.conf
# sed -i 's/127\.0\.0\.1/192\.168\.20\.61,192\.168\.20\.62/' \
/etc/opt/remi/php74/php-fpm.d/www.conf
# cat /etc/opt/remi/php74/php-fpm.d/www.conf|grep listen|grep -v "^;"
# systemctl restart php74-php-fpm
# systemctl status php74-php-fpm
nginx:
upstream PHP74_WEB {
server 192.168.20.61:9000 max_fails=1 fail_timeout=10s;
server 192.168.20.62:9000 max_fails=1 fail_timeout=10s;
}
server {
listen 80;
server_name 192.168.20.62;
location / {
root /data/zabbix/php;
try_files $uri $uri/ /index.php?query_string;
index index.php index.html index.htm;
}
location ~ .php$ {
root /data/zabbix/php;
fastcgi_pass PHP74_WEB;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
systemctl restart nginx
keepalive:
1)安装
yum install keepalived -y
2)配置
cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bk
/etc/keepalived/keepalived.conf
global_defs {
router_id LVS_DEVEL
}
vrrp_script chk_http_port {
script "/root/check_kp.sh"
interval 2
weight -20
}
vrrp_instance VI_1 {
state BACKUP # 两台都是BACKUP
interface enp4s0 # 注意修改网卡信息
virtual_router_id 49 # 同一网络环境下该值不要设置一样(同一套kp一致)
priority 95 # 两台权重不一致,一台要高
mcast_src_ip 192.168.xx.xx # 修改服务ip地址
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_http_port
}
virtual_ipaddress {
192.168.30.141 # 虚拟IP地址
}
}
3)检测脚本
/root/check_kp.sh # 给执行权限[不能和kp配置文件放一起,亲测无效]
#!/bin/bash
nginx_master=$(ps -ef | grep -v grep | grep nginx| grep master)
if [ -n "$nginx_master" ];then
exit 0
else
exit 1
fi
systemctl daemon-reload
systemctl start keepalived
systemctl enable keepalived
浏览器访问虚拟IP地址