Rsync备份服务器的上机实践操作

有关概念在这里我不做说明,网上有很多,在这里我只介绍一下我的上机操作实践,以便空闲之余回看!

Rsync本地模式实战:

[root@oldboy ~]# mkdir /etc/a   ==》创建一个目录

[root@oldboy ~]# rsync -vzrtopg /etc/a /mnt/     ==》将这个新创建的目录备份/mnt/目录

sending incremental file list

a/        ==》备份成功

sent 37 bytes  received 16 bytes  106.00 bytes/sec

total size is 0  speedup is 0.00

[root@oldboy ~]# cd /mnt/   ==》切换到/mnt/目录

[root@oldboy mnt]# ll     ==》查看是否备份成功

总用量 4

扫描二维码关注公众号,回复: 1762940 查看本文章

drwxr-xr-x 2 root root 4096 3月  13 19:38 a

[root@oldboy mnt]# cd ~     

[root@oldboy ~]# mkdir /etc/b   ==》创建一个空白文件/etc/b

[root@oldboy ~]# rsync -avz --delete /etc/b /mnt/   ==》尝试删除/mnt/目录下的文件

sending incremental file list

b/

sent 37 bytes  received 16 bytes  106.00 bytes/sec

total size is 0  speedup is 0.00

[root@oldboy ~]# cd /mnt/      ==》黄色部分是我在删除的过程中的一次次尝试 ,显示出来我对删除中不熟练

[root@oldboy mnt]# ll

总用量 8

drwxr-xr-x 2 root root 4096 3月  13 19:38 a

drwxr-xr-x 2 root root 4096 3月  13 19:39 b

       

[root@oldboy mnt]# rsync -avz /etc/b/  /mnt/

sending incremental file list

./

 

sent 29 bytes  received 15 bytes  88.00 bytes/sec

total size is 0  speedup is 0.00

[root@oldboy mnt]# ll

总用量 8

drwxr-xr-x 2 root root 4096 3月  13 19:38 a

drwxr-xr-x 2 root root 4096 3月  13 19:39 b

[root@oldboy mnt]# rsync -avz  --delete /etc/b /mnt/      红色部分是两次删除的区别

sending incremental file list

   

sent 34 bytes  received 13 bytes  94.00 bytes/sec

total size is 0  speedup is 0.00

[root@oldboy mnt]# rsync -avz  --delete /etc/b/ /mnt/

sending incremental file list

 

sent 26 bytes  received 12 bytes  76.00 bytes/sec

total size is 0  speedup is 0.00

[root@oldboy mnt]# ll

总用量 0

 

deleting b/

deleting a/

 

Rsync使用远程ssh通道实践上机实战及总结

服务端操作:

[root@backup ~]# rsync -avz /etc/hosts -e 'ssh -p 22 ' oldboy@10.0.0.31:/mnt/

The authenticity of host '10.0.0.31 (10.0.0.31)' can't be established.

RSA key fingerprint is 9a:51:16:25:33:40:0f:5b:04:70:ea:71:12:84:99:69.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '10.0.0.31' (RSA) to the list of known hosts.

[email protected]'s password:

sending incremental file list

hosts

rsync: mkstemp "/mnt/.hosts.i6Resk" failed: Permission denied (13)

sent 202 bytes  received 31 bytes  31.07 bytes/sec

total size is 345  speedup is 1.48

rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]

[root@backup ~]# rsync -avz /etc/hosts -e 'ssh -p 22 ' root@10.0.0.31:/mnt/

[email protected]'s password:

sending incremental file list

hosts

sent 202 bytes  received 31 bytes  93.20 bytes/sec

total size is 345  speedup is 1.48

客户端操作:

[root@nfs01 ~]# cd /mnt/

[root@nfs01 mnt]# ll

总用量 0

[root@nfs01 mnt]# ll

总用量 4

-rw-r--r-- 1 root root 345 3月  13 19:26 hosts

[root@nfs01 mnt]#

但上述传输速度过慢,现对服务端进行一下修改:

修改要连接的服务器的/etc/ssh/sshd_config配置文件:

80 #GSSAPIAuthentication no

81 GSSAPIAuthentication yes

修改为

80 GSSAPIAuthentication no

81 #GSSAPIAuthentication yes

122 #UseDNS yes

修改为

122 UseDNS no

"/etc/ssh/sshd_config" 138L, 3877C 已写入                      

[root@nfs01 mnt]# /etc/init.d/sshd restart

停止 sshd:                                                [确定]

正在启动 sshd:                                            [确定]

Rsync服务器之daemon服务模式上机实战

         -----这才是rsync的主角,这是rsync服务的重点所在。

