Construction of LVS load balancing cluster mode --NET

1, to prepare four virtual machines (configure a Linux LVM, two Web, a windows machine test)

2, shut down the virtual machine Linux firewall and security mechanisms

systemctl stop  firewalld
iptables -F
setenforce 0

 

First, the configuration of the LVM host (the host to add two card, two cards are not a mode, are arranged IP address)

Card a: NET mode 
NIC two: VMnet2 mode
[the root @ localhost ~] # IP A | grep ENO 2 : eno16777728: <BROADCAST, the MULTICAST, the UP, LOWER_UP> MTU 1500 qdisc allows users to pfifo_fast State the UP of qlen 1000 inet 192.168 . 200.111 / 24 brd 192.168 . 200.255 scope Global eno16777728 . 3 : eno33554960: <BROADCAST, the MULTICAST, the UP, LOWER_UP> MTU 1500 qdisc allows users to the UP pfifo_fast State of qlen 1000 inet 172.16 . 1.1 / 16 brd 172.16 . 255.255 scope global eno33554960

1, open the routing function

[root @ localhost ~] # vim / etc / the sysctl.conf // permanently modify the route file 
net.ipv4.ip_forward = 1 
[root @ localhost ~] # sysctl - the p-// check whether the route open 
net.ipv4.ip_forward = 1

2, installation management tools ipvsadm

[root@localhost ~]# yum -y install ipvsadm

Add Module ip_vs

 [root@localhost ~]# modprobe ip_vs
 [root@localhost ~]# lsmod | grep ^ip_vs
 ip_vs                 136798  0 

Check the version

[root@localhost ~]# ipvsadm -v
ipvsadm v1.27 2008/5/15 (compiled with popt and IPVS v1.2.1)

3, add the load allocation policy

[the root @ localhost ~] -t -A the ipvsadm # 172.16 . 1.1 : 80 -s rr    // load a virtual host IP address is 172.16.1.1 port 80, the polling algorithm rr 
[root @ localhost ~] # ipvsadm - -t A 172.16 . 1.1 : 80 -R & lt 192.168 . 200.112 : 80 -m -w . 1   // add the server node 192.168.200.112, net pattern, with a weight. 1 
[the root @ localhost ~] # the ipvsadm -a -t 172.16 . 1.1 : 80 -r 192.168 . 200.113 : 80 -m -w 1
 
------------------------------------ --------
rr: Polling 
wrr: WRR 
lc: Minimum connection 
wlc: weighted least connections

 -------------------------------- ----------------------- 
- a: Add virtual server
 - T: VIP is used to specify the address and TCP ports
 - S: specifies load scheduling algorithm
 - a: Add server
 - R & lt: Specifies the address and TCP RIP port
 -m: NAT using trunked mode (-g: DR mode, - I: mode TUN)
 -w: set the weight (a weight of 0 indicates pause node)

4. Check node status

1 [root@localhost ~]# ipvsadm -Ln
2 IP Virtual Server version 1.2.1 (size=4096)
3 Prot LocalAddress:Port Scheduler Flags
4   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
5 TCP  172.16.1.1:80 rr
6   -> 192.168.200.112:80           Masq    1      0          0         
7   -> 192.168.200.113:80           Masq     1       of 0           of 0  

 

Second, set of two polls (Web) Host

Modify the gateway address of the host, so that the gateway web hosts two points within the network LVS host IP (192.168.200.111)

1, the first host:

[the root @ localhost ~] # Vim / etc / sysconfig / Network-scripts / in ifcfg- eno16777728 
the ONBOOT = Yes 
the IPADDR = 192.168 . 200.112 
NETMASK = 255.255 . 255.0 
the GATEWAY = 192.168 . 200.111    // modify gateway address 
the DNS1 = 202.106 . 0.20 

[the root @localhost ~] # systemctl restart network // network service restart

yum install apache, open service

[root@localhost ~]# yum -y install httpd
[root@localhost ~]# systemctl start httpd

Creating test file

[root@localhost ~]# echo "11111111" > /var/www/html/index.html

2, the second host

[the root @ localhost ~] # Vim / etc / sysconfig / Network-scripts / in ifcfg- eno16777728 
the ONBOOT = Yes 
the IPADDR = 192.168 . 200.113 
NETMASK = 255.255 . 255.0 
the GATEWAY = 192.168 . 200.111 
the DNS1 = 202.106 . 0.20 

[the root @ localhost ~] # systemctl restart network // network service restart

yum install apache, open service

[root@localhost ~]# yum -y install httpd
[root@localhost ~]# systemctl start httpd

Creating test file

[root@localhost ~]# echo "2222222" > /var/www/html/index.html

 

Three, windows test machine

Under IP and virtual host IP windows host in the same network segment, and to be in the same mode

 

 

 

 

 

 

LVS create test scripts on the host, you can see the effect of the poll.

[root@localhost ~]# while :
> do 
> curl 172.16.1.1
> sleep 2
> done
11111111
2222222
11111111
2222222
11111111
2222222

 

Guess you like

Origin www.cnblogs.com/tanxiaojuncom/p/11593917.html