构建rsync远程同步
----------同步源----------------发起端-------------
192.168.1.1 192.168.1.10
1、配置IP地址并保证互通
2、确定备份源
[root@localhost ~]# mkdir /www
[root@localhost ~]# touch /www/{1..100}.html
[root@localhost ~]# rpm -q rsync
3、创建备份账号文件
[root@localhost ~]# vim /etc/rsyncd_users.db
添加:
han:redhat
[root@localhost ~]# chmod 600 /etc/rsyncd_users.db //必须设置为600,否则客户端认证失败。
4、创建rsync配置文件
[root@localhost ~]# vim /etc/rsyncd.conf //系统中无此文件,需手动创建。
添加:
uid = nobody
gid = nobody
use chroot = yes
address = 192.168.56.200
port 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.56.0/24
[www]
path = /www
comment = backup
read only = yes
dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.z
auth users = han
secrets file = /etc/rsyncd_users.db
5、启动(终止)rsync
[root@localhost ~]# rsync --daemon
最好使用:rsync --daemon --config=/etc/rsyncd.conf
在redhat中,也可以使用xinetd程序管理。
#vim /etc/xinetd.d/rsync
将disable改为no
[root@localhost ~]# netstat -anpt | grep rsync
[root@localhost ~]# kill -9 PID号(例如:kill -9 9290)
注意:如果重新启动失败时,先删除pid文件,然后再启动。
[root@localhost ~]# rm -rf /var/run/rsyncd.pid
[root@localhost ~]# rsync --daemon
[root@localhost ~]# netstat -anpt | grep rsync
6、验证:
1)本地验证:(类似复制)
[root@localhost ~]# rsync -rl /etc/httpd/ /tmp/
2)发起端验证:( 把同步源的重要文件同步到发起端,作为备份)
[root@localhost ~]#mkdir /www
[root@localhost ~]#rsync -avz han@192.168.56.200::www /www/
或者
[root@localhost ~]#rsync -avz rsync://han@192.168.56.200::www /www/
增量:
[root@localhost ~]#rsync -avz --delete han@192.168.56.200::www /www/
注:之前学习的内容为下行同步(类似于下载)
上行同步:(类似于上传)
[root@localhost ~]# rsync -avz --delete /www han@192.168.56.200::www
注意:
1、同步源中的权限:要把 read only 改写成 no;
2、同步源中/www/的权限改为757
7、设置计划任务自动远程同步
在发起端作如下操作:
[root@localhost ~]# vim /etc/han.password
redhat
[root@localhost ~]# chmod 600 /etc/han.password
[root@localhost ~]# crontab -e root
添加:
30 22 * * * /usr/bin/rsync -az --delete --password-file=/etc/han.password hehe@192.168.56.200::www /www/
[root@localhost ~]# service crond restart
[root@localhost ~]# chkconfig crond on
配置rsync+inotify实时同步(在发起端设置)
1、调整内核参数
[root@localhost ~]#cat /proc/sys/fs/inotify/max_queued_events
[root@localhost ~]#cat /proc/sys/fs/inotify/max_user_instances
[root@localhost ~]#cat /proc/sys/fs/inotify/max_user_watches
[root@localhost ~]#vim /etc/sysctl.conf
添加:
fs.inotify.max_queued_events = 16384 //事件列队
fs.inotify.max_user_instances = 1024 //实例数
fs.inotify.max_user_watches = 1048576 //每个实例文件数量
[root@localhost ~]#sysctl -p
2、安装inotify软件
[root@localhost ~]#tar -zxvf inotify-tools-3.14.tar.gz -C /usr/src/
[root@localhost ~]#/usr/src/inotify-tools-3.14/
[root@localhost inotify-tools-3.14]#./configure && make && make install
3、验证监控效果
[root@localhost ~]#inotifywait -mrq -e modify,create,move,delete /var/www/html
在另一个终端上(ctrl+shifs+T)进行增删改查的操作。
同步源端:
可以修改上传的目录
uid = nobody
gid = nobody
use chroot = yes
address = 192.168.56.200
port = 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.56.0/24
[www]
path = /var/www/html 目录权限为757,其他账户可写。
comment = hehe
read only = no
dont compress = *.gz *.bz2 *.tgz *.zip *.rar *z
auth users = han
secrets file = /etc/syncuser.db
注意:重启服务
[root@localhost ~]#kill -9 pid
[root@localhost ~]#rsync --daemon
4、编写触发式同步脚本
[root@localhost ~]# vim /etc/han.password
添加:
redhat //han用户的密码
[root@localhost ~]# chmod 600 /etc/han.password
[root@localhost ~]# vim inotify_rsync.sh
#!/bin/bash
INOTIFY="inotifywait -mrq -e modify,create,move,delete /var/www/html/"
RSYNC="rsync -azH --delete --password-file=/etc/han.passwd /var/www/html han@192.168.56.200::www"
$INOTIFY | while read DIRECTORY EVENT FILE
do
if [ $(pgrep rsync | wc -l) -le 0 ];then
$RSYNC
fi
done
脚本的另外写法:
inotifywait -mrq -e modify,create,move,delete /var/www/html/ | while read EVENT
do
rsync -azH --delete --password-file=/etc/han.passwd /var/www/html han@192.168.56.200::www
done
[root@localhost ~]# inotifywait inotify_rsync.sh &> /dev/null //脚本启动不成功则课启动
[root@localhost ~]# ./inotifywait.sh &> /dev/null &
注意:由于时间设置问题,脚本运行时会报错,但不影响使用。
[root@localhost ~]# jobs //查看后台数据
[root@localhost ~]# fg 1 //后台转前台
while read的理解
#!/bin/bash
count=1 //赋值语句,不加空格
cat test | while read line //cat 命令的输出作为read命令的输入,read读到的值放在line中
do
echo "Line $count:$line"
count=$[ $count + 1 ] //注意中括号中的空格。
done
echo "finish"
exit 0

