2.Step 基于密钥的认证配置
- 登录主服务器并使用以下命令生成公钥和私钥:
[jack@onitroad ~]# ssh-keygen -t rsa
使用 ssh-copy-id 命令将公钥复制到从服务器:
[jack@onitroad ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub jack@onitroad
Lsyncd 代表“Live Syncing Daemon”,lsyncd 用于在特定时间间隔后本地和远程同步或者复制文件和目录。
Lsyncd 在后端使用 Rsync 和 ssh。
在本快速教程中,我们将在 CentOS 7 上安装和配置 Lsyncd,以将目录远程同步到另一台服务器。
3.Step Lsyncd配置
- 打开 /etc/lsyncd.conf 文件并像这样修改它:
--- -- User configuration file for lsyncd. - -- Simple example for default rsync. - settings { statusFile = "/tmp/lsyncd.stat", statusInterval = 1, } sync { default.rsync, source="/var/www/html", target="192.168.1.14:/var/www/html", rsync={rsh ="/usr/bin/ssh -l root -i /root/.ssh/id_rsa",} }
使用以下命令启动并启用 lsyncd 服务:
[jack@onitroad ~]# systemctl enable lsyncd [jack@onitroad ~]# systemctl start lsyncd
最后查看lsyncd status Report来控制目录的同步和复制
[jack@onitroad ~]# tail -f 10 /var/log/lsyncd.stat tail: cannot open ‘10’ for reading: No such file or directory ==> /var/log/lsyncd.stat <== Excluding: nothing. Inotify watching 5 directories 1: /var/www/html/ 2: /var/www/html/onitroad.com/ 3: /var/www/html/onitroad.com/public_html/ 4: /var/www/html/onitroad.comfo/ 5: /var/www/html/onitroad.comfo/public_html/
环境:
Server01.onitroad.com:192.168.1.13
Server02.onitroad.com:192.168.1.14
要同步的目录:“/var/www/html”
2.Step安装Lsyncd
[jack@onitroad ~]# yum install epel-release [jack@onitroad ~]# yum install lsyncd -y
日期:2020-06-02 22:18:20 来源:oir作者:oir