推薦-Corosync + Pacemaker 搭建高可用Httpd服務

Corosync + Pacemaker 搭建高可用Httpd服務


實驗描述

1.兩個測試節點,分別為node5.redhat.comnode6.redhat.com地址分別為172.16.100.5172.16.100.6
2.集群服務為httpd,利用nfs做共享存儲,NFS地址為172.16.0.254,NFS已經共享出了一個/www/htdocs目錄并且里面有index.html文件。
3.VIP地址為172.16.100.100
4.兩個節點系統全部為CentOS7.2
5.由于本人還需要上班,所以時間緊張,描述的有點馬虎,請多見諒。如有錯誤的地方,還請提出改正。


配置步驟

1.在所有節點安裝pcs,并啟動相應的pcsd進程

[root@node5 ~]# yum install pcs -y
[root@node5 ~]# systemctl start pcsd.service

[root@node6 ~]# yum install pcs -y
[root@node6 ~]# systemctl start pcsd.service

2.給所有節點上的hacluster用戶設置一個密碼。

[root@node5 ~]# echo “redhat” | passwd –stdin hacluster

[root@node6 ~]# echo “redhat” | passwd –stdin hacluster

3.在一個節點上驗證兩個節點

[root@node5 ~]# pcs cluster auth node5.redhat.com node6.redhat.com
Username: hacluster
Password: 這里輸入的密碼默認不會顯示
node5.redhat.com: Authorized
node6.redhat.com: Authorized

4.將兩個節點加入集群

[root@node5 ~]# pcs cluster setup –name mycluster node5.redhat.com node6.redhat.com
添加節點的輸出信息
Shutting down pacemaker/corosync services…
Redirecting to /bin/systemctl stop pacemaker.service
Redirecting to /bin/systemctl stop corosync.service
Killing any remaining services…
Removing all cluster configuration files…
node5.redhat.com: Succeeded
node6.redhat.com: Succeeded
Synchronizing pcsd certificates on nodes node5.redhat.com, node6.redhat.com…
node5.redhat.com: Success
node6.redhat.com: Success

Restaring pcsd on the nodes in order to reload the certificates…
node5.redhat.com: Success *顯示添加成功*
node6.redhat.com: Success *顯示添加成功*

5.兩個節點同時啟動corosyncpacemaker進程

[root@node5 ~]# systemctl start corosync.service
[root@node5 ~]# systemctl start pacemaker.service

[root@node6 ~]# systemctl start corosync.service
[root@node6 ~]# systemctl start pacemaker.service

6.在兩個節點上安裝httpd進程并設置為開機啟動

root@node5 ~]# yum install httpd -y
systemctl enable httpd.service

root@node6 ~]# yum install httpd -y
systemctl enable httpd.service

7.在兩個節點上安裝nft-utils以實現支持掛載nfs共享

[root@node5 ~]# yum install nfs-utils

[root@node6 ~]# yum install nfs-utils

8.安裝crmsh,CentOS7默認不帶crmsh,需要去網上下載rpm包,我用的是crmsh-2.2.0-7.1.noarch.rpmcrmsh-scripts-2.2.0-7.1.noarch.rpm、python-parallax-1.0.1-10.1.noarch.rpm

[root@node5 ~]# yum install crmsh-2.2.0-7.1.noarch.rpm crmsh-scripts-2.2.0-7.1.noarch.rpm python-parallax-1.0.1-10.1.noarch.rpm -y

[root@node6 ~]# yum install crmsh-2.2.0-7.1.noarch.rpm crmsh-scripts-2.2.0-7.1.noarch.rpm python-parallax-1.0.1-10.1.noarch.rpm -y

9.利用crmsh配置資源

[root@node5 ~]# crm configure

配置VIP資源
crm(live)configure# primitive webip ocf:heartbeat:IPaddr ip=’172.16.100.100’ op monitor interval=20s timeout=40s

配置NFS資源
crm(live)configure# primitive webstore ocf:heartbeat:Filesystem params device=’172.16.0.254:/www/htdocs’ directory=’/var/www/html’ fstype=’nfs’ op start timeout=60s op stop timeout=60s op monitor interval=20s timeout=40s

配置WEB資源
crm(live)configure# primitive webserver systemd:httpd op start timeout=60s op stop timeout=60s op monitor interval=20s timeout=60s

因為是兩節點集群,需要關閉stonith
crm(live)configure# property stonith-enabled=false

crm(live)configure# commit

10.設置這三個服務要同時在一個節點上運行,并且啟動順序一定為VIP -> NFS -> httpd

  設置三個服務在同一節點上運行有兩種方法實現,一種是將所有資源設置到同一個組里面,或者設置排列約束。當然,即設置了組,又定義為了排列約束也是可以的。設置啟動順序那么必須使用順序約束。

