centos7 源码编译安装heartbeat 以及结合nginx测试高可用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7 源码编译安装heartbeat 以及结合nginx测试高可用相关的知识,希望对你有一定的参考价值。

1、环境
CentOS Linux release 7.4.1708 (Core) 3.10.0-693.el7.x86_64
主(heartbeat27=uname -n)
10.0.0.27(ip) 10.0.10.27(心跳) 10.0.0.29(vip)
备(heartbeat28=uname -n)
10.0.0.28(ip) 10.0.10.28(心跳) 10.0.0.29(vip)
2、cat /etc/hosts
10.0.0.27 heartbeat27
10.0.0.28 heartbeat28

3、heartbeat27:(主执行)
route add -host 10.0.10.28 dev ens37
route -n
echo ‘/usr/sbin/route add -host 10.0.10.28 dev ens37‘ >> /etc/rc.d/rc.local
4、heartbeat28:(备执行)
route add -host 10.0.10.27 dev ens37
route -n
echo ‘/usr/sbin/route add -host 10.0.10.27 dev ens37‘ >> /etc/rc.d/rc.local

5、下载对应的源码包并解压
wget http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/958e11be8686.tar.bz2
wget http://hg.linux-ha.org/glue/archive/0a7add1d9996.tar.bz2
wget https://github.com/ClusterLabs/resource-agents/archive/v3.9.6.tar.gz

                tar xf v3.9.6.tar.gz 
                tar jxf 0a7add1d9996.tar.bz2 
                tar jxf 958e11be8686.tar.bz2 

6、安装基础的依赖包
yum install gcc gcc-c++ autoconf automake libtool glib2-devel libxml2-devel bzip2 bzip2-devel e2fsprogs-devel libxslt-devel libtool-ltdl-devel -y

asciidoc  (yum未安装成功)
asciidoc-8.6.9.tar.gz
tar xf asciidoc-8.6.9.tar.gza
./configure
make
make install

7、安装上述三个安装包
groupadd haclient
useradd -g haclient hacluster
7.1、安装Reusable-Cluster-Components-glue--0a7add1d9996
cd Reusable-Cluster-Components-glue--0a7add1d9996
./autogen.sh (看到 Now run ./configure 表示自动生成完成)
./configure --prefix=/usr/local/heartbeat (必须将Cluster Glue和resource-agents和heartbeat都安装在同一目录 因为heartbeat需要依赖这些库)


                                configure 成功之后的状态:
                                                        cluster-glue configuration:
                                                                        Version                  = 1.0.12 (Build: 0a7add1d9996b6d869d441da6c82fb7b8abcef4f)
                                                                        Features                 =
                                                                        Prefix                   = /usr/local/heartbeat
                                                                        Executables              = /usr/local/heartbeat/sbin
                                                                        Man pages                = /usr/local/heartbeat/share/man
                                                                        Libraries                = /usr/local/heartbeat/lib
                                                                        Header files             = /usr/local/heartbeat/include
                                                                        Arch-independent files   = /usr/local/heartbeat/share
                                                                        Documentation            = /usr/local/heartbeat/share/doc/cluster-glue
                                                                        State information        = /usr/local/heartbeat/var
                                                                        System configuration     = /usr/local/heartbeat/etc
                                                                        Use system LTDL          = yes
                                                                        HA group name            = haclient
                                                                        HA user name             = hacluster

        make (可能会报错,a2x: ERROR: "xmllint" --nonet --noout --valid "/home/Reusable-Cluster-Components-glue--b5f160509785/doc/hb_report.8.xml" returned non-zero exit status 4
                                                    gmake[2]: *** [hb_report.8] Error 1
                                                    gmake[2]: Leaving directory `/home/Reusable-Cluster-Components-glue--b5f160509785/doc‘
                                                    gmake[1]: *** [all-recursive] Error 1
                                                    gmake[1]: Leaving directory `/home/Reusable-Cluster-Components-glue--b5f160509785/doc‘
                                                    make: * [all-recursive] Error 1)
        执行此命令   yum -y install docbook-style-xsl
        make
        make install

