阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

116次阅读
没有评论

共计 7137 个字符,预计需要花费 18 分钟才能阅读完成。

通过 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

4.web1 和 web2 中启动 heartbeat

#service heartbeat start

#ssh web2‘service heartbeat start’

 

5. 测试 heartbeat web 高可用

web1 作为主模式测试正常,测试 web 服务器的运行状态

#elinks -dump http://192.168.0.254

  web1

现在将 web1 通过命令实现成为备份模式,来测试 web2 的工作情况:

web1 上执行:

#/usr/share/heartbeat/hb_standby

2012/12/28_19:43:49 Going standby [all].

#elinks -dump http://192.168.0.254

web2

通过测试说明当 web1 作为主模式时,集群资源在 web1 服务上;

当 web2 作为主模式时,集群资源在 web2 服务上

 

6. 重新配置资源实现 web1 与 web2 共享同一个 web 页面

web1

#vim /etc/ha.d/haresources

web1.example.com  192.168.0.254/24/eth0 Filesystems::192.168.0.100:/webfile::/var/www/html httpd

#scp /etc/ha.d/haresources root@web2:/etc/ha.d/

#service heartbeat restart

#ssh web2 ‘service heartbeat restart’

 

7 再重新进行第五步测试,查看结果

web1 作为主模式测试正常,测试 web 服务器的运行状态

#elinks -dump http://192.168.0.254

  nfs

现在将 web1 通过命令实现成为备份模式,来测试 web2 的工作情况:

web1 上执行:

#/usr/share/heartbeat/hb_standby

2012/12/28_19:43:49 Going standby [all].

#elinks -dump http://192.168.0.254

nfs

通过测试说明当 web1 与 web2 其中一个节点故障,不影响 web 的访问,实现了高可用

通过 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

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计7137字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中