linux服务器 rsync 服务搭建
下载及安装
wget https://download.samba.org/pub/rsync/src/rsync-3.1.3.tar.gz tar -zxvf rsync-3.1.3.tar.gz cd rsync-3.1.3 ./configure --prefix=/opt/rsync make && make install cd /opt/rsync cp bin/rsync /usr/bin
配置
#检查版本 rsync --version #配置文件 mkdir -p /opt/rsync cd /opt/rsync touch /etc/rsyncd.conf echo "rsync:111111"> rsyncd.secrets chmod 600 rsyncd.secrets touch rsyncd.motd
rsyncd.conf 配置文件内容:
# /etc/rsyncd: configuration file for rsync daemon mode # See rsyncd.conf man page for more options. # configuration example: port = 873 uid = root gid = root use chroot = yes read only = no write only = no hosts allow = 191.1.1.1 191.1.1.2 hosts deny = * max connections = 4 motd file = /opt/rsync/rsyncd.motd pid file = /opt/rsync/rsyncd.pid exclude = lost+found/ transfer logging = yes log file = /opt/rsync/rsync.log timeout = 900 ignore nonreadable = yes dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 [topic] path = /opt/aaa list = no #igore errors = yes #comment = ftp export area auth users = rsync secrets file = /opt/rsync/rsyncd.secrets #auth users = rsync_backup #虚拟用户名 #secrets file = /opt/rsync/conf/rsync.password #对应的密码 exclude = lost+found/ conf/ nam/
# 服务端启动rsync 命令
# 服务端启动rsync 命令 rsync --daemon --config=/opt/rsync/conf/rsyncd.conf 或者 rsync --daemon --config=/etc/rsyncd.conf #停止: pkill rsync #添加到自启动服务下 echo "/usr/bin/rsync --daemon --config=/opt/rsync/conf/rsyncd.conf" >> /etc/rc.local 或者 echo "/usr/bin/rsync --daemon --config=/etc/rsyncd.conf" >> /etc/rc.local
以上是服务端安装及配置
客户端配置
linux上一版会自带rsync ,如没有则进行如下操作:
客户端 配置 wget https://download.samba.org/pub/rsync/src/rsync-3.1.3.tar.gz tar -zxvf rsync-3.1.3.tar.gz cd rysnc-3.1.3 ./configure --prefix=/opt/rsync make && make install
mkdir -p /opt/rsync/conf cd /opt/rsync/conf/ echo "111111" >rsyncd.secrets #客户端只要密码,不用帐户 chmod 600 rsyncd.secrets
之后同步文件,或者查看文件即可
#查看rsync服务端文件列表 rsync --port=9873 --list-only rsync@10.5.24.45::45topic --password-file=/opt/rsync/conf/rsyncd.secrets #同步文件 rsync --port=9873 -avzP picsource@10.5.24.45::picsource /opt/aaa --password-file=/opt/rsync/conf/pic.password
如需要配置多台,以下提供批量操作方法
#如有rsync,客户端直接拷贝以下命令即可 mkdir -p /opt/rsync/conf mkdir -p /opt/rsync/shell/ cd /opt/rsync/conf/ echo "111111" >rsyncd.secrets chmod 600 rsyncd.secrets cd /opt/rsync/shell/ echo "rsync --port=9873 -avzP rsync@192.1.1.1::topic /opt/aaa/ --password-file=/opt/rsync/conf/rsyncd.secrets" > /opt/rsync/shell/rsync.sh chmod a+x /opt/rsync/shell/rsync.sh mkdir -p /opt/aaaecho "*/1 * * * * root /usr/sbin/ssh /opt/rsync/shell/rsync.sh" >> /etc/crontab
#定时任务会出现多个线程问题,造成内存被抢占。采用文件锁的方式解决,如下: */1 * * * * flock -xn /opt/rsync/shell/rsync.lock -c 'sh /opt/rsync/shell/rsync.sh'
浙公网安备 33010602011771号