When updating production applications, manual deployment is prone to errors and omissions. Here we use Linux’s built-in rsync functionality to automatically sync applications from the test machine to the production machine once they pass testing. We refer to the test machine as the Master and the production machine as the Slave. Applications are synced from the test machine to the production machine, from Master to Slave. All operations below are performed under the root account.
Master Configuration:
1. vi /etc/rsyncd.conf
2. Enter the following content:
- port = 873
- uid = root
- gid = root
- use chroot = yes
- read only = yes
- #limit access to private LANs
- hosts allow = YOURS
- max connections =10
- pid file = /var/run/rsyncd.pid
- log file = /var/log/rsyncd.log
- timeout = 300
- [testlink]
- path = /tmp/rsyntest
- list = yes
- auth users = root
- uid = root
- gid = root
- exclude = *.xml *.properties *.log
- secrets file = /etc/rsyncd.pass
- read only = no
3. If you need to exclude certain files, add exclude = *.xml *.properties *.log under the module section separated by spaces
4. mkdir -p /tmp/rsyntest
5. echo "this is test" > /tmp/rsyntest/test.test
6. echo "root:123456" > /etc/rsyncd.pass – Here root can be another Master user, but it must be a system user.
7. chmod 600 /etc/rsyncd.pass
8. Start rsync command: rsync –daemon –config=/etc/rsyncd.conf;
Stop rsync command: cat /var/run/rsyncd.pid | xargs kill -9 && rm -rf /var/run/rsyncd.pid.
Use the start command to start the Master’s rsync service.
9. Remember to enable iptables on the Master for the Slave machine
-A INPUT -m state –state NEW -m tcp -p tcp –dport 873 -s SlaveIPS -j ACCEPT
Slave Configuration and Testing
1. echo "123456" > /etc/rsyncd.pass
2. chmod 600 /etc/rsyncd.pass
3. cd /tmp/rsyntest
4. Note: The Slave’s /etc/rsyncd.pass should only contain the password, without the username root!!! Otherwise, when running with a specified pass file, rsync -vrtup –delete –password-file=/etc/rsyncd.pass root@masterIP::testlink /tmp/rsyntest, the following error will occur:
- @ERROR: auth failed on module testlink
- rsync error: error starting client-server protocol (code 5) at main.c(1527) [receiver=3.0.6]
On the Master side, the log file /var/log/rsyncd.log will contain the following error:
- 2012/04/09 15:07:48 [28566] name lookup failed for slaveIP: Name or service not known
- 2012/04/09 15:07:48 [28566] connect from UNKNOWN (slaveIP)
- 2012/04/09 15:07:48 [28566] auth failed on module testlink from unknown (slaveIP): password mismatch
5. If the Slave’s /etc/rsyncd.pass is identical to the Master’s, you can only run it as follows without specifying a pass file:
rsync -vrtup –delete root@masterIP::testlink /tmp/rsyntest You will be prompted to enter the password. Enter the password 123456 configured in /etc/rsyncd.pass, and the following output will appear:
- receiving incremental file list
- ./
- test.test
- sent 80 bytes received 183 bytes 75.14 bytes/sec
- total size is 30 speedup is 0.11
6. After sync is complete, run ls -alR|grep "^[-d]"|wc on the corresponding directories of both Master and Slave to check if the folder and file counts match.
rsyncd.conf Configuration Reference and rsync Command Details:
http://hi.baidu.com/xc_hai/blog/item/0ee61e8e321017f2503d9288.html
