CentOS一键配置rsync服务器脚本

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

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

2、赋予脚本权限

  1. chmod +x rsync.sh

3、执行脚本

  1. ./rsync.sh

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

标签:CentosRsync 发布于:2019-10-13 20:58:03