heartbeat httpd nfs 實現高可用web叢集

來源:互聯網
上載者:User

標籤:作業系統   軟體   

一 環境準備

二 拓撲結構

三 前提條件

四 安裝相關軟體

五 配置heartbeat

六 測試web叢集

七 問題匯總

八 共用儲存

一 環境準備

作業系統

centos 6.4 x86_64 迷你安裝

如使用yum 安裝的方式 centos5.5 安裝的是V2.X ,centos 6.4 安裝的是V3.X

YUM 安裝 Vim man ntp “development tools” “server platform development” “desktop platform development”

配置 epel YUM 源

關閉 防火牆 selinux

二 拓撲結構

650) this.width=650;" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top: 0px; border-right: 0px; padding-top: 0px" title="image_thumb1" border="0" alt="image_thumb1" src="http://img1.51cto.com/attachment/201407/6/158322_1404636731IBRK.png" "853" height="596">

三 前提條件(兩個節點都有配置)

1 節點之間主機名稱可以互相解析

web1 ,web2

[[email protected] ~]# vim /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4::1         localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.200.132  web1.daphne.com  web1192.168.200.133  web2.daphne.com  web2

2 節點之間時間同步

[[email protected] ~]# ntpdate ntp.api.bz

3 節點之間配置SSH互信

[[email protected] ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ‘‘[[email protected] ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected][[email protected] ~]# ssh web2[[email protected] ~]# 
 
[[email protected] ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ‘‘[[email protected] ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected][[email protected] ~]# ssh web1[[email protected] ~]# 

四 安裝相關軟體

1 heartbeat 組件說明

  • heartbeat 核心組件
  • heartbeat-gui 圖形管理介面
  • heartbeat-ldirectord 為lvs高可用提供規則自動產生及後端realserver健康狀態檢查組件
  • heartbeat-pils 裝載庫外掛程式介面
  • heartbeat-stonith

2 安裝heartbeat

heartbeat-2.1.4-12.el6.x86_64.rpm
heartbeat-gui-2.1.4-12.el6.x86_64.rpm
heartbeat-pils-2.1.4-12.el6.x86_64.rpm
heartbeat-stonith-2.1.4-12.el6.x86_64.rpm

yum install PyXML libnet pygtk2-libglade net-snmp-libsyum install libtool-ltd( 注  要從源庫安裝 ,不可以epel)lyum install  libnetrpm -ivh heartbeat-*

3 安裝httpd

[[email protected] ~]# yum install httpd[[email protected] ~]# cd /var/www/html/[[email protected] html]# vim index.html web1[[email protected] ~]# service httpd start

測試

650) this.width=650;" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top: 0px; border-right: 0px; padding-top: 0px" title="image_thumb11" border="0" alt="image_thumb11" src="http://img1.51cto.com/attachment/201407/6/158322_1404636731cLDQ.png" "861" height="131">

測試完畢 關閉服務 使其開機不要啟動

[[email protected] ~]# serivce httpd off[[email protected] ~]# chkconfig httpd of[[email protected] ~]# chkconfig --list httpdhttpd          0:off1:off2:off3:off4:off5:off6:off

以上操作在兩個節點都要做

五 配置heartbeat

1設定檔說明

[[email protected] ~]# cd /etc/ha.d/[[email protected] ha.d]# lsauthkeys  harc         rc.d           resource.dha.cf     haresources  README.config  shellfuncs

說明 安裝好的heartbeat 預設沒有設定檔,但提供了設定檔樣本

[[email protected] ha.d]# cd /usr/share/doc/heartbeat-2.1.4/[[email protected] heartbeat-2.1.4]# ls apphbd.cf         faqntips.html        haresources         Requirements.htmlauthkeys          faqntips.txt         hb_report.html      Requirements.txtAUTHORS           GettingStarted.html  hb_report.txt       rsync.htmlChangeLog         GettingStarted.txt   heartbeat_api.html  rsync.txtCOPYING           ha.cf                heartbeat_api.txt   startstopCOPYING.LGPL      HardwareGuide.html   logd.cfDirectoryMap.txt  HardwareGuide.txt    README
我們需要  authkeys ha.cf haresources 三個設定檔
[[email protected] heartbeat-2.1.4]# cp authkeys ha.cf haresources /etc/ha.d/

2 配置authkeys

[[email protected] ha.d]# openssl rand -hex 8 >> authkeys [[email protected] ha.d]# vim authkeys auth 2#1 crc#2 sha1 HI!#3 md5 Hello!2 sha1 7c0f241959ee845d[[email protected] ha.d]# chmod 600 authkeys 

3 配置ha.cf檔案

[[email protected] ha.d]# vim ha.cf 

修改心跳資訊的傳播方式 可以採用 組播 廣播 單播

bcast  eth0

配置叢集中的節點數

node web1.daphne.comnode web2.daphne.com

4 配置haresources

[[email protected] ha.d]# vim haresources web1.daphne.com 192.168.200.10/24/eth0 httpd

5 複製以上三個檔案到web2上

[[email protected] ha.d]# scp authkeys ha.cf haresources web2:/etc/ha.d/

6 啟動web1與web2

先啟動備份節點

[[email protected] ~]# service heartbeat  start[[email protected] ~]# service heartbeat  start

六 測試web叢集

查看IP

[[email protected] ha.d]# ifconfigeth0      Link encap:Ethernet  HWaddr 00:0C:29:7D:C1:D7            inet addr:192.168.200.132  Bcast:192.168.200.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fe7d:c1d7/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:9069 errors:0 dropped:0 overruns:0 frame:0          TX packets:9159 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:1707993 (1.6 MiB)  TX bytes:1846141 (1.7 MiB)eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:7D:C1:D7            inet addr:192.168.200.10  Bcast:192.168.200.255  Mask:255.255.255.0          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1lo        Link encap:Local Loopback            inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host          UP LOOPBACK RUNNING  MTU:16436  Metric:1          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
650) this.width=650;" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px;  border-top: 0px; border-right: 0px; padding-top: 0px" title="image_thumb12" border="0" alt="image_thumb12" src="http://img1.51cto.com/attachment/201407/6/158322_1404636731GD3u.png" "861" height="131">

