HA專題: corosync+pacemaker實現nginx高可用

HA專題: corosync+pacemaker實現nginx高可用

前言

這幾天都會學習高可用集群, 也會將其中的一些實驗寫出來分享給大家, 這個專題估計會寫5篇左右, p.s: 寫博客很累的

實驗介紹

這次的實驗比較簡單, 在CentOS7使用corosync+pacemaker實現兩個節點的nginx高可用

實驗拓撲

Alt textblob.png

實驗環境

主機 IP 功用
node1.anyisalin.com 172.16.1.2 web服務, HA節點
node2.anyisalin.com 172.16.1.3 web服務, HA節點
nfs.anyisalin.com 172.16.1.4 提供nfs服務,網站頁面文件

注意: 本文實驗中所有主機SElinux和iptables都是關閉的

實驗步驟

準備工作

高可用集群必須保證所有節點主機互信, 主機名解析一致, 時間同步

配置hosts文件同步
Alt textblob.png

配置互信
Alt text

Alt textblob.png

blob.png


時間同步
Alt textblob.png

安裝HA集群組件

在RH系6.4之后就可以通過RedHat提供的pcs來進行對集群”全生命周期”的管理, 我們這里先通過pcs安裝集群并自動生成配置文件

[root@node1 ~]# yum install pcs -y #node1安裝pcs
[root@node1 ~]# ssh node2.anyisalin.com 'yum install pcs -y '  #node2安裝pcs
[root@node1 ~]# echo passwd | passwd --stdin hacluster #設置hacluster用戶密碼
[root@node1 ~]# ssh node2.anyisalin.com "echo passwd | passwd --stdin hacluster" #為node2設置hacluster密碼
[root@node1 ~]# systemctl start pcsd ; ssh node2.anyisalin.com "systemctl start pcsd" #啟動pcsd

[root@node1 ~]# pcs cluster auth node1.anyisalin.com node2.anyisalin.com -u hacluster #進行認證
Password: 
node1.anyisalin.com: Authorized
node2.anyisalin.com: Authorized

[root@node1 ~]# pcs cluster setup --name mycluster node1.anyisalin.com node2.anyisalin.com #安裝集群
[root@node1 ~]# pcs cluster start --all #啟動集群

安裝nginx和配置nfs

安裝nginx

[root@node1 ~]# yum install nginx -y       注意: 需epel源
[root@node1 ~]# ssh node2.anyisalin.com "yum install nginx -y " 
[root@node1 ~]# systemctl enable nginx    #由于systemd的特性, 需將nginx設置開機自動啟動
[root@node1 ~]# ssh node2.anyisalin.com "systemctl enable nginx" 

配置nfs
[root@nfs ~]# mkdir /www/htdocs -pv
[root@nfs ~]# echo "<h1>This is NFS on 172.16.1.4</h1>" > /www/htdocs/index.html #創建網頁文件
[root@nfs ~]# vim /etc/exports
/www/htdocs    172.16.1.0/24(ro)

[root@nfs ~]# systemctl start rpcbind.service 
[root@nfs ~]# systemctl start nfs-server.service  #啟動nfs-server

測試nfs
[root@node1 ~]# mount -t nfs 172.16.1.4:/www/htdocs /usr/share/nginx/html/  #掛載成功
[root@node1 ~]# df
Filesystem              1K-blocks    Used Available Use% Mounted on
172.16.1.4:/www/htdocs   52403200 1134336  51268864   3% /usr/share/nginx/html

[root@node1 ~]# umount /usr/share/nginx/html/

使用crmsh配置集群資源

pcs用來安裝集群還可以, 但是配置集群資源, 我用了一次再也不想用了, 實在是不好用, 個人比較喜歡crmsh來配置集群, crmsh大家可以自行去下載, 安裝時可能需要epel源 中的一些軟件

[root@node1 ~]# yum install crmsh-2.1.4-1.1.x86_64.rpm  #安裝crmsh 我們的rpm包是自行下載的


配置資源
[root@node1 ~]# crm configure
crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=172.16.1.8
crm(live)configure# primitive nginx systemd:nginx

crm(live)configure# primitive webstore ocf:heartbeat:Filesystem params device="172.16.1.4:/www/htdocs" directory="/usr/share/nginx/html" fstype="nfs" op start timeout=60s op stop timeout=60s op monitor interval=20s timeout=40s

定義資源組
crm(live)configure# group webservice webip webstore nginx
crm(live)configure# verify
crm(live)configure# property stonith-enabled=false
crm(live)configure# commit

測試

Alt textblob.png

blob.png

blob.png

blob.png

Alt text

Alt text

總結

本文簡單演示HA集群的簡單實現, 非常的簡單. HA最重要的是它的原理, 我以前寫過一篇HA原理的博客, 大家可以看看

作者水平很低, 如果有錯誤及時指出, 如果你覺得本文寫的好請點一波贊~(≧▽≦)/~
作者: AnyISaIln QQ: 1449472454
感謝: MageEdu

原創文章,作者:Net18-AnyISalIn,如若轉載,請注明出處:http://www.www58058.com/14614

(0)
Net18-AnyISalInNet18-AnyISalIn
上一篇 2016-04-10 20:40
下一篇 2016-04-11 11:38

相關推薦

  • bash腳本之進階

    bash腳本 1、終端打印 1、單雙引號(echo) 雙引號: ①在雙引號里面打不出! ②雙引號,可以在文本中使用“;”,“;”在bash中被用作命令定界符。 單引號: 變量替換在單引號中無效。 2、printf:不會自動添加換行符,要手動添加 如下: 結果: 3、補充: echo 要使用轉義系列需要加e,!號除外 2、變量和環境變量 腳本語言通?!?/p>

    Linux干貨 2016-11-28
  • Memcache存儲大數據的問題

    Memcache存儲大數據的問題   huangguisu       Memcached存儲單個item最大數據是在1MB內,如果數據超過1M,存取set和get是都是返回false,而且引起性能的問題。 我們之前對排行榜的數據進行緩存,由于排行榜在我們所有sql select…

    Linux干貨 2015-05-05
  • 基于CentOS7實現LAMP(上)

    基于CentOS7實現LAMP(上)   情景模式: (1)php以模塊方式運行  提供兩個虛擬主機;                    &nbs…

    Linux干貨 2016-08-22
  • lvs-dr 原理與配置

    Lvs-dr 原理與配置 目錄     1、ARP介紹     2、DR模式數據包請求響應流程     3、配置過程    4、總結 1、ARP協議介紹 功能:局域網內,根據IP地址獲取MAC地址。 互聯網上面…

    Linux干貨 2015-09-16
  • grep,find用法-2

    1、顯示當前系統上root、fedora或user1用戶的默認shell; grep -E “^(root|fedora|user1)>” /etc/passwd | cut -d: -f1,7 [root@bogon Desktop]# grep -E “^(root|fedora|user1)\>” /etc/pass…

    Linux干貨 2017-08-04
  • N25-第五周作業

    1、顯示當前系統上root、fedora或user1用戶的默認shell; [root@zf ~]# grep -E "^(root|fedora)\>" /etc/passwd | cut -d: -f1,7   &nbs…

    Linux干貨 2016-12-27
欧美性久久久久