HA搭建web服务器高可用

拓扑:
QJ02 主web==192.168.2.131
QJ03 从web==192.168.2.132
QJ01 NFS====192.168.2.130
1.准备工作:
(1).解析域名

#[[email protected] ~]# vim /etc/hosts
192.168.2.131 QJ02.cn
192.168.2.132 QJ03.cn
[[email protected] ~]# vim /etc/hosts
192.168.2.131 QJ02.cn
192.168.2.132 QJ03.cn

(2). 关防火墙,关掉selinux

# iptables -F
# getenforce
Permissive

2.配置QJ01为NFS服务器,提供存储资源
(1)安装NFS服务器:(3台主机均安装)

[[email protected] ~]# yum -y install nfs-utils
[[email protected] ~]# yum -y install nfs-utils
[[email protected] ~]# yum -y install nfs-utils
[[email protected] ~]# mkdir /wwwdir
[[email protected] ~]# echo "Heartbeat Web test" > /wwwdir/index.html
[[email protected] ~]# vi /etc/exports
/wwwdir 192.168.2.0/24(rw)

(2)配置目录权限

[[email protected] ~]# ll -d /wwwdir/
drwxr-xr-x 2 root root 24 Sep 12 21:33 /wwwdir/
[[email protected] ~]# chmod 777 -R /wwwdir/
[[email protected] ~]# ll -d /wwwdir/
drwxrwxrwx 2 root root 24 Sep 12 21:33 /wwwdir/

(3)开启nfs服务

