Day33综合架构Sersync实时同步

需要准备的虚拟机

角色 外网 内网 安装工具
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

准备备份服务器

[root@backup ~]# yum install rsync -y
[root@backup ~]# cat /etc/rsyncd.conf
uid = rsync
gid = rsync
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 oldboyedu backup!
path = /backup
[data]
comment = welcome to oldboyedu data!
path = /data

创建用户,准备虚拟用户,创建目录,进行授权
[root@backup ~]# mkdir /data
[root@backup ~]# chown -R rsync.rsync /data/
[root@backup ~]# systemctl restart rsyncd

2.准备NFS共享存储

[root@nfs01 ~]# yum install nfs-utils -y
[root@nfs01 ~]# cat /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
[root@nfs01 ~]# groupadd -g 666 www
[root@nfs01 ~]# useradd -u666 -g666 www
[root@nfs01 ~]# mkdir -p /data
[root@nfs01 ~]# chown www.www /data
[root@nfs01 ~]# systemctl restart nfs

客户端测试:
[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/

3.准备web站点程序
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 (httpd程序就可以通过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目录
[root@web01 ~]# mount -t nfs 172.16.1.31:/data /var/www/html/data/User/admin/home/video/

5.接入sersync实时同步工具, 同步NFS数据至 备份服务器的data模块
1.安装
[root@nfs01 ~]# unzip sersync_installdir_64bit.zip
[root@nfs01 ~]# mv sersync_installdir_64bit/sersync/ /usr/local/
2.配置
[root@nfs ~]# cd /usr/local/sersync/conf/
[root@nfs01 ~]# chmod +x /usr/local/sersync/bin/sersync
3.启动
[root@nfs01 ~]# /usr/local/sersync/bin/sersync -rdo /usr/local/sersync/conf/confxml.xml

Lysncd是一款开源的数据实时同步工具,基于inotify和rsync基础之上进行开发。

lsyncd与sersync一样,会监控本地目录,只要当本地目录发生变化则触发动作,这个动作就是同步至远程服务器。Lsyncd应用场景例如CDN镜像、网站数据备份、网站搬家等等。

1.环境准备

rsync   服务端 172.16.1.41 rsync
lsync   客户端 172.16.1.31 lsyncd
[root@nfs01-31:~]# yum install lsyncd
2.backup服务器环境准备

[root@backup-41:~]# cat /etc/rsyncd.conf

uid = rsync
gid = rsync
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
auth users = rsync_backup
secrets file = /etc/rsync.password

[backup]
comment = "backup dir by oldboy"
path = /backup
3.根据配置初始化环境

[root@backup-41:~]# mkdir /backup
[root@backup-41:~]# useradd rsync
[root@backup-41:~]# ll /backup/ -d
drwxr-xr-x 2 root root 6 Aug  2 15:40 /backup/
[root@backup-41:~]# chown rsync.rsync /backup/
[root@backup-41:~]# echo "rsync_backup:123456" >/etc/rsync.password
[root@backup-41:~]# chmod 600 /etc/rsync.password 
[root@backup-41:~]# systemctl start rsyncd.service
4.NFS服务器配置lsync

#安装lsyncd
[root@nfs01-31:~]# yum install lsyncd

配置lsyncd,监控本地目录,触发则立即同步
[root@nfs01-31:~]# 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 = "[email protected]::backup",
 delete= true,
 exclude = { ".*" },
 delay = 1,

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

[root@nfs01-31:~]# mkdir /data
[root@nfs01-31:~]# echo "123456" >/etc/rsync.pwd  #创建密码文件
[root@nfs01-31:~]# chmod 600 /etc/rsync.pwd 
[root@nfs01-31:~]# systemctl start lsyncd.service


[root@nfs01-31:~]# touch /data/{1..10}
[root@nfs01-31:~]# rsync -avz /etc/passwd [email protected]::b

你可能感兴趣的:(Day33综合架构Sersync实时同步)