有6台内网机器,需要使用一些同样的目录和工具,比如tools,每个东西都单独传到6台机器太老土了,于是使用rsync来做文件自动同步。打算拿一台机器来当入口机器。如果后期发布代码在不考虑使用git的条件下,也可以做到统一入口:
安装参考:
https://www.cnblogs.com/tomato0906/articles/7989222.html
我的rsyncd.conf 配置的写法:vim /etc/rsyncd.conf
uid = root
gid = root
use chroot = yes
max connections = 5
pid file = /var/run/rsyncd.pid
port = 873
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
log file = /var/log/rsync.log
#limit access to private LANs
hosts allow=10.248.32.0/255.255.255.0
motd file = /etc/rsyncd.motd
[ftp1]
path = /home/ftp1
comment = ftp export area
[tools]
path = /home/scapp/tools
list = yes
comment = This is tools backup
secrets file = /etc/rsyncd/rsyncd.secrets
exclude = easylife/ samba/
设置密码文件
mkdir /etc/rsyncd
vim /etc/rsyncd/rsyncd.secrets
chown root.root /etc/rsyncd/rsyncd.secrets
dhmod 600 /etc/rsyncd/rsyncd.secrets
设置欢迎内容
vim /etc/rsyncd.motd
打开服务端守护进程
rsync --daemon
ps: 修改rsyncd.conf 不需要重启服务器进程。
在另一台机器上使用命令列出文件:
rsync --list-only root@10.248.32.131::tools
使用命令完成同步:
rsync -avzP root@10.248.32.131::tools /home/scapp/tools
接下来设置定时脚本自动同步:
!/bin/bash
source /etc/profile
date
rsync -avzP root@10.248.32.131::tools /home/scapp/tools
*/10 * * * * sh /root/autosh/tools_backup.sh >> /root/autosh/tools_backup.sh_log ;
# */10 * * * * /usr/bin/rsync -avzP root@10.248.32.131::tools /home/scapp/tools >> /root/autosh/backup.log
最后记一个很棒的东西,没准以后用得上: inotify