Use keepalived do High Available (HA)

 
 
------------------------------------------------ 20,190,818 records not necessarily comprehensive, yet special in-depth principle layer, but current understanding and certainly no big problem (error) ---------------------
 
keepalived can do:
 
. 1, High the Available (HA): i.e., high availability functions and services, high availability Keepalived on the way to the HA used herein, shall failover, assuming the presence of, IP1 number server, and the server number IP2, they were IP has two segments (which no doubt), but IP1 hang time, if the user is still time to access the IP1, IP2 dynamic service switch to the server? This is Keepalived things in HA did above, that is, failover;
 
a): keepalived practice: IP1 on a corresponding server, a corresponding keepalived deployment, and a corresponding virtual IP address; vrrp_instance instance blocks at corresponding /etc/keepalived/keepalived.conf under corresponding to the definition virtual_ipaddress, when the current virtual network adapter name and other IP to be bound to a range of information specified in the current IP1 service, the current IP1 virtual server is out of a new IP address, and set keepalived virtual IP;
 
At this point IP2 on the corresponding server, the same is to deploy a keepalived, and the above-described arrangement, the sync IP2 changes to the machine, except that, at this time need corresponding vrrp_instance example, indicate the current virtual keepalived IP instance, state = bACKUP, i.e. alternate IP services; and the need to ensure that all the services, IPl, Ye, IP2, IP3 or services worth mentioning, must ensure that, in the configuration example corresponding vrrp_instance, virtual_router_id must be the same, here It represents route_id route ID, and so this unique route ID (broadcasting heartbeat period using other services) on the LAN;
 
See here, I believed to have known about the keepalived doing things right; this time on the IP1 server, keepalived start: service keepalived start, at this time through the ip addr, to see to this point in the corresponding eth0 on the card, the inet more of a new virtual IP, and current virtual IP configured keepalived; then switch to, the service IP2, then start keepalived, and then by the ip addr view, you will find that the current IP2 on the server and does not generate a new virtual IP (if generated, then the profile configuration error; primary and standby nodes simultaneously contention virtual IP resources, this phenomenon is called "split-brain");
 
IP1 and IP2 of the server, keepalived started simultaneously, when the primary and standby nodes, the broadcast real-time communication, once the master node keepalived hang IP1, IP2 at this time the spare node can not receive a heartbeat message at this time the standby node IP2 program will call itself to take over take over IP resource master node; directly reflected in the service are: service request through the switch, it will all be mapped to a service engine IP2;
 
phenomenon:
After 1 on IP1 and IP2 server started keepalive, this time by ip addr command, can be observed on the IP1 specified card eht0, add a virtual IP address, and specify IP2 card at the end of the service, the no new and corresponding virtual IP, as follows:
 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link / ether 52: 54: 00: 7b: 43: 41 BRD ff: ff: ff: ff: ff: ff
    inet 172.17.0.5/20 brd 172.17.15.255 scope global eth0
       valid_lft forever preferred_lft forever
                                                192.168.200.16 is the keepalived configured in the virtual IP here, you can see the current virtual IP is mounted to the corresponding eth0 card,
    inet 192.168.200.16/32 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe7b:4341/64 scope link
       valid_lft forever preferred_lft forever
So when we are on the corresponding IP1 server, service keepalived stop, stop off keepalived service on the current IP1 corresponding server; this time to switch to the IP2 server, use the ip addr command, you can see that the current IP2 server eth0 on the card, auto-mount the current 192.168.200.16 virtual IP; then when we are on the IP1 service, re-service keepalived start, started keepalived service when the primary node is automatically snatch IP1 corresponding virtual IPVIP, IP2 server at a time, no longer includes the IP virtual VIP, again as a backup server is present;
 
keepalived为什么可以实现这个功能呢?这个。。好像就是因为它是基于网络的,3,4,7层来实现的交换机制软件,并且故障转移 是通过VRRP协议协议来进行的实现,所以,keepalived的虚拟IP又有一个别名叫做,VIP;
而至于,keepalived当前是如何基于3,4,7层网络而实现的交换机制以及VRRP协议的实现等,当前还暂未深究;
 
keepalived的安装方式:
1、wget下载对应的源码包,然后进行编译安装,(LZ自身在进行编译的时候,出现了 fatal error: linux/mpls_iptunnel.h: No such file or directory的异常;未解决,直接使用YUM进行了安装
源码包的编译方式,可参考如下链接: https://www.cnblogs.com/mikeguan/p/6506983.html
尽管最终没有使用源码包的方式进行安装,但推荐还是看一下上述的链接,可以更加清晰了解, /etc/keepalived/keepalived.conf 配置的来源,
2、使用yum直接安装:yum install keepalived
3、可以使用 sysctmctl enable keepalived 设置当前keepalived为自启动
4、常用的keepalived命令:
shell> chkconfig keepalived on
shell> service keepalived start #启动服务
shell> service keepalived stop #停止服务
shell> service keepalived restart #重启服务
 
可以使用journalctl 查看服务是否正常启动
journalctl -xe
 
#/etc/init.d/keepalived restart -- 启动 keepalived
 
#tail -fn 100 /var/log/messages -- 查看 keepalived 状态日志
 
 
 
 

Guess you like

Origin www.cnblogs.com/zh94/p/11923022.html