故障示範
關閉web1上的heartbeat
[[email protected] ~]# service heartbeat stopStopping High-Availability services: Done.

查看web2上的IP

ifconfigeth0      Link encap:Ethernet  HWaddr 00:0C:29:61:E4:6B            inet addr:192.168.200.133  Bcast:192.168.200.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fe61:e46b/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:8230 errors:0 dropped:0 overruns:0 frame:0          TX packets:8164 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:1698974 (1.6 MiB)  TX bytes:1680369 (1.6 MiB)eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:61:E4:6B            inet addr:192.168.200.10  Bcast:192.168.200.255  Mask:255.255.255.0          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1lo        Link encap:Local Loopback            inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host          UP LOOPBACK RUNNING  MTU:16436  Metric:1          RX packets:0 errors:0 dropped:0 overruns:0 frame:0          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0           RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

測試

650) this.width=650;" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top: 0px; border-right: 0px; padding-top: 0px" title="image_thumb15" border="0" alt="image_thumb15" src="http://img1.51cto.com/attachment/201407/6/158322_1404636732lYsH.png" "871" height="119">

 

七 問題匯總

節點間的檔案同步

1Rsync+Inotify組合方案來解決節點之間的同步問題

2共用儲存方案

八 共用儲存

1 配置NFS伺服器

[[email protected] ~]# yum install nfs*[[email protected] ~]# mkdir -pv /web/html/[[email protected] ~]# vim /web/html/index.html [[email protected] ~]# vim /etc/exports /web/html/ 192.168.200.0/24(rw,async)[[email protected] ~]# service rpcbind start[[email protected] ~]# service nfs start

節點測試 掛載

web1

[[email protected] ~]# mount -t nfs 192.168.200.138:/web/html /mnt[[email protected] ~]# cd /mnt[[email protected] mnt]# lsindex.html[[email protected] ~]# umount /mnt

修改haresource檔案

[[email protected] ha.d]# vim /etc/ha.d/haresourcesweb1.daphne.com 192.168.200.10/24/eth0 Filesystem::192.168.200.138:/web/html::/var/www/html::nfs  httpd

同步haresource設定檔

[[email protected] ha.d]# cd /etc/ha.d/[[email protected] ha.d]# scp haresources web2:/etc/ha.d/

重啟heartbeat

[[email protected] ~]# service heartbeat restart[[email protected] ~]# service heartbeat restart

測試web服務

650) this.width=650;" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; border-top: 0px; border-right: 0px; padding-top: 0px" title="image_thumb17" border="0" alt="image_thumb17" src="http://img1.51cto.com/attachment/201407/6/158322_1404636732XmIF.png" "862" height="136">

 
 
 
 
 
 
 
 
 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.