1. Create a configuration file
The configuration file does not exist and needs to be created yourself
mkdir /etc/rsyncdtouch /etc/rsyncd/rsyncd.conf #主配置文件; touch /etc/rsyncd/rsyncd.secrets #用户名密码配置文件;touch /etc/rsyncd/rsyncd.motd #连接时提示信息chmod 600 /etc/rsyncd/ rsyncd.secrets #将密码权限修改, added security echo "wys:123456" >> /etc/rsyncd/rsyncd.secrets # Write the account and password, note that the account must be the system account, and the password is a custom password vim /etc/rsyncd/rsyncd.confuid = root # Users running rsync gid = root #运行rsync的用户组use chroot = yes #是否chroot到访问目录max connections = 4 #最大并发数port = 873 #运行端口 #motd file = /etc/rsyncd/ rsyncd.motd #连接时提示信息log file = /var/log/rsyncd.log #指定保存日志文件pid file = /var/run/rsyncd.pid #运行Pid文件 [wys] #模块名称 path = /tmp/test #同步目录 comment = a test #注释 ignore errors #忽略--delete caused by I/O error hosts allow = 192.168.1.0/24 #该模块允许IP hosts deny = 0.0.0.0/32 #该模块禁止的IP auth users = wys #该模块认证的用户 secrets file = /etc/rsyncd/rsyncd.secrets #登陆用户名密码
2. Create a startup script
[[Email protected] shell]# vim rsyncd.py #!/usr/bin/env python# chkconfig: 35 24 96## date: 2015.11.10# ver: 1.0# use centos 6.x# config: /etc/rsyncd/rsyncd.conf# exit : # 0 ==> exit_success# 1 ==> EXIT_FAILUREimport sys,os,commands,getopt,signalrsync = '/usr/bin/ Rsync ' cfile = '/etc/rsyncd/rsyncd.conf ' pfile = '/var/run/rsyncd.pid ' prog = ' Rsync ' daemon = '%s --daemon --config=%s % (rsync,cfile) process = Os.popen ("ps -ef | grep rsync | grep -v ' grep ' | awk ' { PRINT $2} '). Read (). split (' \ n ') [0]if os.path.exists (PFILE): rpfile = open (PFILE). read (). Strip () else: rpfile = "Def start (): if not os.path. Exists (rsync): print "fatal: no such Programme " sys.exit (1) if not Os.path.exists (CFILE): print "Fatal: config file does not exist " sys.exit (1) print "start %s:" % prog if os.path.exists (PFILE): if PROCESS == RPFILE: print "%s is runing!" % prog else: try: os.remove (PFILE) except: print "[Error] pid file delete failed, please check! " else: print "delete the pid File ... " start ( ) else : a,b = Commands.getstatusoutput (daemon) if a !=0 : print b sys.exit (1) p rint "[OK]" def stop (): print "stop %s:" % prog try: os.kill (int (RPFILE), signal. SIGKILL) except (ioerror, valueerror): print "%s is not runing!" % prog else: if Os.path.exists (PFILE): try: os.remove (PFILE) except: print "[Error] pid file delete failed, please check! " else: print "Delete the pid file ..." stop () else: print "[OK]" if __name__ == ' __main__ ': arg = sys.argv[1:] if Len (sys.argv[1:]) > 1: print "Too many arguments! only one! " sys.exit (0) if not arg : print "You must enter parameters!" sys.exit (0) if ' starT ' in arg: start () sys.exit (0) elif ' Stop ' in arg: stop () sys.exit (0) elif ' restart ' in arg or ' reload ' in arg: stop () start () sys.exit (0) else: print "only supports the following parameters: [start| Stop|restart|reload] "
I recently learned Python, practice, write or find, this script is written in Shell simple ~
Then configure Chkconfig
CP Rsyncd.py/etc/init.d/rsyncdchkconfig--add RSYNCD
Start the RSYNCD service
[[Email protected] shell]# service RSYNCD StartStart Rsync:[ok]
3. Client Connection
RSYNC-AVZP [email protected]::wys/tmp/test #格式是 [email protected]/ip::module is the last sync to local folder description:-a parameter, equivalent to-rlptgod,-r is recursive-l is the link file, which means to copy the link file;-p to maintain the original file permissions;-T to keep the file in its original user group;-O to keep the original owner of the file;-D is equivalent to block device files;-Z transfer time compression;-P transfer progress; Try it yourself. can read the document;
Simple introduction to other synchronization parameters
RSYNC-AVZP--delete [email protected]::wys/tmp/test #表示客户端上的数据要与服务器端完全一致, delete if there are files that do not exist on the server in the directory. Rsync-avzp--delete-- Password-file=/root/rsync.password [email protected]::wys/tmp/test #这是当我们以wys用户登录rsync服务器同步数据时, password will be read Rsync.password This file, the file is saved as a pure password, echo "123456" >/root/rsync.password
This article is from "Cool King" blog, please be sure to keep this source http://coolk.blog.51cto.com/1752609/1711543
Rsync Service-Side quick Build