天天看點

伺服器架構之性能擴充-第十一章(12)第十一章、Linux高可用(HA)高性能(HPC)

高可用:(high-availablility)是一組互相信任的計算機組織在一起,當其中的一個成員出現故障,由其它成員來接替它的工作提供服務。

它的作用是提供備援,并沒有提高系統性能。

高可用要用到資料的共享,高可用狀态下資料共享有磁盤複制和共享磁盤方式,其中磁盤複制在資料量小更新較少時适用。

高可用就要用到心跳檢測工具,我們這裡适用heartbeat實作,Heartbeat 項目是 Linux-HA 工程的一個組成部分,它實作了一個高可用叢集系統。

環境:我們使用兩台計算機做輕按兩下熱備,系統為centos5.6

共享磁盤的方式做兩個叢集,兩個主機一個是192.168.211.7和192.168.211.8,他們和測試主機windows7在同一個網段,win7ip為192.168,211,1他們之間有一根心跳線連接配接10.0.0.1和10.0.0.2.

<a target="_blank" href="http://blog.51cto.com/attachment/201210/232830248.jpg"></a>

配置執行個體

我們使用setup分别給eth0和eth1配置設定ip,其中eth0使用vmlan1路由和win7在同一網段,eth1使用vmlan2路由。然後,我們要使各個主機之間ping通。

<a target="_blank" href="http://blog.51cto.com/attachment/201210/232842532.gif"></a>

<a target="_blank" href="http://blog.51cto.com/attachment/201210/232850975.gif"></a>

1、我們可以到Linux-ha.org 下載下傳該軟體

在安裝之前要先安裝pkconfig,glib2-devel,e2fsprongs和libnet。其中libnet需要源碼安裝。

<a target="_blank" href="http://blog.51cto.com/attachment/201210/232859440.gif"></a>

2、建立使用者群組

Groupadd –g 2000 haclient

Useradd –u 2000 –g haclient hacluster

3、Yum -y install heartbeat

4、配置heartbeat

配置檔案,我們可以到解壓的heartbeat/doc/目錄複制一份到/etc/ha.d/目錄下,保證兩個centos主機的配置檔案相同,我們配置好一台,然後scp或rsync一份給另一台主機即可。

<a target="_blank" href="http://blog.51cto.com/attachment/201210/232907122.gif"></a>

<b>Vi  /etc/ha.d/ha.cf</b>

<b></b>

Bcast eth1            //eth1做心跳檢測

keepalive 3            //3秒更新一次

deadtime 30             //10秒更新伺服器

warntime 5              //5秒警告級别            

udpport 694           //端口    

auto_failback on            //自動切換

node   node1              //節點1,接主機名

node   node2             //節點2

logfile /var/log/ha-log       //日志

respawn hacluster /usr/lib/heartbeat/ipfail

ping 10.0.0.2

Haresource檔案

<b>Vi /etc/ha.d/haresource</b>

Node1  192.168.211.9/24 httpd    //轉發的伺服器位址

<b>Vi /etc/ha.d/authkeys</b>

Auth 1

1 crc hello

<b>#Scp  ha.cf [email protected]:/etc/ha.d  //server2需要同樣的配置</b>

<b>#Scp  haresource [email protected]:/etc/ha.d</b>

<b>#Scp  authkeys [email protected]:/etc/ha.d</b>

<a target="_blank" href="http://blog.51cto.com/attachment/201210/232916270.gif"></a>

Chmod 600 authkeys

<a target="_blank" href="http://blog.51cto.com/attachment/201210/232925742.gif"></a>

Service heartbeat restart

會看到多了一個eth1:0的網卡

<a target="_blank" href="http://blog.51cto.com/attachment/201210/232932963.gif"></a>

這時對192.168.211.7開啟apache,然後做解析

<b>Vi /etc/hosts</b>

192.168.211.7      node1

192.168.211.8      node2

然後分别通路一下。

<a target="_blank" href="http://blog.51cto.com/attachment/201210/232939621.gif"></a>

<a target="_blank" href="http://blog.51cto.com/attachment/201210/232946911.gif"></a>

這時停止node1,會看到node2會自動進行開啟eth1:0網卡。

<a target="_blank" href="http://blog.51cto.com/attachment/201210/232955649.gif"></a>

<a target="_blank" href="http://blog.51cto.com/attachment/201210/233004269.gif"></a>

這時192.168.211.9一會就可以ping通通路了。

本文轉自zsaisai 51CTO部落格,原文連結:http://blog.51cto.com/3402313/1032767

繼續閱讀