其中rsync用户默认是不存在的,需要创建用户
[root@rsync ~]# useradd rsync -s /sbin/nologin -M
[root@rsync ~]# cat /etc/passwd|grep rsync
rsync:x:501:501::/home/rsync:/sbin/nologin
[root@rsync ~]# id rsync
uid=501(rsync) gid=501(rsync) 组=501(rsync)
为什么用虚拟用户?
应答:文件和进程都要满足属主的要求,文件和进程的存在一定是需要用户的,也是为了安全问题。
创建/backup目录,并且属主和属组都属于rsync
[root@rsync ~]# mkdir /backup/ -p
[root@rsync ~]# chown -R rsync.rsync /backup/
[root@rsync ~]# ls -ld /backup/
drwxr-xr-x 2 rsync rsync 4096 12月 9 2016 /backup/
创建配置文件/etc/rsync.password,默认不存在这个配置文件
[root@rsync ~]# cat /etc/rsync.password
rsync_backup:linuxidc
[root@rsync ~]#chmod 600 /etc/rsync.password
[root@rsync ~]# ls -l /etc/rsync.password
-rw-------. 1 root root 20 11月 29 01:14 /etc/rsync.password
启动服务:
[root@rsync ~]# rsync --daemon
[root@rsync ~]#ps -ef|grep rsync|grep -v grep ##查看进程有没有启动
root 3046 1 0 15:19 ? 00:00:00
加入开机自启动
[root@rsync ~]# tail -1 /etc/rc.local
/usr/bin/rsync --daemon
三、Rsync客户端的安装
编辑配置文件/etc/rsync.passwd,该配置文件默认不存在
vim /etc/rsync.passwd
[root@linuxidc backup]# cat /etc/rsync.password
linuxidc
chmod 600 /etc/rsync.passwd
创建backup目录
mkdir -p /backup
cd /backup
touch stu{01,100}
客户端推送:
方法1:
[root@linuxidc backup]# rsync -avz /backup/ rsync_backup@172.16.1.41::backup/ --password-file=/etc/rsync.password
方法2:
[root@linuxidc backup]# rsync -avz /backup/ rsync://rsync_backup@172.16.1.41/backup/ --password-file=/etc/rsync.password
从客户端把服务端的东西拉回来的方案
服务端:
[root@linuxidc backup]# touch 1 234
[root@linuxidc backup]# ls
1 234
客户端:
[root@linuxidc ming]# rsync -avz rsync_backup@172.16.1.41::backup/ /ming/ --password-file=/etc/rsync.password
receiving incremental file list
./
1
234
sent 105 bytes received 204 bytes 618.00 bytes/sec
total size is 0 speedup is 0.00
[root@linuxidc ming]# ls
1 234
四、Rsync多模块实战
1.1.1 多模块实战
实例1:
环境:
[root@linuxidc ~]# cat /etc/rsyncd.conf
#rsync_config_____________________________start
#created by linuxidc 15:01 2007-6-5
##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/rsyncd.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]
path = /backup
[chen]
path = /chen
#rsync_config________________________end
服务器端:
[root@linuxidc ~]# mkdir /chen
[root@linuxidc ~]# ls -ld /chen/
drwxr-xr-x 2 rsync rsync 4096 12月 2 18:58 /chen/
客户端
[root@linuxidc ~]# ls -ld /ming
drwxr-xr-x 2 root root 4096 12月 2 18:26 /ming
[root@linuxidc ~]# rsync -avz /ming/ rsync_backup@172.16.1.41::chen/ --password-file=/etc/rsync.password
sending incremental file list
./
ming1
ming10
ming2
ming3
ming4
ming5
ming6
ming7
ming8
ming9
sent 463 bytes received 201 bytes 1328.00 bytes/sec
total size is 0 speedup is 0.00
服务端查看效果:
[root@linuxidc chen]# ls
ming1 ming10 ming2 ming3 ming4 ming5 ming6 ming7 ming8 ming9
实例2:
环境:
[root@linuxidc chen]# cat /etc/rsyncd.conf
#rsync_config_____________________________start
#created by linuxidc 15:01 2007-6-5
##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/rsyncd.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]
path = /backup
[chen]
path = /chen
[luo]
path = /luo
ignore errors
read only = false
list = false