Rsync以守护进程(socket)的方式传输数据
Rsync以守护进程(socket)的方式传输数据
Rsync服务部署
一、以守护进程(socket)的方式传输数据(重点)
部署环境:
分别用uname命令查看各系统相关信息
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[root@A-Server58 ~]# uname -r
2.6.18-308.el5
[root@A-Server58 ~]# uname -s
Linux
[root@A-Server58 ~]# uname -o
GNU/Linux
[root@A-Server58 ~]# uname -i
x86_64
[root@A-Server58 ~]# uname -n
A-Server58
|
操作系统
| 主机名 | 网卡eth0 | 默认网关 | 用途 |
| root@A-Server58 | 192.168.1.111 | 192.168.1.1 | Rsync服务端 |
| root@B-Server64 | 192.168.1.121 | 192.168.1.1 | Rsync 节点 |
| root@C-Server58 | 192.168.1.119 | 192.168.1.1 | Rsync 节点 |
子网掩码均为255.255.255.0
具体需求:
要求在A-Server上以rsync守护进程的方式部署rsync服务,使得所有rsync节点客户端主机,可以把本地数据通过rsync的方式备份到数据备份服务器A-Server上,本例的客户端仅以B-Server、C-Server为例
备份拓扑

- 部署rsync服务
1)rsync服务端配置过程
配置rsyncd.conf
首先确认软件是否安装
|
1
2
3
|
[root@A-Server58 ~]# rpm -aq rsync
rsync-3.0.6-4.el5_7.1
|
[root@A-Server58 ~]# vi /etc/rsyncd.conf #增加如下配置,
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#Rsync server
#created by mrxiong 15:01 2014-5-5
##rsyncd.conf start##
uid = root
gid = root
use chroot = no
max connections = 2000
timeout = 600
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 = 192.168.1.1/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
[dingjian]
comment = www by mrxiong15:01 2014-5-5
path = /dingjian/
|
|
1
2
3
4
5
6
7
8
9
10
11
|
[root@A-Server58 ~]# dos2unix /etc/rsyncd.conf
dos2unix: converting file /etc/rsyncd.conf to UNIX format ...
[root@A-Server58 /]# mkdir dingjian
[root@A-Server58 /]# ls -ld dingjian
drwxr-xr-x 2 root root 4096 Apr 23 01:05 dingjian
|
创建同步的本地目录/dingjian 并根据需要授权
目录和/etc/rsync.password为配置文件中path = /dingjian/参数的配置
配置用于rsync同步的账号、密码及账号文件以限
[root@A-Server58 ~]# echo "rsync_backup:dingjian">/etc/rsync.password
#其中rsync_backup:95862909中的rsync_backup为同步传输用到的虚拟账号,这个账号仅为rsync的账号,不需要是系统账号,后面的dingjian为密码,不超过8位
|
1
2
3
4
5
6
7
8
9
10
11
|
[root@A-Server58 ~]# chmod 600 /etc/rsync.password #权限必须为600
[root@A-Server58 ~]# cat /etc/rsync.password
rsync_backup:95862909
[root@A-Server58 ~]# ll /etc/rsync.password
-rw------- 1 root root 22 Apr 22 19:47 /etc/rsync.password
[root@A-Server58 ~]#
|
启动rsync服务
以守护进程方式来启动rsync服务
|
1
|
[root@A-Server58 ~]# rsync --daemon
|
拓展:rsync的进程参数选项
--daemon #表示以守护进程的方式启动rsync服务
--address #绑定指定ip地址
--config=FILE #更改配置文件路径,而不是默认的/etc/rsyncd.conf
--port=PORT #更改其它端口提供服务,而不是缺省的873端口
提示:以上几个选项为了解内容,生产场景使用的不多
通过端口查服务
|
1
2
3
4
5
6
7
8
9
10
11
|
[root@A-Server58 ~]# lsof -i tcp:873
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsync 27185 root 3u IPv4 44404 0t0 TCP *:rsync (LISTEN)
[root@A-Server58 ~]# netstat -lntup|grep 873
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 27185/rsync
|
设置rsync服务开机自启动
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[root@A-Server58 ~]# echo "/usr/bin/rsync --daemon">>/etc/rc.local
[root@A-Server58 ~]# cat /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
|
注意当然还可以用chkconfig rsync on命令,但是必须要编写适合chkconfig操作脚本才行
重起rsync的组合命令
|
1
2
3
|
[root@A-Server58 ~]# pkill rsync #关闭rsync服务
[root@A-Server58 ~]# rsync --daemon #启动rsync服务
|
检查启动的进程
|
1
|
[root@A-Server58 ~]# ps -ef |grep rsync
|
几个进程管理命令
杀进程:pkill rsync
killall rsync 可能一次杀不死,要连按连杀
killall -9 rsync 强制杀死进程 -9
kill -9 4084 利用端口号加-9 强制进程,
2)rsync客户端配置过程
请注意与服务端的配置区别
服务端192.168.1.119 192.168.1.121分别做如下操作
|
1
2
3
4
5
6
7
8
9
10
11
|
[root@B-Server64 ~]# echo "95862909">/etc/rsync.password #这里仅配置密码,不需要账号,这是与服务端的区别
[root@B-Server64 ~]# chmod 600 /etc/rsync.password #必须为600权限
[root@B-Server64 ~]# cat /etc/rsync.password
95862909
[root@B-Server64 ~]# ll /etc/rsync.password
-rw-------. 1 root root 9 Apr 22 20:01 /etc/rsync.password
|
此时rsync服务配置大功告成!
检查部置的rsync服务
默认情况,以下均为rsync客户端执行操作,下面以ip192.168.1.121 B-Server为例说明:
推送(即从客户端同步文件或目录到服务器端)
从客户端推送/etc 目录到服务端rsync指定的目录(本文档为/dingjian)下
rsync -avzP /etc rsync_backup@192.168.1.111::dingjian/ --password-file=/etc/rsync.password
从服务端指定的/dingjian目录把数据拉取到客户端本地/tmp目录下
rsync -avzP rsync_backup@192.168.1.111::dingjian/ --password-file=/etc/rsync.password /tmp
排除打包
方法一:
在客户端操作:
[root@B-Server64 tmp]# rsync -avz --exclude=etc --exclude=tmp . rsync_backup@192.168.1.111::dingjian --password-file=/etc/rsync.password
使用--exclude=进行排除
方法二:
在服务端配置rsyncd.conf参数实现
加入排除参数 exclude=etc tmp
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
[root@A-Server58 dingjian]# cat /etc/rsyncd.conf
sync server
#created by oldboy 15:01 2009-6-5
##rsyncd.conf start##
uid = root
gid = root
use chroot = no
max connections = 2000
timeout = 600
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 = 192.168.1.1/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
exclude=tmp etc
[dingjian]
comment = www by old0boy 14:18 2012-1-13
path = /dingjian/
|
重启rsync服务 杀进程,重启服务
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@A-Server58 dingjian]# pkill rsync
[root@A-Server58 dingjian]# ps -ef|grep rsync
root 27624 27033 0 22:45 pts/0 00:00:00 grep rsync
[root@A-Server58 dingjian]# rsync --daemon
[root@A-Server58 dingjian]# ps -ef|grep rsync
root 27626 1 0 22:45 ? 00:00:00 rsync --daemon
root 27632 27033 0 22:45 pts/0 00:00:00 grep rsync
|
测试推送备份
[root@B-Server64 tmp]# rsync -avz . rsync_backup@192.168.1.111::dingjian --password-file=/etc/rsync.password
无差异同步
要实现这种同步方法就要使用--delete参数了
本地测试
[root@B-Server64 tmp]# rsync -avzP --delete /null/ /tmp/
拉取方法
[root@B-Server64 tmp]# rsync -avzrtopg --delete --progress rsync_backup@192.168.1.111::dingjian/ /tmp/ --password-file=/etc/rsync.password
推送方法
[root@B-Server64 tmp]# rsync -avzrtopg --delete --progress . rsync_backup@192.168.1.111::dingjian/ --password-file=/etc/rsync.password
执行--delete参数从rsync服务端往rsync客户端拉取数据时,一定要小心,最好不用,它比从rsync客户端带--delete参数往rsync服务端推送危险得多,客户端带--delete参数往服务端推送仅删除服务端模块下的数据,而前者有能力删除rsync客户端本地的所有数据,包括根下的所有目录
生场场景没有特殊要求,应避免使用,一般是有需要两台服务器之间,必须要求数据一致且时时性又不是很高的情况,如两台负载均衡下面的web服务器之间的同步,或者高可用双机配置之间的同步等。
多目录模块同步
配置/etc/rsyncd.conf配置文件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#Rsync server
#created by oldboy 15:01 2009-6-5
##rsyncd.conf start##
uid = root
gid = root
use chroot = no
max connections = 2000
timeout = 600
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 = 10.0.0.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
########################################
[dingjian]
comment = www by old0boy 14:18 2012-1-13
path = /dingjian/
#####################################
[www]
comment = www by old0boy 14:18 2012-1-13
path = /data0/www/www/
#####################################
[bbs]
comment = bbs by old0boy 14:18 2012-1-13
path = /data0/www/bbs/
#####################################
[blog]
comment = blog by old0boy 14:18 2012-1-13
path = /data0/www/blog/
|
重启rsync服务
pkill rsync
ps -ef|grep rsync
rsync --daemon
ps -ef|grep rsync
Rsync以守护进程(socket)的方式传输数据的更多相关文章
- Linux中的两种守护进程stand alone和xinetd
Linux中的两种守护进程stand alone和xinetd --http://www.cnblogs.com/itech/archive/2010/12/27/1914846.html#top 一 ...
- Linux守护进程详解(init.d和xinetd) [转]
一 Linux守护进程 Linux 服务器在启动时需要启动很多系统服务,它们向本地和网络用户提供了Linux的系统功能接口,直接面向应用程序和用户.提供这些服务的程序是由运行在后台 的守护进程来执行的 ...
- Linux守护进程详解(init.d和xinetd)
一 Linux守护进程 Linux 服务器在启动时需要启动很多系统服务,它们向本地和网络用户提供了Linux的系统功能接口,直接面向应用程序和用户.提供这些服务的程序是由运行在后台的守护进程来执行的. ...
- 守护进程与Supervisor
博客链接:http://www.cnblogs.com/zhenghongxin/p/8676565.html 消息队列处理后台任务带来的问题 在系统稍微大些的时候,我们经常会用到消息队列(实现的方式 ...
- Linux守护进程的编程实现(转)
http://blog.csdn.net/zg_hover/article/details/2553321 http://blog.csdn.net/kongdefei5000/article/det ...
- Linux守护进程的编程实现
Linux 守护进程的编程方法 守护进程(Daemon)是执行在后台的一种特殊进程.它独立于控制终端而且周期性地执行某种任务或等待处理某些发生的事件.守护进程是一种非常实用的进程.Linux的大多数s ...
- Linux进程学习(孤儿进程和守护进程)
孤儿进程和守护进程 通过前面的学习我们了解了如何通过fork()函数和vfork()函数来创建一个进程.现在 我们继续深入来学习两个特殊的进程:孤儿进程和守护进程 一.孤儿进程 1.什么是 孤儿进程如 ...
- Linux企业级项目实践之网络爬虫(6)——将程序设计成为守护进程
在linux或者unix操作系统中在系统的引导的时候会开启很多服务,这些服务就叫做守护进程.为了增加灵活性,root可以选择系统开启的模式,这些模式叫做运行级别,每一种运行级别以一定的方式配置系统. ...
- Linux编程实现守护进程
Linux 守护程序 守护进程(Daemon)它是在一个特定的过程的背景进行.它独立于控制终端的和周期性地执行某些任务或待某些事件.是一种非常实用的进程. Linux的大多数server就是用守护进程 ...
随机推荐
- Django 数据库进阶操作
基本操作 # 增 # # models.Tb1.objects.create(c1='xx', c2='oo') 增加一条数据,可以接受字典类型数据 **kwargs # obj = models.T ...
- 清晰理解redux中的
首先需要明白 Redux 的单一状态树的概念,所谓的单一状态树,就是指“所有的 state 都以一个对象树的形式储存在一个单一的 store 中.” 比如我们有这么一个状态树(或者你叫它状态对象也行) ...
- java驼峰法和下划线法字符串的相互转换
java驼峰法和下划线法字符串的相互转换 1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class ...
- P1319 【压缩技术】
题面嘤嘤嘤 刚做完P1320,突然发现这里有一个没有括号的压缩技术,就抱着试一试的心态来做一做... 洛谷真有趣,让我正着做一遍,反着做一遍... 好,进入正题 这题比较便捷的是边读边做 具体细节看代 ...
- Spring源码阅读环境搭建
目录 安装gradle 导入Spring源码 创建测试模块my-test 其他问题 spring-aspects模块构建时报错 本文思维导图 本文将粗略的搭建一个Spring源码的阅读环境,为后面的源 ...
- datav轮播表使用事例
官方事例地址: http://datav.jiaminghi.com/guide/scrollBoard.html 安装: npm install @jiaminghi/data-view 局部引入: ...
- MySQL优化步 (InnoDB)
MySQL优化步 (InnoDB) 优化的优先级 数据库结构设计 SQL语句 数据库存储引擎和选择和参数配置 系统选择及优化 硬件升级 图书 MySQL必知必会 高性能MySQL 深入浅出MySQL ...
- P1224 [NOI2013]向量内积
传送门 发现这个内积和矩乘有点像,考虑构造一个 $n$ 行 $m$ 列的矩阵 $A$,每一行都是一个题目给定的 $m$ 维向量 设 $B=AA^T$ ,其中 $A^T$ 为 $A$ 的转置矩阵,那么对 ...
- Codeforces 1215F. Radio Stations
传送门 题目看一半:"woc 裸的 $2-sat$ 白给??" 看完以后:"...???" 如果没有 $f$ 的限制,那就是个白给的 $2-sat$ 问题,但是 ...
- ELK-6.5.3学习笔记–elk基础环境安装
本文预计阅读时间 13 分钟 文章目录[隐藏] 1,准备工作. 2,安装elasticsearch. 3,安装logstash. 4,安装kibana 以往都是纸上谈兵,毕竟事情也都由部门其他小伙伴承 ...