实现免密登陆,更方便的同步目录与文件。

一、SSH互信

1.生成key文件

ssh-keygen -t rsa 

2.远程拷贝公钥

ssh-copy-id -i  .ssh/id_rsa.pub root@192.168.101.206

3.测试免密登陆

ssh 192.168.101.206

二、Rsync同步

目标服务器

yum install rsync

本地服务器

yum install rsync
rsync -avP  /root/rysnc  192.168.101.206:/root/download

二、实时同步

安装inotify

yum install inotify

编写脚本inotify.sh

#!/bin/bash
dst_host="192.168.101.206"  
directory="/root/download" 
usr="root" 
inotify_cmd="inotifywait -mrq -e modify,create,delete,attrib  ${directory}" 
rsync_cmd="rsync -azP --delete ${directory} ${usr}@${dst_host}:${directory}" 
${inotify_cmd} | while read DIRECTORY EVENT FILE
do
        ${rsync_cmd} > /dev/null
done

后台运行

nohup ./inotify.sh &