51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 4674|回复: 0
打印 上一主题 下一主题

[转贴] heartbeat 配置两台web服务器高可用集群案例

[复制链接]
  • TA的每日心情
    擦汗
    昨天 08:59
  • 签到天数: 1021 天

    连续签到: 2 天

    [LV.10]测试总司令

    跳转到指定楼层
    1#
    发表于 2021-4-2 10:30:10 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
    通过heartbeat 配置两台web服务器高可用集群案例:
      拓扑:

      wKioL1PV0tOjalk4AAHKE76SLdU561.jpg
      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  (测试)


      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
      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/ ... 1.4-11.el5.i386.rpm
      #wget http://dl.fedoraproject.org/pub/ ... 1.4-11.el5.i386.rpm
      #wget http://dl.fedoraproject.org/pub/ ... 1.4-11.el5.i386.rpm
      #wget http://dl.fedoraproject.org/pub/ ... 1.4-11.el5.i386.rpm
      #wget http://dl.fedoraproject.org/pub/ ... .1.6-7.el5.i386.rpm
      #wget http://dl.fedoraproject.org/pub/ ... 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

      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的访问,实现了高可用。
    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-9-20 07:53 , Processed in 0.085010 second(s), 24 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

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