Linux高可用集羣(Corosync+Pacemaker)

說在前面:

   這個編輯器也太霸道了,,兩個瀏覽器,,一個不能粘貼,一個不能上圖,只能保存草稿之後切換,  t_0004.gif

   造孽啊! 寫博不易,且看且珍惜   [蠟燭]


ntp服務器配置

# vim /etc/ntf.conf 加入如下配置
.
# 國家授時中心
restrict 210.72.145.44
restrict 202.120.2.101
restrict 1.cn.pool.ntp.org
# 允許本網絡內機器同步
restrict 172.16.43.0 mask 255.255.255.0 nomodify
.
server 210.72.145.44
server 202.120.2.101
server 1.cn.pool.ntp.org
# 配置完畢  service ntpd restart
# 注意 時間服務器配置後需要等待10-15分鐘
# ntpstat 可查看時間服務器狀態
# 客戶端使用ntpdate來同步時間 (集羣中十分常用)


高可用概念:

   採用架構冗餘(2臺以上機器)

   底層節點信息傳遞(下圖 Messaging/Infrashructrue 層)

   計算機資源管理與協調(下圖 Resource Allocation 層)與一身架構設計


高可用架構一覽

wKioL1NSOHniJ9ZxAAH4UkK1c5M291.jpg

來自https://www.suse.com/Document


高可用方案

   ML messaging/infrashructrue

   CRM cluster resource manager

   RA resource agent(resorce provider)


   i)  Corosync/OpenAIS [ML] + (Pacemaker,crm) [CRM]

   ii) heartbeat v1 [ML] + haresource [CRM]

   iii)heartbeat v2 [ML] + (crm,crmsh/hb_gui) [CRM]

   iv) Cman+Corosync [ML] + Pacemaker [CRM]

   # 以上方案在功能特點上沒有區別,在於易用性


   v) PCS + Conga + Pacemaker + Corosync

   vi) PCS + Pcsd + Pacemaker + Corosync

   # 以上均爲全生命週期集羣配置


   vii) Cman + RHCS

   # 重量級解決方案


實驗配置

   172.16.43.200  master.king.com  <- 主控節點,負責配置集羣,但不參與

   172.16.43.1    slave1.king.com  <- 集羣節點1

   172.16.43.2    slave2.king.com  <- 集羣節點2


實驗過程

   i) 主控節點配置

# 安裝 ansible
yum -y install ansible-1.5.4-1.el6.noarch.rpm
# 配置複製節點互信
ssh-keygen -t rsa
# 此處需要 slave1.king.com 在主控節點上解析
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
或
scp ~/.ssh/id_rsa.pub [email protected]:/root/.ssh/authorized_keys
# 安裝corosync,pacemaker,pcs,crmsh
yum -y install corosync pacemaker
yum -y install pssh-2.3.1-2.el6.x86_64.rpm
yum -y install crmsh-1.2.6-4.el6.x86_64.rpm
# 集羣節點項配置
cd /etc/corosync
cp corosync.conf.example corosync.conf
# 編輯配置文件
vim corosync.conf
    totem {
        version: 2
        secauth: on  # 集羣節點需要驗證才能加入集羣
        threads: 0
        interface {
            ringnumber: 0
            bindnetaddr: 172.16.43.0 # 在此網段進行廣播
            mcastaddr: 226.94.43.1   # 多播地址
            mcastport: 5405
            ttl: 1
        }
    }
    logging {
        fileline: off
        to_stderr: no
        to_logfile: yes
        to_syslog: yes
        logfile: /var/log/cluster/corosync.log
        debug: off
        timestamp: on
        logger_subsys {
            subsys: AMF
            debug: off
        }
    }
    amf {
        mode: disabled
    }
    service {
        ver:    0
        name:   pacemaker   # 啓動corosync時啓動pacemaker服務
    }
    aisexec {
        user:   root
        group:  root
    }
# 生成corosync節點驗證信息
corosync-keygen

   ii): 集羣節點安裝corosync + pacemaker + crmsh + pssh 及配置

# 配置集羣節點互信,分別在集羣節點1,2上執行
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
.
# 配置管理節點將管理的集羣節點信息 /etc/ansible/hosts
[server]
slave1.king.com
slave2.king.com
.
# all 是代表hosts文件中所定義所有集羣主機, all 也可換 server當前的意義是等價的
# 安裝 corosync pacemaker crmsh pssh 注意crmsh , pssh 沒有用yum源
# 本地文件先拷貝在安裝的
ansible all -m yum -a 'name=corosync state=present'
ansible all -m yum -a 'name=pacemaker state=present'
ansible all -m copy -a 'src=./crmsh-1.2.6-4.el6.x86_64.rpm dest=/root'
ansible all -m copy -a 'src=./pssh-2.3.1-2.el6.x86_64.rpm dest=/root'
# pssh crmsh的本地安裝
ansible all -m command -a 'yum -y install /root/pssh-2.3.1-2.el6.x86_64.rpm'
ansible all -m command -a 'yum -y install /root/crmsh-1.2.6-4.el6.x86_64.rpm'
# 將主控節點配置好的信息同步到集羣節點    authkey , corosync 到 slave1,slave2
ansible all -m copy -a 'src=/etc/corosync/authkey dest=/etc/corosync'
ansible all -m file -a 'path=/etc/corosync/authkey mode=400'
ansible all -m copy -a 'src=/etc/corosync/corosync.conf dest=/etc/corosync'
ansible all -m service -a 'name=corosync state=started'
# 更多modual及參數請詳見
ansible-doc modualname

   iii): 配置集羣資源

crm # 在主控節點中進入crm管理器
crm > status # 查看集羣狀態
. 圖1
# 這裏是雙節點集羣 , 一旦失效就可能導致資源無法轉移 , 所以這裏設置不需要 隔離設備
crm(live)configure > property stonith-enabled=false
crm(live)configure > property no-quorum-policy=ignore
# 查看設置
. 圖2
crm > help # 獲得crm菜單幫助
# 使用configure配置主資源 注意 提示符 處的菜單路徑
crm(live)configure > primitive webip ocf:heartbeat:IPaddr params ip=172.16.43.88 op monitor interval=30s timeout=20s onfail restart
crm(live)configure > primitive webfile ocf:heartbeat:Filesystem params device='172.16.43.200:/htdocs' directory='/var/www/html' fstype='nfs' op monitor intetval=30s timeout=20s onfail restart
crm(live)configure > primitive webhttp ocf:heartbeat:httpd
crm > status # 查看集羣狀態, 此時資源處於均衡負載
. 圖3
# 將資源加入組實現資源聚合
crm(live)configure > group webserivce webip
crm(live)configure > group webserivce webfile
crm(live)configure > group webserivce webhttp
# 將資源加入排列順序實現資源啓動先後
order order_webip_webfile_webhttp mandatory: webip webfile webhttp
. 圖4


wKioL1NSWBOxNLEDAAK0PpsT7DQ752.jpg

圖1

wKiom1NSWD-QirOvAAJWdSp4YSw741.jpg

圖2

wKioL1NSWBnxY0xaAAOEhI58KSI220.jpg

圖3

wKioL1NSWBzxno6JAAOZQNgeRaY365.jpg

圖4


  iv): 測試

       .圖

wKioL1NSWZ-gqQiGAAVZG9yVXVk685.jpg


   先發出來, 標記  .圖 的地方正在編輯上傳中....  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章