Nothing to do, build a load Balancer cluster, as for the load Balancing cluster construction process, find time to write down. This time the main write file synchronization between the cluster, as well as the online test environment to build.
I have seen a lot of companies have no online testing environment, really collapsed, do not build how to ensure that the line and the environment consistent.
I use three servers this time:
192.168.138.3 Web Server
192.168.138.4 Web Server
192.168.138.10 Web server + on-line test environment + source Station
Of these, 3 4 servers serve as Web servers in the cluster, and are part of the load Balancing cluster.
10 of these servers are not open to the world, the Code is published to the server, tested on that server, and the program is synchronized to other clustered servers by the server while the site background and automatic scripts are located on the server. (If you are able to configure the server for security, you can only access your company's internal network, connect to the internal network via VPN at home, so that you can secure the background)
This article is for everyone rsync service, as for the IP configuration, Web server building, you can see my previous article.
Here we for the development of convenience, on the 10 server to establish a rule, that is, as long as the rsync.txt exists we will start synchronization, so long as the development upload the file synchronization begins, the synchronization is completed automatically delete the file.
The first step: the author here is installed centos6.4 has been installed by default rsync so I no longer install, not installed can install themselves, the process is relatively simple
Step Two: Install INotify Inotify-tools
The author here centos6.4 has been installed by default inotify, if you want to see whether the installation can use the following command
Ll/proc/sys/fs/inotify
If the following three items are listed, the certificate has been installed
-rw-r--r--1 root root 0 February 1 13:59 max_queued_events
-rw-r--r--1 root root 0 February 1 13:59 max_user_instances
-rw-r--r--1 root root 0 February 1 13:59 max_user_watches
No installed readers can install themselves, and then we need to install the Inotify-tools tool
tar -zxvf inotify-tools-3.14. Tar . GZCD inotify-tools-3.14. /configure--prefix=/usr/local/inotify-Toolsmake doinstall
Step Three: Configure the client server
Make sure you figure it out before you tell me. 10 is the client 3 4 is the service side this does not fall down is 10 of the files synchronized to 3 4 above
First configure the 3 4, where I post my own configuration file/etc/rsyncd.conf
UID =Nobodygid=Nobodyusechroot=Nomax Connections=TenStrict Mode=Nopidfile=/var/run/Rsyncd.pidlockfile=/var/run/Rsync.locklogfile=/usr/data/rsync/Rsyncd.log[laiwojia-Data]path=/usr/website/html/www.laiwojia.la/data/Comment=web4 Filesignore errorsread only=NoWriteNoly =nohosts Allow=192.168.138.10hosts Deny= *List=falseUID=Rootgid=Rootauth Users=laiwojiasecretsfile=/usr/local/rsync/conf/Server.pass[laiwojia]path=/usr/website/html/www.laiwojia.la/Comment=web4 Filesignore errorsread only=NoWriteNoly =nohosts Allow=192.168.138.10hosts Deny= *List=falseUID=Rootgid=Rootauth Users=laiwojiasecretsfile=/usr/local/rsync/conf/server.pass
We have configured here two modules ' laiwojia-data ' and ' Laiwojia ', where ' Laiwojia-dada ' as long as the changes are to be synchronized (think of the background on the 10 above, then the data inside the file is the background generated persistent files, Background configuration, and then the entire cluster is common), and ' Laiwojia ' This module is the module used to publish the system, you need to have a ' rsync.txt ' file in the site to synchronize. (we can see that the files in ' data ' cannot be published by the publishing system.)
Looking at the above configuration, we understand that the '/usr/website/html/www.laiwojia.la/data/' directory must exist, '/usr/local/rsync/conf/server.pass ' This secret file must also exist
The contents of the secret file are
laiwojia:123abc+-
Remember 3 4 as a service-side password file to have a prefix some kinky written ' 123abc+-' will not go through
Then we configure the 10, where I post the configuration file
UID ==chroot =ten=file =/var/run/ file =/var/run/file =/usr/data/rsync/rsyncd.log
Then also to create a secret file '/usr/local/rsync/conf/server.pass ' because 10 is the client, so the secret does not have a prefix
123abc+-
Fourth step: Writing shell scripts
The first is to change the shell script for synchronization, we named ' inotify-ha-rsync.sh ' content as
#!/bin/Bashhost3=192.168.138.3Host4=192.168.138.4src=/usr/website/html/www.laiwojia.la/data/Dst3=laiwojia-Datadst4=laiwojia-Datauser=Laiwojia/usr/local/inotify-tools/bin/inotifywait-mrq--timefmt'%d/%m/%y' --format'%T%w%f%e' -e modify,delete,create,attrib $src| whileRead Files Do/USR/BIN/RSYNC-VZRTOPG--delete--progress--password-file=/usr/local/rsync/conf/server.pass $src [email protected] $host 3:: $DST 3/USR/BIN/RSYNC-VZRTOPG--delete--progress--password-file=/usr/local/rsync/conf/server.pass $src [email protected] $host 4:: $DST 4Echo "${files} was RSYNCD">>/tmp/rsync.log2>&1 Done
OK, let's test it.
Build the test.php in the '/usr/website/html/www.laiwojia.la/data/' directory and rewrite its contents, we'll look at the results (run the shell beforehand)
vim test.php# Below is content <? Phpthis is a testhello Tom!
See the results of the operation
And see if there are test.php found on the 3 and 4 machines, two have test.php files in them, so let's look at the content.
Cat test.php
<?php
This is a test
Hello, Tom.
OK, this real-time sync is done.
We're going to look at the rest. Considering the deployment of the online test, we'll start by creating a shell script named Ha-rsync.sh, as in the following
!/bin/Bashhost3=192.168.138.4Host4=192.168.138.3src=/usr/website/html/www.laiwojia.la/Excludedir= $src"data/"$src"Rsync.txt"Dst3=Laiwojiadst4=Laiwojiauser=Laiwojiarsync_file=${SRC}"Rsync.txt"if[-F"$rsync _file" ] Then/USR/BIN/RSYNC-VZRTOPG--delete--progress--exclude= $excludedir--password-file=/usr/local/rsync/conf/server.pass $src [email protected] $host 3:: $DST 3/USR/BIN/RSYNC-VZRTOPG--delete--progress--exclude= $excludedir--password-file=/usr/local/rsync/conf/server.pass $src [email protected] $host 4:: $DST 4fiRM-RF $SRC"Rsync.txt"
Okay, let's test it.
Touch Rsync.txt Touch test.html
Then run the script and go to each server to see if it's all there. In this case, if you send the code to 10, no rsync.txt will not sync, then this is the test can be carried out on-line test, and so on, the development will upload a rsync.txt and then start syncing
Of course, there can be more complex, such as security, some configuration files do not let it sync to avoid one day you sent the wrong to send the local, you can also specify that the directory is not synchronized, and so on, these can be achieved, but the shell is a little more complicated to write
RSYNC enables load Balancing cluster file synchronization to build online test deployment environment