推薦-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.rpmpython-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
下一篇 2016-04-05

相關推薦

  • 詳解linux磁盤管理

                           磁盤管理 設備文件 1. I/O ports:I/O設備地址 2. 一切皆文件,open(),read(),write(),close(),對設備的操作也都是通     過這…

    Linux干貨 2016-08-29
  • MySQL高級特性-合并表

    1. Merge Tables         如果愿意的話,可以把合并表看成一種較老的、有更多限制的分區表,但是它們也有自己的用處,并且能提供一些分區表不能提供的功能。 合并表實際是容納真正的表的容器??梢允褂锰厥獾腢NION語法來CREATE TABLE。下面是一個合并表的例子: mysql> &n…

    Linux干貨 2015-04-13
  • 企業實時同步方案—-Sersync介紹

    原創作品,允許轉載,轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://nolinux.blog.51cto.com/4824967/1433109 Sersync 項目利用 Inotify 和 Rsync 技術實現對服務器數據實時同步的解決方案,其中 Inotify 用于監控 Sersync…

    Linux干貨 2016-08-15
  • Code Review中的幾個提示

    Code Review應該是軟件工程最最有價值的一個活動,之前,本站發表過《簡單實用的Code Review工具》,那些工具主要是用來幫助更有效地進行這個活動,這里的這篇文章,我們主要想和大家分享一下Code Review代碼審查的一些心得。 首先,我們先來看看Code Reivew的用處: Code reviews 中,可以通過大家的建議增進代碼的質量。 …

    Linux干貨 2015-04-03
  • 關于 磁盤、文件系統管理

                   磁盤、文件系統管理               1  設備識別2  設備分區3 …

    系統運維 2016-08-30
  • 震驚??!iptables還能這樣用!

    基本語法:iptables [-t 表] [操作命令] [鏈][規則匹配器][-j 目標動作] 系統的INPUT和OUTPUT默認策略為DROP; # iptables -P INPUT DROP # iptables -P OUTPUT DROP 1、限制本地主機的web服務器在周一不允許訪問;新請求的速率不能超過100個每秒;web服務器包含了admin…

    系統運維 2017-04-18

評論列表(1條)

  • stanley
    stanley 2016-04-05 22:27

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

欧美性久久久久