|
|
楼主 |
发表于 2018-1-13 17:55:46
|
显示全部楼层
内容正式开始前,我已经在集群中添加了新的节点controller1(IP地址为10.0.0.14)。
& [8 d) S7 v- u9 g$ i' `. i3 V
/ |" \% c+ ?( F7 B1 h- p
% g8 P- f F) o; e: F: D N* ]' z% {1 k, M2 r
' G4 {2 g+ D6 D/ e0 }0 e在所有节点上安装软件:2 D r4 w+ F% R/ ]7 R2 X6 B0 \9 o
# yum install -y mariadb-galera-server xinetd rsync
9 O/ m1 L% z3 r, t
7 m) O. h7 U$ H" F. y9 {8 I: P) o) M" F: g# L
在节点1初始化数据库:
^; ~8 L9 {3 H2 e) f0 R2 _) j# systemctl start mariadb.service7 }3 b( D- b) X' `. I2 o
# mysql_secure_installation
+ b, [' ^$ k4 i4 _$ j6 r3 ]# mysql -u root -p -e "CREATE USER 'clustercheck'@'localhost' IDENTIFIED BY '123456';"
( G* u& G# l9 x# I6 J2 ~' ]# systemctl stop mariadb.service( Z1 R) N- }. }% p
" O' \/ q: t0 p" N
" U) w' m! w* \1 P( X9 C在所有节点上配置MariaDB和Galera:: ]" G; E- M4 H; j
# vi /etc/my.cnf.d/galera.cnf$ r7 F7 }) K0 d' t
[mysqld]$ [/ h/ R( t6 B
binlog_format=ROW
# l: n. p; {3 o% ]+ O. a# Z' qdefault-storage-engine=innodb
$ U4 Q; @+ n+ U% `' linnodb_autoinc_lock_mode=2, V8 Z9 }9 a3 l# K$ g
innodb_locks_unsafe_for_binlog=1
5 ?, E/ i% P4 \4 E7 o' Kquery_cache_size=0 F' R; \& g7 x" j( B' C ~/ x9 u5 l; i
query_cache_type=0
. g" G" g: k, _" E8 Z" h: _' C$ Cbind-address=controller16 c1 g9 b5 D+ [4 R
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
$ L7 J0 a4 p- }wsrep_cluster_name="my_wsrep_cluster"
# X. T+ R* i# |wsrep_cluster_address="gcomm://controller1,controller2,controller3"
0 [/ _5 l4 p; ?8 \5 E8 Xwsrep_slave_threads=1
9 v' o& M) m) U$ C% Q* b7 O& {wsrep_certify_nonPK=1! v( ]; @# C3 Y+ ^
wsrep_max_ws_rows=131072
' G' q1 P* u% D+ }; h8 @* Wwsrep_max_ws_size=1073741824! n# j8 Y" @( @, R$ }5 E0 G
wsrep_debug=0
1 a' v4 \" q: N. D1 U$ f' owsrep_convert_LOCK_to_trx=0
( t1 p: j7 ?9 Q+ h5 xwsrep_retry_autocommit=1
( `7 b4 T& t) |! n0 gwsrep_auto_increment_control=18 C$ b" v0 T, Z1 \' a, P" {
wsrep_drupal_282555_workaround=0
' ~: L* [2 g- Rwsrep_causal_reads=03 I- ?' |% T1 w! Y9 y4 g a6 d
wsrep_notify_cmd=4 O# R( Y3 v5 v3 f8 a! F' ? E
wsrep_sst_method=rsync
F& [6 B8 h' b' ?, ]wsrep_sst_auth=root:8 H+ q# X; ~' r
“bind-address=”配置成/etc/hosts中的本机名称。
* |/ L" Z0 }0 }$ i2 l注意:如果“bind-address=0.0.0.0”,则在本机所有IP的3306端口进行监听,包括VIP。这将导致后续haproxy无法在VIP的3306端口监听。
% y+ R6 D* y5 D( r7 U; l7 O
. B( J; x: J0 U, k/ Z3 ?8 y l2 g# o: ~2 @: O
在节点1执行如下命令:0 D. K" o" N' f$ c! ~ K- O
# sudo -u mysql /usr/libexec/mysqld --wsrep-cluster-address='gcomm://' &
- j* ?9 O2 _2 b& t需要记住屏幕上的进程id,后面有用。$ D- @- P# o+ W/ X0 q+ r- z ^) U* I
) W4 e1 p6 X' w- m2 Q1 z0 P( g5 e. [6 `1 D0 U7 |1 ]% G: |
在节点2、节点3:
3 [( }9 W6 Z3 N6 }; N- d+ Q# V# systemctl start mariadb.service
, i( _# e* b9 i2 L$ {# systemctl status -l mariadb.service
- V* B6 g8 d7 e
3 W& f9 q4 f) ^, \% e: l( d( B9 v( x; \4 \ i# n
在任意节点确认集群的成员数量:/ C( n+ o. Z7 @- `2 |
# mysql -u root -e 'SELECT VARIABLE_VALUE as "wsrep_cluster_size" FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME="wsrep_cluster_size"'5 J, |' o! `6 u
+--------------------+
1 I* L- L: H. V" W| wsrep_cluster_size |
3 m: K" |& B! [; x+--------------------+( W" V& _+ R; o+ q4 F
| 3 |" S0 @$ M1 V M, S1 T. E1 ^
+--------------------+; z3 R6 j5 f/ Y$ N1 q) f
6 N" |+ V3 S/ m: E1 H* s# v
' g0 v5 X% A: X/ [1 O% G0 ~以上状态均正常,重启节点1的服务:
$ z3 ~5 I% @; F/ ^0 p' S5 j- i# kill <mysql PIDs>: w! V( P- r% P) L! v9 z! @8 q
# systemctl start mariadb.service; s9 @/ z1 z3 b- N! w0 J# J5 \
. v! y+ k$ e$ `# Y! w2 T& a3 @+ }
Z' ]7 x& K( p; E. N) M# P* b
5 t! x, `7 {0 q6 v" X! w. G
: W( T0 k; [* G6 u5 t: e; R% n5 A8 Y p) i
在所有节点上创建健康检查登录信息文件:
6 O* C! p8 ?5 f9 [0 Q8 ~6 N: g# vi /etc/sysconfig/clustercheck$ U* B4 p% q1 x1 Q z) O2 k
MYSQL_USERNAME=clustercheck
( |: O. c* A3 o/ r9 ?' @1 L2 A8 EMYSQL_PASSWORD=123456, E4 c! n# v' d8 \: K; [
MYSQL_HOST=localhost
$ p6 N" j1 d" G) VMYSQL_PORT=3306
1 F8 T# j3 J- f# K8 o) Z! w8 _- y8 x: V# Z$ g
. U/ p% x( c# y# j% Q* r) k' u# W
在所有节点上创建供HAProxy调用的健康检查服务:" q7 _5 [* E. |$ y7 Y, ~
#vi /etc/xinetd.d/galera-monitor
* s2 N# {% \3 E% ^& _( Z- M0 jservice galera-monitor( B8 _$ P: x5 I7 ^
{$ O: G+ @: |+ {% l. Q
port = 9200
: m* A2 [: g) rdisable = no
- I) _4 c. v- M, x/ Msocket_type = stream& Z) [% t$ ^- G j- G { v
protocol = tcp
E& y5 `5 T7 j" @. Q! vwait = no. J. ~: |4 S% n! B9 M
user = root
* J: o, h$ Y+ u+ |! f: M8 Kgroup = root
$ g# \& G3 C& ?; k2 B! ugroups = yes) ~! M9 K! c: g$ G" v; Y
server = /usr/bin/clustercheck
( O1 f3 y6 x: ^) a$ p% U- Utype = UNLISTED
+ t9 q N, |) U, p, N" Nper_source = UNLIMITED1 R9 G( u2 T7 w
log_on_success =; ?, Z- P6 e4 T1 x9 Q
log_on_failure = HOST
" k1 A& R e' w3 f0 U% J4 p7 S5 nflags = REUSE
( i3 u) n# _9 n* b; q% I) \}
9 D# x! `% \' l6 j* {; R/ C+ P此处检查状态的端口为9200。, K6 `7 @! z5 ?
. f& ]5 P6 W+ t4 _ s+ U% N
: x& ~0 v. n7 R3 W, S在所有节点上启动xinetd服务,clustercheck需要这个服务:
* {7 ]- T7 K& P" V7 y! O# systemctl daemon-reload
2 g. i9 H% h/ a7 d# systemctl enable xinetd$ R- C9 D- |7 y: r9 I* R3 h7 Q
# systemctl start xinetd# S) }4 i. J- c0 M5 J5 C4 I
1 b' V1 X3 M" K. r( D5 {
: ~1 m& o) N$ `5 V0 J( i
测试检查效果:" E/ u6 ]; T& ?. \* U# k$ x! u/ k; S
# clustercheck
- N6 B8 c8 V0 AHTTP/1.1 200 OK, `9 K2 n7 s. P: T' l& C
Content-Type: text/plain
; L4 y8 j. \' R( g4 e4 z# c( ?Connection: close
% J! S: e0 S& ?$ G% IContent-Length: 32
) A% p( G4 w8 p8 ~: J7 N4 v/ m* s9 C/ x+ o5 q& N
Galera cluster node is synced.
0 F- e( [ ~0 L: e" e! b9 i2 n' S4 l( Y; Q; @6 S6 s6 F" q
或:. z! v: x6 n' x( A
# telnet 10.0.0.14 9200
# \1 j3 u& I# o* m! [$ YTrying 10.0.0.14...
! c7 u, n1 P5 M" Z7 Z% MConnected to 10.0.0.14.
$ _6 g# V; `3 _' X: J- WEscape character is '^]'.0 c/ E' E V% \; U' s
HTTP/1.1 200 OK
* n0 T- a+ h5 M! I: X0 _Content-Type: text/plain) f4 ]7 U' C7 v+ T) T; v
Connection: close
: C* G: b' D2 V4 q* _Content-Length: 320 X+ k9 x7 @5 Z
- H- k4 i& q% j/ u+ j. iGalera cluster node is synced.9 l& j \ J( N
Connection closed by foreign host.
. V/ H) s& x8 m9 `/ S- H9 g, ^5 ]. C& Z1 d. O" c5 M
" r% R- v' n8 [; ~8 v0 }
7 B+ x1 l& Z3 X f/ g在所有节点上配置haproxy.cfg:
. B4 Z, w0 R6 L( f: p! v# vi /etc/haproxy/haproxy.cfg+ N2 ?" a* s# I
global
9 ^$ @1 F3 o7 _6 ?0 G, Mchroot /var/lib/haproxy
8 Z* [% n) N* J( T+ C9 Ddaemon J+ Q- m: B, o/ t$ O3 A
group haproxy! T5 I6 W+ ?9 ~7 Z& J4 E" s5 E. A
maxconn 40009 n( p( _5 w/ y f7 U1 \, b7 Y
pidfile /var/run/haproxy.pid# c3 F N$ E7 a) a
user haproxy# @/ u% Y& ?( n, b6 H
& t* c# Y4 W- D
defaults8 ?1 j, I( ~1 w
log global
4 Z& t2 v9 o9 Umaxconn 4000
, b8 O0 w9 l( ~" O9 joption redispatch/ B4 z A* \" j9 `# A8 k" O6 U: @2 Z
retries 3* h0 @* z1 e3 ~ E0 _
timeout http-request 10s
0 b. [ ]' U' u+ c) A# B9 j6 _timeout queue 1m1 Q7 B) @2 e5 X" E4 P1 \7 h6 x
timeout connect 10s! i1 v$ b* @& G
timeout client 1m
( T/ ?1 ]) y: \8 m; dtimeout server 1m- A2 \1 }/ h3 P7 z
timeout check 10s, {# F* D2 E& l( P& j
4 u& n' ^: n3 J* i K3 W
listen galera_cluster
- R8 e% Q& E2 Y- g% o. Hbind 10.0.0.10:33063 q+ F- G H5 ?& p2 K1 L. ?) U
balance source1 R# E, y7 I9 b7 g8 L
option httpchk
* G8 o0 @2 }) sserver controller1 10.0.0.14:3306 check port 9200 inter 2000 rise 2 fall 5. U' H8 @! f; z5 c7 b5 n* B
server controller2 10.0.0.12:3306 check port 9200 inter 2000 rise 2 fall 5
' j1 }1 A8 z6 h/ m7 h' Q/ W4 R1 I( cserver controller3 10.0.0.13:3306 check port 9200 inter 2000 rise 2 fall 5
5 r3 G+ x2 U: n! W) ^3 U# P$ s& A+ k- g2 h) O
1 |8 D9 \0 L1 l查看资源当前在哪个节点:( g" S! ?; d. [* U9 c7 C
# crm_mon1 H/ [- M6 F5 T, P3 G8 E
2 {) H) a) G" o! c
4 `2 N7 v) \% ]: h! [ g
重启资源所在节点的haproxy服务:
U3 r$ j, t& `0 _8 B$ G# systemctl restart haproxy.service
9 I3 h" J \4 ~7 c; [9 T# systemctl status -l haproxy.service |
|