本文主要是介绍集群 day-44 (集群介绍, 18.2 keepalived介绍, 18.3/18.4/18.5 用keepalived配置高可用集群 ),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
18.1 集群介绍
18.2 keepalived介绍
18.3 用keepalived配置高可用集群(上)
清空配置文件,粘贴模板
global_defs {notification_email {aming@aminglinux.com}notification_email_from root@aminglinux.comsmtp_server 127.0.0.1smtp_connect_timeout 30router_id LVS_DEVEL
}vrrp_script chk_nginx {script "/usr/local/sbin/check_ng.sh"interval 3
}vrrp_instance VI_1 {state MASTERinterface ens33virtual_router_id 51priority 100advert_int 1authentication {auth_type PASSauth_pass aminglinux>com}virtual_ipaddress {192.168.188.100}track_script {chk_nginx}}
#!/bin/bash
#时间变量,用于记录日志
d=`date --date today +%Y%m%d_%H:%M:%S`
#计算nginx进程数量
n=`ps -C nginx --no-heading|wc -l`
#如果进程为0,则启动nginx,并且再次检测nginx进程数量,
#如果还为0,说明nginx无法启动,此时需要关闭keepalived
if [ $n -eq "0" ]; then/etc/init.d/nginx startn2=`ps -C nginx --no-heading|wc -l`if [ $n2 -eq "0" ]; thenecho "$d nginx down,keepalived will stop" >> /var/log/check_ng.logsystemctl stop keepalivedfi
fi
18.4 用keepalived配置高可用集群(中)
主和备 都 要把防火墙关闭
从的设备
global_defs {notification_email {aming@aminglinux.com}notification_email_from root@aminglinux.comsmtp_server 127.0.0.1smtp_connect_timeout 30router_id LVS_DEVEL
}vrrp_script chk_nginx {script "/usr/local/sbin/check_ng.sh"interval 3
}vrrp_instance VI_1 {state BACKUPinterface ens33virtual_router_id 51priority 90advert_int 1authentication {auth_type PASSauth_pass aminglinux>com}virtual_ipaddress {192.168.188.100}track_script {chk_nginx}}
#时间变量,用于记录日志
d=`date --date today +%Y%m%d_%H:%M:%S`
#计算nginx进程数量
n=`ps -C nginx --no-heading|wc -l`
#如果进程为0,则启动nginx,并且再次检测nginx进程数量,
#如果还为0,说明nginx无法启动,此时需要关闭keepalived
if [ $n -eq "0" ]; thensystemctl start nginxn2=`ps -C nginx --no-heading|wc -l`if [ $n2 -eq "0" ]; thenecho "$d nginx down,keepalived will stop" >> /var/log/check_ng.logsystemctl stop keepalivedfi
fi
默认页配置文件
默认页配置文件
18.5 用keepalived配置高可用集群(下)
模拟测试
如果有多台backup 服务器角色时,把权重设置不同级别
vi /etc/keepalived/keepalived.conf
这篇关于集群 day-44 (集群介绍, 18.2 keepalived介绍, 18.3/18.4/18.5 用keepalived配置高可用集群 )的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!