sersync服务部署

一,部署rsync
#yum -y install rsync
#创建服务用户:useradd rsync -s /sbin/nologin -M(不创建家目录)
#创建配置文件:vim /etc/rsyncd.conf
id = root
gid = root
use chroot = no
max connections = 2000
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 192.168.1.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password

[test]
comment = test
path = /data/test

[data]
comment = data
path = /data
#创建rsync同步密码文件,并设置权限为600
[root@122_server ~]# echo "oldboy"> /etc/rsync.password
[root@122_server ~]# cat /etc/rsync.password
oldboy
[root@122_server ~]# chmod 600 /etc/rsync.password
[root@122_server ~]# ll /etc/rsync.password 
-rw------- 1 root root 20 Sep 23 09:51 /etc/rsync.password
#特别提醒(尤其是新手这里有巨坑,不要问我是怎么知道的因为我就是新手):sersync服务端密码文件只写密码,不要写用户名;
#以为sersync是将监控变动的文件推到客户端,相对而言对方是rsync的服务端;否则会报“@ERROR: auth failed on module tests”
#sersync客户端文件中要写用户名和密码:“echo "rsync_backup:oldboy"> /etc/rsync.password
#rsync客户端只需要安装和创建密码文件即可,密码文件中不需要用户名;(客户端安装方式参考以上步骤,此处略)
#启动服务:rsync --daemon
#加入开机自启
vim /etc/rc.local
#在文件末尾插入:rsync --daemon
#master与slave端都创建rsync同步目录(这里只用test做测试)
mkdir /data/test -p
#手动同步文件
rsync -avzP /data/test/001.txt [email protected]::test/ --password-file=/etc/rsync.password
"""
sending incremental file list
001.txt

sent 68 bytes  received 27 bytes  17.27 bytes/sec
total size is 0  speedup is 0.00
"""
#此处容易报错“@ERROR: auth failed on module test”(下面有可能导致此问题的的解决方案)
二、部署sersync
1、下载安装包:
2,部署软件
tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
mkdir -p /usr/local/sersync-2.5.4/{bin,conf,log}
cp GNU-Linux-x86/confxml.xml /usr/local/sersync-2.5.4/conf/
cp GNU-Linux-x86/sersync2 /usr/local/sersync-2.5.4/bin/
ln -s /usr/local/sersync-2.5.4/ /usr/local/sersync
#配置sersync
vim conf/confxml.xml
<sersync>
    <localpath watch="/data/test"> # 定义本地要同步的目录
        <remote ip="192.168.1.115" name="test"/> # 同步到哪台机器上 /data/test模块rsync端模块名字
    </localpath>
    <rsync>
        <commonParams params="-aruz"/>
        <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
       # 修改内容为 rsync的密码文件以及 同步所使用的账号
        <userDefinedPort start="false" port="874"/><!-- port=874 -->
        <timeout start="false" time="100"/><!-- timeout=100 -->
        <ssh start="false"/>
    </rsync>
    <failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
   # 当同步失败后,日志记录到/usr/local/sersync/logs/rsync_fail_log.sh文件中,并且每60分钟对失败的log进行重新同步
    <crontab start="false" schedule="600"><!--600mins-->
        <crontabfilter start="false">
            <exclude expression="*.php"></exclude>
            <exclude expression="info/*"></exclude>
        </crontabfilter>
    </crontab>
    <plugin start="false" name="command"/>
</sersync>

#启动服务

/usr/local/sersync/bin/sersync2 -d -r -o /usr/local/sersync/conf/confxml.xml

"""
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /data/test && rsync -aruz -R --delete ./ [email protected]::test --password-file=/etc/rsync.password >/dev/null 2>&1
run the sersync:
watch path is: /data/test
"""
 
#@ERROR: auth failed on module test
#rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
关于这个auth失败的问题,有以下可能的情况:
1、密码输入错误: 请再次确认你登录用户的密码无误 2、secrets file格式错误: secrets file的文件格式是 rsync_backup:oldboy 表示rsync_backup用户的rsync密码是oldboy 3、配置文件写错: 最坑爹的一个,看看自己模块配置下面的auth users、secrets file有没写错 4、secrets file权限问题 服务端的secrets file权限必须是600, 可以使用chmod 600 /data/test


5、secrets file文件拥有者与rsync运行者 服务端rsync服务是以什么用户运行,则必须保证secrets file文件拥有者必须是同一个 假设root运行rsync --daemon,则secrets file的owner也必须是root 6、如果是以--password-file=file的方式附带密码 确保客户端密码文件格式无误,与服务端的密码文件不同, 客户端的不用加上用户名,即直接是 oldboy

 

 
* 参考oldboy视频整理

猜你喜欢

转载自www.cnblogs.com/sparkss/p/11570644.html