Rsync服务扩展应用

Rsync服务扩展应用

一、守护进程之多模块功能配置

第一个里程:在配置文件中添加NFS模块
#rsync_config
#created by HQ at 2019
##rsyncd.conf start##
uid = rsync
gid = rsync
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
list = false
hosts allow = 172.16.1.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
[backup]
comment = "backup dir by oldboy"
path = /backup
[nfs]
comment = "nfs dir by rsync"
path = /nfs
第二个里程:重启rsync服务
[root@backup backup]# killall rsync
[root@backup backup]# rsync --daemon
第三个里程:新建备份目录,并将所属组与所属变成rsync管理用户
[root@backup /]# mkdir nfs
[root@backup /]# chown rsync. /nfs
第四个里程:测试
    [root@nfs01 tmp]# rsync -avz /tmp/a.txt   rsync_backup@172.16.1.41::nfs --password-fi
le=/etc/rsync.password sending incremental file list
a.txt

sent 70 bytes  received 27 bytes  194.00 bytes/sec
total size is 4  speedup is 0.04
[root@nfs01 tmp]# 

二、守护进程之排除功能实践

第一种方式:排除单个或连续文件
#排除多个
[root@nfs01 test_dir]# rsync -avz /test_dir/ --exclude=b.txt --exclude=d.txt rsync_ba
ckup@172.16.1.41::nfs --password-file=/etc/rsync.password sending incremental file list
./
a.txt
c.txt

sent 121 bytes  received 49 bytes  340.00 bytes/sec
total size is 0  speedup is 0.00
#排除多个
[root@nfs01 test_dir]# rsync -avz /test_dir/ --exclude={a.txt,d.txt} rsync_backup@172
.16.1.41::nfs --password-file=/etc/rsync.password sending incremental file list
./
b.txt
c.txt

sent 121 bytes  received 49 bytes  340.00 bytes/sec
total size is 0  speedup is 0.00
#排除连续的文件
[root@nfs01 test_dir]# rsync -avz /test_dir/ --exclude={b..d}.txt rsync_backup@172.16
.1.41::nfs --password-file=/etc/rsync.password sending incremental file list
./
a.txt

sent 75 bytes  received 30 bytes  210.00 bytes/sec
total size is 0  speedup is 0.00
[root@nfs01 test_dir]# 
第二种方式:排除多个文件,新建一个文件然后将需要排除的文件名放到这个文件中
[root@nfs01 test_dir]# cat exclude_file.txt 
b.txt
d.txt
exclude_file.txt

[root@nfs01 test_dir]# rsync -avz /test_dir/ --exclude-from=/test_dir/exclude_file.tx
t  rsync_backup@172.16.1.41::nfs --password-file=/etc/rsync.password sending incremental file list
./
a.txt
c.txt

sent 125 bytes  received 49 bytes  348.00 bytes/sec
total size is 0  speedup is 0.00

三、守护进程之创建备份目录

#说明:如果需要在备份目录下创建子文件夹,可以在模块名后面添加需创建的文件名,可以分开每个部门需要备份的数据,不会全部放在一个文件夹中
[root@nfs01 test_dir]# rsync -avz /etc/hosts  rsync_backup@172.16.1.41::nfs/sa/ --pas
sword-file=/etc/rsync.password sending incremental file list
created directory sa
hosts

sent 189 bytes  received 27 bytes  432.00 bytes/sec
total size is 352  speedup is 1.63
[root@nfs01 test_dir]# 
#备份服务器
[root@backup nfs]# tree
.
├── a.txt
├── c.txt
└── sa
    └── hosts

1 directory, 3 files
[root@backup nfs]# 

四、守护进程之访问控制(建义只使用前两种方法配置)

第一种情况:只有白名单,白名单网段与主机信息允许,其余阴止
#备份服务器,注释黑名单
[root@backup nfs]# egrep 'allow|deny' /etc/rsyncd.conf 
hosts allow = 172.16.1.0/24
#hosts deny = 0.0.0.0/32
[root@backup nfs]# killall rsync
[root@backup nfs]# rsync --daemon
#远程服务器,10网段进行同步,同步连接被阻止
[root@nfs01 test_dir]# rsync -avz /etc/hosts  rsync_backup@10.0.0.41::nfs/sa/ --passw
ord-file=/etc/rsync.password @ERROR: Unknown module 'nfs'
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3
.0.6]
#白名单中的网段主机进行同步,同步连接被允许
[root@nfs01 test_dir]# rsync -avz /etc/hosts  rsync_backup@172.16.1.41::nfs/sa/ --password-file=/etc/rsync.password sending incremental file list
sent 26 bytes  received 8 bytes  68.00 bytes/sectotal size is 352  speedup is 10.35
第二种情况:只有黑名单,黑名单网络与主机信息阻止,其余允许
#备份服务器,注释白名单,将10网段添加到配置文件中
[root@backup nfs]# egrep 'allow|deny' /etc/rsyncd.conf 
#hosts allow = 172.16.1.0/24
hosts deny =10.0.0.0/24
[root@backup nfs]# killall rsync
[root@backup nfs]# rsync --daemon 
#存储服务器,10网段进行同步连接,访问被阻止
[root@nfs01 test_dir]# rsync -avz /etc/hosts  rsync_backup@10.0.0.41::nfs/sa/ --passw
ord-file=/etc/rsync.password @ERROR: Unknown module 'nfs'
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3
.0.6]
#除黑名单网段外进行同步连接,访问被允许
[root@nfs01 test_dir]# rsync -avz /etc/hosts  rsync_backup@172.16.1.41::nfs/sa/ --pas
sword-file=/etc/rsync.password sending incremental file list

