A, LVS1 server configuration
Installation ipvsadm, keepalived
[root@localhost ~]# yum -y install ipvsadm keepalived
Configuration profiles keepalivedde
[root@localhost ~]# vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { [email protected] [email protected] [email protected] } notification_email_from [email protected] smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_MASTER vrrp_skip_check_adv_addr vrrp_strict vrrp_garp_interval 0 vrrp_gna_interval 0 } vrrp_instance VI_1 { state MASTER interface eno16777728 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.200.201 } } virtual_server 192.168.200.201 80 { delay_loop 6 lb_algo rr lb_kind DR persistence_timeout 50 protocol TCP real_server 192.168.200.113 80 { weight 1 TCP_CHECK{ connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.200.11 80 { weight 1 TCP_CHECK{ connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } } ############################################################# vrrp_instance VI_2 { state BACKUP interface eno16777728 virtual_router_id 52 priority 90 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.200.202 } } virtual_server 192.168.200.202 80 { delay_loop 6 lb_algo rr lb_kind DR persistence_timeout 50 protocol TCP real_server 192.168.200.113 80 { weight 1 TCP_CHECK{ connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.200.11 80 { weight 1 TCP_CHECK{ connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } }
Turn off the firewall, security policy, start the service and view
# Turn off the firewall, security policy [root @ localhost ~ ] # systemctl STOP firewalld [root @ localhost ~] # iptables - F [root @ localhost ~] # setenforce 0 # start keepalived service [root @ localhost ~ ] # systemctl Start keepalived # View VIP [root @ localhost ~] # ip A | grep inet inet 127.0 . 0.1 / 8 scope Host LO inet6 :: 1 / 128 scope Host inet 192.168 . 200.111 / 24- brd 192.168 .200.255 scope global eno16777728 inet 192.168.200.201/32 scope global eno16777728 inet6 fe80::20c:29ff:fef0:4297/64 scope link #查看策略 [root@localhost ~]# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.200.201:80persistent RR 50 # discovery server 192. 168.200 .11 problematic -> 192.168 . 200.113 : 80 the Route . 1 0 0 the TCP 192.168 . 200.202 : 80 RR persistent 50 -> 192.168 . 200.113 : 80 the Route . 1 0 0
Two, LVS2 server configuration
Installation ipvsadm, keepalived
[root@localhost ~]# yum -y install ipvsadm keepalived
Configuration profiles keepalivedde
[root@localhost ~]# vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { [email protected] [email protected] [email protected] } notification_email_from [email protected] smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_MASTER vrrp_skip_check_adv_addr vrrp_strict vrrp_garp_interval 0 vrrp_gna_interval 0 } vrrp_instance VI_1 { state BACKUP interface eno16777728 virtual_router_id 51 priority 80 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.200.201 } } virtual_server 192.168.200.201 80 { delay_loop 6 lb_algo rr lb_kind DR persistence_timeout 50 protocol TCP real_server 192.168.200.113 80 { weight 1 TCP_CHECK{ connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.200.11 80 { weight 1 TCP_CHECK{ connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } } ############################################################# vrrp_instance VI_2 { state MASTER interface eno16777728 virtual_router_id 52 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.200.202 } } virtual_server 192.168.200.202 80 { delay_loop 6 lb_algo rr lb_kind DR persistence_timeout 50 protocol TCP real_server 192.168.200.113 80 { weight 1 TCP_CHECK{ connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.200.11 80 { weight 1 TCP_CHECK{ connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } }
Turn off the firewall, security policy, start the service and view
# Turn off the firewall, security policy [root @ localhost ~ ] # systemctl STOP firewalld [root @ localhost ~] # iptables - F [root @ localhost ~] # setenforce 0 # start keepalived service [root @ localhost ~ ] # systemctl Start keepalived # View VIP [root @ localhost ~] # ip A | grep inet inet 127.0 . 0.1 / 8 scope Host LO inet6 :: 1 / 128 scope Host inet 192.168 . 200.112 / 24- brd 192.168 .200.255 scope global eno16777728 inet 192.168.200.202/32 scope global eno16777728 inet6 fe80::20c:29ff:fe96:8ef5/64 scope link #查看策略 [root@localhost ~]# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.200.201:80 rr persistent 50 -> 192.168.200.113:80 Route 1 0 0 TCP 192.168.200.202:80 rr persistent 50 -> 192.168.200.113:80 Route 1 0 0
Four, Apache server configuration (same)
[root@localhost ~]# ifconfig lo:0 192.168.200.201 netmask 255.255.255.255 [root@localhost ~]# ifconfig lo:1 192.168.200.202 netmask 255.255.255.255 #查看配置 [root@localhost ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 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 valid_lft forever preferred_lft forever inet 192.168.200.201/32 scope global lo:0 valid_lft forever preferred_lft forever inet 192.168.200.202/32 scope global lo:1 valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eno16777728: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:fb:c6:2d brd ff:ff:ff:ff:ff:ff inet 192.168.200.113/24 brd 192.168.200.255 scope global eno16777728 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fefb:c62d/64 scope link valid_lft forever preferred_lft forever
Routing Configuration
[root@localhost ~]# route add -host 192.168.200.201 dev lo:0 [root@localhost ~]# route add -host 192.168.200.202 dev lo:1
Configuration parameters
[root@localhost ~]# vim /etc/sysctl.conf net.ipv4.conf.all.arp_ignore=1 net.ipv4.conf.all.arp_announce = 2 net.ipv4.conf.default.arp_ignore = 1 net.ipv4.conf.default.arp_announce = 2 net.ipv4.conf.lo.arp_ignore = 1 net.ipv4.conf.lo.arp_announce = 2 #启用参数 [root@localhost ~]# sysctl -p net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.all.arp_announce = 2 net.ipv4.conf.default.arp_ignore = 1 net.ipv4.conf.default.arp_announce = 2 net.ipv4.conf.lo.arp_ignore = 1 net.ipv4.conf.lo.arp_announce = 2
Install httpd service
[root @ localhost ~] # yum - the y-install httpd # prepare a test page [root @ localhost ~] # echo " 111111 " > / var / the WWW / HTML / index.html # services start, turn off the firewall [root @ localhost ~ ] systemctl the restart the httpd # [the root @ localhost ~ ] # systemctl STOP firewalld [the root @ localhost ~] # iptables - F. [the root @ localhost ~] # the setenforce 0
Five test