标签:res gre oba 记录 ddr 用户 影响 版本 bin
18.1 集群介绍Linux集群概述
用keepalived配置高可用
#目录路径
[root@taoyuan ~]# ls /etc/keepalived/keepalived.conf
/etc/keepalived/keepalived.conf
[root@taoyuan ~]# > !$
> /etc/keepalived/keepalived.conf
[root@taoyuan ~]# vim /etc/keepalived/keepalived.conf
#内容如下
global_defs {
notification_email {
pingbuqingyun@taoyuan.com
}
#出现问题时发送邮件
notification_email_from root@taoyuan.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
#上述自定义参数
vrrp_script chk_nginx {
script "/usr/local/sbin/check_ng.sh"
interval 3
}
#检测脚本,检测时间3s一次
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass taoyuan>com
}
virtual_ipaddress {
192.168.0.100
}
#定义VIP,也就是公有ip
track_script {
chk_nginx
}
#加载chk_nginx
}
#路径
[root@taoyuan ~]# vim /usr/local/sbin/check_ng.sh
#路径名字自定义
#内容如下
#!/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 start
n2=`ps -C nginx --no-heading|wc -l`
if [ $n2 -eq "0" ]; then
echo "$d nginx down,keepalived will stop" >> /var/log/check_ng.log
systemctl stop keepalived
fi
fi
[root@taoyuan ~]# chmod 755 /usr/local/sbin/check_ng.sh
[root@taoyuan ~]# systemctl start keepalived
[root@taoyuan ~]# ps aux |grep keep
root 2084 0.0 0.0 120740 1404 ? Ss 10:01 0:00 /usr/sbin/keepalived -D
root 2085 0.0 0.1 122812 3108 ? S 10:01 0:00 /usr/sbin/keepalived -D
root 2086 0.0 0.1 127244 2940 ? S 10:01 0:00 /usr/sbin/keepalived -D
root 2213 0.0 0.0 112676 980 pts/0 R+ 10:02 0:00 grep --color=auto keep
* 日志
[root@taoyuan ~]# less /var/log/messages
* 132上编辑配置文件
* 132上编辑监控脚本
#内容
#时间变量,用于记录日志
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
systemctl start nginx
n2=ps -C nginx --no-heading|wc -l
if [ $n2 -eq "0" ]; then
echo "$d nginx down,keepalived will stop" >> /var/log/check_ng.log
systemctl stop keepalived
fi
fi
* 给脚本755权限
* 132上也启动服务 systemctl start keepalived
**测试高可用**
* 先确定好两台机器上nginx差异,比如可以通过curl -I 来查看nginx版本
* 测试1:关闭master上的nginx服务
* 测试2:在master上增加iptabls规则
* iptables -I OUTPUT -P vrrp -j DROP
* 测试3:关闭master上keepalived服务
* 测试4:启动master上的keepalived服务
集群介绍、keepalived介绍、用keepalived配置高可用集群
标签:res gre oba 记录 ddr 用户 影响 版本 bin
原文地址:http://blog.51cto.com/3622288/2065715