Linux系统构架 - HA集群配置

1、安装html

HA 即(high available)高可用,又被叫作双机热备,用于关键性业务。node

简单理解就是,有两台机器 A 和 B,正常是 A 提供服务,B 待命闲置,当 A 宕机或服务宕掉,会切换至 B 机器继续提供服务。linux

经常使用实现高可用的开源软件有 heartbeat 和 keepalived,其中keepalived 有负载均衡的功能。nginx

1.准备两台机器,主的ip:192.168.1.116 从的ip:192.168.1.115vim

修改主的,从的名字:主叫master 从叫slave浏览器

[root@localhost ~]# hostname master
[root@localhost ~]# bash
[root@master ~]#
[root@localhost ~]# hostname slave
[root@localhost ~]# bash
[root@slave ~]#

2.关闭防火墙,两台同时操做bash

 vim /etc/selinux/config

找到
SELINUX=enforcing
改成
SELINUX=disabled
 setenforce 0
iptables -F
service iptables save

3.编辑hosts网络

 vi /etc/hosts
添加
192.168.1.116 master
192.168.1.115 slave

4.安装heartbeat,两台机器都操做负载均衡

查看是否有这个包,ssh

yum list |grep heartbeat

安装扩展源。去www.lishiming.net搜索epel

wget www.lishiming.net/data/attachment/forum/epel-release-6-8_64.noarch.rpm
rpm -ivh epel-release-6-8_64.noarch.rpm
yum install -y heartbeat
yum install -y libnet

 2、配置

主的

cd /usr/share/doc/heartbeat-3.0.4/
cp authkeys ha.cf haresources /etc/ha.d/
cd /etc/ha.d/
vim authkeys
两台机器通讯,用来验证
#auth 1
#1 crc
#2 sha1 HI!
#3 md5 Hello!
改成
auth 3
#1 crc
#2 sha1 HI!
3 md5 Hello!
chmod 600 authkeys
vim haresources
默认所有注释
找到
#node1  10.0.0.170 Filesystem::/dev/sda1::/data1::ext2
改成
master  192.168.1.110/24/eth0:0 nginx
主的名字  流动ip  网段  网卡  服务
vim ha.cf
所有删掉,写入
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport 694
ucast eth0 192.168.1.115
auto_failback on
node master
node slave
ping 192.168.1.1
respawn hacluster /usr/lib64/heartbeat/ipfail

debugfile /var/log/ha-debug //该文件保存 heartbeat 的调试信息
logfile /var/log/ha-log  //heartbeat 的日志文件
logfacility local0   //日志级别
keepalive 2   //多少时间去探测一次 2秒
deadtime 30  //若是30秒ping不通认为死掉了
warntime 10  //10秒ping不通发出警告
initdead 60  //预留60秒。可能对方在重启
udpport 694  //心跳线,通讯端口
ucast eth0 192.168.1.115  //用单独网卡或者串口连接心跳线,对方ip
auto_failback on  //若是备启动了,主再次激活,备主动放弃。
node master
node slave  //指定主和从,各占一行,主在上从在下
ping 192.168.1.1 //仲裁的地址,判断双方是不是活的
respawn hacluster /usr/lib64/heartbeat/ipfail //以哪一个用户身份去运行这个检查网络链接性脚本,对方不存活,把他拉起来的。

 

两台都安装scp命令才能拷贝

yum install openssh-clients -y
scp authkeys haresources ha.cf slave:/etc/ha.d/
yes/no:yes
root@slave's password:***

从的配置

cd /etc/ha.d/
vim ha.cf
把
ucast eth0 192.168.1.115
改成
ucast eth0 192.168.1.116

两台同时安装nginx

yum install nginx -y

 3、启动

/etc/init.d/heartbeat start
ifconfig


eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:CE:99:EA inet addr:192.168.1.110 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 流动ip
ps aux |grep ngin
nginx 启动成功

/etc/init.d/heartbeat start
ps aux|grep nginx
没有启动
ifconfig
没有eth0:0 流动ip没有流动到从上

主:

echo '1111master' > /usr/share/nginx/html/index.html
能够用流动ip访问

从:

echo '2222222slave' > /usr/share/nginx/html/index.html

主:

/etc/init.d/heartbeat stop

ifconfig
ps
都没有了
刷新浏览器,
变成 222*slave

ifconfig
ps
启动
相关文章
相关标签/搜索