rsync 3.1.1源码编译安装配置
server端配置
vim /usr/local/rsyncd.conf
pid file = /var/run/rsyncd.pid
port = 873
pid = root
gid = root
use chroot = no
max connections = 200
timeout 600
lock file = /var/run/rsyncd.lock
log file = /var/run/rsyncd.log
secrets file = /usr/local/rsyncd.secrets
motd file = /etc/rsyncd.motd
[test]
path = /home/
ignore errors
read only = true
list = false
hosts allow = *
#hosts deny = 0.0.0.0/32
auth users root #该用户系统中存在且对后面指定的备份目录拥有权限
comment = ocpyang test
vim /usr/local/rsyncd.motd
++++++++++++++++++++++++++++++++++++
Wlecome to ocpyang rsync services #欢迎信息
++++++++++++++++++++++++++++++++++++
-指定rsync访问的密码,密码不需要和系统账号密码相同
vim /usr/local/rsyncd.secrets
root:snow01
ln -s /usr/local/rsyncd.conf /etc/rsyncd.conf
ln -s /usr/local/rsyncd.motd /etc/rsyncd.motd
ln -s /usr/local/rsyncd.secrets /etc/rsyncd.secrets
chmod 600 /usr/local/rsyncd.secrets
chown root:root /usr/local/rsyncd.secrets
启动rsync
/usr/bin/rsync --daemon --config=/etc/rsyncd.conf
netstat -lntp | grep 873
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 10689/rsync
tcp 0 0 :::873 :::* LISTEN 10689/rsync
pkill rsync
客户端服务器配置
vim /etc/rsyncd.secrets
snow01 #密码
chmod 600 /etc/rsyncd.secrets
rsync -vzrtopg --progress --delete [email protected]::test /ocpyang/
rsync -vzrtopg --progress --delete [email protected]::test /ocpyang/ --password-file=/etc/rsyncd.pwd
新建同步脚本
vim /rsync.sh
rsync -vzrtopg --progress --delete [email protected]::test /testbak/
rsync -vzrtopg --progress --delete [email protected]::test /testbak/ --password-file=/etc/rsyncd.pwd
chmod +x /root/rsync.sh #赋予权限
手动同步文件
cd /
./rsync.sh
自动同步:
crontab -e
0,5 * * * * /rsync.sh #每隔五分钟同步一次
16 10 * * * /root/rsync.sh #每天16点01同步一次
重启
/etc/init.d/cron restart
如果你只需同步一次可以后台运行
nohup ./rsync.sh &
nohup用法
查看当前终端下的后台进程:
直接执行:jobs
直接输入:fg {jobid} //这里的{jobid}是通过jobs命令中看到的进程前[]中的数字1.2.3.4等。
例如 fg 1
ctrl +z 暂停
ctrl +c 停止