构建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. #Leetcode# 836. Rectangle Overlap

    https://leetcode.com/problems/rectangle-overlap/ A rectangle is represented as a list [x1, y1, x2, y ...

  2. 判断String类型字符串是否为空的方法

    在项目中经常遇到要判断String类型的字段是否为空操作 我们可以用Apache提供的StringUtils这个工具类,不用自己去判断,也不用自己封装判断空的方法 它有两个版本,一个是org.apac ...

  3. Django--CRM--modelformset的用法

    一 . modelformset用法 其实和modelform方法差不多,只不过是显示的时候可以直接修改,显示的select的那种模式 from django.forms import modelfo ...

  4. bpmn.js & BPMN diagram

    bpmn.js & BPMN diagram BPMN 2.0 for the web https://github.com/bpmn-io/bpmn-js https://demo.bpmn ...

  5. 《Tensorflow从入门到精通》

    第一 开发环境搭建 1. tensorflow的环境搭建 windows下安装cpu版tensorflow: pip install tensorflow 在ubuntu上安装gpu版tensorfl ...

  6. Java之ArrayList自定义排序,通过实现comparator比较器接口

    两种排序方式: 1.实体类实现Comparable接口,重写compareTo(T o)方法,在其中定义排序规则,那么就可以直接调用Collections.sort()来排序对象数组 2.在调用方法的 ...

  7. vue自定義指令

    自定義指令可以允許代碼複用, 全局自定義指令 vue.directive('指令名',{鉤子函數:指令函數}) 局部自定義指令: vue({ directives:{指令名:{鉤子函數:指令函數} } ...

  8. SpringJdbc框架

    import javax.sql.DataSource; import org.springframework.jdbc.core.JdbcTemplate; import JdbcUtils.Jdb ...

  9. Lodop控件NewPage();测试输出空白页

    LODOP.NewPage();和LODOP.NewPageA();是强制分页语句,两者的区别可查看本博客的相关博文:Lodop强制分页LODOP.NewPage()和LODOP.NewPageA() ...

  10. 简单聊聊Linux学习经历

    学习,是我们一生中都规避不了的一个话题,人的一生中都是在不断的学习,无论是功成名就的人士,还是一无是处的小混混,始终都处在一个不断学习的环境中,只是学习的内容千差万别,有的人是为了提升自己各方面的能力 ...