首页 > 系统服务 > 详细

Linux系统构架 - HA集群配置

时间:2016-01-20 22:17:02      阅读:183      评论:0      收藏:0      [点我收藏+]

一、安装

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

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

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

技术分享

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

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

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

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

 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,两台机器都操作

查看是否有这个包,

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

 二、配置 主的

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/lib/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/lib/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

 

Linux系统构架 - HA集群配置

原文:http://www.cnblogs.com/wangshaojun/p/5146633.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!