两台机器

服务端:

[root@backup ~]# ifconfig eth0  

eth0      Link encap:Ethernet  HWaddr 00:0C:29:F7:EC:E5  

          inet addr:10.0.0.41  Bcast:10.0.0.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fef7:ece5/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:1150 errors:0 dropped:0 overruns:0 frame:0

          TX packets:993 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:134810 (131.6 KiB)  TX bytes:122678 (119.8 KiB)

[root@backup ~]# cat /etc/redhat-release

CentOS release 6.7 (Final)

[root@backup ~]# uname -r

2.6.32-573.el6.x86_64

[root@backup ~]# rsync --version

rsync  version 3.0.6  protocol version 30

Copyright (C) 1996-2009 by Andrew Tridgell, Wayne Davison, and others.

Web site: http://rsync.samba.org/

Capabilities:

    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,

    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,

    append, ACLs, xattrs, iconv, symtimes

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you

are welcome to redistribute it under certain conditions.  See the GNU

General Public Licence for details.

Rsync 的配置文件在/etc/rsycnd.conf   默认是不存在的

可以man rsyncd.conf 查看配置文件里的内容,然后再来添加

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

#rsync_config__________________________start

#created by oldboy 20:30 2018-3-13

##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

[backup]

path = /backup

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

#rsync_config________________end

~                                                                                

"/etc/rsyncd.conf" 21L, 488C 已写入

  

[root@backup ~]# id rsync   ==》查看rsync用户是否存在

id: rsync:无此用户

[root@backup ~]# useradd rsync -s /sbin/nologin -M   -M:不建家目录

[root@backup ~]# tail -1 /etc/passwd

rsync:x:501:501::/home/rsync:/sbin/nologin

[root@backup ~]# rsync --daemon   ==》启动服务

[root@backup ~]# ps -ef |grep rsync|grep -v grep   ==》查看是否启动

root      27649      1  0 20:39 ?        00:00:00 rsync --daemon

[root@backup ~]# ll -d /backup

ls: 无法访问/backup: 没有那个文件或目录

[root@backup ~]# mkdir /backup

[root@backup ~]# ls -ld /backup

drwxr-xr-x 2 root root 4096 3月  13 20:44 /backup

[root@backup ~]# chmod 777 /backup   ==》不安全

[root@backup ~]# ll -d /backup

drwxrwxrwx 2 root root 4096 3月  13 20:44 /backup

[root@backup ~]# chmod 755 /backup

[root@backup ~]# ll -d /backup

drwxr-xr-x 2 root root 4096 3月  13 20:44 /backup

[root@backup ~]# chown rsync.rsync /backup   权限越小越安全

[root@backup ~]# ll -d /backup

drwxr-xr-x 2 rsync rsync 4096 3月  13 20:44 /backup

[root@backup ~]# ll /etc/rsync.passwd

ls: 无法访问/etc/rsync.passwd: 没有那个文件或目录

[root@backup ~]# vim /etc/rsync.passwd

rsync_backup:oldboy     用户:密码

[root@backup ~]# cat /etc/rsync.passwd

rsync_backup:oldboy

[root@backup ~]# ls -l /etc/rsync.passwd

-rw-r--r-- 1 root root 21 3月  13 20:50 /etc/rsync.passwd

[root@backup ~]# chmod 600 /etc/rsync.passwd    修该/etc/rsync.passwd文件权限,注意此处必须为600不然会在日志文件中报错

[root@backup ~]# ls /etc/rsync.passwd -l

-rw------- 1 root root 21 3月  13 20:50 /etc/rsync.passwd

 

 

 

 

 

 

 

客户端:

[root@nfs01 ~]# ifconfig eth0

eth0      Link encap:Ethernet  HWaddr 00:0C:29:82:B0:96  

          inet addr:10.0.0.31  Bcast:10.0.0.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe82:b096/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:2391 errors:0 dropped:0 overruns:0 frame:0

          TX packets:1654 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:243484 (237.7 KiB)  TX bytes:228034 (222.6 KiB)

[root@nfs01 ~]# cat /etc/redhat-release

CentOS release 6.7 (Final)

[root@nfs01 ~]# uname -r

2.6.32-573.el6.x86_64

[root@nfs01 ~]# rsync --version

rsync  version 3.0.6  protocol version 30

Copyright (C) 1996-2009 by Andrew Tridgell, Wayne Davison, and others.

Web site: http://rsync.samba.org/

Capabilities:

    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,

    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,

    append, ACLs, xattrs, iconv, symtimes

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you

