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

[经验分享] CentOS5.8 HA集群之基于crm配置 heartbeat + nfs + httpd

[复制链接]

尚未签到

发表于 2019-1-7 11:20:39 | 显示全部楼层 |阅读模式
大纲
一、系统环境
二、基于heartbeat的GUI管理示例




一、系统环境
CentOS5.8 x86_64
node1.network.com    node1    172.16.1.101
node2.network.com    node2    172.16.1.105
NFS Server         /www      172.16.1.102



拓扑图



二、基于heartbeat的GUI管理示例

1、准备工作

(1)、时间同步
[root@node1 ~]# ntpdate s2c.time.edu.cn
[root@node2 ~]# ntpdate s2c.time.edu.cn
可根据需要在每个节点上定义crontab任务
[root@node1 ~]# which ntpdate
/sbin/ntpdate
[root@node1 ~]# echo "*/5 * * * * /sbin/ntpdate s2c.time.edu.cn &> /dev/null" >> /var/spool/cron/root
[root@node1 ~]# crontab -l
*/5 * * * * /sbin/ntpdate s2c.time.edu.cn &> /dev/null(2)、主机名称要与uname -n,并通过/etc/hosts解析
node1
[root@node1 ~]# hostname node1.network.com
[root@node1 ~]# uname -n
node1.network.com
[root@node1 ~]# sed -i 's@\(HOSTNAME=\).*@\1node1.network.com@g'  /etc/sysconfig/network
node2
[root@node2 ~]# hostname node2.network.com
[root@node2 ~]# uname -n
node2.network.com
[root@node2 ~]# sed -i 's@\(HOSTNAME=\).*@\1node2.network.com@g'  /etc/sysconfig/network
node1添加hosts解析
[root@node1 ~]# vim /etc/hosts
[root@node1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.1.101node1.network.com node1
172.16.1.105node2.network.com node2
拷贝此hosts文件至node2
[root@node1 ~]# vim /etc/hosts
[root@node1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.1.101node1.network.com node1
172.16.1.105node2.network.com node2
[root@node1 ~]# scp /etc/hosts node2:/etc/
The authenticity of host 'node2 (172.16.1.105)' can't be established.
RSA key fingerprint is 13:42:92:7b:ff:61:d8:f3:7c:97:5f:22:f6:71:b3:24.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node2,172.16.1.105' (RSA) to the list of known hosts.
root@node2's password:
hosts                                                     100%  233     0.2KB/s   00:00
(3)、ssh互信通信
node1
[root@node1 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
Generating public/private rsa key pair.
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? n                                            # 我这里已经生成过了
[root@node1 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub node2
root@node2's password:
Now try logging into the machine, with "ssh 'node2'", and check in:
  .ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
[root@node1 ~]# setenforce 0
[root@node1 ~]# ssh node2 'ifconfig'
eth0      Link encap:Ethernet  HWaddr 00:0C:29:D6:03:52  
          inet addr:172.16.1.105  Bcast:255.255.255.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fed6:352/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9881 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11220 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5898514 (5.6 MiB)  TX bytes:1850217 (1.7 MiB)
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:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1112 (1.0 KiB)  TX bytes:1112 (1.0 KiB)
同理node2也需要做同样的双击互信,一样的操作,此处不再演示2、安装heartbeat一系列的软件包(需配置epel源)
node1
[root@node1 ~]# yum install -y heartbeat heartbeat-pils heartbeat-stonith heartbeat-guinode2

[root@node2 ~]# yum install -y heartbeat heartbeat-pils heartbeat-stonith heartbeat-gui3、配置密钥文件authkeys

[root@node1 ~]# cd /etc/ha.d/
[root@node1 ha.d]# cp /usr/share/doc/heartbeat-2.1.4/{ha.cf,authkeys} .
[root@node1 ha.d]# ls
authkeys  ha.cf  harc  rc.d  README.config  resource.d  shellfuncs
[root@node1 ha.d]# vim authkeys
[root@node1 ha.d]# tail -2 authkeys
auth 2
2 sha1 UTen4saEz4g=                                # 这里使用sha1认证,可自行定义
[root@node1 ha.d]# chmod 600 authkeys
[root@node1 ha.d]# ll authkeys
-rw------- 1 root root 672 Jan  6 22:29 authkeys        # 保证权限为6004、配置主配置文件ha.cf
[root@node1 ha.d]# vim ha.cf
[root@node1 ha.d]# grep "^[^#]" ha.cf             # 参数可自行根据需要调整
logfile/var/log/heartbeat.log
keepalive 1
deadtime 10
warntime 3
udpport694
mcast eth0 225.0.100.20 694 1 0
auto_failback on
node node1.network.com                # 注意此处的主机名一定要与uname -n结果保持一致
node node2.network.com
ping  172.16.1.1
compressionbz2
compression_threshold 2
crm on                                                 # 添加此项才能使用v2版的heartbeat功能
将以上两个文件的修改同步至node2节点
[root@node1 ha.d]# /usr/lib64/heartbeat/ha_propagate
Propagating HA configuration files to node node2.network.com.
ha.cf                                                   100%   10KB  10.4KB/s   00:00   
authkeys                                                100%  672     0.7KB/s   00:00   
Setting HA startup configuration on node node2.network.com.
chkconfig version 1.3.30.2 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.
usage:   chkconfig --list [name]
         chkconfig --add
         chkconfig --del
         chkconfig [--level ]  5、启动heartbeat服务(请确保资源不能开机启动)
[root@node1 ha.d]# service heartbeat start
Starting High-Availability services:
                                                           [  OK  ]
[root@node1 ha.d]# ssh node2 'service heartbeat start'
Starting High-Availability services:
[  OK  ]
[root@node1 ha.d]# ss -tnl                        # 可以看到5560端口(mgmtd)处于监听状态
Recv-Q Send-Q                                           Local Address:Port                                             Peer Address:Port
0      0                                                            *:111                                                         *:*     
0      0                                                            *:22                                                          *:*     
0      0                                                            *:5560                                                        *:*     
0      0                                                    127.0.0.1:6011                                                        *:*     
0      0                                                            *:955                                                         *:*     
0      0                                                           :::22                                                         :::*     
0      0                                                          ::1:6011                                                       :::*6、hacluster用户添加密码(只需配置一个节点的hacluster的密码)
node1
[root@node1 ~]# grep "hacluster" /etc/passwd
hacluster:x:101:103:heartbeat user:/var/lib/heartbeat/cores/hacluster:/sbin/nologin
[root@node1 ~]# passwd hacluster
Changing password for user hacluster.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.7、登录图形界面
[root@node1 ha.d]# hb_gui &                    # 必须得安装heartbeat软件包才能使用gui
[1] 9228点击登录-->输入密码点ok






登录成功后的界面





8、配置group资源和webip


右键Resources-->Add New Item




  

  选择Item Type为group,点击OK
  


  

  group资源ID修改为webservice,点击ok
  


  

  ResourceID修改为webip,资源代理选择IPaddr,双击IPadd,下面填写此代理的相关参数
  



点击Add,到此一个webservice组和第一个资源webip添加完成



9、配置webstore


右键webservice-->Add New Item




  

  Item Type选择native,点击OK
  


  

  Resource ID修改为webstore,资源代理选择Filesystem,双击选择填写挂载设备,挂载点,文件系统类型
  






点击Add,到此第二个资源webstore添加完成


10、配置httpd


右键webservice-->Add New Item




  

  Item Type选择native,点击OK
  


  

  Resource ID修改为httpd,资源代理选择httpd,此LSB类型的脚本不需要添加额外的参数
  



点击Add,到此第三个资源httpd添加完成


11、给webservice资源组添加位置约束(并非必须)

  

  右键Locations-->Add New Item
  


  

  Item Type选择location,点击OK
  


  

  位置约束ID自行定义,我这里是webservice_on_node1,Resource选择组资源webservice
  


  

  定义Score分数,我这里是INF(正无穷),还可以点击Add Expression,自行定义其他的属性
  


  

  定义完成之后显示如下
  



到此为止,一个排列约束定义完毕


12、启动webservice资源组


右键webservice-->start




  

  启动成功,显示如下
  




浏览器访问http://172.16.1.110,显示如下




可以看到已然正常工作,此时让node1节点模拟故障,看资源是否会自动迁移


  



此时可以看到资源成功迁移至node2节点上了




再用浏览器访问一下,看能否实现高可用





可以看到,正常访问完全没有问题。到此为止,一个基于heartbeat的GUI配置完成,明天继续讲基于CLI的配置方式




注意:为避免出现各种问题,这里关闭了iptables和SElinux








  





运维网声明 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-660302-1-1.html 上篇帖子: centos 安装Heartbeat 下篇帖子: HA高可用方案之heartbeat v1的安装配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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