CentOS key configure shell script rsync Server

1, save the following code to a file, upload it to the server, the name 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 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. # This line is required by the /etc/init.d/rsyncd script
  21. pid file = /var/run/rsyncd.pid
  22. port = 873
  23. #address = $serverip
  24. #uid = nobody
  25. #gid = nobody
  26. uid = root
  27. gid = root
  28. use chroot = yes
  29. read only = yes
  30. #limit access to private LANs
  31. hosts allow=$allowip
  32. hosts deny=*
  33. max connections = 5
  34. motd file = /etc/rsyncd/rsyncd.motd
  35. #This will give you a separate log file
  36. #log file = /var/log/rsync.log
  37. #This will log every file transferred – up to 85,000+ per user, per sync
  38. #transfer logging = yes
  39. log format = %t %a %m %f %b
  40. syslog facility = local3
  41. timeout = 300
  42. [home]
  43. path = $rsyncpath
  44. list=yes
  45. ignore errors
  46. auth users = $username
  47. secrets file = /etc/rsyncd/rsyncd.secrets
  48. EOF
  49. echo “$username:$password” > /etc/rsyncd/rsyncd.secrets
  50. chmod 600 /etc/rsyncd/rsyncd.secrets
  51. cat >/etc/rsyncd/rsyncd.motd<<EOF
  52. +++++++++++++++++++++++++++
  53. + centos.bz  rsync  2011-2012 +
  54. +++++++++++++++++++++++++++
  55. EOF
  56. /usr/bin/rsync –daemon  –config=/etc/rsyncd/rsyncd.conf
  57. echo “/usr/bin/rsync –daemon  –config=/etc/rsyncd/rsyncd.conf” >>/etc/rc.d/rc.local
  58. ps -aux | grep rsync

2、Given Script permission

  1. chmod +x rsync.sh

3、Execute scripts

  1. ./rsync.sh

4、Clients also need to install rsync

Leave a Reply

Your email address will not be published. Required fields are marked *