Lvs cluster for nat Model Based on session binding on centos6

Source: Internet
Author: User

Lvs cluster for nat Model Based on session binding on centos6

Experiment environment: four virtual machines are installed in centos. their respective functions and IP addresses are as follows:

Director:

Eth0 192.168.2.1 (used as VIP) and eth1: 10.0.0.1 (used as DIP)

RS1:

Eth0: 10.0.0.2

RS2:

Eth0: 10.0.0.3

Database Server: Installed mariadb

Eth0: 10.0.0.4

Topology:

Tutorial steps:

1. Prepare the database server, install mariadb, create a user to remotely connect to the database, create a database for use when two RS servers are connected, and grant all permissions to the user's database.

MariaDB [(none)]> CREATEUSERcluster @ '10. %. %. % 'identifiedby 'cluster'; MariaDB [(none)]> CREATEDATABASEcluster; MariaDB [(none)]> GRANTALLONcluster. * TO 'cluster' @ '10. %. %. % '; MariaDB [(none)]> FLUSHPRIVILEGES;

2. Prepare two RS servers. Both RS servers must provide the httpd service. Copy the directory file upload decompressed by the Discuz Forum installer to the/var/www/html/bbs directory and copy it to one of them. Take RS1 as an example. Use httpd

[Root @ node1 ~] # Yuminstall-yphp [root @ node1 ~] # Yuminstall-yphp-mysql [root @ node1 ~] Upload # copy the decompressed upload directory to [root @ node1Discuz] # cpupload // var/www/html/bbs [root @ node1Discuz] # cpupload // var/www/html/bbs ^ C [root @ node1Discuz] # cd/var/www/html/bbs [root @ node1bbs] # chmod-R777config/data/uc_client/uc_server/

Install xinetd on both RS1 and RS2 and start rsync as a service to synchronize the content of the/var/www/html directory at the same time, so that the content on the two servers is consistent. Edit the/etc/rsyncd. conf file with the following content:

# GlobalSettingsuid = nobodygid = nobodyusechroot = nomaxconnections = 10 strictmodes = yespidfile =/var/run/rsyncd. pidlogfile =/var/log/rsyncd. log # Directorytobesynced [backup] path =/var/www/logs = yesreadonly = nowriteonly = nohostsallow = 10.0.0.0/8 hostsdeny = * list = trueuid = rootgid = rootauthusers = logs =/etc/ rsyncd. passwd[Root @ node2 ~] # Echo "backup_transfer: redhat">/etc/rsyncd. passwd # This file is used to authenticate the user identity when another node pushes data. Backup_transfer: redhat [root @ node2 ~] # Echo "redhat">/etc/rsyncd. passwd2 # This file is used to specify a password file in the script when pushing the file to the other node to avoid interaction. [Root @ node2 ~] # Chmod600/etc/rsyncd. passwd [root @ node2 ~] # Chmod600/etc/rsyncd. passwd2 [root @ node2 ~] # Chkconfigrsyncon [root @ node2 ~] # Servicexinetdstart

A script file is provided to automatically push files when files in the site data directory of the two servers change. The script content is:

#! /Bin/bash #/usr/local/bin/inotifywait-mrq -- timefmt '% d/% m/% y % H: % m' -- format' % T % w % f % e '-emodify, delete, create, attrib/var/www/html | whilereadfile; do/usr/bin/rsync-vzrtopg -- delete -- progress/var/www/html/backup_transfer@10.0.0.3: backup -- password-file =/etc/rsyncd. passwd2echo "$ {files} wasrsynced">/var/log/rsync. log2> & 1 done

The transfer IP address defined in the script is the IP address of the other server. You only need to modify the IP address. Other configurations can be identical and will not be repeated.

In addition, you can simply write the corresponding host name in the site root directory to view the effects of ctor's scheduling requests to different hosts during the test.

Because the experiment is simulated in a virtual machine, the communication between two RS and ctor requires RS to point to the DIP ctor's DIP as the gateway.

[Root @ node1 ~] # Route add default gw 10.0.0.1 # set both RS.

3. Set Director

Two NICs are configured on ctor as the network adapter connecting to the Internet, namely VIP: 192.168.2.1. The other network adapter is used as the Intranet gateway and the IP address is 10.0.0.1. In addition, the IP address forwarding function must be enabled, in this way, RS1 and RS2 can communicate with 192.168.2.1 normally in the simulated experiment environment:

[Root @ director ~] # Echo1>/proc/sys/net/ipv4/ip_forward [root @ director ~] # Ipvsadm-A-t192.168.2.1: 80-srr # define cluster service [root @ director ~] # Ipvsadm-a-t192.168.2.1: 80-r10.0.0.2-m # Add RS1 [root @ director ~] # Ipvsadm-a-t192.168.2.1: 80-r10.0.0.3-m # Add RS2

First, test the effect of the default homepage in the browser:

4. Install discuz. After the test is completed, delete node2 in the cluster service and install the Discuz forum on node1. the purpose of deleting the Forum is to accurately locate node1. Enter 192.168.2.1/bbs in the browser to install the Forum. After installation, add node1 to the cluster service.

# [Root @ director ~] # Ipvsadm-d-t 192.168.2.1: 80-r 10.0.0.3

After discuz is installed on node1, start the rsync script file and synchronize the data file to node2. Similarly, node2 also starts the script file to synchronize data to node1.

[Root @ node1 ~] #./Rsync. sh &

Add node2 to the cluster service so that ctor can schedule user requests to different RS.

[Root @ director ~] # Ipvsadm-a-t192.168.2.1: 80-r10.0.0.3

Because the session information is stored on the server, and the Rsync synchronization is enabled between the two RS, the session data information will also be consistent.

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.