首页 > 服务器 > 采用rsync实现两台solaris服务之间的文件同步

采用rsync实现两台solaris服务之间的文件同步

2009年03月22号
查看评论 发表评论 1,511次浏览

目的:
通过技术手段,保持服务器A中的某些目录能够定期同步到服务器B中。
本文针对 Sun Solaris 10 版本,其他版本或其他 unix 服务器仅具有参考价值
对于 Windows 服务器之间的文件同步,也可以采用rsync ,但要使用cwrsync 工具,请从 internet 上搜索资料。
工具:
rsync :在unix平台下广泛采用的同步软件,免费使用,目前最新版本是 2.6.6
crontab :solaris平台上的定时任务管理器
描述:
rsync 同时安装到Server A和Server B。
在Server A上,rsync作为守护进程运行,通过配置,可以使得Server A上的某些目录被rsync发布。
在Server B 上, rsync作为命令行工具运行,可以从运行rsync守护进程的另一台服务器(Server A)上将所发布的目录同步到Server B。
在 Server B 上配置定时任务,以便在指定的时间运行同步命令。
步骤:
1、在 Server A(10.13.40.20) 和 Server B(10.13.40.22) 上安装rsync 软件:
a) 从 http://www.sunfreeware.com/programlistsparc9.html 上查找rsync的最新版本,目前的最新版本是3.0.3,名称: rsync-3.0.3-sol9-sparc-local.gz
b) 通过 ftp 命令将文件上传到Server A和Server B,在个人电脑的 DOS 命令行上执行命令如下:
ftp 10.13.40.20 # 通过 ftp 连接服务器 10.13.40.20
bin # 设定传输模式为二进制
put rsync-3.0.3-sol9-sparc-local.gz # 将本地的文件上传到 10.13.40.20
bye # 退出 ftp 程序
同理:
ftp 10.13.40.22 # 通过 ftp 连接服务器 10.13.40.22
bin # 设定传输模式为二进制
put rsync-3.0.3-sol9-sparc-local.gz # 将本地的文件上传到 10.13.40.22
bye # 退出 ftp 程序
c) 在 Server A 和 Server B 上安装rsync,命令非常简单。在个人电脑的 DOS 命令行上执行下面的命令:
telnet 10.13.40.20 # 连接到 10.13.40.20 的终端界面
gzip -d rsync-3.0.3-sol9-sparc-local.gz # 解压缩 gz 文件
pkgadd -d rsync-3.0.3-sol9-sparc-local.gz # 安装 rsync ,遇到提问,按回车即可
rsync –version # 验证 rsync 安装是否完成
2、在 Server A 上配置rsync服务
a) 编辑rsync的配置文件,/etc/rsyncd.conf ,该文件在安装之初是没有的,需要自己建立。命令如下:
vi /etc/rsyncd.conf # 编辑 /etc/rsyncd.conf 文件
文件内容如下:
uid = root # 以 root 身份访问文件目录
gid = root # 以 root 组身份访问文件目录
use chroot = yes # 可以使用 chroot
max connections = 1 # 最大连接数
syslog facility = local5
pid file = /var/run/rsyncd.pid
hosts allow = 10.13.40.22 # 只允许 10.13.40.22 访问
[grpdomain1] # 这是一个发布项,可以发布多个
path=/export/home/public # 发布的路径
read only=yes # 只读
list = yes # 允许列文件清单
comment= This is ftp original server. # 描述信息
文件在本文所附的目录中可以找到,名称: ServerA\rsyncd.conf
[grpdomain1]将作为其他服务器访问Server A的 rsync 发布目录的一个发布名,这样的小节可以根据需要存在多个。
b) 以守护进程方式启动 rsync 服务,命令如下:
rsync –daemon&
c) 配置 rsync 自启动
vi /etc/rc3.d/S99Rsync # 编辑 /etc/rc3.d/S99Rsync
chmod 700 /etc/rc3.d/S99Rsync # 设置文件可以被属主( root )读写执行
文件内容如下:
rsync –daemon&
文件在本文所附的目录中可以找到,名称: ServerA\S99Rsync
d) 验证服务
登陆Server B,执行命令:
rsync -ztruvoglp –progress rsync://10.13.40.20
grpdomain1 This is ftp original server. # 执行结果
列出了 Server A 上面发布的目录的名称,说明配置成功
3、在 Server B 上面设置自动获取Server A上的文件
a) 为了方便管理,把脚本文件放置在Server B上的特定目录下,下面的命令建立目录 /data/rsync:
mkdir /data/rsync
b) 建立不同步文件的列表清单,清单文件名自己定义,该文件可选,如果不建立该文件,可以直接在后面步骤 C) 的脚本命令中使用参 –exclude 来直接指明。
vi /data/rsync/grpdomain1_exclude_file.list
文件每行表示一条,支持通配符,以发布项作为当前目录,文件内容如下:
grpdomain1.log* # 表示 /data/bea/user_projects/grpdomain1/grpdomain1.log* 不同步
newgrplog # 表示 /data/bea/user_projects/grpdomain1/newgrp 目录及子目录
home/logs
文件在本文所附的目录中可以找到,名称: ServerB\grpdomain1_exclude_file.list
c) 建立同步脚本,可以根据需要建立多个脚本,每个脚本定义自己的调度计划(见后)
vi /data/rsync/rsync-grpdomain1.sh # 编辑文件
chmod 700 /data/rsync/rsync-grpdomain1.sh # 设置文件为仅属主可读些执行
文件内容如下,注意不要换行:
rsync –ztruvoglp –exclude-from=/data/rsync/grpdomain1_exclude_file.list –d –delete –progress rsync://10.13.40.20 /export/home/public
参数说明:
l –ztruvoglp ,表示的是压缩传输、包含子目录、保持相同的权限等,可不理会。
l –exclude-from ,指明从那个文件读取除外文件清单
l –delete ,指明当文件被从 Server A 上删除后,也在 Server B 上删除
l –progress ,是否在控制台上显示明细,如果在定时任务中运行,最好不增加该参数。
l –exclude ,在命令行上直接指明那些文件不同步,格式 –exclude=”hgFF”
l rsync://10.13.40.20:873/grpdomain1 , 同布的源, 873 是缺省端口,可忽略
l /export/home/public 同步目的地
d) 文件在本文所附的目录中可以找到,名称: ServerB\rsync-grpdomain1.sh
e) 检测脚本是否正确,直接执行命令: /data/rsync/rsync-grpdomain1.sh
f) 设定每天 23 点执行同步命令,执行下面的命令
crontab -e # 编辑当前用户的调度表
显示的是一个 vi 界面,文件的内容可能如下,其中黑体部分是我们添加的:
#ident “@(#)root 1.20 01/11/06 SMI”
#
# The root crontab should be used to perform accounting data collection.
#
# The rtc command is run to adjust the real time clock if and when
# daylight savings time changes.
#
10 3 * * * /usr/sbin/logadm
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
1 2 * * * [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1
30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean
# 每天的晚上 24 点运行同步脚本 , 将 10 上的 grpdomain1 文件拷贝到本机
0 23 * * * /data/rsync/rsync-grpdomain1.sh
#10 3 * * * /usr/lib/krb5/kprop_script ___slave_kdcs___
起作用的是 0 23 * * * /data/rsync/rsync-grpdomain1.sh , 其中前面由空格间隔开的五项分别代表分钟 小时 日 月 星期

4、更多的文件目录的同步之 ServerA 的操作
a) 修改 ServerA 的/etc/rsyncd.conf,增加新的描述,参见 [grpdomain1] 的描述
b) 停止 Server A上的rsync守候进程,命令:
ps –ef|grep rsync # 显示 rsync 进程
root 29830 29669 0 10:48:16 pts/2 0:00 grep rsync
root 29755 1 0 09:46:58 ? 0:00 rsync –daemon
kill 29755 #29755 要根据实际的进程号替换
c) 重新启动守候进程,执行:
rsync –-daemon
5、更多的文件目录的同步之ServerB的操作,参见步骤3

例:
rsync –ztruvoglp –exclude-from=/data/rsync/grpdomain1_exclude_file.list –d –delete –progress rsync://10.13.40.20/grpdomain1 /export/home/public

  1. cheap basketball shoes
    发表于 2010年06月21号 09时48分13秒 | 1楼

    Nice bl!

  2. Herve Leger Discount
    发表于 2010年06月24号 01时44分22秒 | 2楼

    Like the way you write .

  3. cheap basketball shoes
    发表于 2010年06月24号 04时44分10秒 | 3楼

    Good point on the concience

  4. fake chanel watches
    发表于 2010年06月25号 11时14分43秒 | 4楼

    I couldn’t have seen it better.

  5. timberland chukka boots
    发表于 2010年06月26号 00时20分56秒 | 5楼

    Cool idea

  6. paul smith trainers
    发表于 2010年06月28号 13时42分26秒 | 6楼

    Oh, I absolutely agree!

  7. MBT Lami Birch
    发表于 2010年07月01号 14时41分58秒 | 7楼

    Very much enjoyed.

  8. handbag
    发表于 2010年07月17号 15时57分38秒 | 8楼

    Bwahahaha, brilliant!

  9. christian louboutin sale
    发表于 2010年07月20号 09时00分06秒 | 9楼

    Beautiful story as usual and amazingly true, thank you for that! You are one of a kind.

  10. dwight howard shoes
    发表于 2010年07月23号 11时10分56秒 | 10楼

    Eeeeuuuuu. That’s shocking!

  11. lebron shoes
    发表于 2010年07月27号 17时56分31秒 | 11楼

    You must be a wonderful person!

  1. 发表于 2010年07月19号 02时00分19秒 | #1
  2. 发表于 2010年07月22号 20时47分02秒 | #2
  3. 发表于 2010年07月22号 20时47分24秒 | #3
  4. 发表于 2010年07月22号 22时43分20秒 | #4
  5. 发表于 2010年07月22号 23时50分12秒 | #5
  6. 发表于 2010年07月22号 23时51分26秒 | #6
  7. 发表于 2010年07月22号 23时51分58秒 | #7
  8. 发表于 2010年07月22号 23时52分14秒 | #8
  9. 发表于 2010年07月22号 23时52分29秒 | #9
  10. 发表于 2010年07月22号 23时53分24秒 | #10
  11. 发表于 2010年07月23号 06时41分32秒 | #11
  12. 发表于 2010年07月23号 15时00分27秒 | #12
  13. 发表于 2010年07月25号 04时10分50秒 | #13
  14. 发表于 2010年07月25号 04时11分07秒 | #14
  15. 发表于 2010年07月25号 04时11分23秒 | #15
  16. 发表于 2010年07月25号 04时11分42秒 | #16
  17. 发表于 2010年07月25号 04时12分03秒 | #17
  18. 发表于 2010年07月25号 09时28分50秒 | #18
  19. 发表于 2010年07月27号 15时08分41秒 | #19
  20. 发表于 2010年07月29号 10时22分25秒 | #20
  21. 发表于 2010年07月30号 11时04分17秒 | #21
  22. 发表于 2010年07月30号 12时54分03秒 | #22
  23. 发表于 2010年07月31号 10时47分13秒 | #23
  24. 发表于 2010年07月31号 17时12分05秒 | #24
  25. 发表于 2010年07月31号 18时26分32秒 | #25
  26. 发表于 2010年07月31号 19时46分29秒 | #26
  27. 发表于 2010年07月31号 21时50分35秒 | #27
  28. 发表于 2010年07月31号 23时40分37秒 | #28
  29. 发表于 2010年08月01号 13时08分36秒 | #29
  30. 发表于 2010年08月01号 13时08分54秒 | #30
  31. 发表于 2010年08月01号 13时09分15秒 | #31
  32. 发表于 2010年08月01号 13时09分57秒 | #32
  33. 发表于 2010年08月01号 13时10分20秒 | #33
  34. 发表于 2010年08月01号 13时10分42秒 | #34
  35. 发表于 2010年08月01号 20时04分29秒 | #35
  36. 发表于 2010年08月02号 02时01分20秒 | #36
  37. 发表于 2010年08月02号 04时26分30秒 | #37
  38. 发表于 2010年08月02号 04时26分46秒 | #38
  39. 发表于 2010年08月02号 04时27分08秒 | #39
  40. 发表于 2010年08月02号 04时27分37秒 | #40
  41. 发表于 2010年08月02号 04时27分58秒 | #41
  42. 发表于 2010年08月02号 11时57分37秒 | #42
  43. 发表于 2010年08月02号 22时32分31秒 | #43
  44. 发表于 2010年08月05号 17时56分49秒 | #44
  45. 发表于 2010年08月05号 19时01分28秒 | #45
  46. 发表于 2010年08月06号 08时25分36秒 | #46
  47. 发表于 2010年08月06号 10时21分35秒 | #47
  48. 发表于 2010年08月06号 13时08分04秒 | #48
  49. 发表于 2010年08月06号 13时08分30秒 | #49
  50. 发表于 2010年08月06号 20时56分51秒 | #50
  51. 发表于 2010年08月06号 22时18分22秒 | #51
  52. 发表于 2010年08月07号 02时07分28秒 | #52
  53. 发表于 2010年08月07号 06时10分57秒 | #53
  54. 发表于 2010年08月07号 07时46分14秒 | #54
  55. 发表于 2010年08月07号 14时09分11秒 | #55
  56. 发表于 2010年08月07号 14时09分39秒 | #56
  57. 发表于 2010年08月07号 16时28分17秒 | #57
  58. 发表于 2010年08月07号 18时01分06秒 | #58
  59. 发表于 2010年08月07号 19时47分27秒 | #59
  60. 发表于 2010年08月07号 20时57分03秒 | #60
  61. 发表于 2010年08月07号 20时57分36秒 | #61
  62. 发表于 2010年08月07号 23时01分46秒 | #62
  63. 发表于 2010年08月08号 00时30分13秒 | #63
  64. 发表于 2010年08月08号 03时46分45秒 | #64
  65. 发表于 2010年08月08号 05时24分36秒 | #65
  66. 发表于 2010年08月08号 06时45分18秒 | #66
  67. 发表于 2010年08月08号 08时12分27秒 | #67
  68. 发表于 2010年08月08号 18时58分48秒 | #68
  69. 发表于 2010年08月08号 19时00分02秒 | #69
  70. 发表于 2010年08月08号 20时37分42秒 | #70
  71. 发表于 2010年08月09号 00时41分02秒 | #71
  72. 发表于 2010年08月09号 01时59分30秒 | #72
  73. 发表于 2010年08月09号 05时49分27秒 | #73
  74. 发表于 2010年08月09号 07时23分24秒 | #74
  75. 发表于 2010年08月09号 08时33分43秒 | #75
  76. 发表于 2010年08月09号 09时55分40秒 | #76
  77. 发表于 2010年08月09号 15时15分33秒 | #77
  78. 发表于 2010年08月09号 16时34分29秒 | #78
  79. 发表于 2010年08月10号 05时04分13秒 | #79
  80. 发表于 2010年08月10号 06时30分22秒 | #80
  81. 发表于 2010年08月10号 12时47分35秒 | #81
  82. 发表于 2010年08月10号 14时44分00秒 | #82
  83. 发表于 2010年08月11号 06时13分29秒 | #83
  84. 发表于 2010年08月11号 08时03分39秒 | #84
  85. 发表于 2010年08月11号 09时45分32秒 | #85
  86. 发表于 2010年08月11号 13时22分28秒 | #86
  87. 发表于 2010年08月11号 22时57分35秒 | #87
  88. 发表于 2010年08月12号 00时47分45秒 | #88
  89. 发表于 2010年08月12号 05时17分49秒 | #89
  90. 发表于 2010年08月12号 06时40分01秒 | #90
  91. 发表于 2010年08月12号 06时40分32秒 | #91
  92. 发表于 2010年08月12号 14时18分12秒 | #92
  93. 发表于 2010年08月12号 14时18分56秒 | #93
  94. 发表于 2010年08月12号 16时21分36秒 | #94
  95. 发表于 2010年08月12号 16时22分06秒 | #95
  96. 发表于 2010年08月12号 16时22分27秒 | #96
  97. 发表于 2010年08月12号 16时22分46秒 | #97
  98. 发表于 2010年08月12号 16时23分11秒 | #98
  99. 发表于 2010年08月12号 16时23分33秒 | #99
  100. 发表于 2010年08月22号 19时57分16秒 | #100
你必需 登陆 才能发表评论.