a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 153|回复: 2

[红旗认证] 高性价比开源软件集群之MySQL集群

[复制链接]
发表于 2012-8-4 12:16:06 | 显示全部楼层 |阅读模式
 mysql集群由三部分组成,治理节点,存储节点,SQL节点.模型图如下图所示:0 @" }9 j- g& {0 c6 i7 k1 R
  治理节点顾名思义是用来治理存储节点和SQL节点的,存储节点和SQL节点都要与治理节点通信,SQL节点用来与应用程序通信,也是对外的接口,应用程序只能也只需访问它,存储节点用来负载均衡存储数据,而所用的存储引擎只能是NDB.一个集群至少由这三部分组成,每部分至少由一个节点组成,当然也可以把这三部分配置在一台电脑上,而且也可以只运行一个mysqld,ndb_mgmd,ndbd,mysqld三个进程在一台电脑上运行就能实现一个目的.我们继续.
, R  f% Z( [- E. R5 [  mysql的安装:2 A3 i1 P, }% T1 e
  网上不少资料以及mysql官网上都说要一个max版本的mysql,其实现在,到官网上随便下一个二进制的server版就行了,现在的server都包含了必需的工具.假如自己编译源码就比较麻烦了,默认情况下,源码编译后是不包含集群的工具的,要自己单独再集群需要的源码再编译才行.这里我们采用第一种方法,直接二进制文件.
. w7 c, S' }7 P. }- b  后请执行下列命令:9 F8 o( b. t% R
  groupadd mysql
8 t: V9 M, s! \  u  useradd -g mysql mysql: j/ Z6 S8 D+ {
  tar -xvf mysql.tar.gz
! ^1 c* M: F8 d3 n) r) ]  cd mysql; v1 C1 [2 `1 e% j0 i8 R! s
  scripts/mysql_install_db --user=mysql( U" ]$ h, U( d
  chown -R root .
% e8 |; f* ~4 K6 Z: E  chown -R mysql data3 R5 F5 h' [4 Q  X" e) G( Y) U% H0 T/ S
  chgrp -R mysql .: _: M% Y" P# F( k
  bin/mysqld_safe --user=mysql8 `( z6 p( ]& x
  注重,在执行上述命令或mysql命令的时候可能会出现一系列的错误,这主要有两个可能,一是权限问题,二是一定要在mysql主目录下执行scripts/mysql_install_db --user=mysql和bin/mysqld_safe --user=mysql 假如你在script或bin或下执行mysql_install_db --user=mysql和mysqld_safe --user=mysql 都可能出现错误.
/ q7 G/ q4 I5 n7 n' b" j; T  配置文件:
# _0 U5 s. t, d3 T" ]& i8 B  配置文件主要有两类,一是治理节点的配置文件,二是普通节点的配置文件.这里附上我的配置文件.
# x/ ]& r3 |3 l  config.ini; X2 ]% f( A; H2 q# @
  my.cnf8 h( ^. f$ n7 I' k4 w
  config.ini中,[ndb_mgmd]指明治理节点的地址 [ndbd]指明数据节点的地址 [mysqld]指明SQL节点的地址) H& Y! x  x/ S
  my.cnf中,[mysql_cluster]指明电脑上的mysqld,ndbd都公用这个配置,当然也可以分开配置,[ndbd]指明ndbd进程使用这个配置, [mysqld]指明mysqld进程使用这个配置.示例配置如下:
" g: s  V1 C/ e  config.ini
2 Y) u' P# u$ L- C) S" z5 ?( r' M  #ExampleNdbclusterstorageengineconfigfile.3 ]" y" ^- d+ h/ \/ e  c* q+ U- R) @
  #- I0 t# v4 w7 I0 K8 q
  [ndbddefault]
) y( L# K5 I3 N1 I. k  NoOfReplicas=2  N# K8 e: T2 m7 l( w
  MaxNoOfConcurrentOperations=10000
4 X* l( ?8 F1 g" R% l7 f  DataMemory=80M
4 A/ P# Z# i# u, |  IndexMemory=24M
( o, t7 z- L# o3 ~0 ~  TimeBetweenWatchDogCheck=30000& W4 _! C. k/ W% _
  DataDir=/var/lib/mysql-cluster* @2 [3 {1 D& h5 r4 ^
  MaxNoOfOrderedIndexes=512* O2 g2 D) G+ G# Q
  [ndb_mgmddefault]
* S5 g# |- k! y6 w7 W, G2 L. @$ k  DataDir=/var/lib/mysql-cluster& c( s4 q* e! d) o
  [ndb_mgmd]: c4 V$ K/ l- f4 X% Q9 ^, V
  Id=17 k8 D0 _7 r7 h! }4 y- l! Q
  HostName=202.115.138.47
1 O3 C  s; d. J5 ~" ~2 g4 \  [ndbd]: D. g' f/ F) H% }( E
  Id=2
% ?# t9 A1 F3 i  HostName=202.115.138.217
$ T) R+ v8 B4 d$ q! e; q  #hostname=localhost. Y% b$ u7 L- F4 r
  datadir=/usr/local/mysql/data, I5 }+ Z+ U1 l; d$ Y# v5 L7 q
  [ndbd]$ i4 M# a7 c" X% Q  D9 y
  Id=3; b) K, \$ ^* s$ }8 [3 X+ k* [! z, G
  HostName=202.115.138.47# f* c' t5 w7 ~) K
  datadir=/usr/local/mysql/data
; _! M' F4 A/ Z6 K  [mysqld]' ^+ O, f7 x1 ?2 ]% S, t$ T* |
  Id=4) X3 A! [+ z& o% i# O
  hostname=202.115.139.47
- {$ K. I1 k+ v' K% m7 E  [mysqld]
" X. }; e$ i# t; ]. @( V1 R  Id=5
+ z& P# l' c6 g! y5 b$ L. `  [mysqld]
0 P3 ]% Z% |4 v% T7 a1 E, D  Id=6
- J" }0 x+ |, E  [mysqld]) V7 j7 P/ R7 s0 W8 X* K2 L- v
  Id=7
回复

使用道具 举报

 楼主| 发表于 2012-8-4 12:16:07 | 显示全部楼层

高性价比开源软件集群之MySQL集群

  #chooseanunusedportnumber
, {1 ]. F' f+ e) ?  #inthisconfiguration63132,63133,and631343 o$ d4 F3 `# H. r7 ]! l
  #willbeused, S! q3 y2 H6 e+ W0 _& c% {; V
  [tcpdefault]
4 y4 V, \# E: E9 U) l0 Z1 o1 f  PortNumber=631326 `5 a, v8 q9 ^# b. D) R! U$ x
  my.cnf
0 V' y) @0 K, s& o+ m8 W4 ]) L  #ExampleMySQLconfigfileformediumsystems.
) g9 s, ?  ?  q. r% h5 D  G  #
4 P2 X5 K& o1 v& j3 F  #ThisisforasystemwithlittlememorywhereMySQLplays
% j9 ^6 t% d' ?) m- C' o  #animportantpart,orsystemsupto128MwhereMySQLisusedtogetherwith
, t' K' t' e. u& |" C  #otherprograms
8 M; m6 I% ]% j& L) Z7 V  #. \" K& b5 V2 j$ A
  #Youcancopythisfileto