rsync服务部署的更多相关文章

  1. Rsync服务部署使用

    rsync服务搭建过程(daemon模式) 配置服务 在/etc/rsyncd.conf文件中写入相应的配置: uid = root gid = root use chroot = no max co ...

  2. rsync 服务部署详解

    第1章 rsync 软件介绍 1.1 什么是rsync rsync 是一款开源的.快速的.多功能的.可实现全量及增量的本地或远程数据同步备份的优秀工具. http://www.samba.org/ft ...

  3. Rsync 服务部署与参数详解

    Rsync 简介 rsync 是一款开源的.快速的.多功能的.可实现全量及增量的本地或远程数据同步备份的优秀工具.Rsync软件适用于unix/linux/windows等多种操作系统平台. 传统的 ...

  4. rsync 服务及部署

    1 rsync简介 1.1 什么是rsync rsync: - a fast, versatile, remote (and local) file-copying toolrsync:是一种快速,多 ...

  5. rsync实时同步服务部署

    部署rsync服务 一.需求:把客户端文件同步到服务端指定位置服务端:备份服务器为 172.16.3.164客户端:推送服务器为 172.16.3.94 二.基础知识: rsync 分为服务器端.客户 ...

  6. Rsync备份服务部署

    1 Rsync服务器架构规划 在搭建服务之前需要做以下规划设计,其中包括:主机规划表.主机IP地址规划表.主机架构图.主机hosts解析以及linux主机基础优化等 1.1 主机规划表 服务器说明 数 ...

  7. Rsync同步部署web服务端配置

    Rsync同步部署web服务端配置 1,参数详解: -v, --verbose 详细模式输出. -q, --quiet 精简输出模式. -c, --checksum 打开校验开关,强制对文件传输进行校 ...

  8. rsync 服务快速部署手册

    一.rsync服务端安装 1.查看rsync安装包 # rpm -qa rsync rsync-3.0.6-12.el6.x86_64 2.安装rsync 系统默认都会安装rsync软件包的,如果查看 ...

  9. Rsync服务端部署流程

    Rsync服务端部署流程       Rsync服务端部署流程: 一.rsync服务端配置流程 配置rsync配置文件/etc/rsyncd.conf 创建同步的本地目录/dingjian 并根据需要 ...

随机推荐

  1. java异常Exception

    学习笔记: 一.程序的异常:Throwable 严重问题:Error ,我们不处理.这种问题一般很严重,不如内存溢出 问题:Exception 编译问题:不是RuntimeException异常.必须 ...

  2. PHP中多个文件包含的问题 (一)

    使用require或者include来包含文件时,包含的文件的内容相对性,这个很容易搞混,所以记录一下. 这个相对性包括 __DIR__,__FILE__,$_SERVER['PHP_SELF'],$ ...

  3. js手机短信验证

    贴代码之前,我们先讲一下这里我们用到的技术主要有1个.setInterval(),这个方法可以实现倒计时的效果. css: .weui_btn_disabled.weui_btn_default { ...

  4. 在C 与 C++混编中, 出现error LNK2019: 无法解析的外部符号 "int __cdecl main_(int,char * *)" (?main_@@YAHHPEAPEAD@Z),该符号在函数 main 中被引用

    main_ 这个函数的头文件 应该做标准化输出 : extern "C" int main_(int argc, char **argv);

  5. 6-1 Quantifiers

    1 Quantifiers are used to describe the number or amount of something. Certain quantifiers are used w ...

  6. [转帖]nginx配置ssl加密(单/双向认证、部分https)

    nginx配置ssl加密(单/双向认证.部分https) https://segmentfault.com/a/1190000002866627   nginx下配置ssl本来是很简单的,无论是去认证 ...

  7. day 7-8 协程

    不能无限的开进程,不能无限的开线程最常用的就是开进程池,开线程池.其中回调函数非常重要回调函数其实可以作为一种编程思想,谁好了谁就去调 只要你用并发,就会有锁的问题,但是你不能一直去自己加锁吧那么我们 ...

  8. day 7 -1 进程理论知识

    一.进程的定义 进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础.在早期面向进程设计的计算机结构中,进程是程序的基本执行实 ...

  9. python爬虫之git的团队协作

    一.Git实践: commit,push,pull,status,add基本是最常用的几个命令. 1.首先我在github上创建了一个项目,然后我在本地的文件建立了一个普通的目录(git_data). ...

  10. Mybaits整合Spring

    整合思路 1.SqlSessionFactory对象应该放到spring容器中作为单例存在. 2.传统dao的开发方式中,应该从spring容器中获得sqlsession对象. 3.Mapper代理形 ...