CentOS一键配置rsync服务器脚本

15 年 ago jony 1

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