Fork me on GitHub
代码改变世界

linux 同步备份 rsyncd 相关设置

2013-10-18 18:11  freefei  阅读(483)  评论(0编辑  收藏  举报

17:25 2013/10/18------------------ rsync linux 同步备份服务器 配置
vi /etc/rsyncd.conf 配置文件
/usr/bin/rsync --daemon 守护进程方式 启动
lsof -i:873 查看启动进程
iptables -A INPUT -p tcp --dport 873 -j ACCEPT 开启防火墙


rsync 配置文件

#pid file = /usr/local/rsync/rsyncd.pid #运行进程的ID写到哪里 原文中有的,我没有使,日志文件

#模块选项
[test] # 这里是认证的模块名,在client端需要指定
max connections = 5 #客户端最大连接数,默认0(没限制)
uid = root #指定该模块传输文件时守护进程应该具有的uid
gid = root #指定该模块传输文件时守护进程应该具有的gid
path = /var/www # 需要做备份的目录
ignore errors # 可以忽略一些无关的IO错误
read only = no #no客户端可上传文件,yes只读
write only = no #no客户端可下载文件,yes不能下载
hosts allow = * #充许任何主机连接
hosts deny = 10.5.3.77 #禁止指定的主机连接
auth users = root # 认证的用户名,如果没有这行,则表明是匿名
secrets file = /etc/rsync.pass # 指定认证口令文件位置

 


----

/usr/bin/rsync -vzrtopg --delete --progress root@192.168.1.107::test /ranmufei/

 

 

 

参考

http://www.iteye.com/topic/604436

http://blog.sina.com.cn/s/blog_5eda2dda01015fcs.html

 

 

 

 

 

测试通过的配置  用普通用户操作 默认服务器已经安装了 软件 centos 6.4 默认已经安装

1 服务器端的conf 配置

uid = nobody
gid = nobody
max connections = 4
read only = true
#hosts allow = 202.207.177.180
hosts allow = *
transfer logging = true
log format = %h %o %f %l %b
log file = /var/log/rsyncd.log
slp refresh = 300
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock

[web]
path = /var/www
comment = Mirror to Hk server
read only = true
list = false
auth users = freefei

[test]
path = /var/www
read only = false
auth users = freefei
secrets file = /etc/rsyncd.secrets

 

2 服务器端 创建密码文件

 vim /etc/rsyncd.secrets

   格式  为 freefei:123456

 

3 客户端 

  客户端只需要配置密码文件即可

vim /etc/rsync.pass  

注意这里的密码 格式为  123456  (只有密码 没有用户名 和服务器端不同)

4  备份文件夹

   备份test模块下的文件同步到 客户端 的“/ranmufei” 文件夹下

 

  /usr/bin/rsync -vzrtopg --delete  --progress freefei@192.168.1.107::test /ranmufei --password-file=/etc/rsync.pass

 

5 rsync 开机启动


vi /etc/rc.local

加上

/usr/bin/rsync --daemon --config=/etc/rsyncd.conf 

 

6 设置自动备份(定时备份 )

   自动备份有两种方式 1 一种是用 系统的定时任务 定时执行 同步命令。

                             crontab 定时命令 

-e 编辑
-r [UserName]: 删除目前的时程表
-l [UserName]: 列出目前的时程表
-v [UserName]:列出用户cron作业的状态
 
找时刻表中加入 一分钟备份一次
 
 --delete  表示服务器如果删除了改文件 备份服务器也要删除 做到真正的同步   切记该选择
 

*/1 * * * * /usr/bin/rsync -vzrtopg --delete --progress freefei@192.168.1.107::test /ranmufei --password-file=/etc/rsync.pass

 

 每天上午920执行rysnc备份任务:
20 9 * * *        /usr/bin/rsync -vzrtopg --delete --progress freefei@192.168.1.107::test /ranmufei --password-file=/etc/rsync.pass

 
 

                             2 另外一种是吧要执行的任务写到shell中 等待执行

  

7 机器防火墙设置 rsync 

 

 

防火墙问题处理

(1) 修改防火墙文件 vi /etc/sysconfig/iptables
删除全部 重新添加上
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]

-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
#ssh
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
#http
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
#mysql
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
#rsync
-A INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT


保存 重启
注意 两台服务器都要这样弄

 

开启:service iptables start

  关闭:service iptables stop

 

http://wenku.baidu.com/view/c326120f844769eae009edfc.html 

http://blog.csdn.net/tsuliuchao/article/details/4742796

数据库备份

 

 

 

注意 wdlinux 一键安装包  要开启管理面板  切记要在防火墙里面 加上 8080端口开启

@ https://github.com/ranmufei

守望者舆情监控

守望者舆情监控系统