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

[经验分享] 高可用集群之heartbeat配置,实现web服务的高可用以及Mariadb高可用

[复制链接]

尚未签到

发表于 2019-1-7 08:37:04 | 显示全部楼层 |阅读模式
  实验配置环境:
# uname -ro
2.6.32-358.el6.i686 GNU/Linux  

  1.修改节点名称,集群的每个节点名称够能够相互解析
1.修改节点node1主机名
# node1.magedu.com
2.修改节点node1主机名
# node2.magedu.com
3.在集群节点node1和node2的/etc/hosts添加如下两行,使其能够相互解析
# vim /etc/hosts
172.16.0.4 node1.magedu.com node1
172.16.0.7 node2.magedu.com node2  
  2.配置ntp服务器
1.查看是否安装ntp服务的软件包
# rpm -qa ntp
ntp-4.2.4p8-3.el6.centos.i686
2.将原来配置文件备份,提供新的编辑配置文件/etc/ntp.conf,
# vim /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
restrict 172.16.0.0 netmask 255.255.0.0 nomodify notrap
server  cn.pool.ntp.org  prefer
server  133.100.11.8
server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
logfile /var/log/ntpstats/ntp.log
3.启动nfp服务
# service ntpd start
4.验证ntp服务
# ntpstat
synchronised to local net at stratum 11
time correct to within 11 ms
polling server every 1024 s
# ntpstat
synchronised to local net at stratum 11
time correct to within 11 ms
polling server every 1024 s
[root@localhost ~]# ntpq -p
remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
dns1.synet.edu. 202.118.1.46     2 u  134 1024  377   95.428  14611.6 2042.24
133.100.11.8    133.100.53.51    2 u  306 1024  377  151.025  14205.3 2064.42
*LOCAL(0)        .LOCL.          10 l   30   64  377    0.000    0.000   0.001  
  3.保证节点一和节点的时间同步
在节点node1和节点node2上配置周期性任务计划,使其时间保持同步
# crontab -e
*/3 * * * * /usr/sbin/ntpdate 172.16.0.6 &> /dev/null  

  4.各节点之间基于ssh密钥认证通信
节点node1和节点node2不需要密码进行通信
1.将节点node1生成的公钥传到节点node2
# ssh-keygen -t rsa -P ''
# ssh-copy-id -i .ssh/id_rsa.pub root@node1
2.将节点node2生成的公钥传到节点node1
# ssh-keygen -t rsa -P ''
# ssh-copy-id -i .ssh/id_rsa.pub root@node2
3.节点node1和node2时间同步
# ssh node1 'date';date
Sun Apr 20 20:32:00 CST 2014
Sun Apr 20 20:32:00 CST 2014  
  

  5.安装配置heartbeat v2
  
1.解决依赖关系(版本不同解决依赖关系所安装的包有所不同)
# yum  install PyXML -y
# yum  install libnet -y
# yum install net-snmp-libs -y
# rpm -ivh heartbeat-2.1.4-12.el6.i686.rpm
# rpm -ivh heartbeat-pils-2.1.4-12.el6.i686.rpm
# rpm -ivh heartbeat-stonith-2.1.4-12.el6.i686.rpm
2.复制heartbeat集群服需要的文件
# cp /usr/share/doc/heartbeat-2.1.4/{haresources,ha.cf,authkeys} /etc/ha.d/
# ls
authkeys  harc         rc.d           resource.d
ha.cf     haresources  README.config  shellfuncs
3.配置authkeys
# openssl rand -hex 8
cc7cb7ada0d820fb
添加如下两行
# vim authkeys
auth 2
2 sha1 cc7cb7ada0d820fb
修改authkeys的权限,必须为600或400否则不能启动
# chmod 600 authkeys
3.配置核心配置文件ha.cf
logfile /var/log/ha-log 启用日志文件
#logfacility    local0
keepalive 800ms      发送心跳信息的间隔
deadtime 4           集群故障之后节点退出集群的时间间隔
warntime 3           警告时间
initdead 90          集群服务启动时的死亡时间间隔
udpport 694          监听端口
mcast eth0 225.0.19.1 694 1 0 启用多播(确保网卡支持多波)
node    node1.magedu.com
node    node2.magedu.com  添加集群节点只能使用主机名
auto_failback on          启用集群节点故障自动转回
ping 172.16.0.1        启用ping节点
compression     bz2       启用压缩功能
compression_threshold 2   超过指定的值时则压缩传输,单位KB
4.定义集群资源,使用httpd测试
4.1在node1和node2节点中安装httpd
# yum install httpd -y
# ssh node1 'yum install httpd -y'
在node1和node2确保httpd开启不能自启
# chkconfig httpd off
# chkconfig --list httpd
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
# ssh node1 'chkconfig httpd off'
# ssh node1 'chkconfig --list httpd'
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
4.2分别为node1和node2通过测试页
# vim /var/www/html/index.html
Cluster Node2
# vim /var/www/html/index.html
Cluter Node1
4.3 在node1和node2中启动httpd服务,并测试,然后手动停止服务
#ssh node1 ' service httpd start'; service httpd start
# ssh node1 'curl node2';curl node1
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0 Cluster Node2
0    24    0    24    0     0    302      0 --:--:-- --:--:-- --:--:--   400
Cluter Node1
# ssh node1 'service httpd stop';service httpd stop;
4.4 # vim haresources 定义httpd资源
node1.magedu.com 172.16.0.19/16/eth1 httpd
5.将haresources,ha.cf,authkeys,原封不动的复制到node1中
# scp -p authkeys ha.cf haresources node1:/etc/ha.d/
# ssh node1 'ls -l /etc/ha.d/'
total 48
-rw-------. 1 root root   657 Apr 20 22:00 authkeys
-rw-r--r--. 1 root root 10591 Apr 20 22:00 ha.cf
-rwxr-xr-x. 1 root root   745 Sep 10  2013 harc
-rw-r--r--. 1 root root  5963 Apr 20 22:00 haresources
drwxr-xr-x. 2 root root  4096 Apr 20 20:48 rc.d
-rw-r--r--. 1 root root   692 Sep 10  2013 README.config
drwxr-xr-x. 2 root root  4096 Apr 20 20:48 resource.d
-rw-r--r--. 1 root root  7862 Sep 10  2013 shellfuncs  

  6.启动node1和node2的集群服务
