- 积分
- 16840
在线时间 小时
最后登录1970-1-1
|

楼主 |
发表于 2018-1-13 17:55:46
|
显示全部楼层
内容正式开始前,我已经在集群中添加了新的节点controller1(IP地址为10.0.0.14)。; j# z) S: c6 L( @7 y z, m! e
5 H g; j& P: ?! d % d: b1 y/ S, y( M
1 k0 E( H& a; s, b1 l1 D# M% m! M$ r3 F' g
在所有节点上安装软件:
6 G4 T7 r2 ?& w5 T, }3 W# yum install -y mariadb-galera-server xinetd rsync: D6 b0 @7 Q. b# P
C# {5 N5 e4 ~# W$ ]' e
. z, B( ~2 I: v* o+ ~7 H# L在节点1初始化数据库:7 {% k, X2 N; p
# systemctl start mariadb.service
0 a/ i+ e. X; b) _% G# mysql_secure_installation+ C" Q- l0 E _( k& H- ~
# mysql -u root -p -e "CREATE USER 'clustercheck'@'localhost' IDENTIFIED BY '123456';"
* }. y. P: W" E3 C6 R5 [# systemctl stop mariadb.service
% A T+ }( [, l( T% {, H. C$ [. T% ?( G" u: ~; G! J' q( C; Q; n
9 G& O+ q0 D+ x, |" @) s在所有节点上配置MariaDB和Galera:
, F4 H5 ~$ y: K& S# vi /etc/my.cnf.d/galera.cnf: U8 E7 o$ l7 Z: S
[mysqld]
* c* v6 m) w2 qbinlog_format=ROW
0 T2 [! k* z1 y' udefault-storage-engine=innodb: |8 I- f& F" n3 O: E5 I
innodb_autoinc_lock_mode=2; e1 {4 V1 v" a/ s
innodb_locks_unsafe_for_binlog=1
, {& g& C/ l2 [4 G; W' Iquery_cache_size=0. V) Z- V' y6 w) h
query_cache_type=0- x8 }% M$ X" d# }, b
bind-address=controller1
# _7 U" q4 y/ }! @wsrep_provider=/usr/lib64/galera/libgalera_smm.so3 a8 u/ q8 ]. P# _
wsrep_cluster_name="my_wsrep_cluster"; x% P+ s9 {6 m1 Q3 a
wsrep_cluster_address="gcomm://controller1,controller2,controller3"5 s1 x* G# U4 o2 K9 O2 L% k9 U* J y; S" Q7 ]
wsrep_slave_threads=1, L0 L; R5 N$ f# X
wsrep_certify_nonPK=1
! w+ C2 D2 t4 ], Ewsrep_max_ws_rows=131072
; x6 }! [; Y9 I6 xwsrep_max_ws_size=10737418246 M" X$ x. z$ t
wsrep_debug=0
0 O; a2 }7 I' }0 awsrep_convert_LOCK_to_trx=07 }' t" Z6 n% X) b0 x* z W
wsrep_retry_autocommit=19 l( F# S9 ~! e1 K) |+ N7 Z
wsrep_auto_increment_control=1
+ V2 Z& t+ r: v% k! [wsrep_drupal_282555_workaround=0) J+ T8 |) k. Y/ X8 ~
wsrep_causal_reads=0
+ ]! |& F$ z4 M' E5 ywsrep_notify_cmd=
* a5 U) A# l% R% M" f `wsrep_sst_method=rsync5 F) W: C# {1 w) @& A3 p8 W
wsrep_sst_auth=root:
$ H# H9 Z# c3 p3 [' F9 N& {“bind-address=”配置成/etc/hosts中的本机名称。7 T: T: E' L2 Z: x1 }
注意:如果“bind-address=0.0.0.0”,则在本机所有IP的3306端口进行监听,包括VIP。这将导致后续haproxy无法在VIP的3306端口监听。
6 r/ R% d% t# i/ i
2 m/ _* ~4 o; e. J' _: O6 J$ |0 q+ q% l
在节点1执行如下命令: `; U7 E* O, f
# sudo -u mysql /usr/libexec/mysqld --wsrep-cluster-address='gcomm://' &
2 G. X" x8 O0 p6 b u需要记住屏幕上的进程id,后面有用。
3 k8 K/ S" w$ u3 c
) |: S! e* c; Y$ \" v, }4 y' F) E) {3 y% Y
在节点2、节点3:- b. d, D" K$ t ]+ g8 m/ m8 O
# systemctl start mariadb.service
/ t! n) B2 _& g! S" o# systemctl status -l mariadb.service
. s1 P0 k$ i( h2 B4 n- P& H s) m+ x, ~# V$ n1 H2 C h2 C8 P" ], Z! G
- Z+ e$ X" }& r& a/ J: `' B# P
在任意节点确认集群的成员数量:# g/ R% {- _' h2 m% l! k
# mysql -u root -e 'SELECT VARIABLE_VALUE as "wsrep_cluster_size" FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME="wsrep_cluster_size"'
, ~; f" j! \: j+--------------------+
g! C" E6 F8 X! O* X O| wsrep_cluster_size |
! ~% P. V0 \* r+ V3 Y2 Y! f+--------------------+
& T3 d6 ?9 ?* s% Y1 F| 3 |
) w; D, C% x1 t& s7 S! c+--------------------+( h+ |3 `- M" S' n
8 s' K* z% z$ L
7 }0 K& ?4 N8 P1 B5 }8 c* ~以上状态均正常,重启节点1的服务:5 `- @2 [) f/ ~! Y2 G
# kill <mysql PIDs>; I: f0 C# L+ v2 L0 I$ Y# y
# systemctl start mariadb.service: Z/ S* x" y3 J4 r8 _! x( N. O" F
1 H; |2 P- ?/ n6 m
. c% V7 i# Y5 ]3 x7 u. M
. I8 ~" _7 [* }+ [7 G
5 a. f8 @# r5 n d# I, Y1 G, u8 ^6 L
在所有节点上创建健康检查登录信息文件: W. P- D. I- M" U1 q: j
# vi /etc/sysconfig/clustercheck
5 l; _% o" _3 R& IMYSQL_USERNAME=clustercheck
) @8 \5 A1 S, h, h$ @ UMYSQL_PASSWORD=123456
* X4 P# ?0 _4 H+ h' MMYSQL_HOST=localhost
@* K6 B7 J0 m6 F+ i' j. IMYSQL_PORT=3306
# p) o. x$ c x* F+ b# `6 {* ~- Q
6 v3 F/ r& M, ^: N: E. M( s5 d. D, ^( p+ p7 q, Z
在所有节点上创建供HAProxy调用的健康检查服务:
6 K% h6 N# O) @, S#vi /etc/xinetd.d/galera-monitor& P. |. t* k$ W* g
service galera-monitor$ ~2 z, z/ z+ Y
{/ p2 q$ F( A0 D' d% O% _) X6 V: O( b7 r
port = 9200
2 I# d* x' J$ t0 K4 R2 c) Pdisable = no
, ]4 Z" _4 g: Asocket_type = stream
. o9 d2 K. n' r/ R1 Rprotocol = tcp0 t& |1 g' t- h* Q4 T
wait = no
- [" S/ N- m( t: Y$ u" auser = root
. i- U3 m% K' v5 Y! }7 s; cgroup = root1 e' X6 `: E2 s7 W6 e
groups = yes
6 h/ N" @7 |8 C8 \! Userver = /usr/bin/clustercheck
# X. J1 |: G8 Otype = UNLISTED+ F5 u4 o3 ]! ?& P9 O1 n' G
per_source = UNLIMITED
$ ?* d7 J& U( v+ n3 j: Alog_on_success =
- W9 b* H' q: C6 A- H4 a( Clog_on_failure = HOST; N2 E6 z9 D3 _) s7 Y# j
flags = REUSE
/ O; B' X9 m B3 f. G w}
, x5 l+ U1 _+ [$ ?- T此处检查状态的端口为9200。: D+ A# A9 Z, Z# J/ L
. g" f( v- ^- E" ]/ v- B, C( D$ I+ L) @8 a" h1 v
在所有节点上启动xinetd服务,clustercheck需要这个服务:6 _1 e) c" k; K Z; o
# systemctl daemon-reload0 T; ^1 E7 c: h
# systemctl enable xinetd
& j' g6 ?' b# j$ f7 U4 ?5 g" X# systemctl start xinetd$ x1 O, c0 `" z
$ o z' Y+ C# B$ L8 _: m; z; d
) c1 l. Q( ^. B7 g" h3 d测试检查效果:/ L" D$ u+ z0 `& o
# clustercheck' U) P1 \9 c4 B I
HTTP/1.1 200 OK
4 I% y* a$ G5 P: A: B8 f7 x6 PContent-Type: text/plain
* e8 P$ l ~5 uConnection: close
: _" a6 O: i# [ o4 g5 PContent-Length: 32
( F O3 X7 g* P& i. V* I1 A( J y/ b- Z+ w- a S- b
Galera cluster node is synced.
) X# R. s1 ~( ^( L4 J; W9 Z" _0 c- |8 o$ z$ @
或:) N6 c' N, y( v. `# R' ~( j
# telnet 10.0.0.14 9200
I4 g/ D6 P; [% D J. qTrying 10.0.0.14...- ?, v7 _1 q# d C8 b* q
Connected to 10.0.0.14.. \, t \( }2 X5 D2 e; D
Escape character is '^]'.6 z, p3 q ?; H. `7 Y
HTTP/1.1 200 OK
. F; Y) r& u& IContent-Type: text/plain) O$ b1 N1 H2 {" U. H- O* z2 I
Connection: close) |5 W* A4 [! l+ {. j' Z& w
Content-Length: 32
. D! X; V- p4 b5 O; k
! O, k; w! n+ U% fGalera cluster node is synced.4 u5 O. P$ m4 R* v8 U2 @ i
Connection closed by foreign host.8 N# Y, b; M2 T) T8 u, c6 b
3 \5 b0 B" V- O4 D& q2 Z
5 ^) n, r9 Y( b2 ~$ W8 L0 a8 }
0 q8 H9 g2 D: f2 B/ v. E$ }/ v' i在所有节点上配置haproxy.cfg:! Z5 x2 `7 ]+ l5 Q! O/ _2 L
# vi /etc/haproxy/haproxy.cfg6 n$ q% Q5 q9 a3 c6 Q
global6 E# n; }, g, s5 \9 }
chroot /var/lib/haproxy
3 p/ g' W9 j% m4 d; Tdaemon
$ ~8 N! |7 L0 R2 V5 K- ]. o$ o3 Mgroup haproxy: H" M' E& s$ M% {9 Y& U: L P
maxconn 4000
7 M' p; ^! ~& g; T: opidfile /var/run/haproxy.pid, A2 o1 O* I1 v; `5 C% W: U
user haproxy" u5 t0 N8 h% @- w h8 p5 z q
1 n$ J7 I% r$ C; q; y& e
defaults7 ?& \2 j- P: c9 v4 `
log global
# L) K7 d5 @* _, ? u8 rmaxconn 4000
; N+ L; G- l. k4 B7 |option redispatch
5 V! }' ~# U- l8 }' K5 uretries 3
6 }* ?+ ?1 ?9 @5 L( gtimeout http-request 10s, C5 x& Y" U8 F/ Y6 j
timeout queue 1m
, j% S7 P$ t8 |+ x2 {( Mtimeout connect 10s8 M, U8 ]! A, D& V* G. p1 s d, r
timeout client 1m
3 D% `# d U3 a# D5 gtimeout server 1m
) R- M) w a" q2 }5 o8 Q; L6 ctimeout check 10s
! o2 ^$ l9 W3 J& y. b7 i; Q! I/ C# F/ _9 i$ W! {3 m; x6 x
listen galera_cluster
X9 q a6 c3 q4 \1 I) o( Obind 10.0.0.10:3306
9 y$ J8 a$ e4 G4 p7 e. T- m( Pbalance source
( W7 B4 N& j7 z; n) p+ V7 {option httpchk
/ F2 k, w r& c- T. |server controller1 10.0.0.14:3306 check port 9200 inter 2000 rise 2 fall 5; K- D& J. ~$ F, p) Y5 x% d
server controller2 10.0.0.12:3306 check port 9200 inter 2000 rise 2 fall 50 X0 S- P, ]8 z4 o4 a) u
server controller3 10.0.0.13:3306 check port 9200 inter 2000 rise 2 fall 5 s6 u+ H% R- n5 R! Y, w: r
; [. d3 a1 D7 e: Q0 v4 K4 n& ?9 W3 _1 v5 k
查看资源当前在哪个节点:1 U; q: k' z5 V) e5 R
# crm_mon
1 b9 d6 }% A. }2 o; n6 t6 y! |; L4 t
4 [" @. f- D1 k, \& W重启资源所在节点的haproxy服务:; P0 x6 z# y) u+ ]
# systemctl restart haproxy.service
7 B4 v3 ^' i; B9 T. ~$ _2 F# M# systemctl status -l haproxy.service |
|