|
|
楼主 |
发表于 2017-9-23 11:31:22
|
显示全部楼层
写这篇文章的时候,其实心里很不爽,国外VPN出了点问题,所以用度娘了,度娘搜出来的东西,80%是一样,有的名字不一样,但是内容还是一样的,corosync pacemaker mysql drbd 的高可用,我在想,如果不用drbd是不是就不能用corosync pacemaker实现高可用了?
% M7 a4 r8 ]0 d# |) u2 ^8 h对度娘的搜索算法,以及竞价排名,我只想说我去年买了个表。
2 Y" ^3 g1 o$ L% J' n V/ | H# M7 Y" Q9 F一,mysql replication主从配置
2 J% j$ K' A; O+ z3 i6 b请参考:mysql replication 主从(master-slave)同步
- a. V2 U% e% w. _4 t( E1 W二,corosync pacemaker安装配置
/ O7 C# h4 R( d" H! Q! }" b8 s9 o+ L! b请参考:corosync pacemaker nginx 高可用 安装配置
+ d* K$ ~3 H% w3 O上面二篇博客的/etc/hosts是定义的不一样的,以mysql replication为准,也就是masters,slave2。1 w# C. P* q" [: `5 W1 K
在这里要注意,改过hosts的名称后,masters节点,要重新生成auth文件的。( w5 Z, w' Z3 c. Q1 e6 J
% C7 m# \3 B a6 E1 J1 X, c9 U[root@masters corosync]# corosync-keygen
1 F& C* }7 e5 }* t7 Y3 Z' S[root@masters corosync]# scp /etc/corosync/authkey root@slave2:/etc/corosync/ //如果有很多节点都要copy
6 K. T4 P' l, s: i' g' W: W |# e$ ^8 Q% x% q
各节点重启corosync。$ A) G) U; o( b1 b9 b
三,masters节点,配置mysql crmsh: W; h. Z7 P+ ?! c
1,配置mysql crmsh3 t b9 s8 R: F: H3 _) N
[root@masters tank]# crm . [; ^7 U: D5 {1 `, R: e
crm(live)# configure
% x9 D8 N# ^4 g8 T5 }crm(live)configure#
' m T3 q7 ~& t4 wcrm(live)configure# property stonith-enabled=false 2 v! a U( G0 S) D. T
crm(live)configure# property no-quorum-policy=ignore S% \- f$ Z+ K) }
crm(live)configure# primitive mysqlip ocf:heartbeat:IPaddr params ip=192.168.10.231 op monitor interval=30s timeout=20s on-fail=restart crm(live)configure# primitive mysqlserver lsb:mysqld
% h- a0 a) @9 E+ e5 lcrm(live)configure# colocation mysql_col inf: mysqlserver mysqlip & d# t! M0 o' `5 V$ e
crm(live)configure# order mysql_after_ip mandatory: mysqlip mysqlserver . m; f8 _$ \# E9 x5 A% o6 |8 d
crm(live)configure# verify
+ w3 e( f8 A" z% j' `) t8 |crm(live)configure# commit
B, g) p h2 H4 G* \# |9 N5 |crm(live)configure# show
0 ]2 M3 y, A( K0 w6 @$ w8 I8 X
& K5 g/ T1 G0 }+ B$ I3 `& l8 i( K+ S( V. a8 k
在这里发现一个问题,在网上看了一些资料,关于monitor后时间配置,有几种版本
$ m- I2 v! x1 c- L% [% y( ] Qmonitor interval=30 timeout=20
% s2 i2 X2 t) t+ A; r- ~* qmonitor interval="30" timeout="20"& @+ q# q6 E+ c/ a
monitor interval="30s" timeout="20s", s% v4 M$ d; q( T+ y7 N5 g
我没有验证这些写法的正确性,但是monitor interval=30s timeout=20s,这种写法肯定是正确的,我用的系统是centos 6.5 64位,并且在帮助文档中也是这种写法。
/ ~/ i h4 Y4 j/ f6 c1 ^6 ~; r- M' ~$ n5 o* L% V
5 Z# ?# j1 ?9 d9 w5 J& b) Y9 f# O这是配置完成后的,通过show查看
0 k9 ^/ P% d0 Q! n+ u# V( }% Z* ]. z
% R# c" R5 I! I' P7 Y) }2,检测mysql各节点状态+ I: @! [0 w! P9 b+ O
1 T2 [# h6 l/ e n1 V! `2 H! w0 ]: _5 P- N5 ]2 n: K8 S
[root@masters tank]# crm status
# \% ^) a* j) cLast updated: Thu Apr 23 02:36:54 2015
' e, P4 @* `) |! d+ n0 kLast change: Thu Apr 23 02:36:06 2015 ! ^: x5 H% |: M# y1 }" P; G- O
Stack: classic openais (with plugin)
' _8 E' ?0 `+ _2 y" V" D+ V% }Current DC: slave2 - partition with quorum 7 B) x8 W1 ]: \/ F4 w- c
Version: 1.1.11-97629de ( ~4 \/ `$ F' x/ g" N& ^ u
5 Nodes configured, 2 expected votes
* S, s- l( d- t3 Resources configured
7 ^: V, |& q+ [ d5 Y
+ C3 V* l, H0 d5 \1 {Online: [ masters slave2 ] //二节点都要在线 9 s' J7 z0 ~3 ]9 L) W ]# x+ s
OFFLINE: [ localhost.localdomain node1 node2 ]
: }; Y2 M/ A; x0 U2 U % J. o' C7 ^" a. Q: f0 h; p; j/ D
webip (ocf::heartbeat:IPaddr): Started masters
, g( }" f. Q5 `, T: }" q nginx_res (lsb:nginx): Started masters $ A5 t: y) K w# P
mysqlip (ocf::heartbeat:IPaddr): Started slave2 ( o0 P/ N: g5 K4 o# c- W* D) y
mysqlserver (lsb:mysqld): Started slave2
: ^/ j, m9 L( p0 A+ N( D: G6 c& l+ Q0 w! o: Q8 v* @# h8 ]
! y3 `" I& ?3 |& ~
. k+ b2 f, f3 G7 ?0 _
! f7 h/ y& \/ {8 k% ?* E) a; ~. ^
: G" t* |* E; b! G3 X& }: z
如果online,节点不全的话,offline的机器上面,执行
, y8 F6 |( T+ j1 j2 ` Q, D- g[root@slave2 ~]# crm node online $ u8 y& c+ ?! V; D5 ~* v: o: J& I
% @' h! n5 t$ u9 ]! E5 x& @' W, `7 x2 v: n
% `& \3 e* a( o$ R* {8 p$ X
) _- V+ x ?1 ~' D' Z: j F7 q1 w" m6 I2 {( a* ]% G
四,测试
" K+ ]6 o4 ^6 y查看复制打印?
7 Q" C8 H0 }2 d" a[tank@localhost ~]$ mysql -u test -p -h 192.168.10.231 //如果实际连接masters的话 0 f8 W6 K' G( n
[root@masters ~]# crm node standby //masters机器,将masters挂起 * [7 ^3 k6 y! ]- [* Q
[tank@localhost ~]$ mysql -u test -p -h 192.168.10.231 //如果成功连接到slave2的话,说明测试成功 |) M- v8 i2 G1 Y/ z6 @
有三台mysql,一主二从,如果主服务器down机了,二台从服务器,能不能自动转成一主一从,并保持数据的完成性呢,MHA可以帮我们解决这问题。
3 L! C4 M: m# z: _4 g2 R& ~& v; _ O3 d" @1 |
; S# \. {& t% O
" J& \0 s% z5 ?. Q0 A8 X! s) e; O* U& q; N2 Y
+ @" z0 b0 ]+ E6 |2 ^) ~+ p
|
|