Heartbeat 配置两台Web服务器高可用集群案例
通过heartbeat 配置两台web服务器高可用集群案例:
拓扑:
web1:192.168.0.101
hostname: web1.example.com
web2:192.168.0.102
hostname:web2.example.com
vip:192.168.0.254
nfs服务器:192.168.0.100(存放web页面)
注意:
1主机名要与uname -n 保持一致
2.web1与web2主机的date时间保持同步
3.web1与web2,ssh双机互信通信
4.关闭iptables 与selinux
环境配置:
1配置主机名
web1:
#vim /etc/sysconfig/network
HOSTNAME=web1.example.com
#hostname web1.example.com
web2:
#vim /etc/sysconfig/network
HOSTNAME=web2.example.com
#hostname web2.example.com
2.配置hosts文件,主机名解析
web1与web2:
#vim /etc/hosts
192.168.0.101 web1.example.com web1
192.168.0.102web2.example.com web2
3.实现web1与web2 ssh双机互信通信
web1:
#ssh-keygen -t rsa -f "~/.ssh/id_rsa -P ""
#ssh-copy-id i .ssh/id_rsa.pub [email protected]
web2:
#ssh-keygen -t rsa -f "~/.ssh/id_rsa -P ""
#ssh-copy-id i .ssh/id_rsa.pub [email protected]
4.时间同步设置
web1 与web2 中设置
#hwclock -s
5.安装web服务器
web1
#yum -y install httpd
#chkconfig httpd off
#echo 'web1' > /var/www/html/index.html (测试)
#service httpd restart
web2
#yum -y install httpd
#chkconfig httpd off
#echo 'web2' > /var/www/html/index.html (测试)
#service httpd restart
6.配置nfs服务器(192.168.0.100)
#mkdir /webfile
#cd /webfile;echo "nfs" >index.html
#vim /etc/exports
/webfile192.168.0.0/24(ro,sync)
#service nfs start
#showmount -e 192.168.0.100
--------------------------------------分割线 --------------------------------------
相关阅读:
--------------------------------------分割线 --------------------------------------
二:安装heartbeat
1.安装 heartbeat 相关软件包,有依赖关系,推荐使用yum安装
heartbeat-2.1.4-11.el5.i386.rpm
heartbeat-pils-2.1.4-11.el5.i386.rpm
heartbeat-stonith-2.1.4-11.el5.i386.rpm
heartbeat-gui-2.1.4-11.el5.i386.rpm
额外依赖包:libnet-1.1.4-3.el5.i386.rpm perl-MailTools-1.77-1.el5.noarch.rpm
#wget http://dl.Fedoraproject.org/pub/epel/5/i386/heartbeat-2.1.4-11.el5.i386.rpm
#wget http://dl.fedoraproject.org/pub/epel/5/i386/heartbeat-gui-2.1.4-11.el5.i386.rpm
#wget http://dl.fedoraproject.org/pub/epel/5/i386/heartbeat-stonith-2.1.4-11.el5.i386.rpm
#wget http://dl.fedoraproject.org/pub/epel/5/i386/heartbeat-pils-2.1.4-11.el5.i386.rpm
#wget http://dl.fedoraproject.org/pub/epel/5/i386/libnet-1.1.6-7.el5.i386.rpm
#wget http://dl.fedoraproject.org/pub/epel/5/i386/perl-MailTools-1.77-1.el5.noarch.rpm
# yum -y localinstall --nogpgcheck *.rpm
2.拷贝配置文件
#cp /usr/share/doc/heartbeat-2.1.4/{haresources,ha.cf authkeys} /etc/had.d/
#cd /etc/had.d/
#chmod 600 authkeys (权限必须为600,否则会出现问题)
3.编辑配置文件
(1)#vim /etc/ha.d/ha.cf
bcast eth0
node web1.example.com
node web2.example.com
(2)身份验证
#dd if=/dev/random count=1 bs=512 |md5sum
#vim authkeys
auth 3
3 md5 ec92b27792a008b420ec5adfe0a34ea0 //为刚才借助dd产生的随机md5加密值
(3)配置资源
#vim haresources
web1.example.com 192.168.0.254/24/eth0 httpd
//主节点为web1.example.com vip:192.168.0.254 高可用的服务为web三个资源作为一组
复制配置文件到web2中
scp /etc/ha.d/{haresources,authkeys,ha.cf} root@web2:/etc/ha.d