day 39 sersync服务

一、准备环境

(一)在backup服务端

1.创建nfsbackup模块

[root@backup ~]# mkdir /nfsbackup
[root@backup ~]# chown rsync.rsync /nfsbackup
[root@backup ~]# ll /nfsbackup -d
drwxr-xr-x 2 rsync rsync 6 May 25 17:14 /nfsbackup

2.配置rsync文件

[root@backup ~]# vim /etc/rsyncd.conf 

gid = rsync
use chroot = no
max connections = 2000
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
#hosts allow = 10.0.0.0/24
#hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
#####################################
[backup]
comment = www by old0boy 14:18 2012-1-13
path = /backup

#####################################
[nfsbackup]
comment = www by old0boy 14:18 2012-1-13
path = /nfsbackup

3.创建密码文件

[root@backup ~]# ll /etc/rsync.password 
-rw------- 1 root root 20 May 25 10:56 /etc/rsync.password
[root@backup ~]# cat /etc/rsync.password
rsync_backup:123456

(二)nfs 客户端

1.创建环境

[root@nfs01 ~]# mkdir -p /server/{scripts,tools}
[root@nfs01 ~]# tree /server/
/server/
├── scripts
└── tools

2 directories, 0 files

2.上传sersync软件包

[root@nfs01 ~]# cd /server/tools/
[root@nfs01 tools]# rz -E
rz waiting to receive.
[root@nfs01 tools]# ll
total 692
-rw-r--r-- 1 root root 708025 May 23  2019 sersync_installdir_64bit.zip

[root@nfs01 tools]# unzip sersync_installdir_64bit.zip 
[root@nfs01 tools]# tree
.
├── sersync_installdir_64bit
│   └── sersync
│       ├── bin
│       │   └── sersync
│       ├── conf
│       │   └── confxml.xml
│       └── logs
└── sersync_installdir_64bit.zip

5 directories, 3 files

3.给sersync创建目录,并创建一个软连接

[root@nfs01 tools]# mkdir -p /app
[root@nfs01 tools]# mv /server/tools/sersync_installdir_64bit/sersync /app
[root@nfs01 tools]# ll /app
total 0
drwxr-xr-x 5 root root 41 Dec 23  2012 sersync

[root@nfs01 tools]# tree /app
/app
└── sersync
    ├── bin
    │   └── sersync
    ├── conf
    │   └── confxml.xml
    └── logs

4 directories, 2 files

[root@nfs01 tools]# /app/sersync/bin/sersync          //执行sersync
-bash: /app/sersync/bin/sersync: Permission denied
[root@nfs01 tools]# chmod +x /app/sersync/bin/sersync
[root@nfs01 tools]# ln -s /app/sersync/bin/sersync  /sbin/     //创建软连接
[root@nfs01 tools]# ll /sbin/sersync 
lrwxrwxrwx 1 root root 24 May 21 02:02 /sbin/sersync -> /app/sersync/bin/sersync
[root@nfs01 tools]# sersync         //执行sersync
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
daemon thread num: 10
parse xml config file
XML Parsing error inside file 'confxml.xml'.
Error: File not found
At line 0, column 0.

sersync执行命令时,默认会在path环境变量中查找 是否有该命令

4.修改confxml.xml文件

 5     <fileSystem xfs="true"/>
 24         <localpath watch="/upload">
 30             <commonParams params="-az"/>
 31             <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.passwd"/>
 36 <failLog path="/var/log/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->

5.创建密码文件

[root@nfs01 conf]# echo '123456' >/etc/rsync.passwd
[root@nfs01 conf]# chmod 600 /etc/rsync.passwd

二、测试

1.启动sersync服务 并同步

[root@nfs01 conf]# sersync -rd -o /app/sersync/conf/confxml.xml
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -r  rsync all the local files to the remote servers before the sersync work
option: -d  run as a daemon
option: -o  config xml name:  /app/sersync/conf/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
WARNING XFS FILE SYSTEM WORK
daemon start,sersync run behind the console 
use rsync password-file :
user is rsync_backup
passwordfile is     /etc/rsync.passwd
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12  = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) 
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /upload && rsync -az -R --delete ./ rsync_backup@172.16.1.41::nfsbackup --password-file=/etc/rsync.passwd >/dev/null 2>&1 
run the sersync: 
watch path is: /upload

2.查看共享目录

  • nfs 客户端 查看目录
[root@nfs01 conf]# ll /upload/
total 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 May 20 22:54 old01.txt
-rw-r--r-- 1 nfsnobody nfsnobody 0 May 20 22:54 old02.txt
-rw-r--r-- 1 nfsnobody nfsnobody 0 May 20 22:54 old03.txt
-rw-r--r-- 1 nfsnobody nfsnobody 0 May 20 22:54 old04.txt
-rw-r--r-- 1 nfsnobody nfsnobody 0 May 20 22:54 old05.txt
-rw-r--r-- 1 nfsnobody nfsnobody 0 May 20 22:54 old06.txt
-rw-r--r-- 1 nfsnobody nfsnobody 0 May 20 22:54 old07.txt
-rw-r--r-- 1 nfsnobody nfsnobody 0 May 20 22:54 old08.txt
-rw-r--r-- 1 nfsnobody nfsnobody 0 May 20 22:54 old09.txt
-rw-r--r-- 1 nfsnobody nfsnobody 0 May 20 22:54 old10.txt
[root@nfs01 conf]# rm -f /upload/old{05..10}.txt
  • backup 服务端 查看目录
[root@backup ~]# ll /nfsbackup/
total 0
-rw-r--r-- 1 rsync rsync 0 May 20 22:54 old01.txt
-rw-r--r-- 1 rsync rsync 0 May 20 22:54 old02.txt
-rw-r--r-- 1 rsync rsync 0 May 20 22:54 old03.txt
-rw-r--r-- 1 rsync rsync 0 May 20 22:54 old04.txt
[root@backup ~]# 

配置inotify 的监控的事件 sersync 什么时候用rsync推送 实时监控目录变量

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 转载:https://www.cnblogs.com/liangml/p/5959571.html 一.为什么要用...
    SkTj阅读 1,518评论 0 1
  • 70 何年部落到阴陵,奕世勤王国史称。夜卷牙旗千帐雪,朝飞羽骑一河冰。蕃儿襁负来青冢,狄女壶浆出白登。日晚鹂鹈泉畔...
    郭零阅读 342评论 0 0