centos7中keepalived原理及高可用(HA)详解
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7中keepalived原理及高可用(HA)详解相关的知识,希望对你有一定的参考价值。
keepadlived原理:keepadlive是通过路由器的VRRP协议实现来实现服务器的高可用防止单点故障发生的技术。
VRRP协议简介:VRRP是一种容错协议,它保证当主机的下一跳坏掉时,可以及时由另一台路由器来代替,从而保持通讯的连续性和可靠性。为了使vrrp能正常工作,要在路由器上配置虚拟路由器号和路由器的虚拟ip地址,同时产生一个虚拟MAC地址,这样在网络这就加入了一个虚拟路由器。一个主路由器和若干个备份路由器组成一个虚拟路由器,当主路由器发生故障时,一个备份路由器成为主路由器,接替他工作。
keepalived配置:①需要两台centos7操作系统(keepalived1、keepalived2)。
②修改主机名:分别编辑2台主机 #vi /etc/hostname加入keepalived1;vi /etc/hostname加入keepalived2
③在/etc/hosts中用IP地址解析主机名:分别编辑两台主机 #vi /etc/hosts在后面加入
192.168.1.1 keepalived1
192.168.1.2 keepalived2 实现两台主机名能相互ping通。
③同步时间:#date; ssh keepalived2 ‘adte‘
④关闭防火墙及selinux:#systemctl disable firewalld #systemctl stop firewalld #setenfore 0(临时关闭selinux) #vi /etc/selinux/config 把SELINUX=enforcing改为SELINUX=disabled
⑤下载keepalived软件:#yum install -y keepalived #rpm -qa | grep keepalived
⑥生产一个随机字符串:#penssl rang -hex 4 用于代替/etc/keepalive/keepalived.conf中auth_pass 1111的“1111”数字。
⑦编辑keepalived.conf配置文件:#cd /etc/keepalived #cp keepalived.conf{,.bak} #vim keepalived.conf
注释掉virtual_server 192.168.200.100 443 这一行及以下的内容,在vim中输入命令 shift:.,$s/^/#/g
把global_defs {
notification_email {
}
改为:
global_defs {
notification_email {
}
把
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
改为:
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_mcast_group4 224.0.0.183
}
把
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
改为:
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass cd7fd940
其中cd7fd940为生产的随机数
把
virtual_ipaddress {
192.168.200.16
192.168.200.17
192.168.200.18
}
改为:
virtual_ipaddress {
192.168.1.100/24
}
其中192.168.1.100为请求服务是的虚拟IP
⑧配置keepalived2,在keepalived2服务器中下载keepalived软件:#yum install -y keepalived
在keepalived1中把keepalived.conf复制到keepalived2中,#scp keepalived.conf 192.168.1.2:/etc/keepalived/
⑨修改keepalived2中keepalived.conf的优先级,#vi /etc/keepalived/keepalived.conf把priority 100 给为priority 99
⑩分别重启2台服务器的keepalived服务:#systemctl restart keepalived 查看日志
#cat /var/log/messeges查看keepalived的状态 #systemctl stop keepalived 再到另一台服务器查看日志并执行#ip addr list查看是否有虚拟IP 192.168.1.100
keepalived加强
需求:实现多台服务器协同工作
方法:分别在多台主机的keepalived.conf加入不同的虚拟IP,当其中一台出现故障之后,其他台服务器分担相应的工作。
本文出自 “12116247” 博客,请务必保留此出处http://12126247.blog.51cto.com/12116247/1914812
以上是关于centos7中keepalived原理及高可用(HA)详解的主要内容,如果未能解决你的问题,请参考以下文章
keepalived双机热备原理及实例部署LVS+keepalived