Manual rsync Deployment

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:

Conf代码  收藏代码
  1. port = 873  
  2. uid = root  
  3. gid = root  
  4. use chroot = yes  
  5. read only = yes  
  6. #limit access to private LANs  
  7. hosts allow = YOURS  
  8. max connections =10  
  9. pid file = /var/run/rsyncd.pid  
  10. log file = /var/log/rsyncd.log  
  11. timeout = 300  
  12.   
  13. [testlink]  
  14. path = /tmp/rsyntest  
  15. list = yes  
  16. auth users = root  
  17. uid = root  
  18. gid = root  
  19. exclude = *.xml *.properties *.log  
  20. secrets file = /etc/rsyncd.pass  
  21. 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:

Java代码  收藏代码
  1. @ERROR: auth failed on module testlink  
  2. 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:

Java代码  收藏代码
  1. 2012/04/09 15:07:48 [28566] name lookup failed for slaveIP: Name or service not known  
  2. 2012/04/09 15:07:48 [28566] connect from UNKNOWN (slaveIP)  
  3. 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:

Shell代码  收藏代码
  1. receiving incremental file list  
  2. ./  
  3. test.test  
  4.   
  5. sent 80 bytes  received 183 bytes  75.14 bytes/sec  
  6. 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

Leave a Comment

Your email address will not be published.