are welcome to redistribute it under certain conditions.  See the GNU

General Public Licence for details.

[root@nfs01 ~]# vim /etc/rsync.password

oldboy

[root@nfs01 ~]# cat /etc/rsync.password

oldboy

[root@nfs01 ~]# chmod 600 /etc/rsync.password

[root@nfs01 ~]# ll /etc/rsync.password

-rw------- 1 root root 7 3月  14 19:24 /etc/rsync.password

[root@nfs01 ~]# cd /mnt/

[root@nfs01 mnt]# mkdir -p /backup

[root@nfs01 mnt]# ll

总用量 0

[root@nfs01 mnt]# ll -d /backup

drwxr-xr-x 2 root root 4096 3月  14 19:25 /backup

 

客户端向服务端推送:

[root@nfs01 mnt]# cd /backup/    ==》在客户端创建一个和服务端相同的目录,目的是为了可以将需要推送的文件都放到该目录下进行推送

[root@nfs01 backup]# touch stu{01..100}   ==》在该目录下创建文件

[root@nfs01 backup]# rsync -avz /backup/ [email protected]::backup/ --password-file=/etc/rsync.password      ==》将该目录下的文件都推送给服务端

sending incremental file list

./

stu001

stu002

stu003

......

stu099

stu100

sent 4425 bytes  received 1911 bytes  12672.00 bytes/sec

total size is 0  speedup is 0.00

[root@backup ~]# ls /backup/   ==》查看服务端下/backup/下的文件

stu001  stu011  stu021  stu031  stu041  stu051  stu061  stu071  stu081  stu091 ==》推送成功

[root@nfs01 backup]# rsync -avz /backup/ rsync://[email protected] /backup/ --password-file=/etc/rsync.password    ==》另一种推送方法

Unexpected remote arg: rsync://[email protected]

rsync error: syntax or usage error (code 1) at main.c(1201) [sender=3.0.6]

[root@nfs01 backup]# rsync -avz /backup/ rsync://[email protected]/backup/ --password-file=/etc/rsync.password

sending incremental file list

./

stu001

stu002

stu003

[root@backup ~]# rm -fr /backup/   ==》注意这里的删除是将该目录及该目录下的文件全删除

[root@backup ~]# cd /backup

-bash: cd: /backup: 没有那个文件或目录

[root@backup ~]#

[root@backup ~]#

[root@backup ~]#

[root@backup ~]# mkdir /backup

[root@backup ~]# chown rsync.rsync /backup

[root@backup ~]# ll /backup/

总用量 0

[root@backup ~]# ll /backup

总用量 0

[root@backup ~]# ll /backup -d

drwxr-xr-x 2 rsync rsync 4096 3月  14 19:48 /backup

[root@backup ~]# ll /backup

总用量 0

-rw-r--r-- 1 rsync rsync 0 3月  14 19:27 stu001

-rw-r--r-- 1 rsync rsync 0 3月  14 19:27 stu002

-rw-r--r-- 1 rsync rsync 0 3月  14 19:27 stu003

-rw-r--r-- 1 rsync rsync 0 3月  14 19:27 stu004

[root@nfs01 backup]# rsync -avz /backup/ rsync://[email protected]/backup/stu01 --password-file=/etc/rsync.password     ==》这里是推送目录下的某一个文件,这里只展示一种方法

sending incremental file list

created directory stu01

./

stu001

stu002

stu003

stu004

stu005

stu006

st[root@backup ~]# ll /backup/   ==》推送成功

总用量 4

drwxr-xr-x 2 rsync rsync 4096 3月  14 19:27 stu01

u007

客户端向服务端拉取文件

[root@nfs01 ~]# rsync -avz [email protected]::backup /backup/stu01 --password-file=/etc/rsync.password  ==》拉取/backup/目录下的stu01文件

receiving incremental file list

created directory /backup/stu01

./

stu01/

stu01/stu001

stu01/stu002

[root@nfs01 backup]# ll

总用量 0

[root@nfs01 backup]# rsync -avz rsync://[email protected]/backup/a /backup/ --password-file=/etc/rsy

rsync.password  rsyslog.conf    rsyslog.d/      

[root@nfs01 backup]# rsync -avz rsync://[email protected]/backup/a /backup/ --password-file=/etc/rsync.password

receiving incremental file list

a

sent 83 bytes  received 130 bytes  426.00 bytes/sec

total size is 0  speedup is 0.00

[root@nfs01 backup]# ll

总用量 0

-rw-r--r-- 1 root root 0 3月  14 20:33 a

猜你喜欢

转载自blog.csdn.net/zisefeizhu/article/details/79569291