|
|
楼主 |
发表于 2018-1-13 17:55:46
|
显示全部楼层
内容正式开始前,我已经在集群中添加了新的节点controller1(IP地址为10.0.0.14)。
0 e6 j. ]; d* S6 w0 j# r0 L7 s
1 }, K- L) s) _) i* d 8 }5 }; Y7 ?3 d3 n
9 V7 B( g1 D, |4 c' r/ P. C
4 m" ]9 [ d7 J! c! s( `* S
在所有节点上安装软件:
; _* Y8 e/ v& @; ?; N# yum install -y mariadb-galera-server xinetd rsync
; n8 ~$ J9 A: O- {% U9 u
1 V5 P7 z3 g6 d; v
1 C8 W; `+ l' c/ x6 ~1 N* I& T在节点1初始化数据库:# P& q# x- Q" L$ ]9 b$ @
# systemctl start mariadb.service9 j1 f7 S' U* Q7 T" k3 ~
# mysql_secure_installation
2 G( {8 Z+ G. h. A: |# j- T/ W" N# mysql -u root -p -e "CREATE USER 'clustercheck'@'localhost' IDENTIFIED BY '123456';". ^+ X. ~& I) @" p# j
# systemctl stop mariadb.service
8 V4 K; b9 O, ^; @4 v P) g2 M1 g" t7 a3 `+ Q- B. y
0 K+ \8 g0 t" ]! H9 q" `在所有节点上配置MariaDB和Galera:/ r! b5 }9 T1 W' z9 }3 [$ T
# vi /etc/my.cnf.d/galera.cnf, U$ s$ }0 k% p u! W8 T8 b7 R( w. ~$ E* i
[mysqld]
6 c& {: H3 y- {8 C I$ a4 A1 ibinlog_format=ROW
S; n0 l0 \6 t1 kdefault-storage-engine=innodb
% ?* J3 a5 _! ?5 f; j+ D8 @innodb_autoinc_lock_mode=29 ~3 j. c" k) s, B8 H2 n
innodb_locks_unsafe_for_binlog=1
! Y) J9 M, L: O2 y# `query_cache_size=0
% v7 {! Y& E: r) @7 t) Yquery_cache_type=0
! ]( t* p$ z$ E) \' Z# v# ^bind-address=controller19 z5 ?" u/ A" R8 _
wsrep_provider=/usr/lib64/galera/libgalera_smm.so5 \# K2 o: o: i8 N8 |
wsrep_cluster_name="my_wsrep_cluster"7 ^; R3 l* y' k* M7 Z
wsrep_cluster_address="gcomm://controller1,controller2,controller3"
, U. \ N0 j: Y0 y; M; A: ^ o; ^wsrep_slave_threads=1
0 d/ m& F. j: ]% Wwsrep_certify_nonPK=1, V e; q( @/ [5 ^
wsrep_max_ws_rows=1310724 S& S% a" P B$ X
wsrep_max_ws_size=1073741824% j& ?7 p: a' i+ R0 ^
wsrep_debug=0, } ]- Z% a9 U9 y% i
wsrep_convert_LOCK_to_trx=0
+ j0 H3 h( e: g- s; N) ?9 z! a" ~wsrep_retry_autocommit=1
& o% k- [( Z& [# P% iwsrep_auto_increment_control=1* t& X& R2 A0 u4 w
wsrep_drupal_282555_workaround=0
. L5 S7 h# o' F/ v$ k% ?& q2 n4 }wsrep_causal_reads=0- T1 I6 W! a; r* c
wsrep_notify_cmd=' h% J; k7 j0 _9 y3 ]% E$ y; L$ n
wsrep_sst_method=rsync
! A0 O/ H# r$ ~ w4 Z2 iwsrep_sst_auth=root:3 o- g3 u9 e* d% }1 Q. {7 V
“bind-address=”配置成/etc/hosts中的本机名称。
8 Y- p9 b: o# b/ H6 B" B4 B7 C注意:如果“bind-address=0.0.0.0”,则在本机所有IP的3306端口进行监听,包括VIP。这将导致后续haproxy无法在VIP的3306端口监听。6 I z7 ~; P% B
* @+ k0 @ Y4 r o. J
+ f1 g1 Q5 b& O0 I0 [2 c在节点1执行如下命令:' x' z, I, m% K2 a) t
# sudo -u mysql /usr/libexec/mysqld --wsrep-cluster-address='gcomm://' &, p) y- d3 v% J& P2 z: C) M
需要记住屏幕上的进程id,后面有用。; p& ]+ N" w( q# k* w
( t2 h1 O, C9 f5 L1 C! ^4 L1 |& |
2 B- v4 S. p% Y5 o/ R! H! k
在节点2、节点3: \: M, Z5 s: O3 ]% F1 P
# systemctl start mariadb.service
* N3 T- u/ ~5 {9 H l1 w8 U; d0 u* y# systemctl status -l mariadb.service/ P! x! N% Z6 q/ `) m# i0 Q- i
$ Z8 N4 q5 Y$ g
) h+ b! t- P1 Z- i+ I, F
在任意节点确认集群的成员数量:
; P7 L4 _' T- l# mysql -u root -e 'SELECT VARIABLE_VALUE as "wsrep_cluster_size" FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME="wsrep_cluster_size"'
' y; t- r0 X& F! S2 `7 F7 M+--------------------+2 h$ W3 s/ L1 m. B5 @
| wsrep_cluster_size |8 M3 A2 N& e/ ]: g* ~& C! [
+--------------------+7 ?! ^' q- K; @- R' d
| 3 |
/ L: s& _/ k* ^" U- |) p# J+--------------------+
" V) G3 {' `2 E" P3 f& i* X, g- ]3 h0 G1 T5 b
F! ]3 p' l8 }1 K/ |以上状态均正常,重启节点1的服务:
; e$ \! T. M# w7 D0 A# kill <mysql PIDs>
# z( ]( K. r$ t6 M/ t2 f6 Z# systemctl start mariadb.service+ U3 p/ X; Y. q' B2 }, n
! E4 m3 p$ b! `
$ I+ o$ I- m! Z4 ^$ r$ G+ l! F- C7 U5 U
7 t& `% S2 j6 x% |3 e: j
* z7 Y0 J. c |3 G& d/ H
在所有节点上创建健康检查登录信息文件:: C" y& Q3 ^8 E4 d1 l
# vi /etc/sysconfig/clustercheck" b5 j! Q5 n" g6 d
MYSQL_USERNAME=clustercheck9 z2 `; F: q/ V* X+ n7 U
MYSQL_PASSWORD=123456
/ L Q2 g, J9 ^; g! hMYSQL_HOST=localhost! B' G. n6 [! c0 i$ }. h% E4 F
MYSQL_PORT=3306: l U" P+ y5 O) e% f3 @
' N$ X, {) T4 j
2 N+ U7 Q1 l) W& B' O在所有节点上创建供HAProxy调用的健康检查服务:
) H- R/ P7 \7 g$ Y#vi /etc/xinetd.d/galera-monitor
; r) r& Q" }. b! `! i `+ ?+ J' Lservice galera-monitor1 s# ~- B K7 [/ E: Y/ }; R' U7 `; H2 t
{- L4 ? }9 O9 B1 @3 ?* R3 N
port = 92006 y% S2 u2 F T/ A% M- o
disable = no) e) `# x; [( \9 n' z' n
socket_type = stream
, I% J8 i: w0 C( e N! ~& Vprotocol = tcp) j+ s9 v& O$ a3 W2 m
wait = no
; B* z/ U, [. D; \; P" muser = root
2 b( S9 |7 F8 m. |: b9 |/ ~5 Bgroup = root% ^. H# S ]6 b9 ~2 D9 b. T
groups = yes# P1 F: w ?( G$ q- F
server = /usr/bin/clustercheck8 b- @# \0 a, [4 D/ N( x$ Z% y
type = UNLISTED
* l+ Q0 d% A: Eper_source = UNLIMITED! c% K& I5 |' ]" k8 u3 y: K; J
log_on_success =
8 V2 S7 f& R) r( wlog_on_failure = HOST
# x8 ?* z( C3 A- b* U2 jflags = REUSE! d0 A/ _) l1 D5 @
}
8 [0 t# u; O }此处检查状态的端口为9200。
i1 }6 q) _6 x8 ~3 c
0 L3 E) u/ N: N8 S4 v
" Y g& W0 X; P7 ?4 i# @在所有节点上启动xinetd服务,clustercheck需要这个服务:! A( P$ J; }# _9 D0 T/ K9 g% X5 b* \7 ]
# systemctl daemon-reload0 ?8 q% X K# w) s
# systemctl enable xinetd: n& W( K! ^; K& ?5 E) g/ O
# systemctl start xinetd
1 J3 `: N2 C1 r' G$ J) Q& @2 n: S" N6 v
6 k7 u ?7 r8 r3 ~% v/ Q' J# t& Z( O测试检查效果:6 ^9 g4 Y) e U: q/ I" l4 ~; L
# clustercheck8 }" Q- v- z& g3 a% u
HTTP/1.1 200 OK: @% F4 O G, U/ C* o
Content-Type: text/plain
' B1 L" b+ q7 }4 \3 E) ?Connection: close& C: Y% u# y/ o n4 k6 R6 p+ Q# G
Content-Length: 32
- C0 z z& J; O( t) y) t' ~, N; k
Galera cluster node is synced.
# X3 J$ K2 l# ]( f! F( e8 e2 y9 e7 f; e; y2 V9 j& k
或:5 }/ W- g5 s5 W) ^, Z$ a& ?, h) z
# telnet 10.0.0.14 9200
/ V o+ }) S) e7 ]( Q# nTrying 10.0.0.14...9 \, w$ f) ]. U, }* f" q0 b5 r
Connected to 10.0.0.14.# D$ ~; t/ h' u9 W* S1 A( L
Escape character is '^]'.7 A) f; w+ Y0 Q4 k
HTTP/1.1 200 OK6 H! N8 O( s( Y, @" |6 ]% T
Content-Type: text/plain
3 S" X+ C5 w: F0 d6 mConnection: close
3 \. i$ w5 E1 q4 s# MContent-Length: 32
" p5 Q# G- U# Z: y& ]! W* G, k4 z+ ]5 J# J1 e1 Z" I! V
Galera cluster node is synced.
% Q5 n! h+ I. x( A8 X$ I2 NConnection closed by foreign host.1 d a2 d2 B% c: M" O3 R
8 S+ P; Q* L9 S. | ' l E1 Z' P0 t4 w2 W$ f0 |( p. m
7 @/ n1 K8 g$ I2 Q* e6 A# c! ^
在所有节点上配置haproxy.cfg:
% `) J K5 |( P% R& A4 G+ p# vi /etc/haproxy/haproxy.cfg0 u6 K: O: ?/ I8 }; V9 @4 t3 v
global0 B. p& b$ C7 z3 m( f
chroot /var/lib/haproxy0 S R; K/ P, w
daemon- U( n9 S& q; U9 A
group haproxy9 w/ A3 N/ x. D* ]4 F
maxconn 40003 i' X, c% L6 M. I* I( V2 f
pidfile /var/run/haproxy.pid
3 j$ c4 t1 S0 }2 h, Euser haproxy4 `! A$ K. t3 a6 z, _
: t9 [$ {4 ?2 x$ t
defaults; W; Y* \# f2 |1 Q1 q
log global! v0 ~+ z+ ^ |. K) ~
maxconn 4000
; o1 r" v* @9 U' O6 a+ _; ooption redispatch
4 e$ e% I2 ^. K' u& X/ \6 h7 Mretries 33 u$ k$ \6 k- i( y, d+ y: A1 F
timeout http-request 10s* ~. h/ \5 q; P9 y) }3 {# X
timeout queue 1m; p U! Y E! v1 z% i1 n
timeout connect 10s0 J6 i% s+ h! v G
timeout client 1m
8 a/ R- U$ W1 Z1 f. U1 ~9 Wtimeout server 1m7 b6 D# |" _) N% Q: l
timeout check 10s7 x3 @9 e- A; Y$ D- }) o% s9 g
v. {! u8 A* C7 d/ i. Y2 T
listen galera_cluster
' Z% \+ v7 ^4 S* }& ?6 Y% ?bind 10.0.0.10:33066 [- @% q; j( y, F
balance source5 O" w5 j8 O" _3 h+ [9 v- I
option httpchk9 b1 v9 B9 P1 t/ L$ W
server controller1 10.0.0.14:3306 check port 9200 inter 2000 rise 2 fall 5
( a* i; ^& Y6 \2 Q' u2 rserver controller2 10.0.0.12:3306 check port 9200 inter 2000 rise 2 fall 5" D/ e1 C' V% X' e' I/ Q
server controller3 10.0.0.13:3306 check port 9200 inter 2000 rise 2 fall 5* S" X- }1 R8 `/ F
0 A4 K& ?$ n9 m+ L, i p5 d
- Y$ O) i+ L+ Q) x查看资源当前在哪个节点:
a5 w' M- }1 i; X3 E$ y# crm_mon
" K2 q6 x$ F: l
8 v1 Q& d0 }- B
! x% U! r# @; P8 k重启资源所在节点的haproxy服务:
& N, G! _# r" V: P# systemctl restart haproxy.service
& i% d0 B2 f: f4 b# systemctl status -l haproxy.service |
|