标签:password 存在 出现 语法 oca tcp 远程同步 ORC rsync服务
rsync远程同步[root@localhost ~]# rpm -q rsync //查看rsync软件包是否存在
配置rsync源服务器
[root@localhost ~]# vim /etc/rsyncd.conf
uid = nobody
gid = nobody //匿名用户
use chroot = yes //禁止进入家目录
address = 192.168.45.133
port 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.45.0/24
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
[wwwroot]
path = /var/www/html //站点同步目录
comment = www.kgc.cn //描述信息
read only = yes //权限
auth users = backuper //指定来访用户
secrets file = /etc/rsyncd_users.db //密码文件
#设置账号登录密码
[root@localhost ~]# vim /etc/rsyncd_users.db
backuper:abc123
#修改文件权限
[root@localhost ~]# chmod 600 /etc/rsyncd_users.db
#启动服务
[root@localhost ~]# rsync -deamon
#查看文件是否启动成功
[root@localhost ~]# netstat -ntap | grep rsync
tcp 0 0 192.168.45.133:873 0.0.0.0:* LISTEN 100732/rsync
主服务器
[root@localhost ~]#systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install httpd -y
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# echo "this is test web" > index.html
[root@localhost html]# cd ..
[root@localhost www]# chmod 777 html/
客户机
root@localhost ~]#systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install httpd -y
[root@localhost ~]# cd /var/www/
[root@localhost www]# chmod 777 html/
格式1:用户名@主机地址::共享模块名
格式2:rsync://用户名@主机地址/共享模块名
[root@localhost ~]# rsync -avz
backuper@192.168.45.132::wwwroot/root
[root@localhost ~]# rsync -avz
rsync://backuper@192.168.45.132/wwwroot/root
第一种方式
[root@localhost www]# rsync -avz backuper@192.168.45.133::wwwroot /var/www/html/
Password:
receiving incremental file list
./
index.html
sent 83 bytes received 172 bytes 14.57 bytes/sec
total size is 17 speedup is 0.07
第二种方式
[root@localhost html]# rm -rf index.html
[root@localhost html]# ls
[root@localhost html]# rsync -avz rsync://backuper@192.168.45.133/wwwroot /var/www/html/
Password:
receiving incremental file list
./
index.html
sent 83 bytes received 172 bytes 72.86 bytes/sec
total size is 17 speedup is 0.07
[root@localhost html]# ls
index.html
#删除刚才同步过来的文件
[root@localhost html]# rm -rf index.html
[root@localhost html]# ls
#创建密码文件
[root@localhost html]# vim /etc/services.pass
abc123
[root@localhost html]# rsync -avz --delete --password-file=/etc/services.pass backuper@192.168.45.133::wwwroot /var/www/html/
receiving incremental file list
./
index.html
sent 83 bytes received 172 bytes 24.29 bytes/sec
total size is 17 speedup is 0.07
[root@localhost html]#
[root@localhost html]# ls
index.html
[root@localhost html]# vim /etc/sysctl.conf
fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 1048576
[root@localhost html]# sysctl -p
fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 1048576
### 安装inotify-tools辅助工具
- inotifywait:用于持续监控,实时输出结果
- inotifywatch:用于短期监控,任务完成后再除结果
```sql
#挂载软件包
[root@localhost html]# mount.cifs //192.168.100.3/GUN /mnt
Password for root@//192.168.100.3/GUN:
[root@localhost html]# cd /mnt
#解压软件包
[root@localhost mnt]# tar zxvf inotify-tools-3.14.tar.gz -C /opt
[root@localhost mnt]# cd /opt/inotify-tools-3.14/
#安装必要软件包+
[root@localhost inotify-tools-3.14]# yum install gcc gcc-c++ make -y
#编译安装
[root@localhost inotify-tools-3.14]# ./configure
[root@localhost inotify-tools-3.14]# make && make install
#监控命令
[root@localhost inotify-tools-3.14]# inotifywait -mrq -e modify,create,move,delete /var/www/html/
[root@localhost ~]# vim /opt/inotify_rsync.sh
#!/bin/bash
INOTIFY_CMD="inotifywait -mrq -e modify,create,attrib,move,delete /var/www/html/"
RSYNC_CMD="rsync-azH --delete --password-file=/etc/services.pass /var/www/html/ backuper@192.168.45.130::wwwroot/"
#读取输出的监控记录
$INOTIFY_CMD | while read DIRECTORY EVENT FILE
do
# 如果rsync未在执行,则立即启动
if [ $(pgrep rsync | wc -l) -le 0 ];then
$RSYNC_CMD
fi
done
标签:password 存在 出现 语法 oca tcp 远程同步 ORC rsync服务
原文地址:https://blog.51cto.com/14469918/2461456