[[email protected] ~]# systemctl start nfs
[[email protected] ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[[email protected] ~]# showmount -e
Export list for Qj01:
/wwwdir 192.168.2.0/24

3.QJ02和QJ03测试nfs 存储挂载并安装httpd web服务器:(只写QJ02一台配置,另一台QJ03配置相同)

[[email protected] ~]# yum install  httpd -y
[[email protected] ~]# systemctl start nfs
[[email protected] ~]# showmount -e 192.168.2.130
Export list for 192.168.2.130:
/wwwdir 192.168.2.0/24
[[email protected] ~]# mount -t nfs 192.168.2.130:/wwwdir /var/www/html/
[[email protected] ~]# systemctl start httpd

测试:

[[email protected] ~]# yum install elinks -y
[[email protected] ~]# elinks --dump 192.168.2.131
  Heartbeat Web test

卸载资源:后期这些资源通过heartbeat直接加载

[[email protected] ~]# umount /var/www/html/
[[email protected] ~]# systemctl stop httpd
[[email protected] ~]# systemctl disable httpd

4.QJ02和QJ03安装heartbeat(只写QJ02一台配置,另一台QJ03配置大致相同<不同处有备注>)
heartbeat在Ceontos7下编译步骤
下载:http://www.linux-ha.org/wiki/Downloads,从官方下载最新的HeartBeat版本
Heartbeat 3.0.6
Cluster Glue 1.0.12
Resource Agents 3.9.6
(1).配置基础环境(配置好网络yum源)
安装依赖包
[[email protected] ~]#yum install -y bzip2 bzip2-devel gcc gcc-c++ autoconf automake libtool e2fsprogs-devel glib2-devel libxml2 libxml2-devel libtool-ltdl-devel asciidoc libuuid-devel docbook
(2).编译Cluster Glue

[[email protected] ~]# tar jxf Cluster_Glue_1.0.12.tar.bz2
[[email protected] ~]#cd Reusable-Cluster-Components-glue--0a7add1d9996/
[[email protected] Reusable-Cluster-Components-glue--0a7add1d9996]# groupadd haclient  创建用户组
[[email protected] Reusable-Cluster-Components-glue--0a7add1d9996]# useradd -g haclient hacluster   创建用户
[[email protected] Reusable-Cluster-Components-glue--0a7add1d9996]# ./autogen.sh
[[email protected] Reusable-Cluster-Components-glue--0a7add1d9996]# ./configure --prefix=/usr/local/heartbeat/
[[email protected] Reusable-Cluster-Components-glue--0a7add1d9996]# make && make install

(3).编译Resource Agents

[[email protected] ~] # tar -zxf resource-agents-3.9.6.tar.gz
[[email protected] ~]# cd resource-agents-3.9.6
[[email protected] resource-agents-3.9.6]# ./autogen.sh
[[email protected] resource-agents-3.9.6]#./configure --prefix=/usr/local/heartbeat --with-daemon-user=hacluster --with-daemon-group=haclient --enable-fatal-warnings=no LIBS=‘/lib64/libuuid.so.1‘
[[email protected] resource-agents-3.9.6]# make
[[email protected] resource-agents-3.9.6]# make install

(4).编译Heartbeat

[[email protected] ~]# tar -jxvf Heartbeat-3.0.6.tar.bz2
[[email protected] ~]# cd Heartbeat-3-0-958e11be8686/
[[email protected] Heartbeat-3-0-958e11be8686]# ./bootstrap
[[email protected] Heartbeat-3-0-958e11be8686]# export CFLAGS="$CFLAGS -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib"
[[email protected] Heartbeat-3-0-958e11be8686]# ./configure --prefix=/usr/local/heartbeat --with-daemon-user=hacluster --with-daemon-group=haclient --enable-fatal-warnings=no LIBS=‘/lib64/libuuid.so.1‘
[[email protected] Heartbeat-3-0-958e11be8686]# make
[[email protected] Heartbeat-3-0-958e11be8686]# make install

(5)生成配置文件:

[[email protected] /]# cd /usr/local/heartbeat/etc/ha.d/
[[email protected] ha.d]# cp /root/Heartbeat-3-0-958e11be8686/doc/{ha.cf,haresources,authkeys} .
[[email protected] ha.d]# chkconfig --add heartbeat
[[email protected] ha.d]# chkconfig heartbeat on
[[email protected] ha.d]# chmod 600 /usr/local/heartbeat/etc/ha.d/authkeys
[[email protected] ha.d]# mkdir -pv /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat/
[[email protected] ha.d]# cp /usr/lib/ocf/lib/heartbeat/ocf-* /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat/
[[email protected] ha.d]# ln -sv /usr/local/heartbeat/lib64/heartbeat/plugins/* /usr/local/heartbeat/lib/heartbeat/plugins/

(6)Heartbeat配置
<1>配置ha.cf----主配置文件
Heartbeat的配置主要涉及到ha.cf、haresources、authkeys这三个文件。
ha.cf: 主配置文件,
haresource: 用来配置要让Heartbeat托管的服务,
authkey: 是用来指定Heartbeat的认证方式。

[[email protected] /]# vim /usr/local/heartbeat/etc/ha.d/ha.cf vim /usr/local/heartbeat/etc/ha.d/ha.cf
24 debugfile /var/log/ha-debug           ##用于记录heartbeat的调试信息
29 logfile/var/log/ha-log                ##用于记录heartbeat的日志信息
34 logfacilitylocal0                    ##设置heartbeat的日志,这里用的是系统日志
48 keepalive 2                              ##设定心跳(监测)时间时间为2秒
56 deadtime 30         ##指定若备用节点在30秒内未收到主节点心跳信号,则接管主服务器资源
61 warntime 10           ##指定心跳延迟的时间为10秒,10秒内备节点不能接收主节点心跳信号,
                                  即往日志写入警告日志,但不会切换服务
71 initdead 120        ##系统启动或重启后预留的忽略时间段,取值至少为deadtime的两倍
76 udpport  694                         ##广播/单播通讯使用的Udp端口
91 #bcast ens32   # Linux             ##使用网卡eno32发送心跳检测
113 #mcast eth0 225.0.0.1 694 1 0    ##采用网卡eth0的Udp多播来组织心跳,一般在备用节点
Bcast、ucast和mcast分别代表广播、单播和多播,是组织心跳的的方式,任选其一
121 ucast ens33 192.168.2.132  ##采用网卡eth32的udp单播来组织心跳,后面跟的IP地址为双机对方IP地址
157 auto_failback on                 ##定义当主节点恢复后,是否将服务自动切回
211 node QJ02.cn                     ##主节点名称
212 node QJ03.cn                     ##备用节点名称
220 ping 192.168.2.1                ##通过ping网关检测心跳是否正常,仅用来测试网络
253 respawn hacluster /usr/local/heartbeat/libexec/heartbeat/ipfail   ##指定和heartbeat一起启动、关闭的进程,否则启动报错
259 apiauth ipfail gid=haclient uid=hacluster     ##设置启动IPfail的用户和组
[[email protected] ha.d]# scp ha.cf  192.168.2.132:/usr/local/heartbeat/etc/ha.d/`(修改121行即可)
ucast ens33 192.168.2.131

<2>配置haresources-----资源文件

[[email protected] ha.d]# vim haresources
 44 #node-name resource1 resource2 ... resourceN
 45 QJ02.cn IPaddr::192.168.2.111/24ens33 Filesystem::192.168.2.130:/wwwdir::/var/www/html::nfs http [[email protected] ha.d]# vim haresources
 44 #node-name resource1 resource2 ... resourceN
 45 QJ02.cn IPaddr::192.168.2.111/24ens33 Filesystem::192.168.2.130:/wwwdir::/var/www/html::nfs httpd

注:QJ02.cn是主服务器的主机名, QJ03上不需要修改。这样资源默认会加一这个主机上。当QJ02坏了,QJ03会再接管。
<3>配置authkeys-----心跳密钥验证文件

[[email protected] ha.d]#vim /usr/local/heartbeat/etc/ha.d/authkeys
auth 3
3 md5 Hello!
[[email protected] ha.d]#vim /usr/local/heartbeat/etc/ha.d/authkeys
auth 3
3 md5 Hello!

<4>编写httpd启动脚本

[[email protected] ha.d]#vim /usr/local/heartbeat/etc/ha.d/resource.d/httpd
[[email protected] ha.d]#vim /usr/local/heartbeat/etc/ha.d/resource.d/httpd
#!/bin/bash
/bin/systemctl $1 httpd
[[email protected] resource.d]#chmod 755 httpd
[[email protected] resource.d]#chmod 755 httpd

<5>测试:(测试后记得关闭)
手动加载VIP 192.168.2.111到ens33上
[[email protected] ~]# cd /usr/local/heartbeat/etc/ha.d/resource.d
测试绑定VIP
[[email protected] resource.d]# ./IPaddr 192.168.2.111/24/ens33 start
INFO: Success
INFO: Success
查看 VIP:
[[email protected] ~]# ifconfig #可以看到 ens33:1 的IP为:192.168.2.111

手动加载NFS存储资源到/var/www/html (加载需要fuser支持,yum install psmisc -y)
[[email protected] resource.d]# ./Filesystem 192.168.2.130:/wwwdir /var/www/html/ nfs start
INFO: Success
INFO: Success
[[email protected] ~]# ls /var/www/html/index.html
/var/www/html/index.html
[[email protected] ~]# df -h
………
192.168.2.130:/wwwdir 18G 1.1G 17G 6% /var/www/html

手动启动httpd服务
[[email protected] ~]# systemctl start httpd

测试打开主服务页面http://192.168.2.131

启动heartbeat

# systemctl start heartbeat
# chkconfig --add heartbeat
# chkconfig heartbeat on

原文地址:http://blog.51cto.com/13719714/2174508

时间: 2024-07-29 10:36:30

HA搭建web服务器高可用的相关文章

heartbeat 配置两台web服务器高可用集群案例

通过heartbeat 配置两台web服务器高可用集群案例: 拓扑: web1:192.168.0.101 hostname: web1.example.com web2:192.168.0.102 hostname:web2.example.com vip:192.168.0.254 nfs服务器:192.168.0.100(存放web页面) 注意: 1主机名要与uname -n 保持一致 2.web1与web2主机的date时间保持同步 3.web1与web2,ssh双机互信通信 4.关闭i

用Heartbeat实现web服务器高可用

用Heartbeat实现web服务器高可用 heartbeat概述: Heartbeat 项目是 Linux-HA 工程的一个组成部分,它实现了一个高可用集群系统.心跳服务和集群通信是高可用集群的两个关键组件,在 Heartbeat 项目里,由 heartbeat 模块实现了这两个功能. 端口号:694 1)heartbeat的工作原理: heartbeat最核心的包括两个.部分,心跳监测部分和资源接管部分,心跳监测可以通过网络链路和串口进行,而且支持冗余链路,它们之间相互发送报文来告诉对方自己

