您的位置:首页 > 理论基础 > 计算机网络

heartbeat httpd nfs 实现高可用web集群

2014-07-06 16:52 686 查看
一环境准备
二拓扑结构
三前提条件
四安装相关软件
五配置heartbeat
六测试web集群
七问题汇总
八共享存储
一环境准备
操作系统
centos6.4x86_64最小化安装
如使用yum安装的方式centos5.5安装的是V2.X,centos6.4安装的是V3.X
YUM安装Vimmanntp“developmenttools”“serverplatformdevelopment”“desktopplatformdevelopment”
配置epelYUM源
关闭防火墙selinux
二拓扑结构



三前提条件(两个节点都有配置)
1节点之间主机名可以互相解析
web1,web2
[root@web1~]#vim/etc/hosts 127.0.0.1localhostlocalhost.localdomainlocalhost4localhost4.localdomain4 ::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6 192.168.200.132web1.daphne.comweb1 192.168.200.133web2.daphne.comweb2
2节点之间时间同步
[root@web1~]#ntpdatentp.api.bz
3节点之间配置SSH互信
[root@web1~]#ssh-keygen-trsa-f~/.ssh/id_rsa-P'' [root@web1~]#ssh-copy-id-i.ssh/id_rsa.pubroot@web2.daphne.com [root@web1~]#sshweb2 [root@web2~]#[root@web2~]#ssh-keygen-trsa-f~/.ssh/id_rsa-P''
[root@web2~]#ssh-copy-id-i.ssh/id_rsa.pubroot@web1.daphne.com
[root@web2~]#sshweb1
[root@web2~]#

四安装相关软件

1heartbeat组件说明

heartbeat核心组件
heartbeat-gui图形管理接口
heartbeat-ldirectord为lvs高可用提供规则自动生成及后端realserver健康状态检查组件
heartbeat-pils装载库插件接口
heartbeat-stonith

2安装heartbeat

heartbeat-2.1.4-12.el6.x86_64.rpm
heartbeat-gui-2.1.4-12.el6.x86_64.rpm
heartbeat-pils-2.1.4-12.el6.x86_64.rpm
heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
yuminstallPyXMLlibnetpygtk2-libgladenet-snmp-libs
yuminstalllibtool-ltd(注要从源库安装,不可以epel)
lyuminstalllibnet
rpm-ivhheartbeat-*
3安装httpd
[root@web1~]#yuminstallhttpd
[root@web1~]#cd/var/www/html/
[root@web1html]#vimindex.html
web1
[root@web1~]#servicehttpdstart

测试





测试完毕关闭服务使其开机不要启动
[root@web1~]#serivcehttpdoff
[root@web1~]#chkconfighttpdof
[root@web1~]#chkconfig--listhttpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

以上操作在两个节点都要做

五配置heartbeat

1配置文件说明
[root@web1~]#cd/etc/ha.d/
[root@web1ha.d]#ls
authkeysharcrc.dresource.d
ha.cfharesourcesREADME.configshellfuncs
说明安装好的heartbeat默认没有配置文件,但提供了配置文件样本
[root@web1ha.d]#cd/usr/share/doc/heartbeat-2.1.4/
[root@web1heartbeat-2.1.4]#ls
apphbd.cffaqntips.htmlharesourcesRequirements.html
authkeysfaqntips.txthb_report.htmlRequirements.txt
AUTHORSGettingStarted.htmlhb_report.txtrsync.html
ChangeLogGettingStarted.txtheartbeat_api.htmlrsync.txt
COPYINGha.cfheartbeat_api.txtstartstop
COPYING.LGPLHardwareGuide.htmllogd.cf
DirectoryMap.txtHardwareGuide.txtREADME我们需要authkeysha.cfharesources三个配置文件[root@web1heartbeat-2.1.4]#cpauthkeysha.cfharesources/etc/ha.d/

2配置authkeys
[root@web1ha.d]#opensslrand-hex8>>authkeys
[root@web1ha.d]#vimauthkeys
auth2
#1crc
#2sha1HI!
#3md5Hello!
2sha17c0f241959ee845d
[root@web1ha.d]#chmod600authkeys


3配置ha.cf文件
[root@web1ha.d]#vimha.cf

