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就是用守护进程 ...
随机推荐
- Python文件重命名代码
import os def re_name(path): for file in os.listdir(path): file_path = os.path.join(path, file) # 判断 ...
- nginx提示地址或端口被占用解决
nginx提示地址或端口被占用解决 今天小编在启动nginx 的时候遇到如下的错误 Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed ...
- ffmpeg Tesseract-OCR 识别文字滤镜 中文识别输出文本
ffprobe -show_entries frame_tags=lavfi.ocr.text -f lavfi -i "movie=in.tif,ocr=datapath=tessdata ...
- linux系统下 android studio的 Terminal 中 执行 gradlew命令找不到
错误显示: 原因是linux系统中优先查找的是PATH环境中的程序,并不是当前目录下,执行当前目录下的程序要加上./. 这个错误很明白了,没有gradlew的执行权限.可以ls -al查看下gradl ...
- java里null强转为某个类会报错吗?
1.定义一个User类如下: /** * @author lizhibiao * @date 2018/11/27 17:21 */public class User{ private String ...
- 去掉有序数组中的重复元素 c/c++
去掉有序数组中的重复元素: int RemoveDuplates(int A[], int nCnt) { ; ; , j = ; i < nCnt && j < nCnt ...
- AKKA学习(一)
AKKA简介 什么是AKKA Akka是一个由Scala编写的,能兼容Sacala和JAVA的,用于编写高可用和高伸缩性的Actor模型框架.它基于了事件驱动的并发处理模式,性能非常的高,并且有很高的 ...
- Luogu P1080 [NOIP2012]国王游戏
题目 按\(a_i*b_i\)升序排序即可. 证明考虑交换法. 对于排序后相邻的两个人\(i,j(a_ib_i\le a_jb_j)\),设前面的总的积为\(s\),则当前答案为\(\max(\fra ...
- PostgreSQL-UNION与Order by 冲突
问题描述 union 连接的两个sql 都包含 order SELECT <property1>, <property2> FROM <table1> ORDER ...
- 虚机Linux最小系统下安装图形界面,与yum配置
出于未知原因,想装一下. 因为有光盘,所以就从光盘安装就可以了. 首先是配置yum下的下载地址: 找到yum的地址,然后打开文件. 然后建立该文件的/media/cdrom路径.将光盘挂载到该路径下. ...