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 默认网关 用途
[email protected] 192.168.1.111 192.168.1.1 Rsync服务端
[email protected] 192.168.1.121 192.168.1.1 Rsync 节点
[email protected] 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为例

备份拓扑

  1. 部署rsync服务

1)rsync服务端配置过程

配置rsyncd.conf

首先确认软件是否安装

1

2

3

[root@A-Server58 ~]# rpm -aq rsync

rsync-3.0.6-4.el5_7.1

[[email protected] ~]# 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同步的账号、密码及账号文件以限

[[email protected] ~]# 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 [email protected]::dingjian/ --password-file=/etc/rsync.password

从服务端指定的/dingjian目录把数据拉取到客户端本地/tmp目录下

rsync -avzP [email protected]::dingjian/ --password-file=/etc/rsync.password /tmp

排除打包

方法一:

在客户端操作:

[[email protected] tmp]# rsync -avz --exclude=etc --exclude=tmp . [email protected]::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

测试推送备份

[[email protected] tmp]# rsync -avz . [email protected]::dingjian --password-file=/etc/rsync.password

无差异同步

要实现这种同步方法就要使用--delete参数了

本地测试

[[email protected] tmp]# rsync -avzP --delete /null/ /tmp/

拉取方法

[[email protected] tmp]# rsync -avzrtopg --delete --progress [email protected]::dingjian/ /tmp/ --password-file=/etc/rsync.password

推送方法

[[email protected] tmp]# rsync -avzrtopg --delete --progress . [email protected]::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

时间: 2024-08-05 19:37:04

Rsync以守护进程(socket)的方式传输数据的相关文章

以守护进程(socket)的方式传输数据(重点)

以守护进程(socket)的方式传输数据(重点) 部署环境: 分别用uname命令查看各系统相关信息 [[email protected]~]# uname -r 6.18-308.el5 [[email protected]~]# uname -s Linux [[email protected]~]# uname -o GNU/Linux [[email protected]~]# uname -i x86_64 [[email protected]~]# uname -n A-Server

rsync以守护进程的方式传输备份数据

本文介绍rsync以守护进程的方式进行数据的传输备份,希望能给学习rsync的童鞋提供一些帮助. 一.环境 1.准备两台服务器,一台为server端,一台为client端 2.逻辑图 二.rsync server端部署 1.检查是否安装rsync [[email protected] ~]# which rsync /usr/bin/rsync 2.配置rsyncd.conf 注意:rsyncd.conf配置文件是不存在的,需要我们自己进行创建,路径为/etc/rsyncd.conf [[ema

ansible 部署基于windows 2008 r2+rsync+alwaysUp(守护进程)

准备:升级PowerShell3.0 及打开WinRM模块 参考文章:http://juestnow.blog.51cto.com/1515305/1875026 下载软件包rsync http://down.51cto.com/data/371729 alwaysUp https://www.coretechnologies.com/products/AlwaysUp/ AlwaysUpCLT https://www.coretechnologies.com/products/AlwaysUp

Rsync总结笔记—以守护进程(socket)方式传输数据

拓扑: 服务端配置:rsync的配置文件是/etc/rsyncd.conf.注意这个文件默认是不存在的,需要手动创建. 下面是一个配置好的rsyncd.conf ######rsyncd.conf####### uid = rsync    ----à非系统虚拟用户 gid = rsync use chroot =no  -à防止出现安全问题 maxconnections = 200   --à最大连接数 timeout = 300           --à超时时间 pid file =/va

Linux中的两种守护进程stand alone和xinetd

--http://www.cnblogs.com/itech/archive/2010/12/27/1914846.html#top 一般使用stand alone /etc/init.d/ 非常少用xinetd /etc/xinetd.d/ Linux守护进程的运行方式 1.独立运行(stand-alone)的守护进程 独立运行的守护进程由init脚本负责管理,所有独立运行的守护进程的脚本在/etc/rc.d/init.d/目录下.系统服务都是独立运行的守护进程,包括syslogd和cron等

Linux守护进程详解(init.d和xinetd)

一 Linux守护进程 Linux 服务器在启动时需要启动很多系统服务,它们向本地和网络用户提供了Linux的系统功能接口,直接面向应用程序和用户.提供这些服务的程序是由运行在后台的守护进程来执行的.守护进程是生存期长的一种进程.它们独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事件.他们常常在系统引导装入时启动,在系统关闭时终止.linux系统有很多守护进程,大多数服务器都是用守护进程实现的.同时,守护进程完成许多系统任务,比如,作 业规划进程crond.打印进程lqd等.有些书籍

Linux守护进程(init.d和xinetd)

一 Linux守护进程 Linux 服务器在启动时需要启动很多系统服务,它们向本地和网络用户提供了Linux的系统功能接口,直接面向应用程序和用户.提供这些服务的程序是由运行在后台 的守护进程来执行的.守护进程是生存期长的一种进程.它们独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事件.他们常常在系统引导装入时启 动,在系统关闭时终止.linux系统有很多守护进程,大多数服务器都是用守护进程实现的.同时,守护进程完成许多系统任务,比如,作 业规划进程crond.打印进程lqd等.有些

linux的守护进程init.d和xinetd.d

Linux 服务器在启动时需要启动很多系统服务,它们向本地和网络用户提供了Linux的系统功能接口,直接面向应用程序和用户.提供这些服务的程序是由运行在后台的守护进程来执行的.守护进程是生存期长的一种进程.它们独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事件.他们常常在系统引导装入时启动,在系统关闭时终止.linux系统有很多守护进程,大多数服务器都是用守护进程实现的.同时,守护进程完成许多系统任务,比如,作 业规划进程crond.打印进程lqd等.有些书籍和资料也把守护进程称作:

守护进程

为什么要引入守护进程:   因为它生存期长,它独立于控制终端.会话周期(下文有解释)执行任务:   由于在linux中,每一个系统与用户进行交流的界面称为终端,每一个从此终端开始运行的进程都会依赖这个终端,这个终端就称为这些进程的 控制终端.当控制终端被关闭时,相应的进程都会自动关闭.但是守护进程却能突破这种限制,它被执行开始运转,直到整个系统关闭时才退出. 守护进程的特性: 1> 守护进程最重要的特性是后台运行. 2> 其次,守护进程必须与其运行前的环境隔离开来.这些环境包括未关闭的文件描述