WEB开发网      濠电姷鏁告繛鈧繛浣冲洤纾瑰┑鐘宠壘閻ょ偓銇勯幇鍫曟闁稿鍠愰妵鍕冀閵娧佲偓鎺楁⒒閸曨偄顏柡宀嬬畱铻e〒姘煎灡绗戦梻浣筋嚙濮橈箓顢氳濠€浣糕攽閻樿宸ュΔ鐘叉啞缁傚秹宕滆绾惧ジ寮堕崼娑樺缂佹宀搁弻鐔风暋閻楀牆娈楅梺璇″枓閺呯姴鐣疯ぐ鎺濇晝闁靛牆妫欓蹇旂節閻㈤潧浠﹂柛銊ョ埣楠炴劙骞橀鑲╋紱闂佽宕樼粔顔裤亹閹烘挸浜归梺缁樺灦閿曗晛螞閸曨垱鈷戦柟鑲╁仜婵″ジ鎮楀☉鎺撴珖缂侇喖顑呴鍏煎緞濡粯娅囬梻浣瑰缁诲倿寮绘繝鍥ㄦ櫇闁稿本绋撻崢鐢告煟鎼淬垻鈯曢柨姘舵煟韫囥儳绋荤紒缁樼箖缁绘繈宕橀妸褌绱濋梻浣筋嚃閸ㄤ即宕弶鎴犳殾闁绘梻鈷堥弫鍌炴煕閳锯偓閺呮瑧妲愬Ο琛℃斀闁绘劕妯婇崵鐔封攽椤旇棄鍔ら摶鐐烘煕閺囥劌澧柛娆忕箻閺屽秹宕崟顒€娅g紓浣插亾濠㈣泛顑囩粻楣冩煙鐎涙ḿ绠橀柨娑樼У椤ㄣ儵鎮欓鍕紙闂佽鍠栫紞濠傜暦閹偊妲诲┑鈩冨絻椤兘寮诲☉銏犖╅柕澶堝労閸斿绱撴担绋库偓鍝ョ矓瑜版帒鏋侀柟鍓х帛閺呮悂鏌ㄩ悤鍌涘 ---闂傚倸鍊烽悞锔锯偓绗涘厾娲煛閸涱厾顔嗛梺璺ㄥ櫐閹凤拷
开发学院数据库MySQL How To Set Up A Load-Balanced MySQL Cluster -... 阅读

How To Set Up A Load-Balanced MySQL Cluster --Part 1

 2007-11-11 15:44:47 来源:WEB开发网 闂傚倸鍊风欢姘缚瑜嶈灋闁圭虎鍠栫粻顖炴煥閻曞倹瀚�闂傚倸鍊风粈渚€骞夐敓鐘插瀭闁汇垹鐏氬畷鏌ユ煙閹殿喖顣奸柛搴$У閵囧嫰骞掗幋婵冨亾閻㈢ǹ纾婚柟鐐灱濡插牊绻涢崱妤冃℃繛宀婁簽缁辨捇宕掑鎵佹瀸闂佺懓鍤栭幏锟�濠电姷鏁告慨顓㈠箯閸愵喖宸濇い鎾寸箘閹规洟姊绘笟鈧ḿ褍煤閵堝悿娲Ω閳轰胶鍔﹀銈嗗笂閼冲爼鍩婇弴銏$厪闁搞儮鏅涙禒褏绱掓潏鈺佷槐闁轰焦鎹囬弫鎾绘晸閿燂拷闂傚倸鍊风欢姘缚瑜嶈灋闁圭虎鍠栫粻顖炴煥閻曞倹瀚�  闂傚倸鍊烽懗鑸电仚缂備胶绮〃鍛村煝瀹ュ鍗抽柕蹇曞У閻庮剟姊虹紒妯哄妞ゆ劗鍘ч埥澶娢熼柨瀣偓濠氭⒑瑜版帒浜伴柛鎾寸☉閳绘柨顫濋懜纰樻嫼闂佸憡绋戦オ鏉戔枔閺冣偓缁绘稓浠﹂崒姘瀳闂佸磭绮幑鍥嵁鐎n亖鏀介柟閭﹀墯椤斿倹淇婇悙顏勨偓鏍ь潖婵犳艾鍌ㄧ憸蹇涘箟閹绢喗鏅搁柨鐕傛嫹
核心提示:How To Set Up A Load-Balanced MySQL(和PHP搭配之最佳组合) Cluster Version 1.0 Author: Falko Timme <ft [at] falkotimme [dot] com> Last edited 03/27/2006This tutoria

How To Set Up A Load-Balanced MySQL(和PHP搭配之最佳组合) Cluster

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 03/27/2006

This tutorial shows how to configure a MySQL(和PHP搭配之最佳组合) 5 cluster with three nodes: two storage nodes and one management node. This cluster is load-balanced by a high-availability load balancer that in fact has two nodes that use the Ultra Monkey package which provides heartbeat (for checking if the other node is still alive) and ldirectord (to split up the requests to the nodes of the MySQL(和PHP搭配之最佳组合) cluster).