! k4 R( ]; }0 Z4 B! q  #/etc/my.cnftosetglobaloptions,
! Y( k; _$ X5 m4 s7 I  #mysql-data-dir/my.cnftosetserver-specificoptionsor
* X& T2 G! o" N6 o) M  #~/.my.cnftosetuser-specificoptions.
. D& Q3 ?; Y: J+ n  #  A' G9 _! A& U
  #Inthisfile,youcanusealllongoptionsthataprogramsupports.
# c1 j6 r6 C) Y# r2 r5 Y/ n  #Ifyouwanttoknowwhichoptionsaprogramsupports,runtheprogram, W. G# F8 q+ Z% u
  #withthe"--help"option." J' O) Z3 @9 |& Z* W0 h( E1 y! L
  #ThefollowingoptionswillbepassedtoallMySQLclients% H4 U/ y  S. h8 G9 D* Z
  [client]
. _$ N  }* {) U* F3 G! G. z  #password=your_password
# D2 E. P9 |0 ~6 B9 \4 c, d  port=3306, B% C0 P8 Q* J: b- s8 X5 N/ `; ]( N
  socket=/tmp/mysql.sock
3 d- q& a/ |* g% q- m  #Herefollowsentriesforsomespecificprograms
: q. M- T; t8 B' i  [  #TheMySQLserver
4 e7 i* _6 c4 q, u1 L) o: K9 s  i  [mysqld]
$ x8 \8 A6 C! ]  port=3306$ M1 a7 U- |( _1 d  j) g
  socket=/tmp/mysql.sock
