sersync实时同步
实时同步概述: ????什么时实时同步:只要当前目录发生变化则会触发一个事件,事件触发后将变化的目录同步至远程服务器 ????为什么要用实时同步:保证数据的连续性,减少人力维护成本,解决NFS单点故障 ????实时同步实现原理:实时同步需要借助Inotify通知接口,用来监控目录的变化,如果监控的目录发生变更,则触发动作 ????sersync优点:国人基于rsync_inotify-tools开发工具,不仅保留了优点同时还强化了实时监控,文件过滤,简化配置等功能,帮助用户提高运行效率,节省事件和网络资源 ? 案例: 实现web上传视频文件,实则是写入NFS至存储,当NFS存在新的数据则会实时的复制到备份服务器 角色????????外网IP(NAT)????????内网IP(LAN)????????安装工具 web01????????eth0:10.0.0.7????eth1:172.16.1.7????httpd、php nfs-server????eth0:10.0.0.31????eth1:172.16.1.31????nfs、sersync backup????????eth0:10.0.0.41????eth1:172.16.1.41????rsync-server
????nfs存储服务 172.16.1.31 ????安装 ????????yum install nfs-utils -t ????配置 ????????vim /etc/exports ????????/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666) ????????groupadd -g666 www????&& useradd -u666 -g666 www ????????mkdir /data && chown -R www.www /data ????启动 ????????systemctl start nfs && systemctl enable nfs web服务器器操作: 172.16.1.7 ????安装: ????????yum install httpd php -y ????配置: ????????mount -t nfs 172.16.1.31:data /var/www/html ????????cd /var/www/html && 上传代码 ????????unzip kaoshi.zip ????启动 ????????systemctl start httpd ????修改上传的大小 ????????vim /etc/php.ini ????????uplad_max_filesize = 200M; ????????post_max_size = 200M; ????????注意修改完记得重启服务:systemctl restart httpd
备份服务器操作如下:172.16.1.41 ????安装: ????????yum install rsync -y ????配置 ????????vim /etc/rsyncd.conf ???? ????uid = www ????????gid = www ????????port = 873 ????????fake super = yes ????????use chroot = no ???????max connections = 200 ????????timeout = 600 ????????ignore errors ????????read only = false ????????list = false ????????auth users = rsync_backup ????????secrets file = /etc/rsync.passwd ????????[backup] ????????comment = commit ????????path = /backup ???? ????[data] ???? ????path = /data ????创建用户 ????groupadd -g666 www && useradd -u666 -g666 www ????echo "rsync_backup:123456" > /etc/rsync.passwd && chmod 600 /etc/rsync.passwd ????mkdir -p /data /backup && chown -R www.www /backup /data ????启动: ????????systemctl restart rsyncd
????安装: ????yum install inotify-tools -y ????wget https://raw.githubusercontent.com/wsgzao/sersync/master/sersync2.5.4_64bit_binary_stable_final.tar.gz ????tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz ????mv GNU-Linux-x86 /usr/local/sersync ????配置: ????????vim /usr/local/sersync/confxml.xml ????????<fileSystem xfs="true"/> ????????<attrib start="true"/> ????????<modify start="true"/> ????????<localpath watch="/data"> ???? <remote ip="172.16.1.41" name="data"/> ????????<commonParams params="-az"/> ???? <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.pass"/> ????????<timeout start="true" time="100"/><!-- timeout=100 --> ????创建客户端密码文件 ????echo "123456" >/etc/rsync.pass ????chmod 600 /etc/rsync.pass ????启动: ????????/usr/local/sersync/sersync2 -dro /usr/local/sersyc/confxml.xml ????注:启动sersync后一定要提取同步的命令,手动运行一次,检查是否存在错误 ? 如何平滑的迁移nfs数据到backup服务器,并且让后续的上传都是上传至backup(不能出现业务中断)
????创建用户 ????groupadd -g 666 www ????useradd -u666 -g666 www ????配置 ????yum install -y nfs-utils -y ????cat /etc/exports ????/data 172.16.1.0/24(rw,anongid=666) ????启动 ????systemctl restart nfs-server
????umount -lf /var/www/html/ && mount -t nfs 172.16.1.41:/data /var/www/html/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |