HA完整結構:
安裝配置高可用集群:
1、節點名稱:集群每個節點的名稱都得能互相解析
/etc/hosts
hosts中主機名的正反解析結果必須跟“uname -n”的結果保持一致;
2、時間必須得同步
使用網絡時間服務器同步時間
3、並非必須:各節點間能基於ssh密鑰認證通信;
安裝:
[root@marvin heartbeat]# yum install corosync -y
配置:
[root@sherry heartbeat]# cd /etc/corosync/
[root@sherry corosync]# ls
corosync.conf.example corosync.conf.example.udpu service.d uidgid.d
[root@sherry corosync]# cp corosync.conf.example corosync.conf
[root@sherry corosync]# vim corosync.conf
compatibility: whitetank #是否兼容0.8以前的版本
totem {
version: 2 #通信協議
secauth: on #安全認證功能 off別人知道多波地址 就可以加入 最好開啟
threads: 0 #0表示默認 認證時候並行線程
interface {
ringnumber: 0 #定義環號,防止心跳信息循環發送 就有一塊網卡就用0
bindnetaddr: 192.168.1.0 #綁定網絡地址
mcastaddr: 225.122.111.111 #224.0.1.0~238.255.255.255 建議用這組臨時
mcastport: 5405 #多波端口
ttl:1 #只發一次 避免環路
}
}
logging {
fileline: off
to_stderr: no #標准錯誤輸出
to_logfile: yes
logfile: /var/log/cluster/corosync.log
to_syslog: no #日志開啟一項即可
debug: off
timestamp: no #是否記錄時間戳
logger_subsys {
subsys: AMF
debug: off
}
}
amf {
mode:disabled #編程相關
}
安裝pacemaker:
[root@sherry corosync]# yum install pacemaker -y
自動啟動pacemaker:(服務不會啟動,還是需要手動啟動)
[root@sherry corosync]# vim corosync.conf
service {
ver:1 #以插件方式運行pacemaker
name:pacemaker
}
aisexec{
user:root
group:root
}
密鑰文件:
#生產環境請手敲密鑰
[root@sherry corosync]# mv /dev/random /dev/random.bak
[root@sherry corosync]# mv /dev/urandom /dev/random
[root@sherry corosync]# corosync-keygen
[root@sherry corosync]# mv /dev/random /dev/urandom
[root@sherry corosync]# mv /dev/random.bak /dev/random
密鑰生產:(權限400)
[root@sherry corosync]# ll
total 24
-r-------- 1 root root 128 May 31 20:54 authkey
-rw-r--r-- 1 root root 476 May 31 20:50 corosync.conf
-rw-r--r-- 1 root root 2663 May 11 06:27 corosync.conf.example
-rw-r--r-- 1 root root 1073 May 11 06:27 corosync.conf.example.udpu
drwxr-xr-x 2 root root 4096 May 11 06:27 service.d
drwxr-xr-x 2 root root 4096 May 11 06:27 uidgid.d
配置文件復制到對應節點:
[root@sherry corosync]# scp -P6789 -p authkey corosync.conf root@marvin:/etc/corosync/
crmsh安裝:
[root@sherry yum.repos.d]# cd /etc/yum.repos.d/
[root@sherry yum.repos.d]# wgethttp://download.opensuse.org/repositories/network:ha-clustering:Stable/CentOS_CentOS-6/network:ha-clustering:Stable.repo [root@sherry yum.repos.d]# yum install crmsh -y
啟動腳本:
[root@sherry corosync]# /etc/init.d/corosync start
[root@sherry corosync]# /etc/init.d/pacemaker start
#停止時候次序相反
實驗服務器:marvin sherry
初始化:
corosync默認啟用了stonith,而當前集群並沒有相應的stonith設備 我們裡可以通過如下命令先禁用stonith:
crm(live)# configure
crm(live)configure# property stonith-enabled=false
crm(live)configure# verify
crm(live)configure# commit
設置投票
crm(live)configure# property no-quorum-policy=ignore
crm(live)configure# verify
crm(live)configure# commit
查看配置所有信息:
crm(live)configure# show
node marvin
node sherry
property cib-bootstrap-options: \
have-watchdog=false \
dc-version=1.1.14-8.el6-70404b0 \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes=2 \
stonith-enabled=false
no-quorum-policy=ignore
定義資源:
定義一個ip:
crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=192.168.1.199
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
node marvin
node sherry
primitive webip IPaddr \
params ip=192.168.1.199
property cib-bootstrap-options: \
have-watchdog=false \
dc-version=1.1.14-8.el6-70404b0 \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes=2 \
stonith-enabled=false
[root@marvin ~]# ip addr show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:0c:34:2c brd ff:ff:ff:ff:ff:ff
inet 192.168.1.220/24 brd 192.168.1.255 scope global eth1
inet 192.168.1.199/24 brd 192.168.1.255 scope global secondary eth1
inet6 fe80::20c:29ff:fe0c:342c/64 scope link
valid_lft forever preferred_lft forever
後期定義監控:kill後會自動啟動
crm(live)configure# monitor webserver 30s:15s #刪除可直接edit 30s監控一次15s延遲
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
primitive webserver lsb:nginx \
meta target-role=Stopped \
op monitor interval=30s timeout=15s
nfs:(定義監控) (定義正確,未提交)
crm(live)configure# primitive webstore ocf:heartbeat:Filesystem params device="sherry:/nfsshared/node1" directory="/mnt/nfs/node1" fstype='nfs' op monitor interval=20s timeout=40s op start timeout=60s op stop timeout=60s on-fail=restart
crm(live)configure# verify
nginx:(定義監控)
crm(live)configure# primitive webserver lsb:nginx op monitor interval=30s timeout=15s on-fail=restart
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
node marvin
node sherry
primitive webip IPaddr \
params ip=192.168.1.199
primitive webserver lsb:nginx
property cib-bootstrap-options: \
have-watchdog=false \
dc-version=1.1.14-8.el6-70404b0 \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes=2 \
stonith-enabled=false
status:
crm(live)# status
Last updated: Wed Jun 1 20:38:32 2016 Last change: Wed Jun 1 20:36:32 2016 by root via cibadmin on sherry
Stack: classic openais (with plugin)
Current DC: marvin (version 1.1.14-8.el6-70404b0) - partition with quorum
2 nodes and 2 resources configured, 2 expected votes
Online: [ marvin sherry ]
Full list of resources:
webip (ocf::heartbeat:IPaddr): Started marvin
webserver (lsb:nginx): Started sherry
資源停止:
crm(live)# resource
crm(live)resource# stop webserver
crm(live)resource# status
webip (ocf::heartbeat:IPaddr): Started
webserver (lsb:nginx): (target-role:Stopped) Stopped
清理資源狀態:
crm(live)resource# cleanup webserver
Cleaning up webserver on marvin, removing fail-count-webserver
Cleaning up webserver on sherry, removing fail-count-webserver
* The configuration specifies that 'webserver' should remain stopped
Waiting for 2 replies from the CRMd.. OK
組操作:
先定義好資源,在加入組
crm(live)# status
Last updated: Wed Jun 1 20:38:32 2016 Last change: Wed Jun 1 20:36:32 2016 by root via cibadmin on sherry
Stack: classic openais (with plugin)
Current DC: marvin (version 1.1.14-8.el6-70404b0) - partition with quorum
2 nodes and 2 resources configured, 2 expected votes
Online: [ marvin sherry ]
Full list of resources:
webip (ocf::heartbeat:IPaddr): Started marvin
webserver (lsb:nginx): Started sherry
crm(live)# configure
crm(live)configure# group webservice webip webserver
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show
node marvin
node sherry
primitive webip IPaddr \
params ip=192.168.1.199
primitive webserver lsb:nginx
group webservice webip webserver
property cib-bootstrap-options: \
have-watchdog=false \
dc-version=1.1.14-8.el6-70404b0 \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes=2 \
stonith-enabled=false
刪除組:
crm(live)resource# stop webservice
crm(live)configure# delete webservice #組下面的資源還是存在
節點操作:
節點離線:
crm(live)# node
crm(live)node# standby marvin #資源自動轉移
節點上線:
crm(live)node# online marvin
節點清理:(節點上資源信息清理)
crm(live)node# clearstate marvin
位置約束:
綁定在一起:
crm(live)configure# colocation webserver_and_webip inf: webserver webip
crm(live)configure# verify
crm(live)configure# commit
查看
crm(live)configure# show
node marvin \
attributes standby=off
node sherry
primitive webip IPaddr \
params ip=192.168.1.199
primitive webserver lsb:nginx
colocation webserver_and_webip inf: webserver webip
property cib-bootstrap-options: \
have-watchdog=false \
dc-version=1.1.14-8.el6-70404b0 \
cluster-infrastructure="classic openais (with plugin)" \
expected-quorum-votes=2 \
stonith-enabled=false
具體查看:
crm(live)configure# show xml
<rsc_colocation id="webserver_and_webip" score="INFINITY" rsc="webserver" with-rsc="webip"/> #webserver跟著webip
順序約束:
crm(live)configure# order webip-before-webserver mandatory: webip webserver #依次順序
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# status
order webip-before-webserver Mandatory: webip webserver
crm(live)configure# show xml
<rsc_order id="webip-before-webserver" kind="Mandatory" first="webip" then="webserver"/>
位置約束
crm(live)configure# location webip_on_marvin webip 200: marvin
crm(live)configure# verify
crm(live)configure# commit
查看:
crm(live)# status
Last updated: Wed Jun 1 21:11:58 2016 Last change: Wed Jun 1 21:11:32 2016 by root via cibadmin on sherry
Stack: classic openais (with plugin)
Current DC: marvin (version 1.1.14-8.el6-70404b0) - partition with quorum
2 nodes and 2 resources configured, 2 expected votes
Online: [ marvin sherry ]
Full list of resources:
webip (ocf::heartbeat:IPaddr): Started marvin
webserver (lsb:nginx): Started marvin
over