centos7自带rsync,今天简单记录下。
yum -y install rsync #启动rsync服务
systemctl start rsyncd.service systemctl enable rsyncd.service #检查是否已经成功启动
netstat -lnp|grep 873
rsync安装配置步骤
服务器端:
1.修改默认配置文件/etc/rsyncd.conf,该成如下:
# /etc/rsyncd: configuration file for rsync daemon mode
# See rsyncd.conf man page for more options.
# configuration example:
uid = root //设置运行rsync 进程的用户
gid = root
use chroot = no
max connections = 4
# pid file = /var/run/rsyncd.pid //CentOS7中yum安装不需指定pid file 否则报错
lock file=/var/run/rsyncd.lock
log file = /var/log/rsyncd.log //此文件定义完成后系统会自动创建
exclude = lost+found/
transfer logging = yes
timeout = 900
ignore nonreadable = yes //同步时跳过没有权限的目录
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 //传输时不压缩的文件
# [ftp] //系统自带例子,没删
# path = /home/ftp
# comment = ftp export area
[simba] //此名字即客户端使用rsync来同步的路径,只是模块名称,无需和文件夹名字相同
path=/usr/local/simba //实际需要同步的路径
comment=simba //和中括号里名字一样就行,备注启动进程可以显示的内容
ignore errors
read only=yes //表示可以pull
write only=no //表示可以push
list=no
auth user=rsyncuser //客户端获取文件的身份此用户并不是本机中确实存在的用户
secrets file=/etc/rsyncd.passwd //用来认证客户端的秘钥文件 格式 USERNAME:PASSWD 此文件权
//限一定需要改为600,且属主必须与运行rsync的用户一致。
hosts allow=* //允许所有主机访问
2.创建密钥文件
echo 'rsyncuser:123456'>/etc/rsyncd.passwd //文件用户名和路径为上面定义,别写错,密码自己定
chmod 600 /etc/rsyncd.passwd //修改权限
3.启动rsync服务
systemctl start rsyncd.service
systemctl enable rsyncd.service
启动后可以查看下日志,是否正常
tail /var/log/rsyncd.log
是否有如下提示:
rsyncd version 3.0.9 starting, listening on port 873
客户端:
1.创建密码文件
echo '123456' >>/etc/rsyncd.passwd //注意这里只需要服务器rsyncd.passwd 中的密码
chmod 600 /etc/rsyncd.passwd
2.测试
将服务器这个ip下的simba目录中内容同步到本地客户机 /tmp目录
rsync -auv --password-file=/etc/rsyncd.passwd rsyncuser@10.5.5.235::simba /tmp
若要在crontab中添加自动同步,则必须指定--password-file 且rsyncuser一定为rsyncd.passwd中定义的,rsynctest 为服务器端【】中定义的
rsync -vzrtopg --delete --port 878 --progress /da/ lgsync@192.168.30.171::data --password-file=/etc/rsyncd.passwd
rsync -vzrtopg --delete --port 878 --progress lgsync@192.168.30.171::data /da/ --password-file=/etc/rsyncd.passwd
服务端
vi /etc/rsyncd.conf
uid = root gid = root port = 878 use chroot = no max connections = 100 timeout = 600 pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock log file = /var/log/rsyncd.log exclude = lost+found/ transfer logging = yes ignore nonreadable = yes dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 [data] comment=data path = /data/rsyncdata/ ignore errors read only = no list = no hosts allow = * auth users = lgsync secrets file = /etc/rsyncd.passwd [lgbak] path = /data/leguan_bak/ ignore errors read only = no list = no hosts allow = 10.30.188.194 120.35.10.209 hosts deny = * auth users = lgsync secrets file = /etc/rsyncd.passwd
服务端 vi /etc/rsyncd.passwd
lgsync:root@2018
客户端 vi /etc/rsyncd.passwd
root@2018
rsync -vzrtopg --delete --port 878 --progress /da/ lgsync@192.168.30.171::data --password-file=/etc/rsyncd.passwd
rsync -vzrtopg --delete --port 878 --progress lgsync@192.168.30.171::data /da/ --password-file=/etc/rsyncd.passwd
inotify-tools可通过EPEL存储库获得。安装EPEL:
客户端
yum install -y epel-release && yum update
然后安装包:
yum install inotify-tools
vi /data/inotify.sh
#!/bin/bash
INOTIFY_CMD="inotifywait -mrq -e modify,create,attrib,move,delete /da/"
RSYNC_CMD="rsync -vzrtopg --delete --port 878 --progress /da/ lgsync@192.168.30.171::data --password-file=/etc/rsyncd.passwd"
$INOTIFY_CMD | while read DIRECTORY EVENT FILE
do
if [ $(pgrep rsync | wc -l) -le 0 ] ; then
$RSYNC_CMD
fi
done
./inotify.sh
后面运行 nohup ./inotify.sh &
或 nohup sh inotify.sh &
v3.14-8.el7。×86_64截至18-18-2018
(adsbygoogle = window.adsbygoogle || []).push({});