手机版
你好,游客 登录 注册
背景:
阅读新闻

Heartbeat 配置两台Web服务器高可用集群案例

[日期:2014-08-01] 来源:Linux社区  作者:feilong0663 [字体:大 中 小]

通过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 root@192.168.0.102

web2:

#ssh-keygen -t rsa -f "~/.ssh/id_rsa -P ""

#ssh-copy-id i .ssh/id_rsa.pub root@192.168.0.101

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 V1实现Web服务双机热备 http://www.linuxidc.com/Linux/2014-04/100635.htm

Heartbeat实现Web服务的高可用群集 http://www.linuxidc.com/Linux/2014-04/99503.htm

Heartbeat+LVS+Ldirectord高可用负载均衡解决方案 http://www.linuxidc.com/Linux/2014-04/99502.htm

DRBD+Heartbeat+NFS高可用性配置笔记 http://www.linuxidc.com/Linux/2014-04/99501.htm

Heartbeat基于CRM使用NFS对MySQL高可用 http://www.linuxidc.com/Linux/2014-03/98674.htm

Heartbeat高可用httpd基于Resources简单配置 http://www.linuxidc.com/Linux/2014-03/98672.htm

--------------------------------------分割线 --------------------------------------


二:安装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

更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2014-08/104926p2.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款