In this document I use Debian Sarge for all nodes. Therefore the setup might differ a bit for other distributions. The MySQL(和PHP搭配之最佳组合) version I use in this setup is 5.0.19. If you do not want to use MySQL(和PHP搭配之最佳组合) 5, you can use MySQL(和PHP搭配之最佳组合) 4.1 as well, although I haven't tested it.

This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

1 My Servers

I use the following Debian servers that are all in the same network (192.168.0.x in this example):

  • sql1.example.com: 192.168.0.101 MySQL(和PHP搭配之最佳组合) cluster node 1
  • sql2.example.com: 192.168.0.102 MySQL(和PHP搭配之最佳组合) cluster node 2
  • loadb1.example.com: 192.168.0.103 Load Balancer 1 / MySQL(和PHP搭配之最佳组合) cluster management server
  • loadb2.example.com: 192.168.0.104 Load Balancer 2

In addition to that we need a virtual IP address : 192.168.0.105. It will be assigned to the MySQL(和PHP搭配之最佳组合) cluster by the load balancer so that applications have a single IP address to access the cluster.

Although we want to have two MySQL(和PHP搭配之最佳组合) cluster nodes in our MySQL(和PHP搭配之最佳组合) cluster, we still need a third node, the MySQL(和PHP搭配之最佳组合) cluster management server, for mainly one reason: if one of the two MySQL(和PHP搭配之最佳组合) cluster nodes fails, and the management server is not running, then the data on the two cluster nodes will become inconsistent ("split brain"). We also need it for configuring the MySQL(和PHP搭配之最佳组合) cluster.

So normally we would need five machines for our setup:

2 MySQL(和PHP搭配之最佳组合) cluster nodes + 1 cluster management server + 2 Load Balancers = 5

As the MySQL(和PHP搭配之最佳组合) cluster management server does not use many resources, and the system would just sit there doing nothing, we can put our first load balancer on the same machine, which saves us one machine, so we end up with four machines.

2 Set Up The MySQL(和PHP搭配之最佳组合) Cluster Management Server

First we have to download MySQL(和PHP搭配之最佳组合) 5.0.19 (the max version!) and install the cluster management server (ndb_mgmd) and the cluster management client (ndb_mgm - it can be used to monitor what's going on in the cluster). The following steps are carried out on loadb1.example.com (192.168.0.103):

loadb1.example.com:

mkdir /usr/src/MySQL(和PHP搭配之最佳组合)-mgm
cd /usr/src/MySQL(和PHP搭配之最佳组合)-mgm
wget http://dev.MySQL(和PHP搭配之最佳组合).com/get/Downloads/MySQL(和PHP搭配之最佳组合)-5.0/MySQL(和PHP搭配之最佳组合)-max-5.0.19-linux-i686-\
glibc23.tar.gz/from/http://www.mirrorservice.org/sites/ftp.MySQL(和PHP搭配之最佳组合).com/
tar xvfz MySQL(和PHP搭配之最佳组合)-max-5.0.19-linux-i686-glibc23.tar.gz
cd MySQL(和PHP搭配之最佳组合)-max-5.0.19-linux-i686-glibc23
mv bin/ndb_mgm /usr/bin
mv bin/ndb_mgmd /usr/bin
chmod 755 /usr/bin/ndb_mg*
cd /usr/src
rm -rf /usr/src/MySQL(和PHP搭配之最佳组合)-mgm

Next, we must create the cluster configuration file, /var/lib/MySQL(和PHP搭配之最佳组合)-cluster/config.ini:

loadb1.example.com:

mkdir /var/lib/MySQL(和PHP搭配之最佳组合)-cluster
cd /var/lib/MySQL(和PHP搭配之最佳组合)-cluster
vi config.ini

[NDBD DEFAULT]
NoOfReplicas=2

[MySQL(和PHP搭配之最佳组合)D DEFAULT]

[NDB_MGMD DEFAULT]

[TCP DEFAULT]

# Section for the cluster management node
[NDB_MGMD]
# IP address of the management node (this system)
HostName=192.168.0.103

# Section for the storage nodes
[NDBD]
# IP address of the first storage node
HostName=192.168.0.101
DataDir= /var/lib/MySQL(和PHP搭配之最佳组合)-cluster

[NDBD]
# IP address of the second storage node
HostName=192.168.0.102
DataDir=/var/lib/MySQL(和PHP搭配之最佳组合)-cluster

# one [MySQL(和PHP搭配之最佳组合)D] per storage node
[MySQL(和PHP搭配之最佳组合)D]
[MySQL(和PHP搭配之最佳组合)D]

Please replace the IP addresses in the file appropriately.

Then we start the cluster management server:

loadb1.example.com:

ndb_mgmd -f /var/lib/MySQL(和PHP搭配之最佳组合)-cluster/config.ini

It makes sense to automatically start the management server at system boot time, so we create a very simple init script and the appropriate startup links:

loadb1.example.com:

echo 'ndb_mgmd -f /var/lib/MySQL(和PHP搭配之最佳组合)-cluster/config.ini' > /etc/init.d/ndb_mgmd
chmod 755 /etc/init.d/ndb_mgmd
update-rc.d ndb_mgmd defaults

Tags:How To Set

编辑录入:coldstar [复制链接] [打 印]
赞助商链接