HA集群配置

回复 收藏
HA集群配置
主:
hostname :master
IP:192.168.0.103
从:
hostname:slave
IP:192.168.0.135


一、调整系统
1.修改hostname
[root@l ~]# hostname Master
[root@localhost ~]# hostname Slave1

2.关闭selinux
[root@Master ~]# setenforce 0
[root@Master ~]# vim /etc/selinux/config
修改以下内容:
SELINUX=disabled

3.关闭防火墙
[root@Master ~]# iptables -F
[root@Master ~]# service iptables save

4.配置hosts
[root@Master ~]# vim  /etc/hosts
尾部添加以下内容:
192.168.0.103 Master
192.168.0.135 Slave1

以上操作都需要在Slave上操作一次。

二、安装配置
1.安装yum扩展源
[root@Master ~]# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@Slave1 ~]# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
32位yum扩展源:http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

2.安装
[root@Master ~]# yum -y install heartbeat
[root@Master ~]# yum -y install libnet  #集群依赖包
[root@Slave1 ~]#  yum -y install heartbeat libnet

3.考培配置文件
[root@Master ~]# cd /usr/share/doc/heartbeat-3.0.4/
[root@Master heartbeat-3.0.4]# cp authkeys ha.cf haresources /etc/ha.d/

4.配置authkeys文件(验证)
[root@Master heartbeat-3.0.4]# cd /etc/ha.d/
[root@Master ha.d]# vim authkeys
修改以下内容:
#auth 1
#1 crc
#2 sha1 HI!
#3 md5 Hello!
改为:
auth 3
#1 crc
#2 sha1 HI!
3 md5 Hello!
[root@Master ha.d]# chmod  600 authkeys

5.配置haresources文件
[root@Master ha.d]# vim  haresources
修改以下内容:
#node1 10.0.0.170 Filesystem::/dev/sda1::/data1::ext2
改为:
Master 192.168.0.222/24/eth0:0 nginx
Master:主的hostname
192.168.0.222/24:流动IP(VIP),主从独立ip,无法实现当机切换。
ngingx :提供服务。

6.配置ha.cf文件
[root@Master ha.d]# mkdir /var/log/ha
[root@Master ha.d]# vim ha.cf
添加以下内容:
debugfile /var/log/ha/ha-debug
logfile /var/log/ha/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport 694
bcast eth0
auto_failback on
node Master
node Slave1
ping 192.168.0.1
respawn hacluster /usr/lib64/heartbeat/ipfail
debugfile:排障log
logfile:log与debugfile类似。
logfacility loca10 :错误级别。
keepalive 2:2秒探测对方是否活着。
deadtime 30:如果30秒检测ping不通,说明死掉。
warntime 10 :10秒ping不通发出警告,记录logfile里。
initdead 60:预留60秒,防止对方重启。
udpport 694:心跳线端口。
bcast eth0:广播找到对方。也可以使用ucast eth0 192.168.0.103 来指定对方IP,但是要求内核版本。
auto_failback on:如果Master活了,Slave主动放弃,切回Master。
node Master :主name。
node Slave1:从name。
ping 192.168.0.1:仲裁判断2机私活活者。
respawn hacluster /usr/lib/heartbeat/ipfail :以那个用户身份运行这个脚本,(脚本检测网络连接性)。
注意:脚本需要判断系统位数
系统是64位,脚本位置在/usr/lib64/heartbeat/ipfail
系统是32位,脚本位置在/usr/lib/heartbeat/ipfail

扩展内容:
心跳线端口应该与正常业务隔离开,确保信息安全。
或者使用串口链接2机。

7.将配置文件传到Slave
[root@Master ha.d]# scp  authkeys haresources ha.cf  Slave1:/etc/ha.d/

8.Slave上修改配置文件
[root@Slave1 ~]# mkdir /var/log/ha
[root@Slave1 ~]# vim  /etc/ha.d/ha.cf
ucast eth0 192.168.0.135
改为
ucast eth0 192.168.0.103

三、安装、配置nginx
1.安装nginx
[root@Master ~]# yum -y install nginx
[root@Slave1 ~]#  yum -y install nginx

2.配置nginx
[root@Master ~]# echo  Master  >  /usr/share/nginx/html/index.html
[root@Slave1 ~]# echo  Slave1  >  /usr/share/nginx/html/index.html

四、启动、测试
1.启动(先主后从)
[root@Master ~]# /etc/init.d/heartbeat start
[root@Slave1 ~]# /etc/init.d/heartbeat start

2.测试
[root@Master ~]# curl 192.168.0.222
Master
表示当前Master为存活,提供网页访问。
现在我们关闭掉Master的heartbeat,看能否切换到备节点。
[root@Master ~]# /etc/init.d/heartbeat  stop
Stopping High-Availability services: Done.
[root@Master ~]# curl 192.168.0.222
Slave1
哈哈,看到没现在成果切换到备用节点勒。。。
2016-08-17 16:48 举报
已邀请:

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: