Foreword
Nginx load balancing in the face of the need to withstand high concurrent situation, while there will be two planes the same directory content needs to be consistent
rsync + inotify is a good solution, compared to rsync + sersync more stability when dealing with large numbers of files
The film will not go Bowen installation preparation, details to view past articles
First, install rsync and modify /etc/rsyncd.conf
install yum - the y-rsync # rsync common profile, comments configuration is not written in a configuration back, otherwise there will be problems uid = root gid = root use chroot = 0 Port = 873 # permit ip access settings, configure according to actual needs, set here for the convenience of the whole network segment *, in a production environment for security specify ip and hosts the allow = * max Connections = 0 timeout = 300 pid File = / var / RUN / rsyncd.pid Lock File = / var / RUN / rsyncd.lock log File = / var / log / rsyncd.log log the format =% T% A% m%% F B Transfer the logging = Yes the syslog Facility= Local3 # square brackets module declaration, the corresponding name, here master_web corresponding to the main web machine configuration, the server may both [slave_web], easy inotify Script Configuration [master_web] # Specify the current block synchronization path on rsync server, this parameter must be specified path = / the Data / dh / the Upload / # comments can be the same module name as the server are slave_web the comment = master_web the ignore errors # whether to allow clients to upload files the Read only = NO List = NO # Specifies a list of user names separated by spaces or commas, and only these users are allowed to connect the module auth = the users rsync # save the password and user name file, you need to generate their own secrets file = /etc/rsyncd.passwd
Second, create /etc/rsyncd.passwd and /root/rsyncd.passwd
# /Etc/rsyncd.passwd content format Username: Password rsync: 123456 # /root/rsyncd.passwd only need to fill in the content from the server's password 123456
Third, the password file to assign permissions
chmod 600 /etc/rsyncd.passwd
chmod 600 /root/rsyncd.passwd
Fourth, the way to start the rsync daemon service and add the boot from the start
/usr/bin/rsync --daemon --config=/etc/rsyncd.conf echo "/usr/bin/rsync --daemon --config=/etc/rsyncd.conf">>/etc/rc.local
Fifth, verify that the code synchronization
Code to the main web server push, 192.168.10.230 command from a web server is configured as a module name rsyncd.conf from the web server, the web server from the IP, slave_web
the rsync is configured from rsyncd.passwd web server username the rsync -vzrtopg --delete --progress / Data / DH / Upload / [email protected] slave_web --password-File :: = / the root / rsyncd.passwd
Sixth, install inotify (two servers to be installed)
wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz --no-check-certificate tar -zxvf inotify-tools-3.14.tar.gz mkdir /usr/local/inotify cd inotify-tools-3.14.tar.gz ./configure --prefix=/usr/local/inotify make && make install # 查看是否安装成功 ls -alh /usr/local/inotify/bin/inotify* # 建立软连接 ln -s /usr/local/inotify/bin/inotifywait /usr/bin/inotifywait ln -s /usr/local/inotify/bin/inotifywatch /usr/bin/inotifywatch
Seven simultaneous monitoring script configuration rsync.sh
#!/bin/bash src=/data/dh/upload/ des=master_web user=rsync host="172.17.0.11" cd $src /usr/bin/inotifywait -mrq --exclude=public --exclude=themes --exclude=wap_themes --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e modify,delete,create,attrib ./ | while read file do rsync -vzrtopg --delete --progress --exclude=themes --exclude=wap_themes --exclude=public $src $user@$host::$des --password-file=/root/rsyncd.passwd echo "$file was rsynced" >> /tmp/rsync.log 2>&1 done
Eight, to empower and run the configuration script
the X-+ chmod / root / rsync.sh nohup SH /root/rsync.sh & # build daemon running rsync.sh script echo "nohup SH /root/rsync.sh &" >> / etc / rc.local Note: Primary two-way real-time synchronization from a web server configured exactly the same, just modify the parts of the module name and ip to