1、保存下面的代码为一个文件,上传到服务器端,名称为rsync.sh

  1. #!/bin/bash
  2. #rsync Written by zhumaohai
  3. #For more information please visit http://www.centos.bz
  4. echo “Please input the rsync username:”
  5. read username
  6. echo “Please input the rsync username password:”
  7. read password
  8. echo “Please input the server ip address:”
  9.  
  10. read serverip
  11. echo “Please input the allow ip address:”
  12. read allowip
  13. echo “Please input the path you want to rsync:”
  14. read rsyncpath
  15. echo “==========================input all completed========================”
  16. echo “==========================install rsync========================”
  17. yum -y install rsync
  18. useradd $username
  19. mkdir /etc/rsyncd
  20. cat >/etc/rsyncd/rsyncd.conf<<eof
  21. # Minimal configuration file for rsync daemon
  22. # See rsync(1) and rsyncd.conf(5) man pages for help
  23. # This line is required by the /etc/init.d/rsyncd script
  24. pid file = /var/run/rsyncd.pid
  25. port = 873
  26. address = $serverip
  27. #uid = nobody
  28. #gid = nobody
  29. uid = root
  30. gid = root
  31. use chroot = yes
  32. read only = yes
  33. #limit access to private LANs
  34. hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0 $allowip
  35. hosts deny=*
  36. max connections = 5
  37. motd file = /etc/rsyncd/rsyncd.motd
  38. #This will give you a separate log file
  39. #log file = /var/log/rsync.log
  40. #This will log every file transferred – up to 85,000+ per user, per sync
  41. #transfer logging = yes
  42. log format = %t %a %m %f %b
  43. syslog facility = local3
  44. timeout = 300
  45. [$username home]
  46. path = $rsyncpath
  47. list=yes
  48. ignore errors
  49. auth users = $username
  50. secrets file = /etc/rsyncd/rsyncd.secrets
  51. eof
  52. echo “$username:$password” > /etc/rsyncd/rsyncd.secrets
  53. cat >/etc/rsyncd/rsyncd.motd<<eof
  54. +++++++++++++++++++++++++++
  55. + centos.bz  rsync  2011-2012 +
  56. +++++++++++++++++++++++++++
  57. eof
  58. /usr/bin/rsync –daemon  –config=/etc/rsyncd/rsyncd.conf
  59. ps -aux | grep rsync

2、赋予脚本权限

  1. chmod +x rsync.sh

3、执行脚本

  1. ./rsync.sh

4、客户端同样需要安装rsync
具体配置见http://www.centos.bz/2011/06/rsync-server-setup/