LVS + Keepalived configuration tutorial, lvskeepalived tutorial

Source: Internet
Author: User

LVS + Keepalived configuration tutorial, lvskeepalived tutorial
1. Prepare the environment

Keepalived Server
Server1 (172.25.8.1)
Server4 (172.25.8.4)

Apache Server
Server2 (172.25.8.2)
Server3 (172.25.8.3)

2. Configure Keepalived Server
Download the Keepalived installation package and install
: Http://www.keepalived.org/software/ there are many, I choose to use the 1.3.5 [root@server1 ~] # Wget http://www.keepalived.org/software/keepalived-1.3.5.tar.gz?root@server1 ~] # Tar zxvf keepalived-1.3.5.tar.gz [root @ server1 ~] # Cd keepalived-1.3.5 [root @ server1 keepalived-1.3.5] #./configure -- with-init = SYSV -- prefix =/usr/local/keeplived... configure: error :!!! OpenSSL is not properly installed on your system .!!! !!! Can not include OpenSSL headers files .!!! The reason is: OpenSSL is not installed in the current system. Solution: Run yum install-y openssl-devel again. /configure command // The following text indicates that the Keepalived configuration is successful ---------------------- Keepalived version: 1.3.5Compiler: gccPreprocessor flags: Compiler flags: -Wall-Wunused-Wstrict-prototypes-Wextra-g-O2Linker flags: Extra Lib:-lcrypto-lssl Use cipher s Framework: YesIPVS use NL lib: now.s syncd attributes: now.s 64 bit stats: nofwmark socket suppor T: YesUse VRRP Framework: YesUse vrrp vmac: YesUse VRRP authentication: YesWith ip rules/routes: YesSNMP vrrp support: NoSNMP checker support: NoSNMP RFCv2 support: NoSNMP RFCv3 support: noworkflow support: noSHA1 support: NoUse Debug flags: NoStacktrace support: NoMemory alloc check: Nolibnl version: NoneUse IPv4 devconf: NoUse libiptc: NoUse libipset: Noinit type: SYSVBuild genhas H: YesBuild documentation: no execute make command [root @ server1 keepalived-1.3.5] # make execute make install Command [root @ server1 keepalived-1.3.5] # make install # create soft link for the startup script [root @ server1 ~] # Ln-s/usr/local/keeplived/etc/rc. d/init. d/keepalived/etc/init. d/[root @ server1 ~] # Ln-s/usr/local/keeplived/etc/keepalived // etc/[root @ server1 ~] # Ln-s/usr/local/keeplived/sbin/keepalived/sbin/[root @ server1 ~] # Ln-s/usr/local/keeplived/etc/sysconfig/keepalived/etc/sysconfig/# grant the execution permission [root @ server1 ~] # Ll/usr/local/keeplived/etc/rc. d/init. d/keepalived-rw-r -- 1 root 1308 Feb 6 06:08/usr/local/keeplived/etc/rc. d/init. d/keepalived [root @ server1 ~] # Chmod + x/usr/local/keeplived/etc/rc. d/init. d/keepalived [root @ server1 ~] # Ll/usr/local/keeplived/etc/rc. d/init. d/keepalived-rwxr-xr-x 1 root 1308 Feb 6 06:08/usr/local/keeplived/etc/rc. d/init. d/keepalived # Start KeepalivedStarting keepalived: [OK] # copy the configuration file to server4 [root @ server1 ~] # Scp-r/usr/local/keeplived/server4:/usr/local/

Keepalived Configuration:

[Root @ server1 ~] # Cat/etc/keepalived. conf | grep-v "#" | grep-v ";" | grep-v "^ $" # The preceding command filters out the parameters that take effect in the configuration file, the grep command-v parameter (reverse selection) removes all comment lines starting with # (well number) and; (semicolon), respectively, you can use ^ $ to represent the remaining blank rows and filter them out! Configuration File for login {icationication_email {root @ locahost} restart keepalived @ localhost smtp_server 127.0.0.1 route 30 router_id LVS_DEVEL limit # vrrp_strict # When server1 and server4 are in keepalive failback, iptables automatically blocks the vip, then the five parties access the real-server Service vrrp_garp_interval 0 vrrp_gna_interval 0} vrrp_instance VI_1 {state MASTER # as the master or backup, we can see the priority of the two keepalive interfaces eth1 virtual_router_id 51 priority 100 # priority authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {172.25.8.100 # virtual ip (vip )}} virtual_server 172.25.8.100 80 {# httpd service port of virt-server delay_loop 6 lb_algo rr # polling, that is, two keepalive hosts lb_kind NAT # persistence_timeout 50 # Applicable to persistent connection services, such as the ftp service, enable the protocol TCP real_server 172.25.8.2 80 {# real-server Service port (80 is apache, 21 is ftp) weight 1 TCP_CHECK {connect_timeout 3 nb_get_retry 3 delay_before_retry 3} real_server 172.25.8.3 80 {# real-server Service port (80 is apache, 21 is ftp) weight 2 TCP_CHECK {connect_timeout 3 nb_get_retry 3 delay_before_retry 3 }}}