設置組

crm(live)configure# group webservice webip webstore webserver

或排列約束

crm(live)configure# colocation webip_with_webstore inf: webip webstore
crm(live)configure# colocation webstore_with_webserver inf: webstore webserver

順序約束

crm(live)configure# order webip_before_webstore Mandatory: webip webstore
crm(live)configure# order webstore_before_webserver Mandatory: webstore webserver
crm(live)configure# commit


驗證配置

1.首先查看集群狀態

crm(live)configure# cd 退出到crmsh的主配置界面
crm(live)#status 輸出status查看集群狀態

Alt text1.jpg

一切正常

2.打開瀏覽器,輸入VIP地址進行查看。

Alt text2.jpg

測試也是正常的

3.將node5節點設置為standby狀態,查看服務是否轉移成功。

crm(live)# node standby node5.redhat.com
crm(live)# status

Alt text3.jpg

可以看到node服務轉移到了node6節點上

4.再次打開瀏覽器進行測試。

2.jpg

服務依舊正常,這樣就實現了我們高可用的目的。


原創文章,作者:張小凡,如若轉載,請注明出處:http://www.www58058.com/14207

(0)
張小凡張小凡
上一篇 2016-04-05 20:47
下一篇 2016-04-05 22:39

相關推薦

  • 系統管理中的三大利刃(htop glances dstat)

    工欲善事情,必先利其器,生產環境中的服務器在處理請求并生成回應數據的時間主要消耗在服務器端,包括了眾多的環節,如何全面了解我們linux服務器的CPU使用率、使用時間、內存占用比例、磁盤IO數據、網絡相關數據等等眾多指標,保證我們的linux服務器順利完成每一個請求,怎能沒有幾個趁手的利刃,而今天就讓我們見識一下系統管理中三大利刃。 相傳一把三尺長的軟劍,叫…

    Linux干貨 2015-11-18
  • MapReduce數據流

    Hadoop的核心組件在一起工作時如下圖所示: 圖4.4高層MapReduce工作流水線   MapReduce的輸入一般來自HDFS中的文件,這些文件分布存儲在集群內的節點上。運行一個MapReduce程序會在集群的許多節點甚至所有節點上運行mapping任務,每一個mapping任務都是平等的:mappers沒有特定“標識物”與其關聯。因此,任意的map…

    Linux干貨 2015-05-13
  • redis主從復制(1)— 慢查詢導致復制中斷

    redis的異常行為是一件令人頭疼的問題。redis提供的錯誤日志只提供了一些server的運行狀態信息,而沒有server在故障現場的操作日志,比如執行了什么命令,命令操作對象的數據結構信息。如果redis也有mysql的slow-log,那么很多性能和故障問題也很容易處理。1、redis rdb在redis2.8版本以前,redis主從數據復制在生產上存…

    Linux干貨 2016-04-12
  • 運維監控大數據的提取與分析

    本文內容整理來自【敏捷運維大講堂】蔣君偉老師的線上直播分享。分別從以下3個維度來分享:1、云時代監控分析的窘境;2、使用標簽標記監控數據的維度;3、監控數據應用場景。 云時代監控分析的窘境 在虛擬化與容器技術廣泛應用的情況下,運維對象大規模地增長,監控平臺每天存儲的指標都以億計,所以監控數據如今已經成了大數據。傳統的監控工具在這種場景下,對于數據的提取分析,…

    系統運維 2017-01-09
  • Redis集群明細文檔

    Redis目前版本是沒有提供集群功能的,如果要實現多臺Redis同時提供服務只能通過客戶端自身去實現(Memchached也是客戶端實現分布式)。目前根據文檔已經看到Redis正在開發集群功能,其中一部分已經開發完成,但是具體什么時候可以用上,還不得而知。文檔來源:http://redis.io/topics/cluster-spec 一、介紹   該文檔是…

    Linux干貨 2015-04-04
  • LVM 邏輯卷管理

    一、概述: LVM: logical Volumn Manager  LVM是建立在硬盤和分區之上的一個邏輯層。可以將多個物理分區整合起來,無需停機,可以對文件系統的大小進行調整。同時,還提供快照功能 二、概念及實現過程: PE :每一個物理卷PV被劃分為稱為PE(Physical Extents)的基本單元,具有唯一編號的PE是可以被LVM尋址的…

    Linux干貨 2015-10-05

評論列表(1條)

  • stanley
    stanley 2016-04-05 22:27

    結構清晰明白,內容詳略得當,贊

欧美性久久久久