实时同步服务


1.搭建web节点 10.0.0.7

1)安装
[root@web01 ~]# yum install httpd php -y

2) 配置
[root@web01 html]# groupadd -g666 www
[root@web01 html]# useradd -u666 -g666 www
[root@web01 html]# sed -i '/^User/c User www' /etc/httpd/conf/httpd.conf
[root@web01 html]# sed -i '/^Group/c Group www' /etc/httpd/conf/httpd.conf

3)上传代码
[root@web01 html]# cd /var/www/html
[root@web01 html]# rz kaoshi.zip
[root@web01 html]# unzip kaoshi.zip
[root@web01 html]# chown -R www.www /var/www/html/

4)启动
[root@web01 ~]# systemctl start httpd
[root@web01 html]# systemctl restart httpd

2.搭建NFS节点10.0.0.31

  1. 安装
    [root@nfs ~]# yum install nfs-utils -y
  2. 配置
    [root@nfs ~]# cat /etc/exports /data 172.16.1.0/24(rw,async,all_squash,anonuid=666,anongid=666)

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

  1. 重启

[root@nfs ~]# systemctl restart nfs-server

  1. web节点上传的资源 ( 写入到NFS共享中 )

[root@web01 html]# mount -t nfs 172.16.1.31:/data /var/www/html/download
修改上传大小(扩展项)

  1. [root[@web01 ](/web01 ) ~]# vim /etc/php.ini <br /> upload_max_filesize = 200M;<br /> post_max_size = 200M;

[root@web01 html]# systemctl restart httpd


3.搭建BACKUP节点 10.0.0.41

1.配置Backup服务器

(增加一个data模块 让其安装NFS服务端,与31完全保持一致)

1)安装Rsync服务端
[root@backup ~]# yum install rsync -y

2)配置Rsync服务端
[root@backup ~]# cat /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
log file = /var/log/rsyncd.log
#####################################
[backup]            
comment = welcome to backup serve
path = /backup

[data]
path = /data


3)初始化操作:
[root@backup ~]# groupadd -g666 www
[root@backup ~]# useradd -u666 -g666 www
[root@backup ~]# mkdir /data
[root@backup ~]# chown -R www.www /data/ /backup

4)准备连接用户的密码文件:
[root@backup ~]# cat /etc/rsync.passwd 
rsync_backup:1
[root@backup ~]# chmod 600 /etc/rsync.passwd

5) 重启服务
[root@backup ~]# systemctl restart rsyncd

6)配置NFS
[root@backup ~]# yum install nfs-utils -y
[root@backup ~]# cat /etc/exports
/data 172.16.1.0/24(rw,async,all_squash,anonuid=666,anongid=666)

7)启动NFS
[root@backup ~]# systemctl enable nfs
[root@backup ~]# systemctl start nfs

2.在NFS服务端上安装Sersync

实时同步工具 (监控data目录)

1) 安装基础工具
[root@nfs ~]# yum install inotify-tools rsync -y


2)安装sersync 
[root@nfs ~]# rz sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs ~]# mv GNU-Linux-x86/ /usr/local/sersync


3)配置Sersync
        configxml.xml

4)为nfs添加了一个客户端的密码文件
[root@nfs ~]# cat /etc/rsync.pass 
123456
[root@nfs ~]# chmod 600 /etc/rsync.pass

5)启动sersync
    [root@nfs ~]# /usr/local/sersync/sersync2  -dro /usr/local/sersync/confxml.xml
6)获取启动后执行的命令 【手动测试一下,确保实时同步是没有问题】
[root@nfs data]# cd /data \
&& rsync -avz -R --delete ./  --timeout=100 rsync_backup@172.16.1.41::data --password-file=/etc/rsync.pass


sersync启动和停止:没有提供任何的脚本:systemctl
停止:kill $(ps -ef |grep sersync | grep -v grep | awk '{print $2}')
启动:/usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml

3.模拟nfs故障:

nfs: systemctl stop nfs
web: umount -lf /var/www/html/2020-10-20 && mount -t nfs 172.16.1.41:/data /var/www/html/2020-10-20

记得要恢复环境:
web—》nfs —-》sersync —》 backup
sersync替换成lsrsync

1.停止sersync
[root@nfs ~]# pkill sersync
2.安装lsyncd
[root@nfs ~]# yum install lsyncd -y
3.配置lsyncd.conf
[root@nfs ~]# cat /etc/rsync.pass
1
[root@nfs ~]# chmod 600 /etc/rsync.pass
[root@nfs ~]# cat /etc/lsyncd.conf

settings {
 logfile = "/var/log/lsyncd/lsyncd.log",
 statusFile = "/var/log/lsyncd/lsyncd.status",
 inotifyMode = "CloseWrite",
 maxProcesses = 8,
}

sync {
 default.rsync,
 source = "/data",
 target = "rsync_backup@172.16.1.41::data",
 delete= true,
 exclude = { ".*" },
 delay = 1,

rsync = {
    binary = "/usr/bin/rsync",
    archive = true,
    compress = true,
    verbose = true,
    password_file = "/etc/rsync.pass",
    _extra = {"--bwlimit=200"}
    }
}

4.初始化操作
[root@nfs ~]# cat /etc/rsync.pass
1
[root@nfs ~]# chmod 600 /etc/rsync.pass

5.启动lsyncd
[root@nfs ~]# systemctl start lsyncd
[root@nfs ~]# systemctl enable lsrsyncd