设为首页 收藏本站
查看: 1130|回复: 0

[经验分享] keepalived高可用集群配置

[复制链接]

尚未签到

发表于 2018-12-29 12:30:18 | 显示全部楼层 |阅读模式
[软件安装]
yum install -y keepalived
rpm -qa keepalived

LB01配置文件
[root@LB_01 ~]# cat /etc/keepalived/keepalived.conf
!Configuration file for keepalived
global_defs {
        notification_email {
        845330082@qq.ocm
        }
        notification_email_from Lufeng.
        lufeng@firewall.loc
        smtp_server 127.0.0.1
        smtp_connect_timeout 30
        router_id lb01
}
vrrp_script chk_nginx_proxy {
script "/home/lufeng/tools/chk_nginx_proxy.sh"
interval 2
weight 2
}

vrrp_instance VI_BBS {
        state MASTER
        interface eth0
        virtual_router_id 55
        priority 150
        advert_int 1
        authentication {
                auth_type PASS
                auth_pass 1111
        }
        virtual_ipaddress {
        192.1.1.45/24 dev eth0 label eth0:1
        }
        track_script {
        chk_nginx_proxy
        }
}
vrrp_instance VI_WWW {
        state BACKUP
        interface eth0
        virtual_router_id 56
        priority 100
        advert_int 1
        authentication {
                auth_type PASS
                auth_pass 1111
        }
        virtual_ipaddress {
        192.1.1.46/24 dev eth0 label eth0:2
        }
}

LB02配置文件
[root@LB_02 tools]# cat /etc/keepalived/keepalived.conf
!Configuration file for keepalived
global_defs {
        notification_email {
        845330082@qq.ocm
        }
        notification_email_from Lufeng.
        lufeng@firewall.loc
        smtp_server 127.0.0.1
        smtp_connect_timeout 30
        router_id lb02
}
vrrp_instance VI_BBS {
        state BACKUP
        interface eth0
        virtual_router_id 55
        priority 100
        advert_int 1
        authentication {
                auth_type PASS
                auth_pass 1111
        }
        virtual_ipaddress {
        192.1.1.45/24 dev eth0 label eth0:1
        }
}
vrrp_script chk_nginx_proxy {
script "/home/lufeng/tools/chk_nginx_proxy.sh"
interval 2
weight 2
}
vrrp_instance VI_WWW {
        state MASTER
        interface eth0
        virtual_router_id 56
        priority 150
        advert_int 1
        authentication {
                auth_type PASS
                auth_pass 1111
        }
        virtual_ipaddress {
        192.1.1.46/24 dev eth0 label eth0:2
        }
        track_script {
        chk_nginx_proxy
        }
}

检查nginx脚本:
[root@LB_02 tools]# cat /home/lufeng/tools/chk_nginx_proxy.sh
#!/bin/sh
if [ `netstat -lntup|grep nginx|wc -l` -ne  1 ];then
        /etc/init.d/keepalived stop
fi

记得加上执行权限:
[root@LB_02 tools]# chmod +x /home/lufeng/tools/chk_nginx_proxy.sh


补充VIP添加及查看方式:
设置网卡的ip别名
#ifconfig eth0:0 192.168.6.100 netmask 255.255.255.0 up
#ifconfig eth0:1 173.173.173.173 netmask 255.255.255.0 up
#ifconfig eth0:2 119.110.120.1 netmask 255.255.255.0 up
先进命令:
#ip addr add 192.168.0.118/24 dev eth0
查看
#ip add|grep 192.168.0
清除ip别名
#ifconfg eth0:0 down
#ifconfg eth0:1 down
#ifconfg eth0:2 down ......

将别名保存到配置文件:
方法1:
1.将增加ip别名的命令填写到/etc/rc.local文件中 即将所有如这样ifconfig eth0:0 192.168.6.100 netmask 255.255.255.0 up的命令一行行全部填写到rc.local文件中去,rc.local文件是作用于linux开机自动执行命令,详细用法g或b一下,这里不详细说明。 这个方法最方便,但不太可靠,有时会失灵。

方法2:
#vi ifcfg-eth0:0
创建eth0:0的配置文件,并将刚才复制的字段粘贴到这个配置文件,按照下文的介绍修改部分信息,修改完成后保存退出  以下是网卡配置文件的部分信息说明,其他类似信息默认即可:
##############################################################################  
# 3Com Corporation 3c905B 100BaseTX [Cyclone]??? //硬件型号,忽略不计
DEVICE=eth0:0???????????????? //虚拟网络接口,随意???????????????????????????????????? ONBOOT=yes??????????????????? //系统启动时激活
BOOTPROTO=static?? ??? ????? //使用静态ip地址????????????????
IPADDR=192.168.6.100????????? //该虚拟网络接口的ip别名,随意
NETMASK=255.255.255.0???????? //子网掩码,对应ip别名
GATEWAY=192.168.6.1?????????? //网关,对应ip别名
HWADDR=00:10:5A:5E:B1:E4????? //网卡MAC地址,无需更改???????????????????
USERCTL=no??????????????????? //是否给予非root用户设备管理权限  ##############################################################################

设置必要开机自启动:
[root@LB_02 tools]# echo "/application/nginx/sbin/nginx">>/etc/rc.local
[root@LB_02 tools]# echo "/etc/init.d/keepalived start">>/etc/rc.local   
[root@LB_02 tools]# cat /etc/rc.local                                   
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/application/nginx/sbin/nginx
/etc/init.d/keepalived start  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-657252-1-1.html 上篇帖子: LVS(DR)+keepalived+nfs+raid+LVM 下篇帖子: lvs(DR)+keepalived+mysql主从
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表