Heartbeat实现web服务器高可用

一.Heartbeat概述: Heartbeat的工作原理:heartbeat最核心的包括两个部分,心跳监测部分和资源接管部分,心跳监测可以通过网络链路和串口进行,而且支持冗余链路,它们之间相互发送报文来告诉对方自己当前的状态,如果在指定的时间内未收到对方发送的报文,那么就认为对方失效,这时需启动资源接管模块来接管运行在对方主机上的资源或者服务. Heartbeat-3.X版本以后被分为了4个模块,这些安装包都可以从官网: http://www.linux-ha.org/wiki/Downloa

高可用集群技术之heartbeat+NFS实现web服务高可用(文本方式配置接口--gui图形配置)

一.高可用集群基本概念   什么是高可用技术呢?在生产环境中我既要保证服务不间断的服务又要保证服务器稳定不down机,但是异常还是会发生,比如说:服务器硬件损坏...导致服务器down机,我该如何保证服务器down机后继续提供服务呢?这时我就应该请出高可用技术来帮忙了,当我们的服务器发生故障后不能继续时,高可用集群技术解决将业务及服务自动转移至其他主机服务器上继续服务,保证服务架构不间断运行. 高可用集群的架构层次: 后端主机层: 这一层主要是正在运行在物理主机上的服务. 2.Message l

