三个任务(blog)版
三个任务
第一个任务备份服务
- nfs和backup两台服务器
- nfs客户端 ——> backup服务端
服务端配置(backup服务器)
1)安装rsync服务
yum install -y rsync
2)修改配置文件
#修改配置文件/etc/rsyncd.conf
uper =yes
uid = rsync #rsync运行 用户 虚拟用户
gid = rsync
use chroot = no
max connections = 2000 #最大连接数
timeout = 600 #连接超时 超时时间
pid file = /var/run/rsyncd.pid #存放服务的pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log #rsync服务端日志
ignore errors
read only = false
list = false
auth users = rsync_backup #rsync服务端进行验证用户用户名
secrets file = /etc/rsync.password #rysnc服务端用于验证密码文件
[nfs_data] #模块对应的目录
path = /nfs_data
3)添加rsync用户
useradd -s /sbin/nologin -M rsync
4)创建密码文件,配置文件中认证用户密码更改密码文件权限
echo 'rsync_backup:123456' > /etc/rsync.password
chmod 600 /etc/rsync.password #不改权限的话会报错
5)创建模板中文件夹并修改属组改为rsync.rsync
mkdir -p /nfs_data
chown -R rsync.rsync /nfs_data
6)重启服务并设置自动启动
systemctl enable rsyncd
systemctl start rsyncd
客户端安装部署(nfs服务器)
1)安装rsync服务
yum install -y rsync
2)免密交互client文件
echo '123456' > /etc/rsync.client
第二个任务nfs存储服务
- nfs和web服务器部署
- web服务器上挂载到nfs上
服务端(nfs服务器)
1)部署 nfs-utils,rpcbind
yum install -y nfs-utils,rpcbind
2)修改配置文件 /etc/exports
/nfsdata/ 172.16.1.0/24(rw,allsquash)
3)创建共享目录并修改所有者
mkdir /nfsdata
chown -R nfsnobody.nfsnobody /nfsdata
4)启动服务 rpcbind 和 nfs(按照先rpc后nfs)
systemctl restart rpcbind
systemclt restart nfs
客户端(web服务器)
1)安装nfs-utils
yum install -y nfs-utils
2)创建挂在目录/ans-upload
mkdir /ans-upload
3)挂载和永久挂载
mount -t nfs 172.16.1.31:/nfsdata/ /ans-upload/
#查看挂载目录没
showmount -e 172.16.1.31
#查看现有挂载
df -h
第三个实时同步服务(Sersync)
- 在nfs端部署
nfs端
1)修改sersync的配置文件和运行文件
软件包下载个好多年不更新了,2.5.4版本
tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs ~]# tree GNU-Linux-x86/
GNU-Linux-x86/
├── confxml.xml
└── sersync2
confxml.xml 配置文件
sersync2 命令
- sersync配置参数
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host> #保留字段,默认即可
<debug start="false"/> #是否开启调试模式,默认false即可
<fileSystem xfs="true"/> #是否开启支持xfs文件系统,Centos7默认都是xfs的了,所以建议true开启
<filter start="false"> #是否开启过滤模式.根据需求开启,例:过滤以.php结尾的文件(.*)\.php
<exclude expression="(.*)\.svn"></exclude> #过滤以.svn结尾的文件
<exclude expression="(.*)\.gz"></exclude> #过滤以.gz结尾的文件
<exclude expression="^info/*"></exclude> #过滤监控目录下的info路径
<exclude expression="^static/*"></exclude> #过滤监控目录下的static路径
<exclude expression="wwwroot/blogwhsir/*"></exclude> #过滤wwwroot/blogwhsir/目录下所有文件
</filter>
<inotify> #inotify监控事件
<delete start="true"/> #如果不开启此项,在删除监控目录下的文件时,目标服务器的文件则不会同时删除,根据需求开启
<createFolder start="true"/> #不开启不能监控子目录,建议true
<createFile start="false"/> #关闭提高通讯性能,默认就好
<closeWrite start="true"/> #是否有closeWrite事件(修改后退出)
<moveFrom start="true"/> #移动/改名
<moveTo start="true"/> #移动/改名
<attrib start="false"/> #文件属性变化
<modify start="false"/> #文件内容修改
</inotify>
<sersync>
<localpath watch="/opt/tongbu"> #指定要监控的本地目录
<remote ip="127.0.0.1" name="tongbu1"/> #指定要同步的目标服务器的IP地址,及目标服务器rsync的[模块]
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync> #配置rsync
<commonParams params="-artuz"/> #rsync的参数
<auth start="false" users="root" passwordfile="/etc/rsync.pas"/> #是否开启rsync的认证模式,需要配置users及passwordfile,根据情况开启(如果开启,注意密码文件权限一定要是600)
<userDefinedPort start="false" port="874"/><!-- port=874 --> #远程目标服务器的端口不是默认端口时使用
<timeout start="false" time="100"/><!-- timeout=100 --> #是否开启rsync的超时时间
<ssh start="false"/>
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> #目标服务器传输失败时会重新传输,再次失败会写入rsync_fail_log中,每隔一段时间timeToExecute)执行脚本再次传输
<crontab start="false" schedule="600"><!--600mins--> #对监控目录与目标服务器每隔一段时间进行一次整体同步,默认600分钟,根据个人情况是否开启
<crontabfilter start="false"> #如果之前开启了文件过滤,这里也要设置过滤
<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="https://blog.whsir.com"/>
<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>
</head>
- 需要修改的内容
<sersync>
<localpath watch="/ans-upload"> #指定要监控的本地目录
<remote ip="127.0.0.1" name="nfsdata"/> #指定要同步的目标服务器的IP地址,及目标服务器rsync的模块
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> #目标服务器传输失败时会重新传输,再次失败会写入rsync_fail_log中,每隔一段时间timeToExecute)执行脚本再次传输
<crontab start="false" schedule="600"><!--600mins--> #对监控目录与目标服务器每隔一段时间进行一次整体同步,默认600分钟,根据个人情况是否开启
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> #目标服务器传输失败时会重新传输,再次失败会写入rsync_fail_log中,每隔一段时间timeToExecute)执行脚本再次传输
2)启动sersync2服务
#创建软连接后,可以直接在命令行使用sersync2命令
ln -s /app/tools/sersync2 /bin/sersync2
#运行sersync2
sersync2 -rdo /app/tools/confxml.xml
最后结果
在web服务器的/ans-upload中创建文件时,会被同步到nfs的/nfsdata目录中,经过sersync实时同步后同步到backup服务器中的/nfs-data中

浙公网安备 33010602011771号