修改心跳信息的传播方式可以采用组播广播单播
bcasteth0
配置集群中的节点数
nodeweb1.daphne.com
nodeweb2.daphne.com

4配置haresources
[root@web1ha.d]#vimharesources
web1.daphne.com192.168.200.10/24/eth0httpd

5复制以上三个文件到web2上
[root@web1ha.d]#scpauthkeysha.cfharesourcesweb2:/etc/ha.d/

6启动web1与web2

先启动备份节点
[root@web2~]#serviceheartbeatstart
[root@web1~]#serviceheartbeatstart

六测试web集群

查看IP
[root@web1ha.d]#ifconfig
eth0Linkencap:EthernetHWaddr00:0C:29:7D:C1:D7
inetaddr:192.168.200.132Bcast:192.168.200.255Mask:255.255.255.0
inet6addr:fe80::20c:29ff:fe7d:c1d7/64Scope:Link
UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1
RXpackets:9069errors:0dropped:0overruns:0frame:0
TXpackets:9159errors:0dropped:0overruns:0carrier:0
collisions:0txqueuelen:1000
RXbytes:1707993(1.6MiB)TXbytes:1846141(1.7MiB)

eth0:0Linkencap:EthernetHWaddr00:0C:29:7D:C1:D7
inetaddr:192.168.200.10Bcast:192.168.200.255Mask:255.255.255.0
UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1

loLinkencap:LocalLoopback
inetaddr:127.0.0.1Mask:255.0.0.0
inet6addr:::1/128Scope:Host
UPLOOPBACKRUNNINGMTU:16436Metric:1
RXpackets:0errors:0dropped:0overruns:0frame:0


故障演示关闭web1上的heartbeat[root@web1~]#serviceheartbeatstop
StoppingHigh-Availabilityservices:
Done.


查看web2上的IP
ifconfig
eth0Linkencap:EthernetHWaddr00:0C:29:61:E4:6B
inetaddr:192.168.200.133Bcast:192.168.200.255Mask:255.255.255.0
inet6addr:fe80::20c:29ff:fe61:e46b/64Scope:Link
UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1
RXpackets:8230errors:0dropped:0overruns:0frame:0
TXpackets:8164errors:0dropped:0overruns:0carrier:0
collisions:0txqueuelen:1000
RXbytes:1698974(1.6MiB)TXbytes:1680369(1.6MiB)

eth0:0Linkencap:EthernetHWaddr00:0C:29:61:E4:6B
inetaddr:192.168.200.10Bcast:192.168.200.255Mask:255.255.255.0
UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1

loLinkencap:LocalLoopback
inetaddr:127.0.0.1Mask:255.0.0.0
inet6addr:::1/128Scope:Host
UPLOOPBACKRUNNINGMTU:16436Metric:1
RXpackets:0errors:0dropped:0overruns:0frame:0
TXpackets:0errors:0dropped:0overruns:0carrier:0
collisions:0txqueuelen:0
RXbytes:0(0.0b)TXbytes:0(0.0b)
测试





七问题汇总

节点间的文件同步

1Rsync+Inotify组合方案来解决节点之间的同步问题

2共享存储方案

八共享存储

1配置NFS服务器
[root@bogon~]#yuminstallnfs*

[root@bogon~]#mkdir-pv/web/html/
[root@bogon~]#vim/web/html/index.html

[root@bogon~]#vim/etc/exports
/web/html/192.168.200.0/24(rw,async)

[root@bogon~]#servicerpcbindstart
[root@bogon~]#servicenfsstart

节点测试挂载

web1
[root@web1~]#mount-tnfs192.168.200.138:/web/html/mnt
[root@web1~]#cd/mnt
[root@web1mnt]#ls
index.html
[root@web1~]#umount/mnt

修改haresource文件
[root@web1ha.d]#vim/etc/ha.d/haresources
web1.daphne.com192.168.200.10/24/eth0Filesystem::192.168.200.138:/web/html::/var/www/html::nfshttpd

同步haresource配置文件
[root@web1ha.d]#cd/etc/ha.d/
[root@web1ha.d]#scpharesourcesweb2:/etc/ha.d/

重启heartbeat
[root@web2~]#serviceheartbeatrestart
[root@web1~]#serviceheartbeatrestart


测试web服务






内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  软件 操作系统