LVS (Linux virtual Server): Linux virtualization server. It is mainly used for load balancing scenarios, to solve the pressure of single node server, and improve the disaster tolerant ability.
LVS according to the way of implementation is divided into: Lvs-nat, LVS-DR, Lvs-tun, Lvs-fullnat
Lvs-nat Features:
1. The dispatcher director configures the dual network card, one piece configures the external network IP as the VIP, the other one NIC is the dip, must and the back end server Rs's rip in the same network, and the Rip Gateway must point to the dip
2. Request messages and response messages are passed through the director, so the director may become a bottleneck if under high load conditions
3. The client does not know the backend host when requesting the resource, so it can hide the backend server and prevent the attack.
The scene of this experiment is to use the Lvs-nat model to build a discuz, a total of four hosts, a LVS host to provide load balancing, two lamp host provides access, an NFS provides remote Storage
| Lvs-nat Server |
LAMP1 Server |
LAMP2 Server |
Server for NFS |
| dip:192.18.254.122 |
Rip1:192.18.254.123 |
rip2:192.18.254.124 |
192.18.254.125 |
| vip:172.18.254.122 |
|
|
|
Host 4: As Server for NFS
1. Start the NFS service
Systemctl Start Nfs.service
2. Create a directory dedicated to remote sharing
Mkdir/web/html
3. Define a host that can access this NFS
vim/etc/exports/web/html 192.18.254.123 (rw), 192.18.254.124 (rw)
4. Re-export the file system
Exports-r
5. Create a user and specify the UID number
Useradd-u Web
6. Modify user permissions so that users can work with the directory
Setfacl-m u:web:rwx/web/html
Host 3: As an HTTP PHP MySQL server
1. Create a directory to mount NFS specifically
Mkdir/hm/html
2. Create a user with the same ID as the NFS server
Useradd-u Web
3. Mount remote NFS to local
Mount-t NFS 192.18.254.125:/web/html
4. Check that the mount status is normal
Mount
5 Installing HTTP PHP mysql
Yum-y Install http PHP php-mysql mariadb
6. Modify the configuration in the http.conf
ServerName www.discuz.com:80DocumentRoot "/hm/html"
7. Start the HTTPD service
Systemctl Start Httpd.service
8. Create a index.html in/hm/html and write some characters
echo "httpd test" >/hm/html
9. Start the database
Systemctl Start Mariadb.service mysql_secure_installation
9. Enter database with root user and password to create Discuz database, Telnet host
Mysql-uroot-p CREATE DATABASE Disdb; GRANT all on disdb.* to ' Disuser ' @192.18.%.% identified by ' dis '; FLUSH privileges;
10. Test if PHP can connect to mariadb. The Index.index in the/hm/html/directory is index.php
<?php $conn =mysql_connect (' 172.18.254.124 ', ' disuser ', ' dis '); if ($conn) echo "OK"; else echo "failure";? >
11. Login Browser Enter hostname to see if it is OK
12. Download Discuz to/hm/html/dis directory, unzip and create the connection
Unzip Discuz_x3.2_sc_utf8.zip
13. Enter/hm/html/dis/upload/config to modify config_global_default.php
Vim config_global_default.php
Modify one of the Dbhost dbuser DBPW diname
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/80/36/wKiom1c7KFGBTbFNAAAhItwG2oE470.png "title=" Lvs-nat experiment. PNG "alt=" Wkiom1c7kfgbtbfnaaahitwg2oe470.png "/>
14. Modify the data Uc_server under Config
chmod 777 Datachmod 777 Uc_server
15. Start the browser type Www.discuz.com/dis step-by-step installation is complete.
16. Modify DocumentRoot
DocumentRoot "/hm/html/dis"
Host 2 configuration and host 3 are basically consistent
Host 1:lvs Server
1. Installing Ipvsadm
Yum-y Install Ipvsadm
2. Add a forwarding Rule
Ipvsadm-a-T 172.18.254.122:80-s rripvsadm-a-T 192.18.254.122:80-r 192.18.254.123:80-mipvsadm-a-T 192.18.254.122:8 0-r 192.18.254.124:80-m
3. View the LVS rules table
Ipvsadm-ln
4. Turn on the route forwarding function
Vim/etc/sysctlnet.ipv4.ip_forward = 1 Sysctl-p
5. See if the firewall and SELinux are turned off
IPTABLES-NVL Getenforce
6. Open the browser and type 172.18.254.122
Attention:
1. In the process of testing LVS, you can put different contents in the index.php of two lamp documetroot to see if the load balancing is based on RR.
The director in 2.lvs-nat needs to turn on the route forwarding feature.
The 3.NFS server needs to grant the corresponding host to mount the corresponding directory, and the client must have an account with the same UID as the NFS service.
Lvs-nat based on NFS storage deployment Discuz