码迷,mamicode.com
首页 > 系统相关 > 详细

Rsync --daemon(守护进程模式)

时间:2015-12-01 19:45:19      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:linux   rsync   daemon   推送   

服务端:

[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@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/ rsync_backup@172.16.1.11::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


本文出自 “DNA种子” 博客,请务必保留此出处http://whyseed.blog.51cto.com/10827449/1718553

Rsync --daemon(守护进程模式)

标签:linux   rsync   daemon   推送   

原文地址:http://whyseed.blog.51cto.com/10827449/1718553

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!