Apache Replication主从复制同步机制实践

来源:互联网 发布:淘宝店主寄语文艺 编辑:程序博客网 时间:2024/06/05 18:24


Apache Replication 主从复制同步机制实践


1.两台server都安装Apache
apt-get install apache2
2.两台server都安装Rsync
apt-get install rsync
3.在ServerA使用cron做计划
crontab -e
进入编辑模式,然后输入下面内容,代表每5分钟会执行一次同步
5 * * * * rsync -avzhe ssh
root@machinenameServerB.domainname.com:/var/www/ /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 execute
4.修改ServerB的/var/www/index.html的内容
5.检查ServerA的/var/www/index.html的内容被更新成ServerB一样的内容


(注意:为了让cron可以不输入密码直接执行rsync,需要设置下ssh-keygen如下:

root@machineAName  # ssh-keygen
Generating 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 root@machineAName
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
| . o             |
|  E .            |
|   o             |
|  .   . S        |
|   + o .  .      |
|  o + +  + o     |
|     + == = .    |
|      =++* .     |
+-----------------+

/tmp
root@machineAName # ssh-copy-id -i /root/.ssh/id_rsa.pub machineBName
The 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
root@machineBName's 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://www.thegeekstuff.com/2011/07/rsync-over-ssh-without-password/)




0 1