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

[经验分享] Heartbeat+httpd+NFS 实现高可用的Web服务器

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-1-14 09:00:08 | 显示全部楼层 |阅读模式
准备工作
1、实验拓扑图
wKiom1S02QTQcxOvAAFJSxjKOk0076.jpg

2、实验时最好事先关闭防火墙与SELinux (两节点都要配置)
node1,node2:
[iyunv@node ~]# service iptables stop  
[iyunv@node ~]# vim /etc/selinux/config  
SELINUX=disabled


3、节点之前主机名互相解析:一定确保主机名和uname -n一致
[iyunv@node ~]# vim /etc/hosts
10.10.0.224  node1.test.com  node1  
10.10.0.225  node2.test.com  node2

4、节点时间必须同步node1,node2:
[iyunv@node ~]# ntpdate 10.10.0.11
[iyunv@node ~]# date
Tue Jan 13 16:41:30 CST 2015

5、节点之间配置SSH互信
node1:
[iyunv@node1 ~]# ssh-keygen  -t rsa -f ~/.ssh/id_rsa  -P ''
[iyunv@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node2.test.com
[iyunv@node1 ~]# ssh node2
[iyunv@node2 ~]# ifconfig

node2:
[iyunv@node2 ~]# ssh-keygen  -t rsa -f ~/.ssh/id_rsa  -P ''
[iyunv@node2 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node1.test.com
[iyunv@node2 ~]# ssh node1
[iyunv@node1 ~]# ifconfig

一、安装相关软件(两节点都需要安装)
1.heartbeat     安装组件说明
heartbeat     核心组件  *   
heartbeat-devel     开发包   
heartbeat-gui     图形管理接口 *   
heartbeat-ldirectord     为lvs高可用提供规则自动生成及后端realserver健康状态检查的组件   
heartbeat-pils     装载库插件接口 *   
heartbeat-stonith     爆头接口 *
注:带*表示必须安装

2.安装heartbeat (node1,node2)
[iyunv@node ~]# yum -y install heartbeat*

3.安装httpd
node1:
[iyunv@node1~]# yum install -y httpd
[iyunv@node1 ~]# service httpd start  
启动 httpd:                                              [确定]  
[iyunv@node1 ~]# echo "node1.test.com" > /var/www/html/index.html
测试访问页面
测试完成之后需要停用httpd,并禁止开机启动
[iyunv@node1 ha.d]# service httpd stop  
停止 httpd:                                              [确定]  
[iyunv@node1 ha.d]# chkconfig httpd off  

node2:
[iyunv@node1~]# yum install -y httpd
[iyunv@node1 ~]# service httpd start  
[iyunv@node1 ~]# echo "node2.test.com" > /var/www/html/index.html
测试访问页面
测试完成之后需要停用httpd,并禁止开机启动
[iyunv@node1 ha.d]# service httpd stop   
[iyunv@node1 ha.d]# chkconfig httpd off  

二、配置heartbeat
1、配置文件说明
[iyunv@node1 ~]# cd /etc/ha.d/  
[iyunv@node1 ha.d]# ls  
harc  rc.d  README.config  resource.d  shellfuncs  shellfuncs.rpmsave、
说明:安装好的heartbeat默认是没有配置文件的,但提供了配置文件样本
[iyunv@node1 heartbeat-2.1.4]# cp /usr/share/doc/heartbeat-3.0.4/{authkeys ha.cf haresources} /etc/ha.d/
说明:三个配置文件是我们需要的分别为,authkeys、ha.cf、haresources
authkeys #是节点之间的认证key文件,我们不能让什么服务器都加入集群中来,加入集群中的节点都是需要认证的
ha.cf #heartbeat的主配置文件
haresources #集群资源管理配置文件(在heartbeat所有版本中都是支持haresources来配置集群中的资源的)

2.配置authkeys文件
[iyunv@node1 ha.d]# openssl rand -base64 8     #生成密钥随机数  
[iyunv@node1 ha.d]# vim authkeys
#auth 1  
#1 crc  
#2 sha1 HI!  
#3 md5 Hello!
auth 1
1 md5 a4ef87crg
[iyunv@node1 ha.d]# chmod 600 authkeys      #修改密钥文件的权限为600  

3.配置ha.cf文件
[iyunv@node1 ha.d]# vim ha.cf
主要修改两处(其它都可以默认):
(1).修改心跳信息的传播方式(这里是广播)
bcast   eth0
(2).配置集群中的节点数
node    node1.test.com  
node    node2.test.com
4.配置haresources文件
[iyunv@node1 ha.d]# vim haresources
node1.test.com IPaddr::10.10.0.11/24/eth0 httpd
5.复制以上三个配置文件到node2上
[iyunv@node1 ha.d]# scp authkeys ha.cf haresources node2:/etc/ha.d/  
6.启动node1与node2
[iyunv@node1 ha.d]# ssh node2 "service heartbeat start"
[iyunv@node1 ha.d]# service heartbeat start         

三、测试web集群
1.查看启动的服务
[iyunv@node1 ha.d]# netstat -ntulp  
2.查看IP
[iyunv@node1 ha.d]# ifconfig  
3.测试
4.故障演示
1).关闭node1上的heartbeat
[iyunv@node1 ha.d]# service heartbeat stop     #将node1中的heartbeat关闭  
2).查看node2上的IP
[iyunv@node2 ~]# ifconfig # 查看node2的IP,可以看到立即转移到node2上  
3).测试
大家可以看到,集群已经转移到node2上,从而实现了Web高可用。

