LVS-Nat
How Server Load balancer Nat works
650) This. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-Right: 0px; "Title =" wps_clip_image-28707 "border =" 0 "alt =" wps_clip_image-28707 "src =" http://img1.51cto.com/attachment/201409/8/8400375_1410198073UvrA.png "Height =" 309 "/>
LVS is the LB implementation method.
LB: Server Load balancer
LVS-Nat
Directory Load Balancing Scheduler
Real Server real load Cluster
Request Message
First, the client requests an HTTP resource, and the VIP that arrives at the Directory through the router is routed to the input chain.
Check whether the requested resource is a local machine, but the local machine is a cluster. The local machine is not provided by Web Services. Modify the requested resource view according to the configuration rules.
The real Real Server rip is sent to dip, and the dip view is sent to Real Server XX and then to XX.
Response Message
Real Server XX views the requested resources, and immediately starts to construct a response packet. After the response packet is constructed, it is sent to directory through dip, and dip is repaired through
Change the source port. Dip forwards data directly from the forword chain to the VIP address. The VIP address is forwarded to the client.
Job example
Vmware1 directory NFS shared MySQL eth0: 192.168.1.118/24 eth1: 172.16.1.143/16
Vmware2 lamp web host1 eth0: 192.168.1.11/24 disable MySQL installation of WordPress
Vmware3 lamp web host2 eth1: 192.168.1.12/24 disable MySQL installation of WordPress
The system is centos6.5
Configure the IP address and create a webpage. Ping the webpage to check whether the host is online.
1. node Real Server Configuration
Ifconfig eth0 192.168.1.11/24 up using virtual channel 3
Route add default GW 192.168.1.11
Yum install httpd mysql-server PHP-mysql PHP-Gd-y
Vim/var/www/html provides webpage files
Service httpd restart
Same configuration as node 2
2. Directory Configuration
First, add a NIC. The configuration can be properly recognized by Linux.
Ifconfig eth0 192.168.1.118/24 up bridging
Ifconfig eth1 172.16.1.143/16 up using virtual channel 3
Yum install httpd mysql-server PHP-mysql PHP-Gd-y
In this case, Ping each node in directory.
Curl http: // 192.168.1.11 test whether the webpage of the next node is normal
3. If the above preparation environment is ready, you can implement real cluster services.
Install the software and configure the yum source Yum install ipvsadm-y
You can use man mongosadm without understanding software commands.
Ipvsadm-A | E-T | u | f service-Address [-s scheduler]
[-P [timeout] [-M netmask]
Ipvsadm-D-T | u | f service-address
Ipvsadm-C
Ipvsadm-A | E-T | u | f service-address-r server-address
[-G | I | M] [-W weight] [-x upper] [-y lower]
-A: Add a cluster.
-E. Modify the Cluster
-C: clear cluster configuration
-D. delete a cluster.
-A: Add Real Server Configuration
-E. Modify the real server configuration.
-D. Delete the real server configuration.
-M: Enable the NAT mode.
-G indicates that the Dr mode is enabled.
-W algorithm weight
-L list information
-N: View Details
Echo "1">/proc/sys/NET/IPv4/ip_forward enable the inter-route forwarding function
Configuration Service
Ipvsadm-a-t 172.16.1.143: 80-s rr
Ipvsadm-a-t 172.16.1.143: 80-r 192.168.1.11-m-W 1
Ipvsadm-a-t 172.16.1.143: 80-r 192.168.1.12-m-W 2
650) This. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-Right: 0px; "Title =" wps_clip_image-4637 "border =" 0 "alt =" wps_clip_image-4637 "src =" http://img1.51cto.com/attachment/201409/8/8400375_1410198076gSK0.png "Height =" 100 "/>
Echo "1">/proc/sys/NET/IPv4/ip_forward enable route forwarding
Configuration is successful. You can check whether poll is performed by curl http: // 172.16.1.118.
We can also change the cluster algorithm and switch clusters based on different services.
650) This. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-Right: 0px; "Title =" wps_clip_image-4656 "border =" 0 "alt =" wps_clip_image-4656 "src =" http://img1.51cto.com/attachment/201409/8/8400375_1410198079q6Xg.png "Height =" 92 "/>
Repeated SADM-e-t 172.16.1.118: 80-s LC retest results
Comparison of various algorithms
Static Algorithms
Dynamic Algorithms
4. Update the experiment
Share MySQL with NFS to Provide forum services for two Real Server Web installations of WordPress
We can build one lamp platform by compiling and installing the source code, and then quickly clone the three.
The IP address is the same as the IP address above.
Directory provides MySQL NFS sharing
Real Server provides Web Services, but MySQL is disabled.
The three VM systems are centos6.5
Will not lamp source code compilation and installation, please see the http://1983939925.blog.51cto.com/8400375/1540799
The key point here is the setup of lamp and MySQL authorization.
(1) share with NFS
Vim/etc/exports
/Www/html 172.16.0.0/16 (no_root_squash, RW)
650) This. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-Right: 0px; "Title =" wps_clip_image-17891 "border =" 0 "alt =" wps_clip_image-17891 "src =" http://img1.51cto.com/attachment/201409/8/8400375_1410198081lXT6.png "Height =" 67 "/>
Service NFS restart
(2) lamp Configuration
Build and install Lamp
Vim/etc/httpd24/HTTP. conf
Specify PID
Pidfile "/var/run/httpd. PID"
Support for. php web files
Directoryindex index. php index.html
Enable Web page settings for VM
Include/etc/httpd24/extra/httpd-vhosts.conf
Supports webpage format settings
Addtype application/X-httpd-PHP. php
Addtype application/X-httpd-PHP-source. PHPs
(3) Virtual Host Configuration
Vim // etc/httpd24/extra/httpd-vhosts.conf
Comment out his example VM
Create a VM
<Virtualhost *: 80>
DocumentRoot "/www/html"
<Directory "/www/html">
Require all granted
</Directory>
Servername www.dingchao.com
</Virtualhost>
650) This. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-Right: 0px; "Title =" wps_clip_image-7473 "border =" 0 "alt =" wps_clip_image-7473 "src =" http://img1.51cto.com/attachment/201409/8/8400375_1410198089vfSj.png "Height =" 235 "/>
(4) MySQL authorizes remote host access
It is important to authorize the local or remote host to access MySQL.
The main configuration file MySQL registration, wp-config.PHP MySQL IP address to provide mysq Service local address
The problem with authorization is that we need to authorize the IP address to be accessed by the shared web service. If the experiment cannot verify the IP address, we can
Connect to the client remotely and test whether the authorization is successful.
MySQL: Check whether there is access permission. If an error occurs, the NFS permission is used. You must solve all the specific problems based on the actual situation.
(5) The Directory cluster is based on domain name resolution
Add the IP address that can be resolved to Linux in the hosts file of the Windows host. This means that we need to resolve and install Wordpress based on the domain name,
And access
C: \ windows \ system32 \ drivers \ etc \ hosts
172.16.1.143 www.dingchao.com
This is mainly because the software has a strong cache for IP address-based access registration, and problems may occur during experiment verification.
Install Wordpress.
Mysql-u root-H 127.0.0.1-P
Creat database WP;
Grant all on WP. * To 'Tom '@ 'shared web ip' identified by '123 ';
(6) The Directory cluster configuration is the same as the RPM configuration above.
(7) Experiment verification: I published an article in the browser real server1. Here I install Wordpress based on the domain name, and then disable real server1 in the background,
Access the word server in the browser to view your article in real server1 and describe that your experiment is successful.
LVS-Dr
Mode work
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/49/07/wKiom1QN7B_TNjr-AAFpyI2bDrA934.jpg "Title =" 36020140903222608939.jpg" alt = "wKiom1QN7B_TNjr-AAFpyI2bDrA934.jpg"/>
1. Important Points
Real Server and directory must be in the same network
Real Server must be configured with the same VIP and directory. in work, the MAC address of dip and
Real Server MAC address
The VIP address configured by the Real Server must be guaranteed. If someone else's ARP request VIP address is resolved, no response will be made, and no VIP address will be advertised.
When there is a distribution from directory, give a response
The basic ease-of-use is the same as the above. However, the directory only needs one Nic, so we need to drop the eth1 of the above directory.
2. Specific Configuration
Directory Configuration
Ifconfig eth0 192.168.100.15/24 up
Ifconfig eth0: 0 192.168.100.20/24 up
Route add default GW 192.168.100.1
Ipvsadm-a-t 192.168.100.20: 80-s rr
Ipvsadm-a-t 192.168.100.20: 80-r 192.168.1.11-g-W 1
Ipvsadm-a-t 192.168.100.20: 80-r 192.168.1.12-g-W 2
Real Server Configuration
Ifconfig eth0 192.168.100.11/24 up
Echo 1>/proc/sys/NET/IPv4/CONF/All/arp_ignore
Echo 1>/proc/sys/NET/IPv4/CONF/eth0/arp_ignore
Echo 2>/proc/sys/NET/IPv4/CONF/eth0/arp_announce
Echo 2>/proc/sys/NET/IPv4/CONF/All/arp_announce
Ifconfig lo: 0 192.168.100.20 netmask 255.255.255.255 broadcast 192.168.100.20 up you can only talk to yourself
Route add default GW 192.168.100.1
Route add-host 192.168.100.20 Dev lo: 0
The configuration for the other node is the same.
The same is true for lab verification.
650) This. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-Right: 0px; "Title =" wps_clip_image-29065 "border =" 0 "alt =" wps_clip_image-29065 "src =" http://img1.51cto.com/attachment/201409/8/8400375_1410198107KZ4F.png "Height =" 327 "/>
Lb lvs-Nat LVS-Dr comprehension and Experiment