LVS + keepalived practice, lvskeepalived practice
1. Install lvs on backup lvs and master LVS respectively
wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
uname -rln -s /usr/src/kernels/2.6.18-164.el5-i686/ /usr/src/linuxtar zxvf ipvsadm-1.24.tar.gzcd ipvsadm-1.24make && make install
Ii. Install keepalived on backup lvs and master lvs respectively.
wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gztar zxvf keepalived-1.1.19.tar.gzcd keepalived-1.1.19./configure --prefix=/usr/local/keepalivedmake make installcp /usr/local/keepalived/sbin/keepalived /usr/sbin/cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/mkdir /etc/keepalived
3. Modify keepalived configurations
vi /etc/sysconfig/keepalivedKEEPALIVED_OPTIONS="-D -f /usr/local/keepalived/etc/keepalived/keepalived.conf"
Vi/etc/init. d/keepalived # update./etc/sysconfig/keepalivedPATH = "$ PATH:/usr/sbin" export PATH
Vi/usr/local/keepalived/etc/keepalived. conf! Configuration File for login {icationication_email {50625185@qq.com} login 50625185@qq.com smtp_server localhost guest 30 router_id NodeA} vrrp_instance VI_1 {state MASTER interface ens160 guest 51 priority 100 advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {192.168.20.229 // virtual IP} virtual_server 192.168.20.229 80 {// define the virtual server delay_loop 6 // The health check time, the Unit is the second lb_algo rr // Load Scheduling Algorithm. Here it is set to rr, that is, the polling algorithm lb_kind DR // LVS implements the load balancing mechanism, the NAT, TUN, and DR modes can be set to persistence_timeout 1 // session persistence time, in seconds (the session persistence time can be extended as appropriate) protocol TCP // forwarding protocol type, there are tcp and udp real_server 192.168.20.200 8151 {// define WEB Server weight 1 // weight TCP_CHECK {// determine the health status of RealServer through tcpcheck connect_timeout 5 // connection timeout nb_get_retry 3 // reconnect times delay_before_retry 3 // reconnection interval connect_port 8151 // check port} real_server 192.168.0000201 8151 {// define WEB Server weight 2 // weight TCP_CHECK {// pass tcpcheck determines the health status of RealServer connect_timeout 5 // connection timeout nb_get_retry 3 // Number of reconnection delay_before_retry 3 // reconnection interval connect_port 8151 // check port }}}
Virtual VIP: 192.168.255.229
Shunting WEB: 192.168.0000200, 192.168.0000201
4. Start keepalived
/etc/init.d/keepalived start
V. Test
ipvsadmIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP docker223:80 rr persistent 1 -> 192.168.20.200:8151 Route 1 0 0
Access http: // 192.168.20.229 through a browser and distribute http: // 192.168.20.200: 8151 WEB Services