|
|
楼主 |
发表于 2018-1-13 17:55:46
|
显示全部楼层
内容正式开始前,我已经在集群中添加了新的节点controller1(IP地址为10.0.0.14)。
- U0 j8 g; {( F& i2 ^* @! P6 n+ f+ u |/ m1 B$ g6 x
) X3 G7 N s& m4 A$ d9 a4 o. Q: |, s; y& d; i6 g
5 I; j+ ~. J: z在所有节点上安装软件:/ K+ s& j2 ]& ?! n2 m. ]
# yum install -y mariadb-galera-server xinetd rsync, k: I) |$ Y+ W7 o3 a- W5 z
8 A$ M1 y/ Q3 K. S
% R' |# `8 j8 l4 o* Q在节点1初始化数据库:
' ?! }% j: n& V! y2 k$ W6 b Z# systemctl start mariadb.service, q( J0 ~, O0 m7 n( U
# mysql_secure_installation" `) y0 Q& a8 E9 o4 l5 a3 Q6 P
# mysql -u root -p -e "CREATE USER 'clustercheck'@'localhost' IDENTIFIED BY '123456';"
7 N8 E3 A } i6 V* d$ G# systemctl stop mariadb.service; d- ?; a6 T# U) T
8 I* {+ h2 m: G! V# f9 @
; ^$ K6 A. U0 f4 M
在所有节点上配置MariaDB和Galera:
E# o% l w8 ~# vi /etc/my.cnf.d/galera.cnf$ ~! i( y) ~9 k. E1 n/ G \8 D' V+ x
[mysqld]
2 {1 g, b" ?2 X0 `6 Ebinlog_format=ROW
! o6 H* b% B* r6 H$ ~) j: d+ I2 Jdefault-storage-engine=innodb
" {3 Z; T Y r# Q; Qinnodb_autoinc_lock_mode=2
; C5 X% p ]. k4 r/ V vinnodb_locks_unsafe_for_binlog=1! |0 W6 `4 a9 _; {8 b" `
query_cache_size=0
. W7 d' \, N+ n8 c5 w+ \6 Uquery_cache_type=0
! @, o# D8 v8 n! l! k0 rbind-address=controller1$ E4 W9 M2 D) y" I/ e
wsrep_provider=/usr/lib64/galera/libgalera_smm.so! A" O) u2 v% _! N/ E0 J. J E. w
wsrep_cluster_name="my_wsrep_cluster"3 B6 _7 B) y2 l a
wsrep_cluster_address="gcomm://controller1,controller2,controller3"
, {/ {# ?3 ~ R( D% [" `* Pwsrep_slave_threads=1
6 t! X3 m0 t2 D# U7 Swsrep_certify_nonPK=1& D& K3 ~3 q$ q$ b5 b
wsrep_max_ws_rows=131072
% R$ |. e7 I, }0 jwsrep_max_ws_size=1073741824
T. a s# G& b7 N3 ~* Q& c- b4 G$ `wsrep_debug=0
- F) m( i1 T9 y% z9 Jwsrep_convert_LOCK_to_trx=0
% S. X- d! ^" e! uwsrep_retry_autocommit=13 p0 B w: e8 t( r3 p4 x
wsrep_auto_increment_control=19 \5 ^2 s7 }* x A8 T
wsrep_drupal_282555_workaround=0+ }* Q8 P5 D, a. @+ e1 y% t. H' f* s8 F( P
wsrep_causal_reads=0 ^: E( o I \1 ~. O
wsrep_notify_cmd=( N! W: B; c2 @, R8 i& s4 ~8 F
wsrep_sst_method=rsync
5 ?3 K' |' ^# D) |7 I" iwsrep_sst_auth=root:# |; W5 x- V! T
“bind-address=”配置成/etc/hosts中的本机名称。
9 h5 {" G7 @% n# z* B1 ^8 ~% C注意:如果“bind-address=0.0.0.0”,则在本机所有IP的3306端口进行监听,包括VIP。这将导致后续haproxy无法在VIP的3306端口监听。
0 G5 ? f; \2 ^& G- z8 E. t3 x, B/ X6 Q2 F7 C
' j' h: U+ e0 T在节点1执行如下命令:
, p# f. @4 V8 H8 } ~# sudo -u mysql /usr/libexec/mysqld --wsrep-cluster-address='gcomm://' & Z% \; n9 }3 Q
需要记住屏幕上的进程id,后面有用。0 @' E1 |, D3 B- p$ R# Q) g
+ L4 {. o/ q3 B: Q' P! R% j7 o3 ^) x4 x
在节点2、节点3:
5 F9 m" A- l: w! _. E0 v. i# systemctl start mariadb.service
6 K: {2 ^6 s3 d+ N& L' a9 `# systemctl status -l mariadb.service
* Z2 p/ l! [0 E" C6 _; h: s; ?; o$ w
0 A" I0 V9 O9 y9 W2 y: d4 E4 `: W在任意节点确认集群的成员数量:) b5 P- X" ?1 c/ S$ m
# mysql -u root -e 'SELECT VARIABLE_VALUE as "wsrep_cluster_size" FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME="wsrep_cluster_size"'
& g' [4 f7 ]* |) |6 {+--------------------+4 W' S n$ W b3 c P& z
| wsrep_cluster_size |* f# `" f, w0 A% P0 K9 [: l
+--------------------+' J" n% F8 D& X4 k8 F! M
| 3 |
7 a* v% N8 Y6 ~4 V6 d! E+--------------------++ `; `0 x( z/ n4 Y% i( p
/ L U$ L) S: I+ S4 c V/ ^' h4 |) ~$ |+ e/ r- \# S' B
以上状态均正常,重启节点1的服务:6 P" ~, ^1 u9 i
# kill <mysql PIDs>
1 S" H4 B4 j v7 ^" ?# systemctl start mariadb.service
4 S5 h8 ^" k) b- \, D+ n e6 F- M& n1 e5 h. M% d% r
& q/ x$ H Q, X# q. }2 c ?8 s, \' N4 H6 ] V* O
7 q0 ?% L2 H3 W; a! G3 i$ l5 Z$ p2 W/ @" K0 H {, ^
在所有节点上创建健康检查登录信息文件:
2 {* T7 D; ]: u# vi /etc/sysconfig/clustercheck
6 ^% H4 {/ `. x* a8 Q6 ~# M2 tMYSQL_USERNAME=clustercheck
4 u0 r* A o8 w! y7 O9 uMYSQL_PASSWORD=123456
2 e! I" A: ?7 P5 x" A) i/ Q( AMYSQL_HOST=localhost
7 J# X" {" n; I% U0 qMYSQL_PORT=3306
* {$ s+ J/ `5 d" u- P* X1 o& W8 I" P& f) X/ \
; h8 J% `( g3 E+ t在所有节点上创建供HAProxy调用的健康检查服务:
; l5 G) j+ u/ L4 j) ^#vi /etc/xinetd.d/galera-monitor& V0 U% ~/ U c) R2 a
service galera-monitor3 `) |5 O& ~3 x, K( n7 c/ K6 Y
{( d4 Z. t& B; d1 J; x2 u5 H
port = 9200
7 x$ Q( v; S& |. V% ddisable = no3 ^. u1 }2 T* V8 j
socket_type = stream
9 M1 i) p! Z1 y- Mprotocol = tcp/ \+ {4 i' ^& e
wait = no6 h( ]8 u* L. v1 g- h y3 I
user = root8 K3 p) B9 [/ V
group = root
# Z5 E7 a% k+ d5 [, ^$ Zgroups = yes: G5 f0 ]- t+ W& E" y3 v
server = /usr/bin/clustercheck
2 ^8 {/ T8 f1 I6 F' u. Z g. i& W2 c9 [type = UNLISTED
8 r) u, a7 D& C4 z1 |1 A/ lper_source = UNLIMITED
& v- `+ F# s" H1 j+ glog_on_success =
. [: O- i. A" j- xlog_on_failure = HOST
5 b- G5 J7 y$ B1 aflags = REUSE8 n# b4 ^1 z+ T6 u. o% O+ S$ A
}
. `; L1 M. w9 j) w/ Z* V6 s7 e此处检查状态的端口为9200。
7 R8 Z' M! \* r3 W& ^; y
, S( W2 v7 [6 C- {
; j, T) X$ Y T; r在所有节点上启动xinetd服务,clustercheck需要这个服务:
* u) X. p! [# q7 R- J ^. P# systemctl daemon-reload& T% N$ b7 g7 t# `% ?
# systemctl enable xinetd4 x9 s& I; f6 G( ~
# systemctl start xinetd0 V* G! b$ E u; A6 M# V/ i
, Q; e6 k+ H4 I. h3 w; ~- q
6 w# k( Y: ^, _+ M# x3 d1 [
测试检查效果:
8 S# V9 J: j$ m- n9 m" M; q. k# clustercheck
# N1 {0 u) x0 n' u8 h4 ^" nHTTP/1.1 200 OK5 O4 ~3 ?7 K7 o
Content-Type: text/plain4 W: I; B5 e7 R1 S6 W4 i
Connection: close7 [; _; [# s7 k" S( f
Content-Length: 326 s( f$ B, O2 T
& G( |% a" r# ^4 L
Galera cluster node is synced.4 t% k( \7 ~" ^& S& b; _! r
' @. t, H# l1 l1 K* M$ |3 l
或:
o5 I+ `( x" c8 [# telnet 10.0.0.14 9200$ b' _' Z: Z# A9 Z& q
Trying 10.0.0.14...+ T" ^7 [2 h" v5 N1 w' O7 H
Connected to 10.0.0.14.. W# V2 K- }# Z
Escape character is '^]'./ @" R3 v% r, m' V6 U
HTTP/1.1 200 OK* f O- Z( g5 ?& Y
Content-Type: text/plain' j$ Q. \/ n, C$ O1 l# b
Connection: close" i8 z; k+ k$ p3 {2 ^2 o( }
Content-Length: 32
) i7 [+ R4 O: R, O! f7 d
- \5 r3 J4 o5 z: I9 Z' Z0 ]" OGalera cluster node is synced.8 V M" b" C: w8 s d' q
Connection closed by foreign host.2 ]" d& f. B# p
# M6 ]1 [) Q; p9 {2 L0 T
1 y. U$ D9 l8 Q( G6 c( l
. t6 d6 d7 F- t( F# N ^/ I在所有节点上配置haproxy.cfg:
+ b# G) \& Z. g! I1 G9 W+ Q# vi /etc/haproxy/haproxy.cfg- h, k2 f5 D. O0 g: @' j; F6 e8 H5 o
global, d" s/ X* @% X) j
chroot /var/lib/haproxy
! O% X7 r& P n: @& T1 b9 Zdaemon: T' S, R9 A7 N
group haproxy
7 m* Z7 O& G, F9 e* k. Umaxconn 4000
- E. v6 |5 [9 U6 S; E5 ]pidfile /var/run/haproxy.pid+ h( Q8 ^+ k; F$ H. q9 }6 R$ [
user haproxy
* ]1 B0 W- I8 N7 r. i: n/ b& {; ]" f. W' }: G M4 J
defaults
) N0 c! g( P7 ?( _log global
+ [* I) S$ }, P O* C6 m) Umaxconn 4000& P! w5 E* ~8 M4 ?
option redispatch& G# w% t( g7 I& G1 Z1 Z; K
retries 3
2 h+ L5 R3 A- x. btimeout http-request 10s( \* Q9 T, o& I F
timeout queue 1m
9 c2 i) s& Q/ A+ ^4 btimeout connect 10s3 m1 d) y: b/ s/ l" d0 t
timeout client 1m
' B2 G' ~5 n5 B+ \( a6 ]; H- T) Ltimeout server 1m- ?5 E2 a& O) }! u
timeout check 10s
) Z. f( l% Q( @) b( n& _
' Q Q" C7 V% }$ l9 G* C- \listen galera_cluster
4 |7 }) W( W' h) h' |7 i2 I. Wbind 10.0.0.10:3306
3 ]5 A4 }$ f) I* b2 t3 abalance source" |. S: V( d; T9 W
option httpchk
; }* ]6 j, T4 z0 a4 ?9 Wserver controller1 10.0.0.14:3306 check port 9200 inter 2000 rise 2 fall 5' z. V; Y8 m( J' q& G, D$ c
server controller2 10.0.0.12:3306 check port 9200 inter 2000 rise 2 fall 5
8 m9 p% G) O( i1 Gserver controller3 10.0.0.13:3306 check port 9200 inter 2000 rise 2 fall 5+ h/ n8 c! m' C( _+ v$ \/ g
+ w) A- Y- `" l1 ^/ r& J( v" r) t( `. V$ N
查看资源当前在哪个节点:. n7 Z- q1 s2 z- F* Q' r* k4 i
# crm_mon( b' E/ {1 S! D& R
- Q% H4 H# ]/ i J. V
7 L& t9 `& T% _8 v1 U重启资源所在节点的haproxy服务:& g% q- a6 I; M0 t) K- `9 k
# systemctl restart haproxy.service
+ _4 t9 n+ A- h9 @7 W# systemctl status -l haproxy.service |
|