Configure LVS + Keepalived + ipvsadm on CentOS 7
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
[Root @ LVS1 ~] # Yum install-y httpd
[Root @ LVS1 ~] #/Etc/init. d/httpd start
[Root @ LVS1 ~] # Cd/var/www/html/
[Root @ LVS1 html] # echo "OK"> keep.html
[Root @ LVS1 ~] # 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
[Root @ LVS1 ~] #/Etc/init. d/network restart
[Root @ LVS1 ~] #/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
[Root @ LVS2 ~] # Yum install-y httpd
[Root @ LVS2 ~] #/Etc/init. d/httpd start
[Root @ LVS2 ~] # Cd/var/www/html/
[Root @ LVS2 html] # echo "OK"> keep.html
[Root @ LVS2 ~] # 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
[Root @ LVS2 ~] #/Etc/init. d/network restart
[Root @ LVS2 ~] #/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
[Root @ KEEP ~] # 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
[Root @ KEEP ~] #/Etc/init. d/network restart
[Root @ KEEP ~] # Cd/data/keepalived/
[Root @ KEEP keepalived] # tar zxvf keepalived-1.2.12.tar.gz
[Root @ KEEP keepalived] # cd keepalived-1.2.12/
[Root @ KEEP keepalived-1.2.12] #./configure -- prefix =/usr/local/keepalived
[Root @ KEEP keepalived-1.2.12] # make
[Root @ KEEP keepalived-1.2.12] # make install
[Root @ KEEP keepalived-1.2.2] # ln-s/usr/local/keepalived/etc/
[Root @ KEEP keepalived-1.2.2] # ln-s/usr/local/keepalived/etc/rc. d/init. d/keepalived/etc/init. d/
[Root @ KEEP keepalived-1.2.2] # ln-s/usr/local/keepalived/etc/sysconfig/
[Root @ KEEP keepalived-1.2.2] # ln-s/usr/local/keepalived/sbin/keepalived/usr/sbin/
[Root @ KEEP keepalived-1.2.12] # cd
# Keepalived health check HTTP_GET
[Root @ KEEP ~] #/Usr/local/keepalived/bin/genhash-s 10.10.10.140-p 80-u/keep.html
MD5SUM = eff5bc1ef8ec9d03e640fc4370f5eacd
[Root @ KEEP ~] #/Usr/local/keepalived/bin/genhash-s 10.10.10.150-p 80-u/keep.html
MD5SUM = eff5bc1ef8ec9d03e640fc4370f5eacd
[Root @ KEEP ~] # 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
}
}
[Root @ KEEP ~] #/Etc/init. d/keepalived restart
5. Run the ipvsadm command on keepalived: 10.10.10.30 to test
[Root @ KEEP ~] # Yum install-y ipvsadm
[Root @ KEEP ~] # 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.
[Root @ LVS1 html] # echo ""> keep.html
[Root @ KEEP ~] # 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.
[Root @ LVS1 html] # echo "OK"> keep.html
[Root @ KEEP ~] # 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
LVS-NAT for Linux Server LB Clusters
LB cluster-LVS-NAT mode for cluster services in Linux
LVS-NAT + ipvsadm implement service cluster on RHEL 5.7
Realization of LVS-NAT and LVS-DR model of Linux Virtual Server
Build an LVS load balancing test environment