The configuration of server4 is exactly the same as that of server1.

[root@server1 ~]# cat /etc/keepalived/keepalived.conf | grep -v "#" | grep -v ";"| grep -v "^$" ! Configuration File for keepalivedglobal_defs {   notification_email {    root@localhost   }   notification_email_from keepalived@localhost   smtp_server 127.0.0.1   smtp_connect_timeout 30   router_id LVS_DEVEL   vrrp_skip_check_adv_addr   vrrp_garp_interval 0   vrrp_gna_interval 0}vrrp_instance VI_1 {    state BACKUP    interface eth1    virtual_router_id 51    priority 100    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {    172.25.8.100    }}virtual_server 172.25.8.100 80 {    delay_loop 6    lb_algo rr    lb_kind DR    protocol TCP    real_server 172.25.8.2 80 {        weight 1       TCP_CHECK {        connect_timeout 3            nb_get_retry 3            delay_before_retry 3        }    }real_server 172.25.8.3 80 {        weight 2       TCP_CHECK {            connect_timeout 3            nb_get_retry 3            delay_before_retry 3        }    }}

We can view the data on Server 1.

[root@server1 ~]# ipvsadm -lIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags  -> RemoteAddress:Port           Forward Weight ActiveConn InActConnTCP  172.25.8.100:http rr  -> server2:http                 Route   1      0          0           -> server3:http                 Route   1      0          0   
Apache Server
[root@server2 html]# cat /var/www/html/index.html 

Server2 [root @ server2 html] #/etc/init. d/httpd status httpd (pid 1716) is running... [root @ server3 html] # cat/var/www/html/index.html

Server3 [root @ server3 html] #/etc/init. d/httpd status httpd (pid 1418) is running...

3. Test
[root@foundation8 images]# for i in {1..15}; do curl 172.25.8.100 ;done
// Remove the vip address on Server 1 from [root @ server1 network-scripts] #/etc/init. d/keepalived statuskeepalived (pid 14620) is running... [root @ server1 network-scripts] # ip addr1: lo:
 
  
Mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00: 00: 00: 00: 00: 00 brd 00: 00: 00: 00: 00: 00 inet 127.0.0.1/8 scope host lo inet6: 1/128 scope host valid_lft forever preferred_lft forever2: eth1:
  
   
Mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52: 54: 00: 60: f6: 2b brd ff: ff inet 172.25.8.1/24 brd external scope global eth1 inet6 fe80: 5054: ff: fe60: f62b/64 scope link valid_lft forever preferred_lft forever // when keepalived is running, we found that vip automatically floated to server4 above [root @ server4 keepalived-1.3.5] # ip addr1: lo:
   
    
Mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00: 00: 00: 00: 00: 00 brd 00: 00: 00: 00: 00: 00 inet 127.0.0.1/8 scope host lo inet6: 1/128 scope host valid_lft forever preferred_lft forever2: eth1:
    
     
Mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52: 54: 00: 90: 8f: e4 brd ff: ff inet 172.25.8.4/24 brd 172.25.8.255 scope global eth1 inet 172.25.8.100/32 scope global eth1 inet6 fe80 :: 5054: ff: fe90: 8fe4/64 scope link valid_lft forever preferred_lft forever [root @ server4 keepalived-1.3.5] #/etc/init. d/keepalived statuskeepalived (pid 11398) is running... [root @ server4 keepalived-1.3.5] # Define SADM-lIP Virtual Server version 1.2.1 (size = 4096) Prot LocalAddress: Port sched1_flags-> RemoteAddress: Port Forward Weight ActiveConn InActConnTCP 172.25.8.100: http rr-> server2: http Route 1 0 8-> server3: http Route 2 0 7 // the access is still successful ~ [Root @ foundation8 images] # for I in {1 .. 15}; do curl 172.25.8.100; done
    
   
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.