程序笔记   发布时间:2022-07-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了基于rsync daemon 实现 sersync大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

基于rsync daemon 实现 sersync

1,环境:
数据服务器:10.1.1.40
备份服务器:10.1.1.41
软件:sersync,关闭selinux 和防火墙 

2,数据服务器上的配置
#在数据服务器上下载sersync,并拷贝至相应的目录,设置PATH变量
[root@data-centos8 ~]#wget https://storage.googleapis.com/google-code-archivedownloads/
v2/code.google.com/sersync/sersync2.5.4_64biT_Binary_stable_final.tar.
gz
[root@data-centos8 ~]#tar xf sersync2.5.4_64biT_Binary_stable_final.tar.gz
[root@data-centos8 ~]#cp -a GNU-Linux-x86 /usr/local/sersync
[root@data-centos8 ~]#echo 'PATH=/usr/local/sersync:$PATH' >
/etc/profile.d/sersync.sh
[root@data-centos8 ~]#source /etc/profile.d/sersync.sh
#sersync目录只有两个文件:一个是二进制程序文件,一个是xml格式的配置文件
[root@data-centos8 ~]#ls /usr/local/sersync/
confxml.xml sersync2
#确认安装rsync客户端工具
[root@data-centos8 ~]#rpm -q rsync &> /dev/null || dnf -y install rsync
#备份sersync配置文件
[root@data-centos8 ~]#cp /usr/local/sersync/confxml.xml{,.bak}
[root@centos8 ~]# vim /usr/local/sersync/confxml.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"/> # 是否开启调试模式
<fileSystem xfs="false"/>
<filter start="false"> #不开启文件过滤功能,当为true时,以下类型的文件将不同
步
<exclude expression="(.*).svn"></exclude>
<exclude expression="(.*).gz"></exclude>
<exclude expression="^info/*"></exclude>
<exclude expression="^static/*"></exclude>
</filter>
<inotify> # 监控事件,默认监控
delete/close_write/moved_from/moved_to/create folder
<delete start="true"/>
<createFolder start="true"/>
<createFile start="false"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="true"/> #修改此行为true,文件属性变化后也会同步
<modify start="false"/>
</inotify>
<sersync> # rsync命令的配置段
<localpath watch="/data/www"> #修改此行,需要同步的源目录或文件,建议同步
目录
<remote ip="备份服务器IP" name="BACkup"/> #修改此行,指定备份服务器地址和rsync
daemon的模块名,如果下面开启了ssh start,此时name为远程sHell方式运行时的目标目录
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-artuz"/> # 指定rsync选项
<auth start="true" users="rsyncuser" passwordfile="/etc/rsync.pas"/> #修
改此行,为true,定备份服务器的rsync配置的用户和密码文件
<userDefinedPort start="false" port="874"/><!-- port=874 -->#指定rsync的
非标准端口号
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/> #默认使用rsync daemon运行rsync命令,true为使用远程sHell模
式
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every
60mins execute once--> #错误重传及日志文件路径
<crontab start="false" schedule="600"><!--600mins--> #不开启crontab功能
<crontabfilter start="false"> #不开启crontab定时传输的筛选功能
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
<plugin start="false" name="command"/>
</sersync>
#####################################以下行不需要修改
####################################
<plugin name="command">
<param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix
/opt/tongbu/mmm.sh suffix-->
<filter start="false">
<include expression="(.*).php"/>
<include expression="(.*).sh"/>
</filter>
</plugin>
<plugin name="socket">
<localpath watch="/opt/tongbu">
<deshost ip="192.168.138.20" port="8009"/>
</localpath>
</plugin>
<plugin name="refreshCDN">
<localpath watch="/data0/htdocs/cms.xoyo.com/site/">
<cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx"
passwd="xxxx"/>
<sendurl base="http://pic.xoyo.com/cms"/>
<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-
9]*).xoyo.com/images"/>
</localpath>
</plugin>
</head>
#创建连接rsynd服务器的用户密码文件,并必须修改权限
[root@data-centos8 ~]#echo magedu > /etc/rsync.pas
[root@data-centos8 ~]#chmod 600 /etc/rsync.pas
[root@centos8 ~]# mkdir -pv /data/www

3,备份服务器上的配置(以独立服务方式运行 rsync)

[root@BACkup-server ~]# dnf install rsync-daemon -y  装包
#创建rsync服务器的配置文件
[root@centos8 ~]#vi /etc/rsyncd.conf
uid = root #提定以哪个用户来访问共享目录,将之指定为生成的文件所有者,默认为nobody
gid = root #默认为nobody
#port = 874 可指定非标准端口,默认873/tcp
#use chroot = no
max connections = 0
ignore errors
exclude = lost+found/
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
reverse lookup = no
#hosts allow = 10.0.0.0/24
[BACkup] #每个模块名对应一个不同的path目录,如果同名后面模块生效
path = /data/BACkup/
comment = BACkup dir
read only = no #默认是yes,即只读
auth users = rsyncuser #默认anonymous可以访问rsync服务器
secrets file = /etc/rsync.pas
#服务器端准备目录
[root@BACkup-centos8 ~]#mkdir -pv /data/BACkup
#服务器端生成验证文件
[root@BACkup-centos8 ~]#echo "rsyncuser:123" > /etc/rsync.pas
[root@BACkup-centos8 ~]#chmod 600 /etc/rsync.pas
#服务器端启动rsync服务
[root@BACkup-centos8 ~]#rsync --daemon #可加入/etc/rc.d/rc.local实现开机启动
[root@BACkup-centos8 ~]#systemctl start rsyncd #CentOS 7 以上版本

3,数据服务器上进行验证

[root@data-centos8 ~]# rsync rsync://10.1.1.41
BACkup         	BACkup dir
[root@data-centos8 ~]#sersync2 -dro /usr/local/sersync/confxml.xml
[root@data-centos8 ~]#touch /data/www/11.txt
[root@BACkup-server ~]# ll /data/BACkup/
@R_72_10586@l 0
-rw-r--r-- 1 root root 0 Jun 28 17:45 11.txt


大佬总结

以上是大佬教程为你收集整理的基于rsync daemon 实现 sersync全部内容,希望文章能够帮你解决基于rsync daemon 实现 sersync所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。