Configure LVS + keepalived + ipvsadm on centos 7

Source: Internet
Author: User

Configure LVS + keepalived + ipvsadm on centos 7


I. Deployment Environment
Keepalived: 10.10.10.30 (centos 7)
Lvs1: 10.10.10.140 (centos 6.4)
Lvs2: 10.10.10.150 (centos 6.4)

2. Configure lvs1: 10.10.10.140
[[Email protected] ~] # Yum install-y httpd
[[Email protected] ~] #/Etc/init. d/httpd start
[[Email protected] ~] # Cd/var/www/html/
[[Email protected] HTML] # echo "OK"> keep.html
[[Email protected] ~] # Vim/etc/sysconfig/network-scripts/ifcfg-eth0
Device = eth0
Hwaddr = 00: 0C: 29: 15: B7: DC
Type = Ethernet
UUID = 93f4695a-8641-4360-9fce-5e3af0e32fc9
Onboot = Yes
Nm_controlled = Yes
Bootproto = static
Ipaddr = 10.10.10.140
Netmask = 255.255.255.0
Gateway = 10.10.10.30
[[Email protected] ~] #/Etc/init. d/network restart
[[Email protected] ~] #/Sbin/ifconfig eth0: 0 10.10.10.140 broadcast 10.10.10.255 netmask bandwidth 255.255.255 up

3. Configure lvs2: 10.10.10.150
[[Email protected] ~] # Yum install-y httpd
[[Email protected] ~] #/Etc/init. d/httpd start
[[Email protected] ~] # Cd/var/www/html/
[[Email protected] HTML] # echo "OK"> keep.html
[[Email protected] ~] # Vim/etc/sysconfig/network-scripts/ifcfg-eth0
Device = eth0
Hwaddr = 00: 0C: 29: 0d: 33: AC
Type = Ethernet
UUID = e04f57dc-ef9d-4563-bfa4-9c8c1e8fc870
Onboot = Yes
Nm_controlled = No
Bootproto = static
Ipaddr = 10.10.10.150
Netmask = 255.255.255.0
Gateway = 10.10.10.30
[[Email protected] ~] #/Etc/init. d/network restart
[[Email protected] ~] #/Sbin/ifconfig eth0: 0 10.10.10.140 broadcast 10.10.10.255 netmask bandwidth 255.255.255 up


4. Configure keepalived: 10.10.10.30
[[Email protected] ~] # Vim/etc/sysconfig/network-scripts/ifcfg-eno33554984
Hwaddr = 00: 0C: 29: DC: Fe: 1b
Type = Ethernet
Bootproto = static
Defroute = Yes
Peerdns = Yes
Peerroutes = Yes
20174_failure_fatal = No
# Ipv6init = Yes
# Define 6_autoconf = Yes
# Define 6_defroute = Yes
# Ipv6_peerdns = Yes
# Ipv6_peerroutes = Yes
# 6_failure_fatal = No
Name = eno33554984
# UUID = 56cae8b8-235f-471d-9051-2508ee149e48
Onboot = Yes
Nm_controlled = No
Ipaddr = 10.10.10.30
Netmask = 255.255.255.0
[[Email protected] ~] #/Etc/init. d/network restart

[[Email protected] ~] # Cd/data/keepalived/
[[Email protected] keepalived] # tar zxvf keepalived-1.2.12.tar.gz
[[Email protected] keepalived] # cd keepalived-1.2.12/
[[Email protected] keepalived-1.2.12] #./configure -- prefix =/usr/local/keepalived
[[Email protected] keepalived-1.2.12] # Make
[[Email protected] keepalived-1.2.12] # make install
[[Email protected] keepalived-1.2.2] # ln-S/usr/local/keepalived/etc/
[[Email protected] keepalived-1.2.2] # ln-S/usr/local/keepalived/etc/rc. d/init. d/keepalived/etc/init. d/
[[Email protected] keepalived-1.2.2] # ln-S/usr/local/keepalived/etc/sysconfig/
[[Email protected] keepalived-1.2.2] # ln-S/usr/local/keepalived/sbin/keepalived/usr/sbin/
[[Email protected] keepalived-1.2.12] # cd

# Keepalived health check http_get
[[Email protected] ~] #/Usr/local/keepalived/bin/genhash-s 10.10.10.140-P 80-U/keep.html
Md5sum = eff5bc1ef8ec9d03e640fc4370f5eacd

[[Email protected] ~] #/Usr/local/keepalived/bin/genhash-s 10.10.10.150-P 80-U/keep.html
Md5sum = eff5bc1ef8ec9d03e640fc4370f5eacd

[[Email protected] ~] # Vim/etc/keepalived. conf
! Configuration file for keepalived
Global_defs {
Router_id lvs_devel
}

Vrrp_instance vi_1 {
State master
Interface eno33554984
Virtual_router_id 51
Priority100
Advert_int 1
Authentication {
Auth_type pass
Auth_pass 1111
}
Virtual_ipaddress {
10.10.10.250
}
}

Virtual_server 10.10.10.250 80 {
Delay_loop 6
Lb_algo WRR
Lb_kind Dr
Nat_mask 255.255.255.0
Persistence_timeout 50
Protocol TCP

Real_server 10.10.10.140 80 {
Weight 1
Http_get {
URL {
Path/keep.html
Digest eff5bc1ef8ec9d03e640fc4370f5eacd
}
}
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}

Real_server 10.10.10.150 80 {
Weight 1
Http_get {
URL {
Path/keep.html
Digest eff5bc1ef8ec9d03e640fc4370f5eacd
}
}
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
[[Email protected] ~] #/Etc/init. d/keepalived restart

5. Run the ipvsadm command on keepalived: 10.10.10.30 to test
[[Email protected] ~] # Yum install-y ipvsadm
[[Email protected] ~] # Ipvsadm-ln
IP Virtual Server version 1.2.1 (size = 4096)
Prot localaddress: Port sched1_flags
-> Remoteaddress: port forward weight activeconn inactconn
TCP 10.10.250: 80 WRR persistent 50
-> 10.10.10.140: 80 Route 1 0 0
-> 10.10.10.150: 80 Route 1 0 0

Run 10.10.10.140.
[[Email protected] HTML] # echo ""> keep.html
[[Email protected] ~] # Ipvsadm-ln
IP Virtual Server version 1.2.1 (size = 4096)
Prot localaddress: Port sched1_flags
-> Remoteaddress: port forward weight activeconn inactconn
TCP 10.10.250: 80 WRR persistent 50
-> 10.10.10.150: 80 Route 1 0 0

Then run 10.10.140.
[[Email protected] HTML] # echo "OK"> keep.html
[[Email protected] ~] # Ipvsadm-ln
IP Virtual Server version 1.2.1 (size = 4096)
Prot localaddress: Port sched1_flags
-> Remoteaddress: port forward weight activeconn inactconn
TCP 10.10.250: 80 WRR persistent 50
-> 10.10.10.140: 80 Route 1 0 0
-> 10.10.10.150: 80 Route 1 0 0


Configure LVS + keepalived + ipvsadm on centos 7

Related Article

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.