openstack ha
基礎(chǔ)知識(shí)
高可用 (High Availability,簡(jiǎn)稱 HA)
??高可用性是指提供在本地系統(tǒng)單個(gè)組件故障情況下,能繼續(xù)訪問應(yīng)用的能力,無論這個(gè)故障是業(yè)務(wù)流程岖研、物理設(shè)施、IT軟/硬件的故障警检。最好的可用性孙援, 就是你的一臺(tái)機(jī)器宕機(jī)了,但是使用你的服務(wù)的用戶完全感覺不到扇雕。你的機(jī)器宕機(jī)了拓售,在該機(jī)器上運(yùn)行的服務(wù)肯定得做故障切換(failover),切換有兩個(gè)維度的成本:RTO (Recovery Time Objective)和 RPO(Recovery Point Objective)镶奉。RTO 是服務(wù)恢復(fù)的時(shí)間础淤,最佳的情況是 0,這意味著服務(wù)立即恢復(fù)哨苛;最壞是無窮大意味著服務(wù)永遠(yuǎn)恢復(fù)不了鸽凶;RPO 是切換時(shí)向前恢復(fù)的數(shù)據(jù)的時(shí)間長(zhǎng)度,0 意味著使用同步的數(shù)據(jù)建峭,大于 0 意味著有數(shù)據(jù)丟失玻侥,比如 ” RPO = 1 天“ 意味著恢復(fù)時(shí)使用一天前的數(shù)據(jù),那么一天之內(nèi)的數(shù)據(jù)就丟失了亿蒸。因此使碾,恢復(fù)的最佳結(jié)果是 RTO = RPO = 0,但是這個(gè)太理想祝懂,或者要實(shí)現(xiàn)的話成本太高,全球估計(jì) Visa 等少數(shù)幾個(gè)公司能實(shí)現(xiàn)拘鞋,或者幾乎實(shí)現(xiàn)砚蓬。
??對(duì) HA 來說,往往使用共享存儲(chǔ),這樣的話宪躯,RPO =0 召夹;同時(shí)往往使用 Active/Active (雙活集群) HA 模式來使得 RTO 幾乎0印机,如果使用 Active/Passive 模式的 HA 的話掉盅,則需要將 RTO 減少到最小限度普气。HA 的計(jì)算公式是[ 1 - (宕機(jī)時(shí)間)/(宕機(jī)時(shí)間 + 運(yùn)行時(shí)間)]滑负,我們常常用幾個(gè) 9 表示可用性:
- 2 個(gè)9:99% = 1% * 365 = 3.65 * 24 小時(shí)/年 = 87.6 小時(shí)/年的宕機(jī)時(shí)間
- 4 個(gè)9: 99.99% = 0.01% * 365 * 24 * 60 = 52.56 分鐘/年
- 5 個(gè)9:99.999% = 0.001% * 365 = 5.265 分鐘/年的宕機(jī)時(shí)間费尽,也就意味著每次停機(jī)時(shí)間在一到兩分鐘仅父。
- 11 個(gè) 9:幾乎就是幾年才宕機(jī)幾分鐘叛薯。 據(jù)說 AWS S3 的設(shè)計(jì)高可用性就是 11 個(gè) 9。
服務(wù)的分類
HA 將服務(wù)分為兩類:
有狀態(tài)服務(wù):后續(xù)對(duì)服務(wù)的請(qǐng)求依賴于之前對(duì)服務(wù)的請(qǐng)求笙纤。
OpenStack有狀態(tài)的服務(wù)包括OpenStack數(shù)據(jù)庫(kù)和消息隊(duì)列耗溜。
無狀態(tài)服務(wù):對(duì)服務(wù)的請(qǐng)求之間沒有依賴關(guān)系,是完全獨(dú)立的省容。
OpenStack無狀態(tài)的服務(wù)包括nova-api抖拴、nova-conductor、glance-api腥椒、keystone-api阿宅、neutron-api、nova-scheduler笼蛛。
HA 的種類
HA 需要使用冗余的服務(wù)器組成集群來運(yùn)行負(fù)載洒放,包括應(yīng)用和服務(wù)。這種冗余性也可以將 HA 分為兩類:
Active/Passive HA:集群只包括兩個(gè)節(jié)點(diǎn)簡(jiǎn)稱主備伐弹。在這種配置下拉馋,系統(tǒng)采用主和備用機(jī)器來提供服務(wù),系統(tǒng)只在主設(shè)備上提供服務(wù)惨好。在主設(shè)備故障時(shí)煌茴,備設(shè)備上的服務(wù)被啟動(dòng)來替代主設(shè)備提供的服務(wù)。典型地日川,可以采用 CRM 軟件比如 Pacemaker 來控制主備設(shè)備之間的切換蔓腐,并提供一個(gè)虛機(jī) IP 來提供服務(wù)。
Active/Active HA:集群只包括兩個(gè)節(jié)點(diǎn)時(shí)簡(jiǎn)稱雙活龄句,包括多節(jié)點(diǎn)時(shí)成為多主(Multi-master)回论。在這種配置下,系統(tǒng)在集群內(nèi)所有服務(wù)器上運(yùn)行同樣的負(fù)載分歇。以數(shù)據(jù)庫(kù)為例傀蓉,對(duì)一個(gè)實(shí)例的更新,會(huì)被同步到所有實(shí)例上职抡。這種配置下往往采用負(fù)載均衡軟件比如 HAProxy 來提供服務(wù)的虛擬 IP葬燎。
1、主動(dòng)/被動(dòng)(Active/Passive)配置
主備概念,主節(jié)點(diǎn)出問題時(shí)谱净,備節(jié)點(diǎn)頂上窑邦。一般用VIP實(shí)現(xiàn),使用Pacemaker和Corosync壕探。
2冈钦、主動(dòng)/主動(dòng)(Active/Active)配置
無狀態(tài)使用VIP進(jìn)行負(fù)載平衡,可以使用HAProxy軟件李请。
Openstack controller ha實(shí)現(xiàn)方案
本次的ha測(cè)試環(huán)境采用五臺(tái)物理機(jī),其中三臺(tái)為controller節(jié)點(diǎn)瞧筛,一臺(tái)為compute ,一臺(tái)為network
controller節(jié)點(diǎn)上,整體的架構(gòu)圖如下:
三臺(tái)物理服務(wù)器組成 pacemaker 集群,創(chuàng)建多個(gè)虛機(jī)捻艳,安裝各種應(yīng)用驾窟,具體如下:
Service | Process | Mode | HA stragegy |
---|---|---|---|
keystone | httpd | AA | 負(fù)載均衡+多實(shí)例 |
glance | openstack-glance-api | AA | 負(fù)載均衡+多實(shí)例 |
glance | openstack-glance-registry | AA | 負(fù)載均衡+多實(shí)例 |
nova | openstack-nova-api | AA | 負(fù)載均衡+多實(shí)例 |
nova | openstack-nova-conductor | AA | AMQP+多實(shí)例 |
nova | openstack-nova-scheduler | AA | AMQP+多實(shí)例 |
nova | openstack-nova-consoleauth | AA | AMQP+多實(shí)例 |
nova | openstack-nova-novncproxy | AA | 負(fù)載均衡+多實(shí)例 |
neutron | neutron-server | AA | 負(fù)載均衡+多實(shí)例 |
cinder | openstack-cinder-api | AA | 負(fù)載均衡+多實(shí)例 |
cinder | openstack-cinder-scheduler | AA | AMQP+多實(shí)例 |
cinder | openstack-cinder-volume | AA | 主備+pacemaker切換 |
mysql | Mariadb-server | AA | Galera cluster |
rabbitmq | rabbitmq-server | AA | cluster + mirror queue |
haproxy | haproxy | AP | 多實(shí)例+pacemaker切換VIP |
memcache | memcached | AA | 負(fù)載均衡+多實(shí)例 |
具體的配置過程如下:
# 在所有l(wèi)b節(jié)點(diǎn),安裝pacemaker組件认轨,啟動(dòng)pcsd服務(wù)绅络,并配置hacluster賬戶
$ yum install -y pacemaker pcs psmisc policycoreutils-python
$ systemctl start pcsd.service
$ systemctl enable pcsd.service
$ echo <some_password> | passwd hacluster --stdin
# 在任意一個(gè)節(jié)點(diǎn)初始化lb集群
$ pcs cluster auth ip1 ip2 ip3
Username: hacluster
Password:
server-33: Authorized
server-34: Authorized
server-35: Authorized
$ pcs cluster setup --name lb_cluster ip1 ip2 ip3
# 在所有l(wèi)b節(jié)點(diǎn),啟動(dòng)corosync & pacemaker服務(wù)
$ systemctl start corosync.service
$ systemctl enable corosync.service
$ systemctl start pacemaker.service
$ systemctl enable pacemaker.service
# 配置lb集群的特性
$ pcs property set stonith-enabled=false
$ pcs property set no-quorum-policy=ignore
$ pcs property set start-failure-is-fatal=false
$ pcs resource defaults resource-stickiness=10
# 創(chuàng)建vip與haproxy資源嘁字,并添加限制恩急,確保p_vip運(yùn)行在haproxy服務(wù)正常的節(jié)點(diǎn)
$ pcs resource create p_vip ocf:heartbeat:IPaddr2 ip=ip4 cidr_netmask=24 op monitor interval=2s
$ pcs resource create p_haproxy systemd:haproxy op monitor interval=2s --clone
$ pcs constraint colocation add p_vip with p_haproxy-clone --force
$ pcs resource meta p_vip migration-threshold=3 failure-timeout=60s
# 下面是pacemaker+corosync+galera的安裝過程
# 在此之前先創(chuàng)建集群,創(chuàng)建方法參考pacemaker+corosync+haproxy
# 安裝必要的包
$ yum install -y MariaDB-server MariaDB-client percona-xtrabackup socat #MariaDB的版本不要是5.0.x 纪蜒,使用10.1.x,否則會(huì)報(bào)錯(cuò)
$ yum install -y pacemaker pcs psmisc policycoreutils-python
$ yum install -y openstack-resource-agent
# 創(chuàng)建用戶wsrep_sst
$ mysql -e 'grant all on *.* to "wsrep_sst"@"%" identified by "DJ1JAs8z"'
$ mysql -e 'grant all on *.* to "wsrep_sst"@"localhost" identified by "DJ1JAs8z"'
# 寫入配置 /etc/my.cnf.d/wsrep.cnf衷恭,注意后綴是cnf,完成garela集群的配置
[mysqld]
binlog_format=row
wsrep_on=ON
wsrep_cluster_address="gcomm://ip1,ip2,ip3?pc.wait_prim=no" # 三臺(tái) MariaDB 的 IP
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_name="openstack"
wsrep_slave_threads=4
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth=wsrep_sst:DJ1JAs8z
wsrep_node_address=ip1 # 本機(jī)的地址
[xtrabackup]
parallel=2
[sst]
streamfmt=xbstream
transferfmt=socat
sockopt=,nodelay,sndbuf=1048576,rcvbuf=1048576
# 配置pacemaker管理Galera集群
$ pcs resource create p_mysql ocf:mysql-wss binary=/usr/sbin/mysqld test_passwd=DJ1JAs8z test_user=wsrep_sst socket=/var/lib/mysql/mysql.sock --disabled --clone
# 注意纯续,這一步的mysql-wss可以在github上搜到随珠,需要在/usr/lib/ocf/resource.d/放入mysql-wss
$ pcs resource update p_mysql op monitor interval=90 timeout=300
$ pcs resource update p_mysql op stop interval=0 timeout=120
$ pcs resource update p_mysql op start interval=0 timeout=300
# 啟動(dòng)數(shù)據(jù)庫(kù)服務(wù)
$ pcs resource enable p_mysql
使用 HAProxy 的反向代理功能代理后端的 Galera 集群
# 在galera 節(jié)點(diǎn)安裝xinetd服務(wù),并在/etc/xinetd.d/目錄下創(chuàng)建galeracheck:
service galeracheck
{
port = 49000
disable = no
socket_type = stream
protocol = tcp
wait = no
user = nobody
group = nobody
groups = yes
server = /usr/bin/galeracheck
bind = 0.0.0.0
only_from = 0.0.0.0
per_source = UNLIMITED
cps = 512 10
flags = IPv4
instances = UNLIMITED
}
# galeracheck的來源及配置項(xiàng):https://github.com/olafz/percona-clustercheck
# 最后 /etc/haproxy/haproxy.cfg:
listen mysql
bind 0.0.0.0:3307
mode tcp
balance source
option tcplog
option clitcpka
option srvtcpka
option httpchk
timeout client 48h
timeout server 48h
server mysql-2 192.168.0.7:3306 check port 49000 inter 5000 rise 2 fall 3 backup
server mysql-3 192.168.0.8:3306 check port 49000 inter 5000 rise 2 fall 3 backup
server mysql-1 192.168.0.6:3306 check port 49000 inter 10s fastinter 2s downinter 3s rise 3 fall 2s
參考:
世民談云計(jì)算