Heartbeat高可用http

Heartbeat高可用http

  1. 实验图

  2. heartbeat高可用http

一、实验图:

1.png

二、heartbeat高可用http(Heartbeat V1 haresource)

  • heartbeat节点ssh互信

  • heartbeat节点名称相互解析,uname -n

  • heartbeat节点时间一致性

安装前准备:

ssh多节点互信

[root@node4 ~]# ssh-keygen -t rsa
[root@node4 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node3
root@node3's password: 
Now try logging into the machine, with "ssh 'root@node3'", and check in:
  .ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
[root@node4 ~]#

节点时间一致检查

[root@node4 ~]# ntpdate 192.168.3.10
[root@node4 ~]# ssh node3  'date';date
Mon Jul  4 20:30:39 CST 2016
Mon Jul  4 20:30:39 CST 2016
[root@node4 ~]#

多节点名称解析

[root@node4 ~]# ssh node3  'uname -n';uname -n
node3
node4
[root@node4 ~]#

安装heartbeat:

[root@node4 ~]# yum install perl-TimeDate PyXML libnet net-snmp-libs libtool-ltdl -y
[root@node4 ~]# rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
[root@node3 ~]# yum install perl-TimeDate PyXML libnet net-snmp-libs libtool-ltdl -y
[root@node3 ~]# rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm

准备heartbeat配置文件:

[root@node4 ~]# cd /usr/share/doc/heartbeat-2.1.4/
[root@node4 heartbeat-2.1.4]# cp authkeys ha.cf haresources /etc/ha.d/
[root@node4 heartbeat-2.1.4]# cd /etc/ha.d/
[root@node4 ha.d]# 

[root@node4 ha.d]# vi authkeys    #配置双节点心跳信息通信密码
    auth 3
    3 md5 Hello!manager1
[root@node4 ha.d]# vi ha.cf
    logfile /var/log/ha-log                #定义日志格式
    keepalive 2                            
    deadtime 30
    warntime 10
    udpport 694                            #监听694端口
    mcast eth0 225.0.3.1 694 1 0            #节点多播方式转发心跳信息
    auto_failback on
    node    node3                        #heartbeat集群存在节点数
    node    node4
    ping 192.168.3.1                    #ping节点仲裁
    compression    bz2
    compression_threshold 2
[root@node4 ha.d]# chmod 600 authkeys    #修改认证密码文件的权限
[root@node4 ha.d]# vi haresources
    node4  192.168.3.50/24/eth0 httpd    #以node4节点为dc,并且定义集群VIP与资源http服务
[root@node4 ha.d]# scp ha.cf haresources authkeys node3:/etc/ha.d/    #node3节点也需要此配置
    ha.cf                                                               100%   10KB  10.3KB/s   00:00    
    haresources                                                         100% 5939     5.8KB/s   00:00    
    authkeys                                                            100%  651     0.6KB/s   00:00    
[root@node4 ha.d]#

安装httpd服务:

[root@node4 ha.d]# yum install httpd -y
[root@node4 ha.d]# echo "<h1>nnode4 web server</h1>" > /var/www/html/index.html
[root@node4 ha.d]# chkconfig httpd off                                    #关闭http服务开机自启动
[root@node4 ha.d]# service httpd stop                                    #关闭http服务,因为资源服务的启动都是有heartbeat来完成
Stopping httpd:                                            [  OK  ]
[root@node4 ha.d]#

[root@node3 ha.d]# yum install httpd -y
[root@node3 ha.d]# echo "<h1>nnode3 web server</h1>" > /var/www/html/index.html
[root@node3 ~]#  chkconfig httpd off
[root@node3 ~]# service httpd stop                                    
Stopping httpd:                                            [  OK  ]
[root@node3 ~]#

启动heartbeat服务,并测试:

[root@node4 ha.d]# service heartbeat restart
Stopping High-Availability services: 
Done.

Waiting to allow resource takeover to complete:
Done.

Starting High-Availability services: 
2016/07/04_20:59:23 INFO:  Resource is stopped
Done.

[root@node4 ha.d]#


[root@node3 ~]# service heartbeat restart    #我在node3启动heartbeat时,报错,检查报错是认证文件的权限不对,修改修改权限为600就可以了
Stopping High-Availability services: 
Done.

Waiting to allow resource takeover to complete:
Done.

Starting High-Availability services: 
2016/07/04_21:00:13 INFO:  Resource is stopped
 Heartbeat failure [rc=6]. Failed.

heartbeat: udpport setting must precede media statementsheartbeat[2154]: 2016/07/04_21:00:13 ERROR: Ba
d permissions on keyfile [/etc/ha.d/authkeys], 600 recommended.heartbeat[2154]: 2016/07/04_21:00:13 ERROR: Authentication configuration error.
heartbeat[2154]: 2016/07/04_21:00:13 ERROR: Configuration error, heartbeat not started.
[root@node3 ha.d]# chmod 600 authkeys 
[root@node3 ha.d]# service heartbeat restart
Stopping High-Availability services: 
Done.

Waiting to allow resource takeover to complete:
Done.

Starting High-Availability services: 
2016/07/04_21:01:51 INFO:  Resource is stopped
Done.

[root@node3 ha.d]#

ns1测试:

[root@ns1 ~]# curl 192.168.3.50
<h1>nnode4 web server</h1>
[root@ns1 ~]#

2.png

这一部分到此OK,接着做.

二、heartbeat高可用http(Heartbeat V2 crm heartbeat gui工具)

修改配置:

[root@node4 ha.d]# service heartbeat stop
[root@node3 ha.d]# service heartbeat stop
[root@node4 ha.d]# vi ha.cf 
    crm     on
[root@node3 ha.d]# vi ha.cf 
    crm     on

安装heartbeat-gui工具:

[root@node4 ~]# yum install pygtk2-libglade
[root@node4 ~]# rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpm 
[root@node3 ~]# yum install pygtk2-libglade
[root@node4 ~]# rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpm

启动heartbeat服务:

[root@node4 ~]# service heartbeat start
[root@node3 ~]# service heartbeat start
[root@node4 ~]# passwd hacluster                #此用户使我们在安装heartbeat-gui时创建,我们登录gui时需要此用户和密码,默认没有密码,需要我们设置,才能准确登录gui
[root@node3 ~]# passwd hacluster
[root@node4 ~]# hb_gui &            #打开gui工具报错,gui工具是监听在5560端口,如果打不开,可以检查此端口是否监听
[1] 2810
[root@node4 ~]# 
Traceback (most recent call last):  File "/usr/bin/hb_gui", line 41, in <module>    
import gtk, gtk.glade, gobject  File "/usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py", line 64, in <module>    _init()  
File "/usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py", line 52, in _init    _gtk.init_check()RuntimeError: could not open display
X11-forward报错
需要安装如下包,安装完成之后重新登录shell即可
[root@node4 ~]# yum install -y xorg-x11-xauth
[root@node4 ~]# hb_gui &
node3不知道为什么报错了,直接killall heartbeat 系统重启,之后就可以了。

测试gui工具:

3.png

设置http服务:

4.png

接着添加web_vip,有顺序,先启动的资源,先添加,后启动的资源后添加,那我们应该先启动IP,接着再去启动http服务

5.png

6.png

7.png

测试web服务:

[root@ns1 ~]# curl 192.168.3.50
<h1>nnode4 web server</h1>

修改node4为standby:

8.png

服务已经发生切换:

[root@ns1 ~]# curl 192.168.3.50
<h1>nnode3 web server</h1>

设置共享存储:

[root@ns1 ~]# exportfs -arv
exporting 192.168.3.0/24:/www/htdocs
[root@ns1 ~]# echo "<h1>nfs web server</h1>" > /www/htdocs/index.html

客户端安装nfs-utils,并且测试挂载:

[root@node4 ~]# yum install nfs-utils -y
[root@node4 ~]# cat /var/www/html/index.html 
<h1>nfs web server</h1>
[root@node4 ~]#

停止资源,重新配置资源组:

9.png

10.png

测试网页:

[root@ns1 ~]# curl 192.168.3.50
<h1>nfs web server</h1>
[root@ns1 ~]#

设置node3为standby,检查服务转移到node4:

11.png

Heartbeat高可用mysql在此环境上接着做。

原创文章,作者:nice_neo_linux,如若转载,请注明出处:http://www.178linux.com/22001

(1)
nice_neo_linuxnice_neo_linux
上一篇 2016-07-07
下一篇 2016-07-07

相关推荐

  • 第一周-2:Linux部分常用命令使用示例、查看命令行工具使用手册以及LinuxFHS部分目录简介

    一、部分命令使用示例: 1、ifconfg 在命令行界面下或系统配置脚本中用于配置、控制及查询TCP/IP网络接口的系统管理工具 [netartisan@localhost 桌面]$ ifconfig eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500 &n…

    Linux干货 2016-11-07
  • linux第五周小结

    不知不觉已经第五周了,好快啊!这周我们主要讲了读命令,查找命令,压缩,解压缩,安装等命令,今天我总结一下查找命令 查找命令主要有:locate和find命令,但我们经常用到的也最实用的当属find,下面我重点总结一下find命令 有时可能需要在系统中查找具有某一特征的文件(例如文件权限、文件属主、文件长度、文件类型等等)。这样做可能有很多原因。可能出于安全性…

    2017-08-13
  • Linux用户、组和权限管理

    知识框架图 学习笔记 用户和组 UID root:0 系统用户:1-499、1-999 普通用户:500+、1000+ GID 管理员组:0 系统组:1-499、1-999 普通组:500+、1000+ 安全上下文 进程:运行中的程序 进程所能访问资源的权限取决于进程运行用户本身 组的类别 主要组 用户有且只能有一个主要组 组名=用户名,组中只能有一个用户 …

    2018-03-17
  • Linux运维学习历程-第九天-bash脚本初步了解

    概述:   本章重点在于讲解bash脚本的基础知识,为今后学习使用bash脚本打下基础 一、bash基础特性         程序:指令+数据             指令:由程序文件提供         &n…

    Linux干货 2016-08-18
  • read,locate ,find 的总结及相关联系

    read 变量名 read 变量名1 [变量名2] < 文件名不支持管道read 变量名1 [变量名2] <<< “值1 [值2] …”使用read来把输入值分配给一个或者多个shell变量     -p 指定要显示的提示     # read -p…

    Linux干货 2017-08-12
  • N25_第二周作业

    前言 我们这次使用HAProxy作为负载均衡调度器来实现后端httpd服务的负载均衡和动静分离,实现将来自用户的80端口的http请求转发只后端8080端口的server服务 HAProxy介绍 HAProxy的是一个免费的,非常快速和可靠的解决方案,提供高可用性,负载均衡和代理对TCP和HTTP的应用程序。它特别适用于非常高流量网站。多年来,它已成为标准的…

    Linux干货 2016-12-12

评论列表(1条)

  • liangxiaoming
    liangxiaoming 2016-07-12 13:00

    厉害啊!!