7.2、安装resource-agents-3.9.6/
cd resource-agents-3.9.6/
./autogen.sh
./configure --prefix=/usr/local/heartbeat


                        configure成功之后:
                                                    resource-agents configuration:
                                                    Version                  = UNKNOWN
                                                    Build Version            = 02beac55c1da0ad99a5a19bd3b2333bcff7e916c
                                                    Features                 =
                                                    Prefix                   = /usr/local/heartbeat
                                                    Executables              = /usr/local/heartbeat/sbin
                                                    Man pages                = /usr/local/heartbeat/share/man
                                                    Libraries                = /usr/local/heartbeat/lib
                                                    Header files             = /usr/local/heartbeat/include
                                                    Arch-independent files   = /usr/local/heartbeat/share
                                                    Documentation            = /usr/local/heartbeat/share/doc/resource-agents
                                                    State information        = /usr/local/heartbeat/var
                                                    System configuration     = /usr/local/heartbeat/etc
                                                    HA_BIN directory prefix  = /usr/local/heartbeat/libexec
                                                    RA state files           = /usr/local/heartbeat/var/run/resource-agents
                                                    AIS Plugins              = 
                                                    CFLAGS                   =  -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib -ggdb3  -fgnu89-inline -fstack-protector-all -Wall -

        ln -s  /usr/local/heartbeat/lib/* /lib/
        ln -s  /usr/local/heartbeat/lib/* /lib64/ 
        make
        make install

7.3、安装Heartbeat-3-0-958e11be8686/
cd Heartbeat-3-0-958e11be8686/
./bootstrap
./configure --prefix=/usr/local/heartbeat(报错:configure: error: in /root/Heartbeat-3-0-958e11be8686‘:<br/>configure: error: Core development headers were not found<br/>Seeconfig.log‘ for more details)
执行该命令:export CFLAGS="$CFLAGS -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib"
./configure --prefix=/usr/local/heartbeat

                configure成功之后:
                                        heartbeat configuration:
                                        Version                  = "3.0.6"
                                        Executables              = "/usr/local/heartbeat/sbin"
                                        Man pages                = "/usr/local/heartbeat/share/man"
                                        Libraries                = "/usr/local/heartbeat/lib64"
                                        Header files             = "/usr/local/heartbeat/include"
                                        Arch-independent files   = "/usr/local/heartbeat/share"
                                        Documentation files      = "/usr/local/heartbeat/share/doc/heartbeat"
                                        State information        = "/usr/local/heartbeat/var"
                                        System configuration     = "/usr/local/heartbeat/etc"
                                        Init (rc) scripts        = "/etc/rc.d/init.d"
                                        Init (rc) defaults       = "/etc/sysconfig"
                                        Use system LTDL          = "yes"
                                        HA group name            = "haclient"
                                        HA group id              = "1000"
                                        HA user name             = "hacluster"
                                        HA user user id          = "1000"
                                        Build dopd plugin        = "yes"
                                        Enable times kludge      = "yes"
                                        CC_WARNINGS              = " -Wall -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wdeclaration-after-statement -Wpointer-arith -Wwrite-strings -Wcast-qual -Wcast-align -Wbad-function-cast -Winline -Wmissing-format-attribute -Wformat=2 -Wformat-security -Wformat-nonliteral -Wno-long-long -Wno-strict-aliasing -Werror "
                                        Mangled CFLAGS           = " -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib  -Wall -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wdeclaration-after-statement -Wpointer-arith -Wwrite-strings -Wcast-qual -Wcast-align -Wbad-function-cast -Winline -Wmissing-format-attribute -Wformat=2 -Wformat-security -Wformat-nonliteral -Wno-long-long -Wno-strict-aliasing -Werror  -ggdb3 -funsigned-char"
                                        Libraries                = "-lbz2 -lz -lc -luuid -lrt -ldl  -lltdl"
                                        RPATH enabled            = ""
                                        Distro-style RPMs        = "no"

make(错误:?/usr/local/heartbeat/include/heartbeat/glue_config.h:105:0: error: "HA_HBCONF_DIR" redefined [-Werror]
glue.config.h中 宏?HA_HBCONF_DIR被定义了多次)
vi 编辑/usr/local/heartbeat/include/heartbeat/glue_config.h 注释掉最后一行 定义宏的代码
make
make install

cd /usr/local/heartbeat/share/doc/heartbeat
cp ?ha.cf authkeys?haresources? /usr/local/heartbeat/etc/ha.d

vim /usr/local/heartbeat/etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694

ucast ens37 10.0.10.28

        auto_failback on
        node    heartbeat27
        node    heartbeat28

ping 10.0.10.28

        respawn hacluster /usr/local/heartbeat/libexec/heartbeat/ipfail(此处可能会出现问题:使用find / -name ipfail查找对应的路径)

ln -svf /usr/local/heartbeat/lib64/heartbeat/plugins/RAExec/ /usr/local/heartbeat/lib/heartbeat/plugins/RAExec/
ln -svf /usr/local/heartbeat/lib64/heartbeat/plugins/
/usr/local/heartbeat/lib/heartbeat/plugins/

vim /usr/local/heartbeat/etc/ha.d/authkeys
修改:
auth 3 表示使用id为3的验证 下边需要定义一个3的验证算法 #(这里要保持一致,输了2下面就对应2,输了3下面就对应3)
3 md5 Hello! #口令(Hello!)随便给 主从配置相同即可
chmod 600 /usr/local/heartbeat/etc/ha.d/authkeys

辅助ip
ip addr add 10.0.0.29/24 dev ens33 label ens33:1

vim /usr/local/heartbeat/etc/ha.d/haresources

heartbeat27 10.0.0.29/24/ens33:1 nginx

cd /usr/local/heartbeat/etc/ha.d/
scp authkeys ha.cf haresources [email protected]:/usr/local/heartbeat/etc/ha.d/ 然后修改新一下文件:
修改ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694

ucast ens37 10.0.10.27

            auto_failback on
            node    heartbeat27
            node    heartbeat28

ping 10.0.10.27

            respawn hacluster /usr/local/heartbeat/libexec/heartbeat/ipfail(此处可能会出现问题:使用find / -name ipfail查找对应的路径)
修改haresources 文件

heartbeat28 10.0.0.29/24/ens33:1 nginx

chmod 600 /usr/local/heartbeat/etc/ha.d/authkeys

安装nginx(http://blog.51cto.com/13754781/2299553)
修改默认的index.html页面,做测试(主要是为了直观的检验有无主动切换)
设置开机自启动(http://blog.51cto.com/13754781/2296191)
启动nginx

service heartbeat start

service heartbeat status
heartbeat OK [pid 1422 et al] is running on heartbeat27 [heartbeat27]...

浏览器中输入vip (windows中要做解析)
可以通过关闭主备服务器,观察页面呈现的形式,即可。

注意加粗的区别!!!!

排版不是很好,解决问题就好!欢迎交流!!

以上是关于centos7 源码编译安装heartbeat 以及结合nginx测试高可用的主要内容,如果未能解决你的问题,请参考以下文章

源码编译安装Heartbeat

centos7 编译xplico

Mysql系列二:Centos7.4安装mysql5.7.28源码

求大神指导Centos7 源码编译安装Nginx+PHP 配置动静分离

Linux源码安装httpd:Centos7

heartbeat 编译安装配置