本文共 1901 字,大约阅读时间需要 6 分钟。
1.两台server都安装Apacheapt-get install apache22.两台server都安装Rsyncapt-get install rsync3.在ServerA使用cron做计划crontab -e进入编辑模式,然后输入下面内容,代表每5分钟会执行一次同步5 * * * * rsync -avzhe ssh /var/www/
下面这个是配置的格式:
# ┌───────────── min (0 - 59) # │ ┌────────────── hour (0 - 23) # │ │ ┌─────────────── day of month (1 - 31) # │ │ │ ┌──────────────── month (1 - 12) # │ │ │ │ ┌───────────────── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0) # │ │ │ │ │ # │ │ │ │ │ # * * * * * command to execute4.修改ServerB的/var/www/index.html的内容5.检查ServerA的/var/www/index.html的内容被更新成ServerB一样的内容
(注意:为了让cron可以不输入密码直接执行rsync,需要设置下ssh-keygen如下:
# ssh-keygenGenerating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:a2:ff:3e:7b:2d:b4:98:27:0a:3d:1b:0b:98:51:98:3c The key's randomart image is:+--[ RSA 2048]----+| || . o || E . || o || . . S || + o . . || o + + + o || + == = . || =++* . |+-----------------+
/tmp # ssh-copy-id -i /root/.ssh/id_rsa.pub machineBNameThe authenticity of host 'machineBName (10.185.98.24)' can't be established.RSA key fingerprint is cd:9d:d5:81:7b:38:3e:4c:41:0b:cb:72:de:51:03:da.Are you sure you want to continue connecting (yes/no)? yes/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'machineBName"and check to make sure that only the key(s) you wanted were added.
关于ssh-keygen可以参考:)
转载地址:http://iuzlo.baihongyu.com/