Application of the DR pattern based on LVs to PHP

Source: Internet
Author: User

LVS-DR mode:

The client requests the resource on the server, sends the request message, requests the message arrives the LVS scheduler, the dispatcher splits the message header, views the target IP of the request to be itself, then chooses a real server server randomly according to the request target port and according to the scheduling algorithm, At this point in the request packet header in the sub-package layer frame, that is, the MAC address, the source Mac is itself, the target Mac is the RS server. The RS server receives the message request and processes the request, constructs the response message and sends it to the client, without the scheduler, thus avoiding the concurrency bottleneck caused by the overload of the scheduler. Because RS is sending a response message directly to the client, a public IP address on the RS server is required to configure the scheduler.

Characteristics:

1, each RS server an interface can, but need to be in the same physical network;

2, the Gateway of each RS service cannot point to the IP on the IP;RS server on the scheduler and the IP on the dispatcher and the RS server communication should usually be on the same network, but the two will not be on the same network as the public IP on the scheduler;

3, each RS need to set the kernel parameters, in the setting of public network IP and routing;

Structure of the LVS-DR mode: (Non-original)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7F/FA/wKiom1cy_pmgHWz5AAF3NMWk0w4274.png "title=" R $) 939ut@1ou3j74neu{mqi.png "width=" 658 "height=" 394 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" WIDTH:658PX;HEIGHT:394PX; " alt= "Wkiom1cy_pmghwz5aaf3nmwk0w4274.png"/>

Lab Preparation: IP addresses are all public addresses

1, virtual machine 172.18.250.76 172.18.250.99 LVS Scheduler a network card to open two IP

2. Virtual machine 172.18.250.77 172.18.250.99 (configuration on Lo alias) Real Server

3. Virtual machine 172.18.250.79 172.18.250.99 (configuration on Lo alias) Real Server


One: Install Ipvsadmin:

   Management LVs Service is Ipvs,ipvs is managed by Ipvsadmin command, similar to iptables.

]# yum-y Install ipvsadm]# ipvsadm-ln//view Ipvs defined rules IP Virtual Server version 1.2.1 (size =4096) Prot localaddress:port Scheduler Flags, remoteaddress:port Forward Weight activeconn inactconn

Configure the network card:

]# ifconfig eth0:0    172.18.250.99 netmask 255.255.0.0]# ifconfigeth0:0          Link encap:ethernet HWaddr 00:0c:29:f6:9e:df inet addr:172.18.250.99 bcast:172.18.255.255 mask:255.255.0.0 Up broadcast RUNNING multicast mtu:1500 metric:1

Configure the VIP address on both RS:

]# ifconfig lo:0 172.18.250.99 netmask 255.255.255.255 Broadcast 172.18.250.99//set lo:0 as host and broadcast only to yourself]# Route add-host 172.18.250.99 Dev lo:0//Setup Request message is self, then outgoing message source IP is also own]# echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore]# echo 1 >/proc/sys/n et/ipv4/conf/lo/arp_ignore]# Echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce]# echo 2 >/proc/sys/net/ipv4/ Conf/lo/arp_announce

apr_announce: defines the limit level of the network card when declaring its own mac-ip, three commonly used 0,1,2

   0:

       1: Try to avoid responding to ARP requests in the MAC is not the network card, a host has a number of network cards, one of the network card received the ARP request, found that the requested Mac is the other piece of the computer network card, this time received the ARP request of this network card to try to avoid the response.

        2: Always use the most appropriate network card to respond, a host has a number of network cards, one of the network card received the ARP request, found that the requested Mac is another piece of network card, this time received the ARP request of this network card must not respond, only to find the request of the MAC is its own to give and respond.      

    arp_ignore: Defines the response level of the NIC in response to an external ARP request, commonly used for 0,1

      0: Default value, regardless of which Nic received the ARP request, as long as the Mac has been found to respond.
      1: Always use the most appropriate network card to respond, a host has a number of network cards, one of the network card received the ARP request, found that the requested Mac is another piece of network card, this time received the ARP request of this network card must not respond, only to find the request of the MAC is its own to give and respond.


There are three ways to isolate the VIP on the RS server from responding to client requests and address conflicts:

1, on the front-end of the Gateway interface static binding;

2, the use of arptables on each RS;

3, modify the kernel parameters on each RS to limit the ARP response and notification;


Configuration rules:

]# ipvsadm -a -t 172.18.250.99:80 -s rr [[email protected] ~]#  ipvsadm -a -t 172.18.250.99:80 -r 172.18.250.77:80 -g -w 1[[ email protected] ~]# ipvsadm -a -t 172.18.250.99:80 -r  172.18.250.79:80 -g -w 2[[email protected] ~]# ipvsadm -lnip virtual  Server version 1.2.1  (size=4096) prot localaddress:port scheduler flags   -> RemoteAddress:Port            forward weight activeconn inactconn      tcp   172.18.250.99:80 rr  -> 172.18.250.77:80              Route   1      0           0           -> 172.18.250.79:80              Route   2       0          0  -a: Add, Manage cluster-t: Indicates scheduler ip-s: Specify scheduling algorithm-A: Add, manage Rs-r on cluster: Indicates RS-G:LVS Dr Model-W: Weight


Second, install Nginx, PHP, Mariadb-server on two real servers

]# yum-y Install nginx php php-mysql mariadb-server

Create a test page on two RS:

]# echo "Hello RS1" >/var/www/html/index.html]# echo "Hello RS2" >/var/www/html/index.html

Request on another virtual machine:

]# Curl Http://172.18.250.99/index.htmlHello rs2]# Curl Http://172.18.250.99/index.htmlHello rs1]# Curl/HTTP/ 172.18.250.99/index.htmlhello rs2]# Curl Http://172.18.250.99/index.htmlHello RS1//For load balancing Fruit

Third, installation Phpwind forum   

]# Unzip Phpwind_utf8_8.7.zip//operate on two RS]# mv phpwind_utf8_8.7/upload/var/www/html/

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7F/FB/wKiom1czHGnTqiF-AAG9QJBwMUY279.png "title=" 3L (v% 9mh95l69ql$2en{e8w.png "width=" 666 "height=" 232 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:666px;height:232px; " alt= "Wkiom1czhgntqif-aag9qjbwmuy279.png"/>

Note: Phpwind installation is complete, you will always be prompted to install the Phpwind, just change the name of install.php on the line.

Test for load balancing when accessing PHP applications:

]# curl ..... </TD></TR></TABLE><BR/></div></body>

Consider two points:

1. Whether the cluster needs to share storage

2. Whether clients and clusters need to maintain sessions

1. Do I need to share storage?

Need, if the client has done the operation on the 172.18.250.77 server, the other situation dispatched to the 172.18.250.79 this server, then the client in this request just do the write operation, there will be no resources found, so need to share the MySQL storage.


2. Whether to keep the session:

Choose whether to keep the session based on business needs

Method:

1, according to the SH scheduling algorithm, the client from the same IP request to the same RS server

2, according to the client's cookie binding, to request the same RS server

Application of the DR pattern based on LVs to PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.