Lvs-dr:direct Routing, known as direct routing, is forwarded by modifying the MAC address of the request message; The source MAC address is the MAC address of the dip's interface, the MAC address of the target Mac when the front-end host picks out the rip of the back-end Rs. ; The IP address address will not change from the new package; for LVS-DR structure diagram
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/80/1F/wKioL1c5J7zi1oFtAABo5bCsOgM103.png "title=" 111. PNG "alt=" Wkiol1c5j7zi1oftaabo5bcsogm103.png "/>
1. When the client requests the resource, Route 1 sends the request message to the forward host, and Route 1 does not change the IP daemon of the request message when it is sent to the front-end host, but adds a layer of Mac daemon to the message.
2, the current end of the host received the request message, unpacking the original Mac Guardian; add another layer of Mac daemon to the backend host
3, when the back-end host network card eth1 received the request message, found that the local Lo network card has the message guard VIP address, and then sent the request to Lo
4, the LO receives the request, processes the request, constructs the response message, then adds a layer of IP guard after the constructed response message, forwards it to Route 2 via eth1, and then sends it to the client via Route 2.
Related features:
(1), the request message must pass the front-end host, the response message cannot pass through the front-end host
(2), each back-end host needs to modify the kernel parameters
(3), the front-end host and the back-end host must be in the same physical network, while the back-end host Gateway cannot point to the front-end host
The KEEPALIVED:VRRP protocol is the implementation of HA high-availability clusters, while keepalived is the implementation of the VRRP protocol.
Keepalived is a highly available clustering solution based on the VRRP protocol, which can be used to solve single point of failure problems, with a high availability cluster using keepalived, typically two servers, a master server (master), A standby server (BACKUP), the master server will periodically send special messages to the standby server, to prove that they are intact, the normal provision of services, when the standby server can not accept the message sent by the primary server, the standby server will take the primary server's IP directly to provide services
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/80/23/wKiom1c5MRWDz0CeAAA13aVZcLE191.png "title=" 111. PNG "alt=" Wkiom1c5mrwdz0ceaaa13avzcle191.png "/>
Experiment Preparation:
Virtual machine 1:172.18.42.100; as the master node
Virtual machine 2:172.18.42.200; as a standby node
Virtual machine 3:172.18.42.111; Web services as a Web Server 1
Virtual machine 4:172.18.42.222; Web services as a Web Server 2
lo:1:172.18.42.42; as the VIP of RS
First, install the Keepalived service on virtual machine 1, then edit its configuration file
[[email protected] ~]# yum install keepalived -y ## Yum installation keepalived[[email protected] ~]# vim /etc/keepalived/keepalived.conf ## To edit a configuration file! configuration file for keepalivedglobal_defs { # #定义全局配置段 notification_email { # #通知邮件发送给谁 [email protected] # #发送给本机 } notification_ email_from # #指明邮件发件人是谁 smtp_server 127.0.0.1 # #发件人地址 smtp_connect_timeout 30 # #发送邮件的超时时长 router_id wtc # #路由设备的标识号 vrrp_mcast_group4 244.0.42.20 # #vrrp协议通过ipv4来组播通知}vrrp_instance vi_1 { # #定义虚拟路由配置 state master # #指明当前节点此虚拟路由的初始状态 interface eth0 ## Indicates that the NIC interface is bound to implement multicast (interface for VRRP work bindings) virtual_router_id 110 # #虚拟路由ID号, Valid range 8-bit binary: 0-255 priority 100 # #指明当前虚拟路由的nice值 (priority) advert_int 1 # #vrrp通告的时间间隔; default is 1s authentication { # #认证机制 auth_type pass # #简单认证方式 auth_pass lm97gg51 # #密码 } virtual_ipaddress { ## Specify Virtual Ip 172.18.42.42 dev eth0 label eth0:1 # #使用网卡接口别名 }}virtual_server 172.18.42.42 80 { # #定义虚拟路由配置     DELAY_LOOP 6&Nbsp; # #指明服务轮询时间间隔 lb_algo rr ## Specify the scheduling method for load Balancing lb_kind dr # #指明集群的类型 protocol tcp # #指明服务协议 real_server 172.18.42.111 80 { # #指明Web主机1的IP地址及端口 weight 1 # #指明权重; http_get { # #获取HTTP服务; url { path / # #健康状态检测时请求资源的URL status_code 200 # #基于获取的内容进行健康状态判定 } connect_timeout 3 # #连接的超时时长 nb_get_retry 3 # #尝试次数 delay_ before_retry 3 # #两次尝试之间的时间间隔 } } real_server 172.18.42.222 80 { ## Indicates the address and port of web host 2 weight 1 http_get { url { path / status_code 200 &nBsp; } connect_ Timeout 3 nb_get_retry 3 delay_before_retry 3 } }}
The keepalived configuration file on virtual machine 2 only needs to change state to backup and priority to 100 smaller number.
Second, testing whether to achieve high availability
[[email protected] keepalived]# ifconfig # #虚拟机1eth0:1 Link encap:Ethernet HWaddr 00:0C:29:B1:AB:69 inet addr:172.18.42.42 bcast:0.0.0.0 mask : 255.255.255.255 up broadcast running multicast mtu:1500 metric:1 # #说明主节点上的VIP已经OK [[email protected] keepalived]# ifconfig # #虚拟机2eth0 link encap:ethernet hwaddr 00:0c:29:40:4a:7f inet addr:172.18.42.200 bcast:172.18.255.255 mask : 255.255.0.0 inet6 addr: fe80::20c:29ff: Fe40:4a7f/64 scope:link &nbsP; up broadcast running multicast mtu : 1500 metric:1 rx packets:80542 errors:0 dropped:0 overruns:0 frame:0 TX packets:11417 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:11251698 (10.7 MIB) tx bytes :1622540 (1.5 MIB) # #备节点上的优先级没有主节点上的高; So I won't preempt vip[[email protected] keepalived]#. service keepalived stop # #关闭虚拟机1上的keepalived服务Stopping keepalived: [ ok ][[email protected] keepalived]# ifconfig # #主节点上的VIP没了eth0 Link encap:Ethernet HWaddr 00:0C:29:B1:AB:69 inet addr:172.18.42.100 bcast : 172.18.255.255 mask:255.255.0.0 inet6 addr: fe80::20c:29ff:feb1:ab69/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:19877 errors:0 dropped:0 overruns:0 frame:0 tx packets:3082 Errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:9751959 (9.3 MIB) TX bytes:299076 (292.0 kib) [[Email protected] keepalived]# ifconfig # #虚拟机2eth0 link encap:ethernet HWaddr 00:0C:29:40:4A:7F inet addr:172.18.42.200 Bcast:172.18.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:fe40:4a7f/64 scope: Link up broadcast running multicast MTU:1500 Metric:1 RX Packets:81871 errors:0 dropped:0 overruns:0 frame:0 tx packets:11648 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:11389486 (10.8 MIB) TX bytes:1653638 (1.5 MiB) eth0:1 link encap:ethernet hwaddr 00:0c:29:40:4a:7f inet addr:172.18.42.42 bcast :0.0.0.0 mask:255.255.255.255 up broadcast running multicast mtu:1500 metric:1 # #备节点抢占了主节点的VIP [[email protected] keepalived]# service keepalived start # #开启虚拟机1的keepalived服务Starting keepalived: [ ok ][[email protected] keepalived]# ifconfig eth0 link encap: ethernet hwaddr 00:0c:29:b1:ab:69 inet addr:172.18.42.100 Bcast:172.18.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:feb1:ab69/64 scope:link up broadcast running multicast mtu:1500 metric:1 Rx packets:20864 errors:0 dropped:0 overruns:0 frame:0 tx packets:3313 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:9878452 (9.4 MIB) TX bytes:315410 (308.0 kib) eth0:1 link encap:ethernet hwaddr 00:0c:29:b1:ab:69 inet addr:172.18.42.42 Bcast:0.0.0.0 Mask:255.255.255.255 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 # #主节点把VIP抢过来了 [[email protected] keepalived]# ifconfig ##Virtual Machine 2eth0 link encap:ethernet hwaddr 00:0c:29:40:4a:7f inet addr:172.18.42.200 Bcast:172.18.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:fe40:4a7f/64 Scope:Link up broadcast running multicast mtu:1500 metric:1 rx packets:83291 errors:0 dropped:0 overruns:0 frame:0 tx packets:12242 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 rx bytes:11562232 (11.0 MIB) TX bytes:1721278 (1.6 MIB) ## The VIP on the standby node is gone.
Third, set the virtual machine 3WEB host kernel parameters
[[email protected] ~]# echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore # #仅在请求的目标IP在本地主机的某个接口上时 before giving a response [email protect ED] ~]# echo 1 >/proc/sys/net/ipv4/conf/lo/arp_ignore [[email protected] ~]# echo 2 >/proc/sys/net/ipv4/conf/lo/ Arp_announce # #禁止本机向其他网络接口通告自己的网卡接口信息 [[email protected] ~]# echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce[[ Email protected] ~]# ifconfig lo:1 172.18.42.42 netmask 255.255.255.255 broadcast 172.18.42.42 # #添加RS上的VIP; [[Email Protec Ted] ~]# Route add-host 172.18.42.42 lo:1 # #指明发送响应报文还是经由此网卡接口
Virtual Machine 4 is set up in the same way
Iv. Testing for load balancing
[[email protected] keepalived]# curl http:// 172.18.42.42
v. Test for high availability to back-end hosts
[[email protected] keepalived]# ipvsadm -ln ## Close the virtual Machine 3 Web service ip virtual server version 1.2.1 (size=4096) prot localaddress:port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 172.18.42.42:80 rr -> 172.18.42.222:80 # #自动删除虚拟机3的Web服务 0[[email protected] keepalived]# curl http://172.18.42.42
Note the problem:
(1) The time between each node must be synchronous; can be implemented based on Ntpdate
(2) To ensure that the kernel parameters Arp_ignore not external response, Arp_announce cannot advertise
This article is from the "WTC" blog, so be sure to keep this source http://wangtianci.blog.51cto.com/11265133/1773886
Keepalived enables high availability of LVS-DR clusters