; `  z5 A" O/ i7 _5 r  skip-locking+ o# m. R' q" ?2 @% v! z
  key_buffer=16M9 S3 ~, K& f, u* Y# n1 M, G2 U
  max_allowed_packet=1M! o& ~" q. O' h  G0 s: W
  table_cache=64
) I6 w' a, S& Q5 k/ E: Q  sort_buffer_size=512K1 _  R8 J( w  Q
  net_buffer_length=8K0 B6 G) F! x/ S4 m/ _. x0 G
  read_buffer_size=256K6 E3 a% Y* s* t+ E5 A
  read_rnd_buffer_size=512K
! X5 D* D1 ?. S+ n+ B" D: T  myisam_sort_buffer_size=8M
' @" {: U8 F$ B# z" S( k) Z  #Don‘tlistenonaTCP/IPportatall.Thiscanbeasecurityenhancement,! W) w" ?& w2 p& N" q) ^
  #ifallprocessesthatneedtoconnecttomysqldrunonthesamehost.% @: X% _* H' M1 C
  #AllinteractionwithmysqldmustbemadeviaUnixsocketsornamedpipes.
* h: ~' H$ C3 z  #NotethatusingthisoptionwithoutenablingnamedpipesonWindows
) c3 f5 G- B8 b  #willrendermysqlduseless!
* c( ]  V/ m- {1 F  P( o2 l. {% m  #
0 ~* X+ y9 \' q+ g  #skip-networking
( v; z+ r; H: o+ E  ]  #ReplicationMasterServer# j7 _' ^8 t; D+ n0 v7 L
  #binaryloggingisrequiredforreplication1 K" L: Y0 X( X: E9 ~& H$ I
  log-bin=mysql-bin
7 m8 _  g0 i. y  P  #requireduniqueidbetween1and2^32-1
5 r% a' u( r; O0 Q; H  #defaultsto1ifmaster-hostisnotset
. W1 k6 ^' ?2 C3 Q- l  #butwillnotfunctionasamasterifomitted
! l8 [$ N% P6 Q6 Y& @  server-id=1
/ a8 k9 ~, h5 L7 C  #ReplicationSlave
. i$ L5 K% N& i/ q( z+ J3 Z2 T8 r  #0 t/ k5 V1 H9 N; f, u1 A
  #Toconfigurethishostasareplicationslave,youcanchoosebetween
; t& w3 k: r6 |4 P# A  #twomethods:
( k% H  s+ ^; h- S& z. h* O  ## {, b7 Y/ j* P1 U. S4 s) x6 W/ D! B
  #1)UsetheCHANGEMASTERTOcommand-
& D' m4 o" L3 W' h4 k0 w5 G' ^  #thesyntaxis:
  w1 V; D# s( m8 s2 P  #
0 K. D3 S4 d. I. ~' W  #CHANGEMASTERTOMASTER_HOST=host,MASTER_PORT=port,3 y- f; ~. Y9 D' k+ n" Q
  #MASTER_USER=user,MASTER_PASSWORD=password;
1 t7 m% f, c& F: I/ x  #
2 D/ K( A: s5 M9 X  #whereyoureplacehost,user,passwordbyquotedstringsand" k4 b# U, Q0 k, ?# {
  #portbythemaster‘sportnumber.
  _3 T& U; x; U' i' c+ H3 V  #  x+ }5 B" S1 E1 X) J. }
  #Example:+ B& C* r5 _/ E* `) F- {
  #9 A! @9 x: H7 c) h
  #CHANGEMASTERTOMASTER_HOST=‘125.564.12.1‘,MASTER_PORT=3306,
1 m6 z: _7 e: [" \, j  #MASTER_USER=‘joe‘,MASTER_PASSWORD=‘secret‘;
( }4 o! d+ G! I$ M* j2 Y  #
- C: G% d% v1 e$ v3 x  #OR& h7 q5 v$ w! b% M0 g
  ## ]: Z6 \  g; ?+ A: O( c
  #2)Setthevariablesbelow.However,incaseyouchoosethismethod,then& N9 |1 r. U4 c+ i0 t, w% l
  #startreplicationforthefirsttime,theslavewillcreateamaster.infofile,andanylater
1 K" d  a" \* s, l7 [  #changeinthisfiletothevariables‘valuesbelowwillbeignoredand+ Q& L6 q. D2 e9 V/ u
  #overriddenbythecontentofthemaster.infofile,unlessyoushutdown
4 |4 ]/ `5 R2 W* b* m1 t/ f9 a- r  #theslaveserver,deletemaster.infoandrestarttheslaverserver.
; ?3 `% m+ f4 F. D3 S  #Forthatreason,youmaywanttoleavethelinesbelowuntouched8 ~9 ]1 l  Y9 j
  #andinsteaduseCHANGEMASTERTO! n+ I! R8 c4 \( `5 w' w
  #/ G( V) a) R, E6 j; P
  #requireduniqueidbetween2and2^32-1
9 M: \5 _5 m) M" O) K! ~  #
: m: U/ L! ?" [7 v' ^7 j, N% h. s  #defaultsto2ifmaster-hostisset" [6 _+ ~2 Q' B$ ?) J) g1 _& [
  #butwillnotfunctionasaslaveifomitted</p>% P: L& A8 G2 e! o4 S8 S+ m" m
  #server-id=2; w6 o4 h6 D4 z4 _7 [5 J  ]
  #9 T' X3 D5 n4 k( s5 m& O2 n* g
  #Thereplicationmasterforthisslave-required
  R+ P- I5 S9 G' f# b( z5 j  #master-host=hostname
# W; q& s) O! o: b9 Z% U* a  #
# D/ V6 Y7 Q! e; }, }! \5 U( n- d  #Theusernametheslavewilluseforauthenticationwhenconnecting
. k* v2 H4 w4 @8 R( v# w  #tothemaster-required
$ O" ~- P. z6 D/ e6 c  #master-user=username0 d3 @, Y7 @( Q+ ?
  #
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-8-4 12:16:08 | 显示全部楼层

高性价比开源软件集群之MySQL集群

  #Thepasswordtheslavewillauthenticatewithwhenconnectingto% i% K9 ]  Y8 ]5 l0 O# T
  #themaster-required
: l4 o+ [" f" n; t, u! Q  #master-password=password
3 t  Y4 z) H$ I/ f  #
2 }+ X$ }3 W0 k+ s  #Theportthemasterislisteningon.
9 T' J% F8 ]% X8 d5 J+ \  #optional-defaultsto3306# C4 Q( M4 P& S+ x! \4 D
  #master-port=port
2 m% {4 W% I3 c/ P  #  E" j5 `- X, q
  #binarylogging-notrequiredforslaves,butrecommended2 D$ X4 F  E7 I& G/ Z- X
  #log-bin=mysql-bin* w6 U& l1 z7 k1 u$ @. V
  #Pointthefollowingpathstodifferentdedicateddisks
  c/ T2 ]6 g0 b2 c  #tmpdir=/tmp/
: u4 [' C" C! p5 @2 u$ O  #log-update=/path-to-dedicated-directory/hostname
: ^9 H$ h) n! V  #UncommentthefollowingifyouareusingBDBtables
; _- G( y! d" g6 O  #bdb_cache_size=4M
8 R3 b/ w) {0 J1 M7 n: F. i  #bdb_max_lock=100007 H3 [5 t/ r" t5 c* A
  #UncommentthefollowingifyouareusingInnoDBtables; l- p7 P7 ?( k# A  q1 |
  #innodb_data_home_dir=/usr/local/mysql/data/3 r) [: ^9 w4 M4 d# s' Q; A# S
  #innodb_data_file_path=ibdata1:10M:autoextend/ i& \8 S0 U* O3 W) t
  #innodb_log_group_home_dir=/usr/local/mysql/data/7 M( y- }( @: _/ n, x% A
  #innodb_log_arch_dir=/usr/local/mysql/data/
, h, N. T. i, y  N  #Youcanset.._buffer_pool_sizeupto50-80%, M0 V5 @( m# U6 J0 K
  #ofRAMbutbewareofsettingmemoryusagetoohigh
1 s) _# Q5 o2 E* b. h* Q  #innodb_buffer_pool_size=16M1 S: S8 ]2 D! ~4 h6 p' \
  #innodb_additional_mem_pool_size=2M0 f- q5 c4 o. U
  #Set.._log_file_sizeto25%ofbufferpoolsize6 V# ~6 J$ q5 ^% @
  #innodb_log_file_size=5M) c: ?3 t6 \2 V
  #innodb_log_buffer_size=8M
% w( x/ E! ]1 e, @  #innodb_flush_log_at_trx_commit=1
% M& Q; v9 T1 ]' l  W  #innodb_lock_wait_timeout=50
9 C2 `  u0 z& }, g7 S4 g. j  #addbyendall
. A% s: I; B) q- O; H4 P  [mysqld]
% {9 E' z3 W3 {, p2 i  ndbcluster4 j0 x& m+ H/ R8 I2 h4 [! t  v! n3 L/ H
  ndb-connectstring=202.115.138.2170 M7 b4 f9 b9 v& q- k+ C
  [mysql_cluster]
3 h8 D9 B4 P$ @$ F- x/ r' D0 L  ndb-connectstring=202.115.138.217  M# E5 Y6 X# K. b
  [mysqldump]
$ J, S6 L5 L5 @- d4 g' ~  quick
4 }, Y8 |% t9 U* D' U8 f' F1 I  max_allowed_packet=16M: o$ E; g8 _3 i/ \' l0 U
  [mysql]
/ A6 m. \% V) a  no-auto-rehash
3 d( }+ w; }  \7 W  #RemovethenextcommentcharacterifyouarenotfamiliarwithSQL; `0 i: @5 E' W
  #safe-updates4 g& `$ j& c, C, e( U/ q/ j
  [isamchk]
