以下为脚本:
1.主机脚本(192.168.29.3)
1 vi /etc/rc.conf
nfs_server_enable="YES"
nfs_server_flags="-u -t -n 4"
mountd_flags="-r"
2 vi /etc.exports
/quark/ /quark/somains /quark/ldbm /quark/mysql/var -mapall=root -network 192.168.29.0 -mask 255.255.255.0
3 vi /tools/monitor.sh
#!/bin/sh
/quark/bin/monitor --host 192.168.29.3 25 10 5 /tools/failover.sh &
4 vi /tools/failover.sh
#!/bin/sh
/quark/bin/quark stop
/quark/bin/sql-server.sh stop
/quark/bin/openldap.sh stop
/quark/bin/web-server.sh stop
/quark/bin/web-admin.sh stop
ifconfig fxp0 down
5 vi /tools/takeover.sh
#!/bin/sh
ifconfig fxp0 192.168.29.3 netmask 255.255.255.0 up
route add default 192.168.29.20
/quark/bin/quark start
/quark/bin/sql-server.sh start
/quark/bin/openldap.sh start
/quark/bin/web-server.sh start
/quark/bin/web-admin.sh start
备机脚本;(192.168.29.4)
1vi/etc/rc.conf
nfs_client_enable="YES"
nfs_client_flags="-n 4"
2.vi/tools/monitor.sh
#!/bin/sh
/quark/bin/monitor --host 192.168.29.3 25 10 6 /tools/failover.sh &
3 vi /tools/failover.sh
#!/bin/sh
ifconfig fxp0 down
ifconfig fxp0 192.168.29.3 netmask 255.255.255.0 up
route add default 192.168.29.20
/quark/bin/quark start
/quark/bin/sql-server.sh start
/quark/bin/openldap.sh start
/quark/bin/web-server.sh start
/quark/bin/web-admin.sh start
4vi /tools/takeover.sh
#!/bin/sh
/quark/bin/quark stop
/quark/bin/sql-server.sh stop
/quark/bin/openldap.sh stop
/quark/bin/web-server.sh stop
/quark/bin/web-admin.sh stop
ifconfig fxp0 192.168.29.4 netmask 255.255.255.0 up
route add default 192.168.29.20
5vi /tools/mount.sh
#!/bin/sh
mount -t nfs 192.168.29.3:/quark/domains /data/domains
mount -t nfs 192.168.29.3:/quark/ldbm /data/ldbm
mount -t nfs 192.168.29.3:/quark/mysql/var /data/var
6 vi /tools/mirror.sh
#1/bin/sh
/quark/bin/cpbk -rn /data/domains /quark/domains
/quark/bin/cpbk -rn /data/ldbm /quark/ldbm
/quark/bin/cpbk -rn /data/var /quark/mysql/var
--------------------------------------------------------------
LINUX双机热备
LINUX 系统下双机热备
主服务器;MAIL1 10.154.4.42
备服务器:MAIL2 10.154.4.43
配置主服务器:MAIL1
1. 修改/etc/rc.conf
vi /etc/rc.conf
nfs_server_enable=”YES”
nfs_server_flags=“-u –t –n 4”
mountd_flags=”-r”
2. 修改/etc/exports
vi /etc/exports
/quark/domains *(rw,all_squash,anonuid=8888,anongid=8888)
/quark/ldbm *(rw,no_root_squash)
/quark/mysql/var *(rw,all_sqush,anonuid=8889,anongid=8889)
配置备服务器:MAIL2
1 .修改/etc/rc.conf
vi /etc/rc.conf
nfs_client_enable=”YES”
nfs_client_flags=”-n 4”
2)vi mount.sh(启动挂载脚本)
#!/bin/sh
mount –t nfs 10.154.4.42:/quark/domains /data/domains
mount –t nfs 10.154.4.42:/quark/ldbm /data/ldbm
mount –t nfs 10.154.4.42:/quark/mysql/var /data/var
注:系统要时刻运行/quark/tools/mount.sh脚本。使得从机时刻挂载着主机开放出来的分区。
5)vi mirror.sh(启动同步数据的脚本)
#!/bin/sh
/quark/bin/cpbk –rn /data/domains /quark/domains
/quark/bin/cpbk –rn /data/ldbm /quark/ldbm
/quark/bin/cpbk –rn /data/var /quark/mysql/var
6)crontab –e –uroot
59 3,5,7,9,11,13,15,17,19,21,23 * * * /quark/tools/ bakup.sh &
注:
1. 所用到的脚本程序
monitor.sh ---à 监听程序
failover.sh ---à 监听失败处理
takeover.sh ----à 恢复脚本
mount.sh -----à 挂载脚本
mirror.sh -----à 同步数据的脚本
2 . 配置好主服务器和备服务器所要用到的脚本后,要修改这些脚本的权限
如:chmod 755 monitor.sh
chmod 755 failover.sh
chmod 755 takeover.sh
chmod 755 mount.sh
chmod 755 mirror.sh
3. 主服务器上monitor.sh脚本要在系统启动时就执行,把此脚本的路径加入到系统的启动脚本中。如下:
cd /etc/rc.d
vi rc.local
/quark/tools/monitor.sh
5. 备服务器上monitor.sh, mount.sh两个脚本要在系统启动时就执行,把这两个脚本的路径加入到系统的启动脚本中。如下:
cd /etc/rc.d
vi rc.local
/quark/tools/monitor.sh
/quark/tools/mount.sh
4. 当主服务器恢复故障后,要在备服务器上手动执行takeover.sh这个脚本。如下;
cd /quark/tools
./takeover.sh