Lvs:
LVS is a four-tier open source load balancer, working in the NetFilter framework input chain, which is based on different calculations
method to dispatch the user's request to the back-end server, it is not limited by the SOCKT socket file, performance than nginx seven layer
Load balancer performance is much higher.
Type:
Lvs-nat: Multi-target IP Dnat, by modifying the destination address and port in the request message to the RIP and port implementation of a selected RS
LVS-DR: By encapsulating a Mac header for the request message, the source Mac is the Mac of the interface where the dip is located,
The target Mac is the MAC address of the interface of the selected RS Rip, the source Ip/port and the target ip/port are unchanged;
Lvs-tun: To encapsulate an IP header again in the header of the request original message
Lvs-fullnat: Modify the source and destination IP of the request message
Related terms:
Ds:director Server, refers to the front-end load Balancer node.
Rs:real Server. A server that provides services on the back end.
VIP: IP address as the target of the user's request
Dip:ds and RS communicate with each other
RIP: Back-end server IP
Cip:client IP Client IP
CIP <–> VIP = DIP <–> RIP
How the Lvs-nat type works:
When a user requests to reach the director Server, the requested data message is first reached to the prerouting chain in the kernel space. At this point the source of the message IP for the CIP, the target IP for VIP prerouting check found that the target IP packet is local, the packet sent to the input chain Ipvs than to the packet request service is cluster services, if, The target IP address of the packet is modified according to the dispatch algorithm to a server IP on the back end, then the packet is sent to the postrouting chain. At this point the source IP of the message for CIP, the target IP for the RIP postrouting chain through the selection route, the data packages to real server real server than the discovery target for their own IP, start building response message back to director Server. At this point the source IP of the message for RIP, the target IP for the CIP Director server in response to the client, the source IP address will be modified to its own VIP address, and then respond to the client. At this point the message source IP for the VIP, the target IP for CIP
Environment deployment:
1 Prepare three mainframe A B C D
2 Host A as a DS server, configuration vip:172.18.0.9, dip for: 192.168.10.254
3 Host B C as RS server, the gateway points to the DS server when configuring IP 192.168.10.254
B host IP:192.168.10.3/24 Gateway: 192.168.10.254
C Host IP:192.168.10.4/24 Gateway: 192.168.10.254
(Note: centos7 with nmtui command, CENTOS6 with the Setup command)
D host ip:192.168.10.5 (provide WordPress, etc.)
D Host Configuration: (CENTOS6)
[Root@node1 ~]# yum install-y nfs-utils rpcbind mysql-server nginx
# service Mysqld Start
[Root@node1 ~]# MySQL # CREATE DATABASE and authorized users
mysql> CREATE DATABASE wpdb;
Mysql> Grant all in wpdb.* to ' wpuser ' @ ' 192.168.10.% ' identified by ' Wppass '
Mysql> exit
[Root@node1 ~]# mkdir/data/
[Root@node1 ~]# cd/data/
wget Ftp://172.18.0.1/pub/Sources/sources/httpd/wordpress-4.3.1-zh_CN.zip
[Root@node1 data]# Unzip Wordpress-4.3.1-zh_cn.zip
[Root@node1 data]# chown-r nginx.nginx/data/wordpress
[Root@node1 data]# Vim/etc/exports
/data/wordpress 192.168.10. [34] (rw)
[Root@node1 ~]# Service NFS Start
[Root@node1 ~]# showmount-e 172.18.99.7 # view NFS Shared Directories
B C Two Host configuration:
[Root@centos7 ~]# yum install-y nginx php-fpm php-mysql nfs-utils
[Root@centos7 ~]# mkdir-p/data/wordpress
#vim/etc/nginx/conf.d/wps/conf
server {
Listen default_server;
server_name www.magedu.com;
root/data/wordpress/;
Index index.php index.html index.html;
Location/{
}
Location ~ \.php$ {
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename
/data/wordpress/$fastcgi _script_name;
Include Fastcgi_params;
}
}
Root@centos7 nginx]# Vim nginx.conf
# Default Server # #注释或删除主配置文件里的 default server
[Root@centos7 conf.d]# Nginx
[Root@centos7 conf.d]# systemctl start php-fpm
[Root@centos7 conf.d]# Mount 172.18.99.7:/data/wordpress/data/wordpress
A host configuration:
Ipvsadm-a-T 172.18.0.9-s RR
Ipvsadm-a-T 172.18.0.9:80-r 192.168.10.3-m-W 2
Ipvsadm-a-T 172.18.0.9:80-r 192.168.10.4-m-W 1
Sysctl-w net.ipv4.ip_forward=1 (open core forwarding function)
LVS-DR Model Working principle:
(1) Each server is equipped with VIP
(2) Ditector forwarding data packets to the back-end Realserver, the original packet on the packaging of a layer of Realserver really IP mac arrived.
(3) RS through the VIP back to the packet, the data must be forwarded from lo:0 to the local ethx physical port, and then by the ETHX physical port of the machine forward to the client
(4) Rip and VIP is not necessarily in the same network segment (not the same segment of the possibility of very large, this can play a role in hiding back-end RS)
LVS-DR:
Environment deployment:
1 Prepare four hosts A B C D
2 A host is a DS server: 172.18.0.9
3 B C host is RS server
B host ip:172.18.0.3 C host ip:172.18.0.4
4 D host provides WordPress and other ip:172.18.0.5
Configure D Host: (CENTOS6)
[Root@node1 ~]# yum install-y nfs-utils rpcbind mysql-server nginx
# service Mysqld Start
[Root@node1 ~]# MySQL # CREATE DATABASE and authorized users
mysql> CREATE DATABASE wpdb;
Mysql> Grant all in wpdb.* to ' wpuser ' @ ' 172.18.99.% ' identified by ' Wppass '
Mysql> exit
[Root@node1 ~]# mkdir/data/
[Root@node1 ~]# cd/data/
wget Ftp://172.18.0.1/pub/Sources/sources/httpd/wordpress-4.3.1-zh_CN.zip
[Root@node1 data]# Unzip Wordpress-4.3.1-zh_cn.zip
[Root@node1 data]# chown-r nginx.nginx/data/wordpress
[Root@node1 data]# Vim/etc/exports
/data/wordpress 172.18.99.1[01] (rw)
[Root@node1 ~]# Service NFS Start
[Root@node1 ~]# showmount-e 172.18.99.7 # view NFS Shared Directories
Configure B Host: (CENTOS7)
[Root@centos7 ~]# yum install-y nginx php-fpm php-mysql nfs-utils
[Root@centos7 ~]# mkdir-p/data/wordpress
#vim/etc/nginx/conf.d/wps/conf
server {
Listen default_server;
server_name www.magedu.com;
root/data/wordpress/;
Index index.php index.html index.html;
Location/{
}
Location ~ \.php$ {
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename
/data/wordpress/$fastcgi _script_name;
Include Fastcgi_params;
}
}
Root@centos7 nginx]# Vim nginx.conf
# Default Server # #注释或删除主配置文件里的 default server
[Root@centos7 conf.d]# Nginx
[Root@centos7 conf.d]# systemctl start php-fpm
[Root@centos7 conf.d]# Mount 172.18.99.7:/data/wordpress/data/wordpress
[ Root@centos7 ~]# vim dr.sh ## for real-server configuration &NBSP;VIP