sent 26 bytes  received 8 bytes  68.00 bytes/sec
total size is 352  speedup is 10.35
第三种情况:有白名单也有黑名单,白名单网段或主机信息被充许,黑名单网段或主机被阻止,其它充许
#备份服务器,添加白名单与黑名单
[root@backup nfs]# egrep 'allow|deny' /etc/rsyncd.conf 
hosts allow = 172.16.1.0/24
hosts deny =10.0.0.0/24
[root@backup nfs]# killall rsync 
[root@backup nfs]# rsync --daemon
#存储服务器,黑名单10网段被拒绝访问
[root@nfs01 test_dir]# rsync -avz /etc/hosts  rsync_backup@10.0.0.41::nfs/sa/ --passw
ord-file=/etc/rsync.password @ERROR: Unknown module 'nfs'
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3
.0.6]
#存储服务器,白名单172网段被允许访问
[root@nfs01 test_dir]# rsync -avz /etc/hosts  rsync_backup@172.16.1.41::nfs/sa/ --pas
sword-file=/etc/rsync.password sending incremental file list

sent 26 bytes  received 8 bytes  68.00 bytes/sec
total size is 352  speedup is 10.35
[root@nfs01 test_dir]# 

五、守护进程之无差异备份(慎用,不一小心会把备份目录清空)

#初始备份服务器
[root@backup nfs]# ll
total 4
-rw-r--r-- 1 rsync rsync    0 Feb 12 17:46 a.txt
-rw-r--r-- 1 rsync rsync    0 Feb 12 17:46 c.txt
drwxr-xr-x 2 rsync rsync 4096 Feb 12 18:00 sa
#同步后的备份服务器
[root@backup nfs]# ll
total 4
-rw-r--r-- 1 rsync rsync  0 Feb 12 18:22 10.txt
-rw-r--r-- 1 rsync rsync  0 Feb 12 18:22 1.txt
-rw-r--r-- 1 rsync rsync  0 Feb 12 18:22 2.txt
-rw-r--r-- 1 rsync rsync  0 Feb 12 18:22 3.txt
-rw-r--r-- 1 rsync rsync  0 Feb 12 18:22 4.txt
-rw-r--r-- 1 rsync rsync  0 Feb 12 18:22 5.txt
-rw-r--r-- 1 rsync rsync  0 Feb 12 18:22 6.txt
-rw-r--r-- 1 rsync rsync  0 Feb 12 18:22 7.txt
-rw-r--r-- 1 rsync rsync  0 Feb 12 18:22 8.txt
-rw-r--r-- 1 rsync rsync  0 Feb 12 18:22 9.txt
-rw-r--r-- 1 rsync rsync  0 Feb 12 17:46 a.txt
-rw-r--r-- 1 rsync rsync  0 Feb 12 17:46 b.txt
-rw-r--r-- 1 rsync rsync  0 Feb 12 17:46 c.txt
-rw-r--r-- 1 rsync rsync  0 Feb 12 17:46 d.txt
-rw-r--r-- 1 rsync rsync 29 Feb 12 17:57 exclude_file.txt
[root@backup nfs]# 

#存储服务器,在同步的时候加入--delete参数后,会使两台服务器数据一模一样,会把多的文件进行删除
[root@nfs01 test_dir]# rsync -avz /test_dir/ --delete  rsync_backup@172.16.1.41::nfs 
--password-file=/etc/rsync.password sending incremental file list
./
deleting sa/hosts
deleting sa/
1.txt
10.txt
2.txt
3.txt
4.txt
5.txt
6.txt
7.txt
8.txt
9.txt
b.txt
d.txt
exclude_file.txt

sent 722 bytes  received 258 bytes  1960.00 bytes/sec
total size is 29  speedup is 0.03
[root@nfs01 test_dir]# 
#清空备份目录,存储服务器新建一个空目录然后进行同步
[root@nfs01 test_dir]# mkdir /null
[root@nfs01 test_dir]# rsync -avz /null/ --delete  rsync_backup@172.16.1.41::nfs --pa
ssword-file=/etc/rsync.password sending incremental file list
./
deleting exclude_file.txt
deleting d.txt
deleting c.txt
deleting b.txt
deleting a.txt
deleting 9.txt
deleting 8.txt
deleting 7.txt
deleting 6.txt
deleting 5.txt
deleting 4.txt
deleting 3.txt
deleting 2.txt
deleting 10.txt
deleting 1.txt
sent 29 bytes  received 11 bytes  26.67 bytes/sec
total size is 0  speedup is 0.00
[root@nfs01 test_dir]# 
# 使用空目录进行同步后的备份服务器
[root@backup nfs]# ll
total 0
[root@backup nfs]# 

六、守护进程之列表功能配置(建议关闭此功能,否则会带来安全隐患)

将配置文件中的list=false改成true,即可在客户端中显示rsync服务端中所有模块信息
#备份服务器
[root@backup nfs]# grep "list" /etc/rsyncd.conf 
list = true
[root@backup nfs]# killall rsync
[root@backup nfs]# rsync --daemon

#存储服务器
[root@nfs01 test_dir]# rsync -avz rsync_backup@172.16.1.41::
backup             "backup dir by oldboy"
nfs                "nfs dir by rsync"
[root@nfs01 test_dir]# 
posted @ 2019-03-11 09:18  游走在边缘的人  阅读(104)  评论(0编辑  收藏  举报