Objective:
This article turns to self personal blog http://www.anyisalin.com welcome everyone to visit
RSYNC+INOTIFY+LVS implementation of Web service load Balancing
Lab Environment:
System: CentOS6.7
Service: LVS
Type: Dr model
Machine:
Lvs-director:
Dip:dev eth0 172.16.100.2/24 gw:172.16.100.254
Vip:dev eth0:0 172.16.100.1/24 gw:172.16.100.254
LVS-RS1: Publishing a Web page file server
VIP Dev lo:0 172.16.100.1/32
RIP Dev eth0 172.16.100.7/24 gw:172.16.100.254
Lvs-rs2:rsync Synchronization Server
VIP Dev lo:0 172.16.100.1/32
RIP Dev eth0 172.16.100.8/24 gw:172.16.100.254
DataBase:
IP Dev eth0 172.16.100.200/24 gw:172.16.100.254
Deployment steps:
1. Deploying LVS-DR
2. Configuring database host MySQL Databases
3. Install the Discuz on the RS1 and connect to the database host databases
4. Using Rsync+inotify to synchronize the RS1,RS2 Web site Directory
5. Testing
Experimental steps:
Network configuration:
# #由于LVS-DR on the network part of the configuration is more cumbersome, it is explained in detail in this
Lvs-director: #这里为临时配置, if you need to make a permanent entry, modify the configuration file yourself
Ifconfig eth0 172.16.100.2
Ifconfig eth0:0 172.16.100.1
Lvs-rs1: #这里为临时配置, if you need to make a permanent entry, modify the configuration file yourself
Ifconfig eth0 172.16.100.7 sysctl-w net.ipv4.conf.eth0.arp_ignore=1sysctl-w net.ipv4.conf.all.arp_ignore=1sysctl-w Net.ipv4.conf.all.arp_announce=2sysctl-w NET.IPV4.CONF.ALL.ARP_ANNOUNCE=2IFCONIFG lo:0 172.16.100.1 netmask 255.255.255.255 broadcast 172.16.100.1route add-host 172.16.100.1 Dev lo:0
Lvs-rs2: #这里为临时配置, if you need to make a permanent entry, modify the configuration file yourself
Ifconfig eth0 172.16.100.8sysctl-w net.ipv4.conf.eth0.arp_ignore=1sysctl-w net.ipv4.conf.all.arp_ignore=1sysctl-w Net.ipv4.conf.all.arp_announce=2sysctl-w NET.IPV4.CONF.ALL.ARP_ANNOUNCE=2IFCONIFG lo:0 172.16.100.1 netmask 255.255.255.255 broadcast 172.16.100.1route add-host 172.16.100.1 Dev lo:0
Ipvs configuration:
Lvs-director:
Ipvsadm-a-T 172.16.100.1:80-s wlc-p #由于没有共享session with persistent connection ipvsadm-a-T 172.16.100.1:80-r 172.16.100.7-g-W 2 IPV Sadm-a-T 172.16.100.1:80-r 172.16.100.8-g-W 1
Database Host Configuration:
DataBase:
Yum Install mysql-server #安装mysql数据库service mysqld start #启动mysql服务iptables-F #清空iptables规则mysql-uroot-p-e ' Create dat Abase discuzdatabase; ' #创建discuz数据库mysql-uroot-p-e ' Grant all on discuzdatabase.* to [email protected] '% ' identified by ' Youpass '; "#创建discuz用户并赋予管理discuzdatabase的权限mysql-uroot-p-e ' flush privileges; ' #刷新mysql权限
To configure the Web service:
# #注意事项: Due to some of the mechanisms of rsync+inotify, it is first fully configured on the RS1 discuz in the use of rsync synchronization
Lvs-rs1:
Self-referencing tutorials to install Discuz and httpd services
Configuration RSYNCD:
LVS-RS2:
vim/etc/rsyncd.conf #配置Rsyncd配置文件 uid=root #root为Rsync守护进程的用户 gid=root #root为Rsync守护进程的组 use Chroot=no #不使用chroot max Connections=0 #设置最大连接数, 0 for unrestricted log file=/var/log/rsyncd.log #配置日志文件位置 pid file=/var/run/rsyncd.pid #pid文件存放位置 lock file =/var/run/rsyncd.lock #锁文件存放位置 [WebDir] Path=/var/www/html/comment=rsync from 172.16.100.7 read Only=no list= No start rsync service #启动前检查防火墙规则和SElinux是否关闭 rsync--port=873--address=172.16.100.8--daemon
Lvs-rs1:
Synchronizing files
RSYNC-AVH--delete--progress/var/www/html/172.16.100.8::webdir
INotify Configuration
Installing INotify
./configure--prefix=/usr/local/inotify # #自行下载Inotify make && make install
Writing inotify Synchronization scripts
Vim inotify.sh
#START #!/bin/bash src= "/var/www/html/" host= "172.16.100.8" module= "WebDir"/USR/LOCAL/INOTIFY/BIN/INOTIFYWAIT-MR-- Timefmt '%d/%m/%y%h:%m '--format '%T%w%f '-E close_write,modify,delete,create,attrib $src | While read DATE time DIR FILE; DOFILECHANGE=${DIR}${FILE}/USR/BIN/RSYNC-AVH--delete--progress--exclude-from= "/usr/local/inotify/logs/ Rules.txt "[Email protected] $host:: $module &echo" at ${time} on ${date}, file $FILECHANGE is backed up via rsync " ;> $logdone #end
chmod a+x inotify.sh #给脚本添加执行权限./inotify.sh & #让脚本在后台运行
This article from the "The Anyisalin Blog" blog, reproduced please contact the author!
Rsync+inotify+lvs implementation of Discuz load balancing