四、共享存储
1.配置NFS服务器
[iyunv@nfs ~]# mkdir -pv /web
[iyunv@nfs ~]# vim /etc/exports
/web/      10.10.0.0/16(ro,async)
[iyunv@nfs /]# echo 'NFS Server' > /web/index.html
[iyunv@nfs /]# service portmap start  
[iyunv@nfs /]# service nfs start
[iyunv@nfs /]# showmount -e 10.10.0.226
Export list for 10.10.0.226:  
/web 10.10.0.0/12
2.节点测试挂载
node1:
[iyunv@node1 ~]# mount -t nfs 10.10.0.226:/web /mnt   
[iyunv@node1 mnt]# mount  
[iyunv@node1 ~]# umount /mnt  
[iyunv@node1 ~]# mount  
node2:
[iyunv@node2 ~]# mount -t nfs 10.10.0.226:/web /mnt
[iyunv@node1 mnt]# mount  
[iyunv@node1 ~]# umount /mnt  
[iyunv@node1 ~]# mount
3.修改haresource文件
[iyunv@node1 ~]# vim /etc/ha.d/haresources
node1.test.com IPaddr::10.10.0.11/12/eth0 Filesystem::10.10.0.226:/web::/var/www/html::nfs  httpd
4.同步haresource配置文件
[iyunv@node1 ~]# cd /etc/ha.d/
[iyunv@node1 ha.d]# scp haresources node2:/etc/ha.d/  
5.重启一下heartbeat
[iyunv@node1 ha.d]# ssh node2 "service heartbeat restart"
[iyunv@node1 ha.d]# service heartbeat restart         
6.查看一下端口
[iyunv@node1 ha.d]# netstat -ntulp
7.测试一下Web服务
[iyunv@node1 ha.d]# mount
/dev/sda2 on / type ext3 (rw)  
proc on /proc type proc (rw)  
sysfs on /sys type sysfs (rw)  
devpts on /dev/pts type devpts (rw,gid=5,mode=620)  
/dev/sda1 on /boot type ext3 (rw)  
tmpfs on /dev/shm type tmpfs (rw)  
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)  
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)  
10.10.0.226:/web on /var/www/html type nfs (rw,addr=10.10.0.226)


运维网声明 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-40758-1-1.html 上篇帖子: 利用heartbeat实现高可用集群 下篇帖子: heartbeat搭建高可用NFS 服务器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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