& Q5 m" Y/ b+ v; j6 m  key_buffer=20M
! g  b6 v% @0 _2 d- ?' j  sort_buffer_size=20M' z7 s( m. g. M7 m7 ~
  read_buffer=2M
& j. ~3 x! v+ x  ^& d/ `/ J  write_buffer=2M
& r* H2 _+ a" D+ c  [myisamchk]3 {/ n2 S+ c, X" J3 B/ ^8 S* n
  key_buffer=20M$ g3 F- D4 C) [$ H  |, T$ ^3 }- {
  sort_buffer_size=20M
3 B) X9 G% r: L5 t! m) [  read_buffer=2M; n- O4 A" c9 X
  write_buffer=2M( P6 l& Z+ a6 y- B2 [- w8 L! e5 C, A
  [mysqlhotcopy]" J. a8 u2 ^' Z; P: C8 D8 Y9 U9 d
  interactive-timeout
. {" H2 O: I& Z: ?6 \8 _$ y; ?, n  注重.config.ini中指明了所有的数据节点和SQL节点,它将治理这些地址,数据节点和SQL节点中都指明了治理节点的地址,它们通过它进行与治理节点的通信,但SQL节点中并没有指明数据节点的地址,所以它通过治理节点来与数据节点进程通信.3 V. `+ H: |7 z4 A
  mysql群的启动:3 h& d3 L& {( p" I
  1.启动治理节点:
% W' F4 m* c4 b' I  ndb_mgmd -f /var/lib/config.ini
, |' P& b# ~) z2 N& Y) y0 s  2.启动数据节点:* H2 h1 H3 m1 j. T3 W# E
  ndbd --initial
3 z9 @" }: g. ^/ s+ `9 c! Q8 ^6 l  3.启动SQL节点:2 w5 _$ T, s* D) h
  mysqld_safe --user=mysql" j% b/ {  v  ?" S
  4.关闭群:
+ k6 f+ X' I/ Y! y4 T: J  ndb_mgm -e shutdown
7 ]( r" z  C6 c  它将导致群中ndb_mgm,ndb_mgmd ,ndbd进程暖和的结束.
" D$ \" J" d( e! H* h9 }) r* Q  测试:
4 C: X  N* Q9 h. E/ ?: |  ndb_mgm
3 P4 S5 |9 i5 {5 Y  show</p>
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-2 22:06 , Processed in 0.372217 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表