# ssh node1 'service heartbeat start';service heartbeat start
# ss -untl | grep 80
tcp    LISTEN     0      128                   :::80                   :::*  

  7.验证集群服务:
  
  

  关闭node1中的web服务,web服务正常启动,且vip自动转到inode1
  
  
  

  8.基于heartbeat-gui配置Mariadb高可用集群服务
  
  
所有heartbeat的配置和上面的相同
1.安装heartbeat-gui
rpm -ivh heartbeat-gui-2.1.4-12.el6.i686.rpm
2.在node1和node2的ha.cf添加如下一行
# vim /etc/ha.d/ha/cf
crm on
3.在node1和node2节点中安装Mariadb(具体安装和配置可以参考以前的博客)
4.在node1和node2确保httpd开启不能自启
# chkconfig mysqld off
# chkconfig --list mysqld
mysqld           0:off   1:off   2:off   3:off   4:off   5:off   6:off
# ssh node2 'chkconfig mysqld off'
# ssh node2 'chkconfig --list mysqld'
mysqld           0:off   1:off   2:off   3:off   4:off   5:off   6:off
4.关闭node1和node2中的heartbeat,保证mysqld服务关闭
# ssh node2 'service heartbeat stop';service heartbeat stop
# ssh node2 'service mysqld status';service mysqld status
MySQL is not running[FAILED]
MySQL is not running                                       [FAILED]
5.重启node1和node2中的heartbeat服务,确保保证httpd服务关闭
# ssh node2 'service heartbeat start';service heartbeat start
# ssh node2 'service mysqld status';service mysqld status
MySQL is not running[FAILED]
MySQL is not running                                       [FAILED]
6.验证是否启用heartbeat-gui
# ss -untl | grep 5560
tcp    LISTEN     0      10                     *:5560                  *:*
7.启用heartbeat-gui配置
# hb_gui &  

  

  9. 配置Mariadb高可用
  

  

  10.添加资源
      添加虚拟ip首先在Resources选项中选择添加本地资源

  
  

  
      添加mysqld,直接点击add就能够添加Mariadb
  
      定义资源约束
       添加位置约束使vip和Mariadb更倾向node1节点
  
  
       定义顺序约束,指定资源启动和关闭的顺序
  
  定义Mariadb和vip必须运行于同一个节点
  
  11.启动Mariadb高可用服务
  
  12.验证配置的Mariadb高可用服务,使node1离线并且能够实现故障转移
  
  
  

  总结:

      heartbeat v1和v2必须在每一个节点都必须在每一节点上都进行相同的配置,配
  置高可用主要是实现服务的高可用,一般用几个9来衡量。配置高可用集群必须修改每
  个节点的名称,使其能够解析,并且每个集群节点的时间必须保持同步。当出现如下错
  误时:使用hostname命令修改为响应的主机即可。
  
   service heartbeat start
  Starting High-Availability services:
   Heartbeat failure [rc=6]. Failed.
  

  heartbeat: udpport setting must precede media statementsheartbeat[12088]: 2014/04/23_23:04:40 info: Version 2 support: on
  heartbeat[12088]: 2014/04/23_23:04:40 WARN: File /etc/ha.d/haresources exists.
  heartbeat[12088]: 2014/04/23_23:04:40 WARN: This file is not used because crm is enabled
  heartbeat: baudrate setting must precede media statementsheartbeat[12088]: 2014/04/23_23:04:40 ERROR: Current node [node1.magedu.com ] not in configuration!
  heartbeat[12088]: 2014/04/23_23:04:40 info: By default, cluster nodes are named by `uname -n` and must be declared with a 'node' directive in the ha.cf file.
  heartbeat[12088]: 2014/04/23_23:04:40 info: See also: http://linux-ha.org/ha.cf/NodeDirective
  heartbeat[12088]: 2014/04/23_23:04:40 WARN: Logging daemon is disabled --enabling logging daemon is recommended
  heartbeat[12088]: 2014/04/23_23:04:40 ERROR: Configuration error, heartbeat not started.
  


  

  

  

  
  

  

  

  

  

  

  





运维网声明 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-660160-1-1.html 上篇帖子: heartbeat多播(记录改变过程) 下篇帖子: HA 启动heartbeat以后虚拟IP不出现
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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