服務端:
[root@stu234-11 ~]# cat /etc/rsyncd.conf(默認沒有這個配置文件)
[root@stu234-11 ~]# vi /etc/rsyncd.conf(編輯配置文件)
#rsync_config_______________start
#created by oldboy 15:01 2007-6-5
#QQ 31333741 blog:
http://oldboy.blog.51cto.com
##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" [New] 24L, 571C written
[root@stu234-11 ~]# cat /etc/rsyncd.conf(驗證配置文件)
#rsync_config_______________start
#created by oldboy 15:01 2007-6-5
#QQ 31333741 blog:
http://oldboy.blog.51cto.com
##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
[root@stu234-11 ~]# id rsync
id: rsync:無此用戶
[root@stu234-11 ~]# useradd rsync -s /sbin/nologin -M(建立虛擬用戶,-M爲不建立用戶家目錄)
[root@stu234-11 ~]# id rsync
uid=501(rsync) gid=501(rsync) 組=501(rsync)
[root@stu234-11 ~]# mkdir -p /backup(建立備份目錄)
[root@stu234-11 ~]# ll -d /backup
drwxr-xr-x 2 root root 4096 2015-11-12 10:12 /backup
[root@stu234-11 ~]# chown -R rsync.rsync /backup(改變用戶屬主屬組,-R爲遞歸)
[root@stu234-11 ~]# ll -d /backup
drwxr-xr-x 2 rsync rsync 4096 2015-11-12 10:12 /backup
[root@stu234-11 ~]# rsync --daemon(啓動守護進程)
[root@stu234-11 ~]# netstat -lntup|grep rsync(查看進程是否啓動,可以看出端口號爲873)
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 2181/rsync
tcp 0 0 :::873 :::* LISTEN 2181/rsync
[root@stu234-11 ~]# echo "rsync_backup:oldboy" >/etc/rsync.password(用戶名爲rsync_backup,密碼爲oldboy,放入密碼文件裏)
[root@stu234-11 ~]# cat /etc/rsync.password
rsync_backup:oldboy
[root@stu234-11 ~]# ll /etc/rsync.password
-rw-r--r-- 1 root root 20 2015-11-12 10:18 /etc/rsync.password
[root@stu234-11 ~]# chmod 600 /etc/rsync.password(改變密碼文件權限只有root用戶能讀寫)
[root@stu234-11 ~]# ll /etc/rsync.password
-rw------- 1 root root 20 2015-11-12 10:18 /etc/rsync.password
[root@backup ~]# vim /etc/rc.local(放入開機自啓動)
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/usr/bin/rsync --daemon
~
~
~
~
~
~
~
~
~
~
~
~
~
"/etc/rc.local" 8L, 244C 已寫入
客戶端:
[root@stu234-12 ~]# mkdir -p /backup(建立備份目錄)
[root@stu234-12 ~]# ll -d /backup/
drwxr-xr-x 2 root root 4096 2015-11-12 11:15 /backup/
[root@stu234-12 ~]# echo "oldboy" >/etc/rsync.password(建立密碼文件)
[root@stu234-12 ~]# cat /etc/rsync.password
oldboy
[root@stu234-12 ~]# ll /etc/rsync.password
-rw-r--r-- 1 root root 7 2015-11-12 11:23 /etc/rsync.password
[root@stu234-12 ~]# chmod 600 /etc/rsync.password(改變密碼文件權限只有root用戶能讀寫)
[root@stu234-12 ~]# ll /etc/rsync.password
-rw------- 1 root root 7 2015-11-12 11:23 /etc/rsync.password
客戶端推送實例:
[root@stu234-12 ~]# touch /backup/{a..d}.txt(在backup文件夾下建立文件)
[root@stu234-12 ~]# ll /backup/
總用量 0
-rw-r--r-- 1 root root 0 2015-11-12 11:36 a.txt
-rw-r--r-- 1 root root 0 2015-11-12 11:36 b.txt
-rw-r--r-- 1 root root 0 2015-11-12 11:36 c.txt
-rw-r--r-- 1 root root 0 2015-11-12 11:36 d.txt
[root@stu234-12 ~]# rsync -avz /backup/ [email protected]::backup --password-file=/etc/rsync.password
#(第一處標紅爲backup文件夾下內容推送,不加/爲整個目錄推送;第二處標紅代表爲/etc/rsyncd.conf配置文件裏[backup]模塊下內容)
sending incremental file list
./
a.txt
b.txt
c.txt
d.txt
sent 213 bytes received 87 bytes 600.00 bytes/sec
total size is 0 speedup is 0.00
服務端檢查:
[root@stu234-11 ~]# ll /backup/
總用量 0
-rw-r--r-- 1 rsync rsync 0 2015-11-12 11:36 a.txt
-rw-r--r-- 1 rsync rsync 0 2015-11-12 11:36 b.txt
-rw-r--r-- 1 rsync rsync 0 2015-11-12 11:36 c.txt
-rw-r--r-- 1 rsync rsync 0 2015-11-12 11:36 d.txt