实时同步步骤详解

实时监测目录的变化, 当出现 增 删 改 时, 则触发一个动作, 这个动作就是推送至远程服务器

        1.解决NFS单点故障问题
        2.迁移   ( 本地环境 --> 云环境 )

1.部署备份服务器
①:安装rsync服务

[root@backup ~]# yum install rsync -y

②:配置rsync

        uid = rsync                      # 运行进程的用户
        gid = rsync                      # 运行进程的用户组
        port = 873                       # 监听端口
        fake super = yes                 # 不需要rsync已root身份运行,就可以存储文件的完整属性
        use chroot = no                  # 禁锢推送的数据至某个目录, 不允许跳出该目录
        max connections = 200            # 最大连接数
        timeout = 600                    # 超时时间
        ignore errors                    # 忽略错误信息
        read only = false                # 对备份数据可读写
        list = false                     # 不允许查看模块信息
        auth users = rsync_backup        # 定义虚拟用户,作为连接认证用户
        secrets file = /etc/rsync.passwd # 定义rsync服务用户连接认证密码文件路径


        [backup]                        # 定义模块信息
        path = /backup                      # 定义接收备份数据目录


        [data]
        comment = welcome to oldboyedu data!
        path = /data

③:创建用户,准备虚拟连接用户,创建目录, 进行授权并重启rsync服务

[root@backup ~]# useradd rsync -M -s /sbin/nologin
[root@backup ~]# vim /etc/rsync.passwd
                 rsync_backup:1
[root@backup ~]# chmod 600 /etc/rsync.passwd
[root@backup ~]# mkdir /data
[root@backup ~]# chown -R rsync.rsync /data/
[root@backup ~]# systemctl restart rsyncd

2.部署NFS服务器共享存储
①:安装NFS服务

[root@nfs01 ~]# yum install nfs-utils -y

②:配置NFS文件

[root@nfs01 ~]# vim /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)

③:创建用户及目录并授权

[root@nfs01 ~]# mkdir /data
[root@nfs01 ~]# groupadd -g 666 www
[root@nfs01 ~]# useradd -u666 -g666 www
[root@nfs01 ~]# chown -R www.www /data/

④:重启NFS服务

[root@nfs01 ~]# systemctl restart nfs

3.部署WEB服务器程序
①:安装所需组件

[root@web01 ~]# yum install nfs-utils -y
[root@web01 ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data 172.16.1.0/24
[root@web01 ~]# mount -t nfs 172.16.1.31:/data /mnt
[root@web01 ~]# touch /mnt/hello
[root@web01 ~]# umount /mnt/
[root@web01 ~]# yum install httpd php php-mbstring php-gd -y

②:创建用户及用户组

[root@web01 ~]# groupadd -g666 www
[root@web01 ~]# useradd -u666 -g666 www

③:配置httpd文件以www用户身份运行

[root@web01 ~]# sed -i '/^User/c User www' /etc/httpd/conf/httpd.conf
[root@web01 ~]# sed -i '/^Group/c Group www' /etc/httpd/conf/httpd.conf

④:进入站点下载代码并授权/var/www/html目录属主组权限为www

[root@web01 ~]# cd /var/www/html                #默认网站代码存放的路径
[root@web01 html]# wget http://static.kodcloud.com/update/download/kodexplorer4.40.zip
[root@web01 html]# unzip kodexplorer4.40.zip
[root@web01 html]# chown -R www.www /var/www/html
[root@web01 ~]# systemctl restart httpd

4.将用户写入web主机上的静态类资源自动同步至NFS存储
①:登录admin管理员创建video目录后挂载到NFS服务器

[root@web01 ~]# mount -t nfs 172.16.1.31:/data /var/www/html/data/User/admin/home/video/

5.在NFS服务器部署sersync实时同步工具, 同步NFS数据至备份服务器的data模块
①:安装后将文件移动至/usr/local目录下

[root@nfs01 ~]# unzip sersync_installdir_64bit.zip
[root@nfs01 ~]# mv sersync_installdir_64bit/sersync/ /usr/local/

②:配置并授权

<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host>
    <debug start="false"/>
    <fileSystem xfs="true"/>    <!--centos7 xfs 文件系统-->
    <filter start="false">    <!--过滤-->
    <exclude expression="(.*)\.svn"></exclude>
    <exclude expression="(.*)\.gz"></exclude>
    <exclude expression="^info/*"></exclude>
    <exclude expression="^static/*"></exclude>
    </filter>
    <inotify>    <!--监控哪些事件-->
    <delete start="true"/>
    <createFolder start="true"/>
    <createFile start="true"/>
    <closeWrite start="true"/>
    <moveFrom start="true"/>
    <moveTo start="true"/>
    <attrib start="true"/>
    <modify start="true"/>
    </inotify>


    <sersync>
    <localpath watch="/data"> <!--监控本地的哪个目录,发生了哪些inotify事件,
    推送到哪个服务器的哪个模块-->
        <remote ip="172.16.1.41" name="data"/>
        <!--<remote ip="192.168.8.39" name="tongbu"/>-->
        <!--<remote ip="192.168.8.40" name="tongbu"/>-->
    </localpath>
    <rsync>
        <commonParams params="-avz"/>
        <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.pass"/>
        <userDefinedPort start="false" port="874"/><!-- port=874 -->
        <timeout start="true" time="100"/><!-- timeout=100 -->
        <ssh start="false"/>
    </rsync>
    <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
    <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>


    <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>
[root@nfs01 ~]# chmod +x /usr/local/sersync/bin/sersync
[root@nfs01 data]# vim /etc/rsync.pass
1
[root@nfs01 data]# chmod 600 /etc/rsync.pass

③:启动

[root@nfs01 ~]# /usr/local/sersync/bin/sersync -rdo /usr/local/sersync/conf/confxml.xml

④:提取sersync的同步命令测试是否ok

[root@nfs01 data]# cd /data && rsync -avz -R --delete ./  --timeout=100 rsync_backup@172.16.1.41::dsword-file=/etc/rsync.pass

6.增加一个web节点
7.模拟NFS服务器故障,如何快速切换.
①:为故障时能正常切换使用需要先在备份服务器搭建一个NFS服务备用

[root@backup ~]# yum install nfs-utils -y
[root@backup ~]# vim /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)

②:创建目录,用户及用户组并授权

[root@backup ~]# groupadd -g666 www
[root@backup ~]# useradd -u666 -g666 www
[root@backup ~]# mkdir /data
[root@backup ~]# chown -R www.www /data/

③:修改rsync的权限为www并授权给/backup目录

[root@backup ~]# head -2 /etc/rsyncd.conf
    uid = www
    gid = www
[root@backup ~]# mkdir /backup
[root@backup ~]# chown -R www.www /backup/

④:重启NFS服务

[root@backup ~]# systemctl restart rsyncd nfs

⑤:关闭NFS模拟环境

[root@nfs01 sersync]# systemctl stop nfs

⑥:WEB端卸载NFS并重新挂载到Backup服务器

[root@web01 ~]# umount -lf 172.16.1.31:/data && mount -t nfs 172.16.1.41:/data /var/www/html/data/User/admin/home/video
    
[root@web02 ~]# umount -lf 172.16.1.31:/data && mount -t nfs 172.16.1.41:/data /var/www/html/data/User/admin/home/video
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值