设为首页 收藏本站
查看: 1373|回复: 0

[经验分享] heartbeat httpd nfs 实现高可用web集群

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-7-7 09:10:05 | 显示全部楼层 |阅读模式
一 环境准备
二 拓扑结构
三 前提条件
四 安装相关软件
五 配置heartbeat
六 测试web集群
七 问题汇总
八 共享存储
  一 环境准备
操作系统
centos 6.4 x86_64 最小化安装
如使用yum 安装的方式 centos5.5 安装的是V2.X ,centos 6.4 安装的是V3.X
YUM 安装 Vim man ntp “development tools” “server platform development” “desktop platform development”
配置 epel YUM 源
关闭 防火墙 selinux
  二 拓扑结构
   1.png
三 前提条件(两个节点都有配置)
1 节点之间主机名可以互相解析
web1 ,web2
?
1
2
3
4
5
[iyunv@web1 ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.132  web1.daphne.com  web1
192.168.200.133  web2.daphne.com  web2



2 节点之间时间同步
?
1
[iyunv@web1 ~]# ntpdate ntp.api.bz



3 节点之间配置SSH互信
?
1
2
3
4
[iyunv@web1 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
[iyunv@web1 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@web2.daphne.com
[iyunv@web1 ~]# ssh web2
[iyunv@web2 ~]#



?
1




?
1
2
3
4
[iyunv@web2 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
[iyunv@web2 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@web1.daphne.com
[iyunv@web2 ~]# ssh web1
[iyunv@web2 ~]#



四 安装相关软件
1 heartbeat 组件说明
  • 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
?
1
2
3
4
yum install PyXML libnet pygtk2-libglade net-snmp-libs
yum install libtool-ltd( 注  要从源库安装 ,不可以epel)
lyum install  libnet
rpm -ivh heartbeat-*



3 安装httpd
?
1
2
3
4
5
[iyunv@web1 ~]# yum install httpd
[iyunv@web1 ~]# cd /var/www/html/
[iyunv@web1 html]# vim index.html
web1
[iyunv@web1 ~]# service httpd start



测试
2.png
测试完毕 关闭服务 使其开机不要启动
?
1
2
3
4
[iyunv@web1 ~]# serivce httpd off
[iyunv@web1 ~]# chkconfig httpd of
[iyunv@web1 ~]# chkconfig --list httpd
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off



以上操作在两个节点都要做
五 配置heartbeat
1配置文件说明
?
1
2
3
4
[iyunv@web1 ~]# cd /etc/ha.d/
[iyunv@web1 ha.d]# ls
authkeys  harc         rc.d           resource.d
ha.cf     haresources  README.config  shellfuncs



说明 安装好的heartbeat 默认没有配置文件,但提供了配置文件样本
?
1
2
3
4
5
6
7
8
9
[iyunv@web1 ha.d]# cd /usr/share/doc/heartbeat-2.1.4/
[iyunv@web1 heartbeat-2.1.4]# ls
apphbd.cf         faqntips.html        haresources         Requirements.html
authkeys          faqntips.txt         hb_report.html      Requirements.txt
AUTHORS           GettingStarted.html  hb_report.txt       rsync.html
ChangeLog         GettingStarted.txt   heartbeat_api.html  rsync.txt
COPYING           ha.cf                heartbeat_api.txt   startstop
COPYING.LGPL      HardwareGuide.html   logd.cf
DirectoryMap.txt  HardwareGuide.txt    README



?
1
<font face="微软雅黑">我们需要  authkeys ha.cf haresources 三个配置文件</font>



?
1
[iyunv@web1 heartbeat-2.1.4]# cp authkeys ha.cf haresources /etc/ha.d/



2 配置authkeys
?
1
2
3
4
5
6
7
8
[iyunv@web1 ha.d]# openssl rand -hex 8 >> authkeys
[iyunv@web1 ha.d]# vim authkeys
auth 2
#1 crc
#2 sha1 HI!
#3 md5 Hello!
2 sha1 7c0f241959ee845d
[iyunv@web1 ha.d]# chmod 600 authkeys



3 配置ha.cf文件
?
1
[iyunv@web1 ha.d]# vim ha.cf



修改心跳信息的传播方式 可以采用 组播 广播 单播
?
1
bcast  eth0



配置集群中的节点数
?
1
2
node web1.daphne.com
node web2.daphne.com



4 配置haresources
?
1
2
[iyunv@web1 ha.d]# vim haresources
web1.daphne.com 192.168.200.10/24/eth0 httpd



5 复制以上三个文件到web2上
?
1
[iyunv@web1 ha.d]# scp authkeys ha.cf haresources web2:/etc/ha.d/



6 启动web1与web2
先启动备份节点
?
1
2
[iyunv@web2 ~]# service heartbeat  start
[iyunv@web1 ~]# service heartbeat  start



六 测试web集群
查看IP
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[iyunv@web1 ha.d]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:7D:C1:D7  
          inet addr:192.168.200.132  Bcast:192.168.200.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe7d:c1d7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9069 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9159 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1707993 (1.6 MiB)  TX bytes:1846141 (1.7 MiB)

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:7D:C1:D7  
          inet addr:192.168.200.10  Bcast:192.168.200.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1


lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0



?
1


?
1




?
1
<font face="微软雅黑">故障演示</font>



?
1
<font face="微软雅黑">关闭web1上的heartbeat</font>



?
1
2
3
[iyunv@web1 ~]# service heartbeat stop
Stopping High-Availability services:
Done.



查看web2上的IP
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:61:E4:6B  
          inet addr:192.168.200.133  Bcast:192.168.200.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe61:e46b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8230 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8164 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1698974 (1.6 MiB)  TX bytes:1680369 (1.6 MiB)

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:61:E4:6B  
          inet addr:192.168.200.10  Bcast:192.168.200.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1


lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)



测试
3.png
?
1




七 问题汇总
节点间的文件同步
1Rsync+Inotify组合方案来解决节点之间的同步问题
2共享存储方案
八 共享存储
1 配置NFS服务器
?
1
2
3
4
5
6
7
8
9
10
[iyunv@bogon ~]# yum install nfs*

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

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

[iyunv@bogon ~]# service rpcbind start
[iyunv@bogon ~]# service nfs start



节点测试 挂载
web1
?
1
2
3
4
5
[iyunv@web1 ~]# mount -t nfs 192.168.200.138:/web/html /mnt
[iyunv@web1 ~]# cd /mnt
[iyunv@web1 mnt]# ls
index.html
[iyunv@web1 ~]# umount /mnt



修改haresource文件
?
1
2
[iyunv@web1 ha.d]# vim /etc/ha.d/haresources
web1.daphne.com 192.168.200.10/24/eth0 Filesystem::192.168.200.138:/web/html::/var/www/html::nfs  httpd



同步haresource配置文件
?
1
2
[iyunv@web1 ha.d]# cd /etc/ha.d/
[iyunv@web1 ha.d]# scp haresources web2:/etc/ha.d/



重启heartbeat
?
1
2
[iyunv@web2 ~]# service heartbeat restart
[iyunv@web1 ~]# service heartbeat restart



测试web服务
4.png


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-21717-1-1.html 上篇帖子: 基于heartbeatV2版本的ha-gui工具对httpd做高可用集群(2) 下篇帖子: heartbeat+DRBD+mysql高可用集群实战
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表