负载均衡文件同步

rsync是linux系统下的数据镜像备份工具。使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH、rsync主机同步。第一次同步时 rsync 会复制全部内容,但在下一次只传输修改过的文件。

sersync是基于Inotify开发的,类似于Inotify-tools的工具,sersync可以记录下被监听目录中发生变化的(包括增加、删除、修改)具体某一个文件或某一个目录的名字;

查看是否安装rsync,Centos7系统一般都装了

ll /proc/sys/fs/inotify

如下三项,则已安装

-rw-r--r-- 1 root root 0 Nov 28 11:07 max_queued_events
-rw-r--r-- 1 root root 0 Nov 28 11:07 max_user_instances
-rw-r--r-- 1 root root 0 Nov 28 11:07 max_user_watches

A-- 作为rsync服务器     需要配置rsyncd.conf文件

B-- 作为rsync客户端     不需要配置rsyncd.conf,文件可为空

服务端

1.

#关闭selinux
vi /etc/sysconfig/selinux
#SELINUX=enforcing    #注释掉
SELINUX=disabled      #增加
#重启系统

开启防火墙tcp 873端口(Rsync默认端口),如果是阿里云设置安全组

2.修改/etc/rsyncd.conf (配置文件用文末的)

uid = root                          #运行 rsync 守护进程的用户
gid = root                          #运行 rsync 守护进程的组
use chroot = no                     #若为yes, 则需要root权限,并且在同步符号连接资料时只会同步名称不会同步内容
max connections = 5                 #设置并发连接数,0表示无限制
strict modes = yes                  #是否检查口令文件的权限
port = 873                          #端口,873为 rsync 默认端口
pid file = /var/run/rsyncd.pid      #PID文件路径
lock file = /var/run/rsync.lock     #锁文件路径
log file = /var/log/rsyncd.log      #日志文件路径

#自定义模块名。模块是定义服务器哪个目录要被同步
[backup]
path = /data/test                   #同步目录的路径通过path指定
comment = This is a backup          #定义注释说明的内容
ignore errors                       #忽略一些IO错误
read only = yes                     #是否允许客户端上传数据(双向同步),yes表示不允许
list = no                           #客户端请求显示模块列表时,本模块名称是否显示,默认为yes(true)
hosts allow = 39.99.164.52          #设置哪些主机可以同步数据,多ip和网段之间使用空格分隔或者,分隔,没实践过
auth users = test                   #设置允许连接服务器的账户(自定义命名)
secrets file = /etc/rsyncd.secrets  #密码验证文件名

 

3. 

设置用户密码:
vim /etc/rsyncd.secrets
test:123456

设置600权限:
chmod 600 /etc/rsyncd.secrets

给同步提示信息:
echo "welcecho "welcome to Backup Server" > /etc/rsyncd.motdome to Backup Server" > /etc/rsyncd.motd

启动服务:
rsync --daemon --config=/etc/rsyncd.conf
#关闭服务:pkill rsync

开机启动:
echo "rsync --daemon --config=/etc/rsyncd.conf" >> /etc/rc.local(这是6的)
7的
cat /usr/lib/systemd/system/rsyncd.service(看到service已经创建好了)
systemctl enable rsyncd
查看端口:
ps -ef |grep 873

 

客户端

1.创建测试目录及数据

2.写虚拟用户密码

设置密码文件:
touch /etc/rsyncd.secrets
echo "123456" > /etc/rsyncd.secrets
chmod 600 /etc/rsyncd.secrets

测试:
rsync -avzP --delete --progress test@39.100.136.141::backup --password-file=/etc/rsyncd.secrets  /data/test
用test用户登陆到114.22.168.67的rsync服务器上,把backup模块中指定的数据同步到本地的/data/test目录下

Sersync安装

查看服务器内核是否支持inotify
列出文件目录

ll /proc/sys/fs/inotify

出现下面的内容、说明服务器内核支持inotify
-rw-r--r-- 1 root root 0 Dec 25 12:03 max_queued_events
-rw-r--r-- 1 root root 0 Dec 25 15:05 max_user_instances
-rw-r--r-- 1 root root 0 Dec 25 12:03 max_user_watches

修改inotify默认参数(inotify默认内核参数值太小):

修改inotify默认参数(inotify默认内核参数值太小)
sysctl -a | grep max_queued_events
sysctl -a | grep max_user_watches
sysctl -a | grep max_user_instances
修改参数
sysctl -w fs.inotify.max_queued_events="99999999"
sysctl -w fs.inotify.max_user_watches="99999999"
sysctl -w fs.inotify.max_user_instances="65535"
生效
sysctl -p

参数说明:
max_queued_events:inotify队列最大长度,如果值太小,会出现” Event Queue Overflow “错误,导致监控文件不准确
max_user_watches:要同步的文件包含多少目录,可以用:find /var/www/synctest -type d | wc -l 统计,必须保证max_user_watches值大于统计结果(这里/var/www/synctest为同步文件目录)
max_user_instances:每个用户创建inotify实例最大值

wget https://raw.githubusercontent.com/orangle/sersync/master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz

tar xzf sersync2.5.4_64bit_binary_stable_final.tar.gz

cp confxml.xml confxml.xml-bak

 

 

 

 

 

 

 

 

下面的不用看

安装inotify-tools
inotify-tools是为linux下inotify文件监控工具提供的一套c的开发接口库函数,同时还提供了一系列的命令行工具,这些工具可以用来监控文件系统的事件。 inotify-tools是用c编写的,除了要求内核支持inotify外,不依赖于其他。inotify-tools提供两种工具,一是inotifywait,它是用来监控文件或目录的变化,二是inotifywatch,它是用来统计文件系统访问的次数。现在介绍一下它的使用方法。

其他Linux发行版安装方法可以参见:https://github.com/rvoicilas/inotify-tools/wiki#wiki-getting

下载:http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

 

 tar xzf inotify-tools-3.14.tar.gz ;cd inotify-tools-3.14

./configure --prefix=/data/inotify

make && make install


加入环境变量

echo "PATH=$PATH:/data/inotify/bin/" >>/etc/profile  && source /etc/profile

inotifywatch -h 查看用法

服务端rsync的配置文件:

uid = root
gid = root
use chroot = no
max connections = 5
strict modes = yes
port = 873
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
 
[backup]
path = /data/test
comment = This is a backup
ignore errors
read only = yes
list = no
hosts allow = 39.99.164.52
auth users = test
secrets file = /etc/rsyncd.secrets

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值