heartbeat + drbd + nginx

Posted oldwangtou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了heartbeat + drbd + nginx相关的知识,希望对你有一定的参考价值。

一、环境介绍

1、系统版本:

[[email protected] ha.d]# uname -r
3.10.0-862.9.1.el7.x86_64

2、主机

主机 ip
www-master 10.10.10.109
www-slave 10.10.10.108

 

3、基础准备

systemctl stop firewalld.service                            #关闭防火墙
sed -i s/Enforcing/disabled/g /etc/sysconfig/selinux      #关闭selinux 
ntpdate  0.cn.pool.ntp.org                                  #同步时间

4、host解析

10.10.10.109 www-master
10.10.10.108 www-slave

二、安装DRBD

1、添加附加库(两台都操作)

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

2、安装drbd(两台都操作)

yum install drbd84 kmod-drbd84 -y

3、磁盘分区(两台都操作)

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p

不做磁盘初始化

4、开始配置drbd

modprobe drbd  

提示:centos7没有这个模块,需要升级内核,yum install  kenel* -y

5、修改配置文件/etc/drbd.d/global_common.conf(两台相同配置)

global {
        usage-count yes;
}
common {
        protocol C;
disk {
        on-io-error detach;
}
syncer {
        rate 100M;                  #100M传输速度
 }
}

resource nginx {
                on www-master{
                device /dev/drbd0;
                disk /dev/sdb;
                address 10.10.10.109:7788;
                meta-disk internal;
}
                on www-slave{
                device /dev/drbd0;
                disk /dev/sdb;
                address 10.10.10.108:7788;
                meta-disk internal;
}
}

6、激活前面配置的DRBD资源nginx(两个节点都要执行)

drbdadm create-md nfs

 

7、启动drbd(两个节点都要执行)

systemctl start drbd

    按提示输入 yes

8、一下几个步骤都在主上执行

drbdadm primary nginx                              #设置主
drbdadm -- --overwrite-data-of-peer primary nfs
watch
-n1 cat /proc/drbd

version: 8.4.11-1 (api:1/proto:86-101)
GIT-hash: 66145a308421e9c124ec391a7848ac20203bb03c build by [email protected], 2018-04-26 12:10:42
0: cs:SyncTarget ro:Secondary/Primary ds:Inconsistent/UpToDate C r-----
ns:0 nr:258403840 dw:258403840 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:912557636
[===>................] sync‘ed: 22.1% (891168/1143516)M
finish: 6:13:23 speed: 40,732 (40,112) want: 0 K/sec

等状态同步完成之后,在主上执行一下

mkfs.ext4 /dev/drbd1 

三、Heartbeat环境搭建

 

1、安装heartbeat依赖包

yum install -y bzip2 autoconf automake libtool glib2-devel libxml2-devel bzip2-devel libtool-ltdl-devel asciidoc libuuid-devel psmisc

 



2、安装glue

wget http://hg.linux-ha.org/glue/archive/0a7add1d9996.tar.bz2
tar jxvf 0a7add1d9996.tar.bz2
cd Reusable-Cluster-Components-glue--0a7add1d9996/
groupadd haclient
useradd -g haclient hacluster
./autogen.sh
./configure --prefix=/usr/local/heartbeat/
make
make install

 

3、安装Resource Agents

wget https://github.com/ClusterLabs/resource-agents/archive/v3.9.6.tar.gz
tar zxvf v3.9.6.tar.gz
cd resource-agents-3.9.6/
./autogen.sh
export CFLAGS="$CFLAGS -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib"
./configure --prefix=/usr/local/heartbeat/
vi /etc/ld.so.conf.d/heartbeat.conf               #计入下边内容
/usr/local/heartbeat/lib
ldconfig make make install

4、安装HeartBeat

wget http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/958e11be8686.tar.bz2
tar jxvf 958e11be8686.tar.bz2
cd Heartbeat-3-0-958e11be8686
./bootstrap
export CFLAGS="$CFLAGS -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib"
./configure --prefix=/usr/local/heartbeat/
vi /usr/local/heartbeat/include/heartbeat/glue_config.h
/*define HA_HBCONF_DIR “/usr/local/heartbeat/etc/ha.d/”*/ (注意这行用/**/注释掉)
make
make install

 


2、复制配置文件

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

 


3、设置ha.cf配置文件(两台机器都操作)

debugfile /var/log/ha-debug #日志
logfile /var/log/ha-log
keepalive 2 #设定检查时间间隔
warntime 10 #设定警告时间 
deadtime 30 #设定在时间内没有心跳就立即切换服务
initdead 60 #初始化时间 
udpport 1112 #设定集群节点间的通信协议及端口为udp1112
bcast em1 
ucast em1 10.10.10.109 #设置心跳方式使用单播方式,并且在em1网卡上进行单播 ,ip地址为对方的IP
#baud 19200
auto_failback off #当主节点恢复后,是否自动切回,一般都设为off
node www-master #指定两个节点
node www-slave
ping 10.10.10.1 #两个IP的网关
respawn hacluster /usr/local/heartbeat/libexec/heartbeat/ipfail #使用这个脚本去侦听对方是否还活着(使用的是ICMP报文检测)


4、编辑双机互联验证文件authkeys,添加以下内容:(node1,node2)

# vi /usr/local/heartbeat/etc/ha.d/authkeys
auth 1
1 crc

 

5、给验证文件600权限

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

 
















以上是关于heartbeat + drbd + nginx的主要内容,如果未能解决你的问题,请参考以下文章

heartbeat+drbd+mysql

Heartbeat+Drbd实现

mysql+DRBD+heartbeat

Heartbeat+Drbd+MySQL高可用

drbd+heartbeat+nfs

Heartbeat+DRBD+MySQL高可用方案