搭建 RabbitMQ Server 高可用集群

阅读目录: 准备工作 搭建 RabbitMQ Server 单机版 RabbitMQ Server 高可用集群相关概念 搭建 RabbitMQ Server 高可用集群 搭建 HAProxy 负载均衡 因为公司测试服务器暂不能用,只能在自己电脑上重新搭建一下 RabbitMQ Server 高可用集群,正好把这个过程记录下来,以便日后查看. 公司测试服务器上的 RabbitMQ 集群,我搭建的是三台服务器,因为自己电脑空间有限,这边只能搭建两台服务器用作高可用集群,用的是 Vagrant 虚拟机

HAProxy+KeepAlived实现web服务高可用、动静分离等

大致规划: 主机 IP 描述 VIP 192.168.0.222 对外提供高可用IP haproxy+keepalived (node1) 192.168.0.111 haproxy为后端两台WEB服务的做动静分离:keepalived为haproxy做高可用. haproxy+keepalived (node2) 192.168.0.112 WEB                (node3) 192.168.0.113 提供静态请求响应 Apache+PHP+MySQL   (node4)

搭建LVS+Keepalived高可用负载集群

搭建LVS+Keepalived高可用负载集群 最近,本屌接到公司的任务,公司新上20台服务器,需要搭建一整套架构来运行公司的业务,其中有应用服务器,认证服务器,数据库服务器等.服务器基础架构中的应用服务器集群要有高可用性,且需要负载均衡.当我接到这个任务的时候,脑子里第一个想法就是LVS+Keepalived. 由于公司资金有限,直接上硬件的负载均衡设备是不可能的了,所以只好使用软件来实现,LVS在负载均衡集群中无疑是一种很好的方案,使用LVS可以同时分发10台以下的设备,用在我们这个项目中是

Heartbeat实现web服务高可用(三)

六:Heartbeat实现WEB服务高可用案例 6.1 部署准备 资源环境:继续使用我们之前已经部署好Heartbeat的两台服务器node01.cn和node02.cn,两台机器heartbeat是双主模式我们再捋一捋    node01.cn   eth0 172.10.25.26 外网管理IP                      eth1 10.25.25.16  心跳直连                      VIP  172.10.25.18        node02.cn

如何搭建web服务器 使用Nginx搭建反向代理服务器

转载   如何搭建web服务器 使用Nginx搭建反向代理服务器 :   http://blog.csdn.net/w13770269691/article/details/6977727 引言:最近公司有台服务器遭受DDOS攻击,流量在70M以上,由于服务器硬件配置较高所以不需要DDOS硬件防火 墙.但我们要知道,IDC机房是肯定不允许这种流量一直处于这么高的,因为没法具体知道后面陆续攻击的流量会有多大,如果流量过大就会导致整个IDC网络 瘫痪.我们都知道北方的数据中心和南方的数据中心从带宽出