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
啓動
相關文章
相關標籤/搜索