Chinaunix首页 | 论坛 | 博客
  • 博客访问: 625858
  • 博文数量: 110
  • 博客积分: 3808
  • 博客等级: 中校
  • 技术积分: 1930
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-15 14:32
个人简介

声的伟大!

文章分类

全部博文(110)

文章存档

2014年(1)

2013年(2)

2012年(12)

2011年(81)

2010年(14)

分类: LINUX

2011-09-06 09:39:25

简介: 
 
  rsync是类unix系统下的数据镜像备份工具,从软件的命名上就可以看出来了——remote sync。它的特性如下:
  • 可以镜像保存整个目录树和文件系统。
  • 可以很容易做到保持原来文件的权限、时间、软硬链接等等。
  • 无须特殊权限即可安装。
  • 优化的流程,文件传输效率高。
  • 可以使用rcp、ssh等方式来传输文件,当然也可以通过直接的socket连接。
  • 支持匿名传输,以方便进行网站镜象。
软件下载
rsync的主页地址为:
目前最新版本为3.0.8。可以选择从原始网站下载:ftp/rsync/。


需求如下:

某公司有一台LAMP服务器,为了保障数据库的安全性,需要对其做定时备份,又为了防止数据库服务器出现硬件故障,同时要求将备份数据定时传送至公司内网文件服务器上存档。


一、配置主文件服务器Server

1.安装rsync
# tar xvf rsync-3.0.8.tar.gz
# cd rsync-3.0.8
# ./configure
# make && make install

2.创建配置文件,加入以下内容
# vim /etc/rsync.conf

uid = nobody
gid = nobody
use chroot = no
max connections = 10
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
port = 873
timeout = 300
hosts allow = 192.168.1.60 , 192.168.1.62  //允许哪个客户端可以同步

[www]
read only = yes
list = yes
ignore errors
comment = This is a file back
path = /home/htmlroot/www-net   //同步的路径
auth users = rsyncuser       //同步时验证用户
secrets file = /etc/rsync.passwd    //同步时验证用户密码文件

[admin]
read only = yes
list = yes
ignore errors
comment = This is a file back
path = /home/htmlroot/admin-net
auth users = rsyncuser
secrets file = /etc/rsync.passwd

[vip]
read only = yes
list = yes
ignore errors
comment = This is a file back
path = /home/htmlroot/vip-net
auth users = rsyncuser
secrets file = /etc/rsync.passwd

3.接下来,创建用户、密码对应文件
# vim /etc/rsync.passwd

rsyncuser:123456rsync
# chmod 600 /etc/rsync.passwd   //权限必须为600
# rsync --daemon --config=/etc/rsync.conf   //启动rsync
# echo "rsync --daemon --config=/etc/rsync.conf" >> /etc/rc.local   //加入到开机自动启动

启动后用netstat查看是否开启了873端口



二、设置文件备份服务器

1.安装rsync
# tar xvf rsync-3.0.8.tar.gz
# cd rsync-3.0.8
# ./configure
# make && make instal

2.创建密码文件
# vim /etc/rsync.passwd

123456rsync
# chmod 600 /etc/rsync.passwd

接下来测试
rsync -vzrtuopg --progress --exclude ".svn" rsyncuser@192.168.1.110::www /html/www-syj-net/ --password-file=/etc/rsync.passwd

注:--exclude ".svn"是指在文件传输的过程中,出去.svn目录



另一台备份服务器配置相同,再此掠过

撰写脚本

# vim rsync.sh
#!/bin/bash
#
rsync -vzrtuopg --progress --exclude ".svn" rsyncuser@192.168.1.110::www /html/www-syj-net/ --password-file=/etc/rsync.passwd

# chmod u+x rsync.sh

3.设置同步周期

# crontab -e
*/10 * * * * /root/rsync.sh
# /etc/init.d/crond restart

至此,整个备份方案实施完毕


总结

数据传输安全性:本方案采用的rsync传输,为了提高数据传输安全,可使用如scp、vpn等加密方式传输

客户端安全验证:本方案中在数据库服务器上rsync配置文件设置了客户端来源IP验证。另外,还可以在数据库服务器端架设防火墙,对来源IP地址进行验证

阅读(1521) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~