构建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. WebSocket实现一个聊天室

    聊天室页面-->index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...

  2. Ubuntu18.04安装netstat

    一.简介 Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memb ...

  3. async并发处理

  4. Errors running builder 'DeploymentBuilder' on project

    Errors running builder 'DeploymentBuilder' on project 1.修改java源代码后点击保存,IDE 自动编译并热部署,提示如下错误: Errors o ...

  5. [转帖] BMC安全隐患

    BMC再现漏洞,裸金属云服务器岌岌可危 https://zhuanlan.kanxue.com/article-8006.htm 之前有vt-x 可能有隐患 现在看起来BMC 也就是IPMI 也有隐患 ...

  6. php foreach跳出本次/当前循环与终止循环方法

    continue:跳出本次循环 break:终止循环 exit:用来结束程序执行 return: 用来结束一段代码     $arr= array('le','yang','jun','lecode' ...

  7. npm install、npm install --save与npm install --save-dev区别

    npm install X: 会把X包安装到node_modules目录中 不会修改package.json 之后运行npm install命令时,不会自动安装X npm install X –sav ...

  8. idea中 maven打包时时报错User setting file does not exist C:\Users\lenevo\.m2\setting.xml,

    第一种错误 :idea中 maven打包时时报错User setting file does not exist C:\Users\lenevo\.m2\setting.xml, 解决方案如下:将ma ...

  9. shell expr用法

    expr 计算整数变量值 使用方法如下: linux-zpycfm:/home/test/shell # s=+ -bash: +: command not found linux-zpycfm:/h ...

  10. python 基础篇

    1.编程语言介绍. 1.机器语言:直接用二进制编程,直接对硬件的控制,需对硬件掌握比较深. 优点:执行效率快 缺点:开发效率低下 2.汇编语言:用英文标签代替二进制编写程序,直接对硬件的控制,需对硬件 ...