|
|
楼主 |
发表于 2018-1-13 17:55:46
|
显示全部楼层
内容正式开始前,我已经在集群中添加了新的节点controller1(IP地址为10.0.0.14)。6 _ S( P9 d1 H4 @4 K# ~
. G( S* f) p: U7 f* ], A
, Y' A: {: B3 s5 g' [
4 h3 Y) Z: |4 U
4 o5 x5 r, d1 O& h, p在所有节点上安装软件:
0 q! F9 q8 ]1 h! ^) k" M! G# yum install -y mariadb-galera-server xinetd rsync* m' C: _# @( g. U, ?0 s! S
7 ~2 Z4 T5 p" ^. ?! G, d: T1 Y. r
5 x6 Z/ |& X1 H7 u3 I- g- G; H在节点1初始化数据库:
( R- P2 i) b9 S8 v' [6 N7 ~# systemctl start mariadb.service Z5 b% g' q5 F4 i) ]1 n" ~9 P
# mysql_secure_installation
+ l! z: Q' f3 I4 m* }# mysql -u root -p -e "CREATE USER 'clustercheck'@'localhost' IDENTIFIED BY '123456';"
) V8 p) V r% X# systemctl stop mariadb.service
4 {+ m3 R4 r# q: f; k
# C! G. L1 I% `% P3 [; a H# l1 w+ ^, N+ i& _
在所有节点上配置MariaDB和Galera:
$ f0 v# s* b2 q( Y7 G# vi /etc/my.cnf.d/galera.cnf2 a) l% e9 t- g# F5 A2 t* W
[mysqld]
& o" Q1 ~: {% }4 \1 tbinlog_format=ROW# H) E6 \8 K: i" i6 K
default-storage-engine=innodb
! P% L. N) z1 M. j* uinnodb_autoinc_lock_mode=23 `( ] _4 z. f4 n5 a
innodb_locks_unsafe_for_binlog=1
" v" v8 ]+ R7 c$ }# s4 \+ d) |query_cache_size=04 _! X( b9 k0 b8 e. ~' X
query_cache_type=0
# @" ?9 p3 u7 abind-address=controller1
9 M3 R5 a0 z# [ F3 s: i: t+ x+ _2 ~wsrep_provider=/usr/lib64/galera/libgalera_smm.so f" Q" S/ g1 v" S8 c
wsrep_cluster_name="my_wsrep_cluster"
( K( Q6 Z4 h2 x1 N" [: `wsrep_cluster_address="gcomm://controller1,controller2,controller3"7 i3 N; T. d& n! [
wsrep_slave_threads=1; R' r5 @4 r. S
wsrep_certify_nonPK=1
1 X$ q- p G) Rwsrep_max_ws_rows=131072
* l/ V2 U8 Y( s& [- w) S9 dwsrep_max_ws_size=1073741824
1 j& k/ a B) j0 [! H+ \0 }wsrep_debug=0
) A3 @/ T/ P K- l( W% r5 qwsrep_convert_LOCK_to_trx=0
, \4 Z. E/ n- J$ Q6 \, W* f9 rwsrep_retry_autocommit=1: N2 f/ J3 ^; F/ W
wsrep_auto_increment_control=1, e& q7 P) W" d9 E7 ~$ Z' e' e
wsrep_drupal_282555_workaround=0
/ ~/ A6 ]: p2 Dwsrep_causal_reads=0
8 o, V2 X6 p7 n: K Gwsrep_notify_cmd=
" \2 h- T% T8 B$ x' Owsrep_sst_method=rsync
- i# e1 O9 p& E4 ~. Twsrep_sst_auth=root:
9 A+ f; G; d! n4 F# o“bind-address=”配置成/etc/hosts中的本机名称。
0 N x: H# D$ O: a7 N5 n. e注意:如果“bind-address=0.0.0.0”,则在本机所有IP的3306端口进行监听,包括VIP。这将导致后续haproxy无法在VIP的3306端口监听。% i- m" C! }7 o
, M; N6 A' i* F# d1 Y' n' d9 t& T
2 V" K8 V0 J" j6 W: B- u d3 m在节点1执行如下命令:
! w7 a; M8 v$ p$ o& r6 ?# sudo -u mysql /usr/libexec/mysqld --wsrep-cluster-address='gcomm://' &
1 e5 W0 X1 E0 r7 T$ V需要记住屏幕上的进程id,后面有用。5 W% E5 r' @: F' I% A* g. F o* k) H1 F
5 p) a. Q; R0 j" @6 u+ V7 x, T" {' o5 W
在节点2、节点3:5 e" b3 |& W% O& m# a0 _
# systemctl start mariadb.service
# R3 ?6 N6 v# U; v1 b! F# systemctl status -l mariadb.service. z5 I. |/ e+ G3 X. N w$ p
: a9 t3 A) b7 R+ ` h
2 r, {1 ]0 y' f: f/ q9 Y" R
在任意节点确认集群的成员数量:
1 v0 y e C' U% c; {# mysql -u root -e 'SELECT VARIABLE_VALUE as "wsrep_cluster_size" FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME="wsrep_cluster_size"'
( {# R0 [; s' T$ P+--------------------+2 N) m" y, e; k+ z
| wsrep_cluster_size |2 j& {, `1 F4 O. W& U% ~
+--------------------+
- q2 ?5 g- I) H N& c' G| 3 |" X. k1 S( ~8 c
+--------------------+ p5 n! a5 C5 k
; k8 n3 `6 {/ o0 g2 t
, |# n/ ?5 z4 x2 k! _+ P以上状态均正常,重启节点1的服务:
7 P0 e. {+ x) z% T, T# W# kill <mysql PIDs>
S8 e- s$ |4 ~( X* O# systemctl start mariadb.service
+ y1 ]- P2 ^6 t" Z( j7 g* p0 o8 }3 Q8 u# z
+ R3 K9 b2 ]$ I3 m3 u; _( P' p( M' ^: X1 e' b/ W
8 l3 J+ O9 t3 e& ?; ~/ H/ O: H
3 H i9 F; y+ f+ J9 J在所有节点上创建健康检查登录信息文件:
! J' B( L% n8 m, @ I1 p3 M- N# vi /etc/sysconfig/clustercheck
- e. n" J- p4 _) ~3 w- gMYSQL_USERNAME=clustercheck; Y# F4 A- J: `, z& R0 g4 N
MYSQL_PASSWORD=123456
8 z/ A" V* O$ JMYSQL_HOST=localhost
5 ~0 L+ p) g9 a1 {4 i. vMYSQL_PORT=3306& x6 N# Q7 l; I$ r: [
, D- R$ `3 R) o6 D& K. ~
( K$ n2 u( D3 h5 d |2 z在所有节点上创建供HAProxy调用的健康检查服务:
( X. L8 _3 r3 x- i#vi /etc/xinetd.d/galera-monitor! G' a" h, }1 F3 f2 O0 F) P) x& d+ ~
service galera-monitor
% |6 @1 o4 p( s$ _! h8 h{, Y5 `3 H, C3 B' h% _
port = 92007 {5 X' }, {" I: f
disable = no3 r; c- V0 c+ n* w" H/ d, W
socket_type = stream1 n: d$ S: d1 ~* R$ O
protocol = tcp4 m( ]* @ O$ T
wait = no+ V$ g9 J: s" A$ b* @4 `1 }) ]
user = root
0 K2 C5 m4 x1 f7 I4 Ggroup = root
0 K/ n4 x3 k9 e/ r3 [+ bgroups = yes' C! P7 F9 i. ^3 V
server = /usr/bin/clustercheck1 h7 }) f& [+ x! _7 L. P! T
type = UNLISTED
# N. j; V3 A2 Z& @9 ^/ F# K/ p! Fper_source = UNLIMITED% {% }3 b1 h, P# n* x# F7 ?' s3 A' m
log_on_success =
1 e% e5 j2 [' t/ X$ glog_on_failure = HOST
# P8 J, e1 H% W3 ?9 ?) \flags = REUSE. W( u5 C x0 M; D
}3 A. I' D# t: L; k/ z
此处检查状态的端口为9200。6 W& O! V) }; x& {0 Q
5 q$ K! K' R3 Y. q+ o. f& z
1 k! ]2 j0 C" {& U2 \+ m在所有节点上启动xinetd服务,clustercheck需要这个服务:
. k, l/ J+ W( _$ u0 Y# systemctl daemon-reload
( X/ X; m6 O: g" F( x4 x: m- D/ o# systemctl enable xinetd% Y8 r& Q% l, d& \
# systemctl start xinetd
; t- T: h. {+ H# x7 N. `7 w3 @2 _8 v) W4 L0 T0 y4 U- \
$ r+ A* `$ j- H* E$ G% T测试检查效果:1 Y _7 Q* U' f
# clustercheck
, P* P B8 h! [5 w0 W) ]) a, THTTP/1.1 200 OK5 N7 P, L; v, n% Q$ D8 }6 d
Content-Type: text/plain% |. e! L6 l$ n0 x/ `' O/ G5 c
Connection: close
4 Q- L( n3 x8 Z' y3 c9 J( ?$ RContent-Length: 32
0 F: {, t# d$ U. k
1 s# }( j0 d+ e! q2 v9 nGalera cluster node is synced.
4 u( [# n- b# J y/ e( m1 R0 a7 }
3 g. w# b ?" u或:
3 b4 g. `# [3 d" p) e# telnet 10.0.0.14 9200, c7 A8 r4 d2 G' q
Trying 10.0.0.14...
/ h8 w! }/ N5 t* A" q _4 T! jConnected to 10.0.0.14.
5 @2 Z- Y* P' T* I% N) @) Q7 \Escape character is '^]'.
' t# |6 [) h4 X, l' SHTTP/1.1 200 OK6 }/ T+ \0 k: o
Content-Type: text/plain' c+ L( F- O) `
Connection: close' ?& q/ y6 }$ V2 k0 L/ D6 e
Content-Length: 32! _" }' {" ? O: h: m
4 p6 r0 F; w& K- g7 r; G7 T( j
Galera cluster node is synced.
G$ d" _7 E# \& FConnection closed by foreign host.
3 K! T. U9 Q& N+ P' ?3 d# o( y5 l& g2 b
L U! ^* L7 X
& V% ?+ i$ q: A4 `在所有节点上配置haproxy.cfg:
% F+ I6 {9 }. r- Y) z/ Z# vi /etc/haproxy/haproxy.cfg8 o$ u* Q. \+ h' a& o9 O
global: Y7 r2 I: i8 V' L; j
chroot /var/lib/haproxy4 W) G( |2 A) K6 j5 o
daemon, t! ~# ~: ^- Y, T
group haproxy/ S& f( Q9 c( |2 Q) g( i+ `( u
maxconn 4000
( i7 O* E; ^ c2 q7 `! D( fpidfile /var/run/haproxy.pid
9 x2 c1 P' S, l( i% Q* K4 K1 o8 fuser haproxy0 J; z) \, r# ?; e5 n
% Q6 z/ u# e2 _1 I# ?3 V/ {$ Hdefaults+ @1 F/ M- U* x- v1 N4 }! p
log global
3 r* w# J$ O. n2 s3 n2 O. lmaxconn 4000
2 F/ _. r+ l; \2 `' x9 Qoption redispatch' V# H0 T" H* m5 L# D s
retries 32 G/ H- y4 R$ i5 ?8 W
timeout http-request 10s8 h3 K5 f/ |! }8 G" B2 g
timeout queue 1m
+ v" \! j+ h! S" g: N" itimeout connect 10s
3 L7 T8 I( {! Mtimeout client 1m
) L: K2 f* Q" D4 M# o0 b3 V' Ftimeout server 1m
' s G! k- W+ C4 `4 wtimeout check 10s( | N, {. }$ A$ c( y
7 c' J8 A X! R0 u. p8 l) Elisten galera_cluster
9 J2 E8 [! v: y' m8 j/ fbind 10.0.0.10:3306' Z2 t7 {4 p6 p+ M# ^; e& w
balance source
+ h! F# |' |3 ?, Uoption httpchk8 n& c9 q% i/ s7 H, j3 `
server controller1 10.0.0.14:3306 check port 9200 inter 2000 rise 2 fall 5
+ V, {. M! u. ]5 d; C sserver controller2 10.0.0.12:3306 check port 9200 inter 2000 rise 2 fall 5- L9 c. n% ~( q" U+ r; I
server controller3 10.0.0.13:3306 check port 9200 inter 2000 rise 2 fall 5/ Y7 F/ H8 V! h" ^+ w( P
4 n% ]. a. I* H- ^
( l: _" B( X! {/ m% O. E& R
查看资源当前在哪个节点:- G1 T- u4 D2 S
# crm_mon
. \2 p/ i- ~; f! n
( d3 O3 S# D5 M, K
- K- Z4 U& A# @; q重启资源所在节点的haproxy服务:
+ n6 d' G" i- C4 a/ g& R, q( A# systemctl restart haproxy.service* c1 s* T% u; B+ Z! c
# systemctl status -l haproxy.service |
|