cat >>实验说明:<<EOF web服务器: 192.168.122.162 node1.test.com 192.168.122.244 node2.test.com nfs服务器: 192.168.122.27 nfs.test.com EOF
#①提供主机名
1 2 3 4 5 6 7 8 9 10 11
hostname "node1.test.com" vim /etc/sysconfig/network HOSTNAME=node1.test.com hostname "node2.test.com" vim /etc/sysconfig/network HOSTNAME=node2.test.com hostname "nfs.test.com" vim /etc/sysconfig/network HOSTNAME=nfs.test.com
#②web服务器能够基于公钥登陆
1 2 3 4 5
ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.122.244 ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.122.162
#③提供hosts文件
1 2 3 4 5
cat >>/etc/hosts<<EOF 192.168.122.162 node1.test.com 192.168.122.244 node2.test.com EOF scp /etc/hosts node2:/etc/
#④时间同步
1 2 3 4 5 6 7 8
ntpdate ntp.api.bz echo "*/5 * * * * ntpdate ntp.api.bz &>/dev/null" >> /etc/crontab ``` ```bash yum -y install epel-release yum -y install heartbeat && chkconfig heartbeat on yum -y install httpd && chkconfig httpd off
#⑥提供配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
cp -p /usr/share/doc/heartbeat-3.0.4/{authkeys,ha.cf,haresources} /etc/ha.d cd /etc/ha.d/ chmod 600 authkeys dd if =/dev/random count=1 bs=512 | md5sum cat >>authkeys<<EOF auth1 1 md5 05d7ca80f950d1a7b41322bd39220d2a EOF cat >>ha.cf<<EOF logfacility local0 keepalive 2 deadtime 30 warntime 10 initdead 120 udpport 694 mcast eth1 225.0.0.1 694 1 0 auto_failback on node node1.test.com node node2.test.com ping 192.168.122.1 deadping 30 compression bz2 compression_threshold 2 EOF cat >>haresources<<EOF node1.test.com IPaddr::192.168.122.100/24/eth1 httpd EOF scp /etc/ha.d/{ha.cf,authkeys,haresources} node2:/etc/ha.d/ echo "node1.test.com" > /var/www/html/index.html echo "node2.test.com" > /var/www/html/index.html for x in {1..2};do ssh node$x 'service heartbeat start' start;done yum -y install nfs-utils rpcbind echo "<h1>success</h1>" > /web/htdocs/index.html service nfs start service rpcbind start showmount -e 192.168.122.27 mount -t nfs 192.168.122.27:/web/htdocs /mnt umount /mnt cat >>haresources<<EOF node1.test.com IPaddr::192.168.122.100/24/eth1 Filesystem::172.16.100.27:/web/htdocs::/var/www/html::nfs httpd EOF scp haresources node2:/etc/ha.d/ for x in {1..2};do ssh node$x 'service heartbeat start' start;done
1 2 3 4 5 6 7
#启动heartbeat会出现,稍微等一会,就会发现资源能够正常工作了,如果不行,那么service heartbeat restart即可;下面是首次启动时的输出样例; #Starting High-Availability services: INFO: Resource is stoppedDone. #如果开启了iptables服务器: #iptables -A INPUT -p udp -dport 694 -j ACCEPT #iptables -A OUTPUT -p udp --sport 694 -j ACCEPT
因为我的网卡是eth1,所以全文的网络接口指向的是eth1;;;