rsync 后台服务模式

来源:互联网 发布:下载excel表格软件 编辑:程序博客网 时间:2024/06/07 12:06
rsync 还有一种方式 就是 以后台的形式 运行,相当于作为服务端, 然后 让客户端 进行推或者拉

启动服务

rsync --daemon --config=/etc/rsyncd.conf

查看服务端 启动状况

# lsof -i:873
# ps aux |grep rsync

查重启 rsync 服务

pkill rsync 或者 kill ` cat /var/run/rsyncd.pid `
之后 启动服务: rsync --daemon --config=/etc/rsyncd.conf

192.168.1.6 centos1 作为daemon 端
192.168.1.7 centos2 作为客户端
首先 安装一下 这个命令
yum install -y rsync


在Daemon端 编写配置文件

vim /etc/rsyncd.conf

address = 192.168.1.6
port = 873
log file = /var/log/rsync.log
pid file = /var/run/rsync.pid
lock file = /var/run/rsync.lock
hosts allow = 192.168.1.0/24

[model]
path=/data/
use chroot = no
max connections = 100
read only = no
uid = rsync
gid = rsync
auth users = biaoge
secrets file = /etc/rsyncd.passwd




重点 说几个参数, readonly 就是只读,如果 client 只是拉取服务端数据 可以设置只读.
auth users 这个就是 要同步的一个虚拟用户
rsync -avzP aaa/biaoge@192.168.1.6::model --password-file=/etc/rsync.passwd

注意几个问题:

共享的path uid=rysnc 这个用户要 有权限 chown rsync /data
密码文件 一定要为600
chmod 600 /etc/rsyncd.passwd
chown -R rsync:rsync /data/

如果 有多个客户端可以指定 用空格分开 192.168.1.6 192.168.1.61 , 当然也可以指定一个网段
对于服务端的一些参数,可以通过 man rsyncd.conf 来查看



常见错误以及排查

防火墙,selinux 的问题。 一般 可以查看iptables selinux

[root@centos2 ~]# rsync -avzP biaoge@192.168.1.6::model 1111/
rsync: failed to connect to 192.168.1.6: No route to host (113)
rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.6]


[root@centos2 ~]# rsync -avzP biaoge@192.168.1.6::model 1111/
rsync: failed to connect to 192.168.1.6: Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.6]
可能是服务端 没有开启服务


[root@centos2 ~]# rsync -avzP biaoge@192.168.1.6::model 1111/
@ERROR: access denied to model from unknown (192.168.1.7)
rsync error: error starting client-server protocol (code 5) at main.c(1503) [receiver=3.0.6]
权限 不够导致的错误,hostallow 是否可以包含 192.168.1.7


现在 更改配置 read only =yes
[root@centos2 ~]# rsync -avz bbb biaoge@192.168.1.6::model --password-file=/etc/rsync.passwd
sending incremental file list
ERROR: module is read only
rsync error: syntax or usage error (code 1) at main.c(866) [receiver=3.0.6]
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(759) [sender=3.0.6]

服务端 model 下面的目录灭有了, 所有就不能拉取数据了。
[root@centos2 ~]# rsync -avzp biaoge@192.168.1.6::model 1111/ --password-file=/etc/rsync.passwd
@ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1503) [receiver=3.0.6]




The --password-file option may only be used when accessing an rsync daemon.
rsync error: syntax or usage error (code 1) at main.c(1238) [receiver=3.0.6]
这种 错误 , 原因可能有很多。很有可能是命令敲错了。

在客户端 少写一个冒号
rsync -avz biaoge@192.168.1.6:model /tmp/ --password-file=/etc/rsync.passwd
rsync -avz rsync://biaoge@192.168.1.6:model /tmp/ --password-file=/etc/rsync.passwd
还有可能在Server 端执行了命令。





Client 端 进行推拉 模型

pull

rsync -avzP biaoge@192.168.1.6::model ccc/ --password-file=/etc/rsync.passwd

push

rsync -avzP aaa/ biaoge@192.168.1.6::model --password-file=/etc/rsync.passwd


这里 注意一点 ,如果 要推 push 的话,带斜线 和不带斜线是有区别的。带斜线是 把 aaa 下面的内容 全部推给服务器, 如果不带斜线,就是把 aaa 以及 aaa/ 下面所有内容推送到服务器上.


Client 还有 另外一种写法:

rsync -avz rsync://biaoge@192.168.1.6/model /tmp/ --password-file=/etc/rsync.passwd


rsync -avz /etc/hosts rsync://biaoge@192.168.1.6/model --password-file=/etc/rsync.passwd






在客户端 要 写一个crontab
*/1 * * * * rsync -aqzP biaoge@192.168.1.6::model /data/ --password-file=/etc/rsync.passwd


当然 文本 还没有说,如何排除 一些文件,即同步的时候,有一些 文件,文件夹是不需要同步的 ,这个时候 可以 用一些方法,排除文件,在之后的博客 我会写的.



分享快乐,留住感动 ,你的‘顶‘,是我最大的鼓励.


0 0
原创粉丝点击