mysql的cluster&replication結合

爲了設計一個合理的 MySQL Cluster To MySQL Server 的Replication 結構,
既能滿足現有代碼的修改量,又想能提高系統的併發註文量,
經過幾周的摸索,設計以下的結構:
http://blog.chinaunix.net/photo/33594_081104223443.jpg





33594_081104223443.jpgscreen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" οnmοuseοver="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" οnclick="if(!this.resized) {return true;} else {window.open(this.src);}" onmousewheel="return imgzoom(this);" alt="" border="0">


http://blog.chinaunix.net/photo/33594_081104223443.jpg


爲了應對我們的交易系統中非常高的併發註文的能力,
特設計了一下的結構:
特點介紹:
1,採用 MySQL Cluster  To  MySQL Server  的Replication 結構。
   將MySQL Cluster 的併發插入能力 在 Cluster上發揮,將許許多多的
   Join 查詢扔到Slave 上進行查詢,也是揚長避短吧,雖然有些延遲,但對此要求不高的
   就可以直接在Slave上查詢,
   
http://bugs.mysql.com/39622
   在搭建之初遇到很鬱悶的問題,所幸通過在Cluster的SQL節點上參數:
   ndb-log-update-as-write=0
   得以解決。否則會出現更新數據從服務器上出現主鍵重複的錯誤。
   從服務器上的 mysql.ndb_apply_status 表要重新創建,
   修改成 MyISAM 表,並將主鍵去掉,並建立一個索引。
   爲了在切換的時候查詢的速度能快些。

2,採用 NDB表 和 INNODB表 放一起的方式,圖中的SQL-4 SQL-5,
   兩臺機器屬於SQL節點中的兩個普通節點,但是在SQL-4上同時又
   創建了很多的Innodb的表,對Innodb的操作就直接在此上操作,
   通過設定SQL-5 上的Replication 信息來將這些 Innodb 的表
   內容全部複製到 SQl-5上,作爲SQL-4 的貼身Slave,可以作爲
   SQL-5 的真正的替換,而不出現系統中丟失數據的問題。
3,SQL-4,SQL-5 採用MM 的結構,他們間雖然是互爲複製,但
   同時在寫的,對應用程序來說只有一臺,這樣不會產生一些不必要
   的混亂。
   對SQL-5 爲什麼一定要是Cluster中的節點而不是 單獨拿出來
   作爲一個普通的Slave 的原因是:
   1)系統的設計目標是 SQL-4 宕機後,系統還能正常交易,因爲主要的
      交易表都在Cluster中,全部的配置相關表都在應用的緩存中, SQL-4
      宕機2-3 分鐘不會影響應用程序。
   2)在SQL-4宕機的過程切換過程中,系統的交易數據的寫入是不停止的,
      如何保證將這部分數據續寫到衆多的Slave 中去,這就是SQL-5作爲
      Cluster中節點的目的。
      作爲SQL節點,打開了binlog 日誌並設置爲row複製後,其他 SQL節點
      上的寫入的信息就會反映在SQL-5 上的日誌中,並記錄到 mysql.ndb_binlog_index
      表中,通過 從服務器上 停頓的時間點的查詢,看 mysql.ndb_apply_status 表
      中最大的 epoch 值,到SQL-5 中的 mysql.ndb_binlog_index來找下一個binglog  
      日誌 和 postion ,注意這點和以前的 Master----->Master-Slave ----> Slave
      的切換方式不一樣,和 ( Master --- Master ) -----> Slave 的切換方式也完全
      不一樣。
4,雖然MySQL5.1 還沒有 GA , 但是 mysql_5.1.23_ndb_6.2.15  Cluster
   已經是一個穩定的版本了,有很多成功的案例,在試用階段系統也會穩定,
   因此 各方面最終都同意了這個版本。
5,附上
  SQL1 :10.4.6.220,
  SQL5 :10.4.6.226,
  SQL4 :10.4.6.227,
  Slave01 : 10.4.6.228
  Manager : 10.4.6.224 這樣結構的所有 my.cnf ,ndbconfig.ini 的配置文件信息:
SQL1 :10.4.6.220,
[MYSQLD]
ndbcluster
ndb-connectstring=10.4.6.224
default-storage-engine=ndbcluster
max_connections=1024
default-character-set=cp932
ndb-log-update-as-write=0
memlock
#ndb-cluster-connection-pool=4
#added 2008 08 20 for ...
#BASE config.....
skip-name-resolve  
back_log =350
log-slow-queries = slow.log
long_query_time = 1
table_cache =350
sort_buffer_size = 1M
query_cache_size=512M
query_cache_limit=2M
ndb_force_send=1
engine_condition_pushdown=1
ndb_use_exact_count=0
#1 -- means enable, 0 -- means disable
slave-allow-batching=1
#transaction-isolation = READ-COMMITTED
#add by wangxl ,for "converting HEAP to MyISAM "
max_heap_table_size=64M
tmp_table_size=64M
thread_cache_size=350
#add by liuyf  for primary key repeat
auto_increment_increment=4
auto_increment_offset=4
delayed_queue_size=500
bulk_insert_buffer_size=16M
#MySQL slave config ...........
log-bin=mfx220-bin
#binlog_format="STATEMENT"
binlog_format="ROW"
#binlog_format="MIXED"
server-id       = 20
  SQL5 :10.4.6.226,
  [root@mfx226 ~]# cat /etc/my.cnf
[MYSQL_CLUSTER]
ndb-connectstring=10.4.6.224
[MYSQLD]
ndbcluster
ndb-connectstring=10.4.6.224
default-storage-engine=ndbcluster
max_connections=1024
default-character-set=cp932
ndb-log-update-as-write=0
#ndb-cluster-connection-pool=4
memlock
#added 2008 08 20 for ...
#BASE config.....
skip-name-resolve  
back_log =350
log-slow-queries = slow.log
long_query_time = 1
table_cache =350
sort_buffer_size = 1M
query_cache_size=512M
query_cache_limit=2M
ndb_force_send=1
engine_condition_pushdown=1
ndb_use_exact_count=0
#1 -- means enable, 0 -- means disable
slave-allow-batching=1
transaction-isolation = READ-COMMITTED
#add by wangxl ,for "converting HEAP to MyISAM "
max_heap_table_size=64M
tmp_table_size=64M
thread_cache_size=350
#add by liuyf  for primary key repeat
auto_increment_increment=4
auto_increment_offset=3
#MySQL slave config ...........
log-bin=mfx226-bin
#binlog_format="STATEMENT"
#binlog_format="ROW"
binlog_format="MIXED"
server-id       = 26
replicate-do-db = MAIN
master-host     = 10.4.6.227
master-user     = root
master-password = 123456
replicate-ignore-table =  MAIN.JHF_SYS_POSITION_INSERT
replicate-ignore-table =  mysql.%
replicate-ignore-table =  test.%
relay-log=mfx226-relay-bin
skip-slave-start

SQL4 :10.4.6.227,
[MYSQLD]
ndbcluster
ndb-connectstring=10.4.6.224
default-storage-engine=ndbcluster
max_connections=1024
default-character-set=cp932
ndb-log-update-as-write=0
memlock
#ndb-cluster-connection-pool=4
#added 2008 08 20 for ...
#BASE config.....
skip-name-resolve  
back_log =350
log-slow-queries = slow.log
long_query_time = 1
table_cache =350
sort_buffer_size = 1M
query_cache_size=512M
query_cache_limit=2M
ndb_force_send=1
engine_condition_pushdown=1
ndb_use_exact_count=0
#1 -- means enable, 0 -- means disable
slave-allow-batching=1
transaction-isolation = READ-COMMITTED
#add by wangxl ,for "converting HEAP to MyISAM "
max_heap_table_size=64M
tmp_table_size=64M
thread_cache_size=350
#add by liuyf  for primary key repeat
auto_increment_increment=4
auto_increment_offset=4
delayed_queue_size=500
bulk_insert_buffer_size=16M
#MySQL slave config ...........
log-bin=mfx227-bin
#binlog_format="STATEMENT"
#binlog_format="ROW"
binlog_format="MIXED"
server-id       = 27
  Slave01 : 10.4.6.228
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-locking
key_buffer = 512M
max_allowed_packet = 1M
table_cache =128
sort_buffer_size =1M
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
#transaction-isolation = READ-COMMITTED
max_connections=1024
skip-name-resolve  
back_log = 300
log-slow-queries = slow.log
long_query_time = 1
server-id       = 228
master-host     = 10.4.6.227
master-user     = root
master-password = 123456
#replicate-do-db = MAIN
#replicate-do-db = mysql
#replicate-ignore-table=mysql.ndb_apply_status
relay-log=mfx222-relay-bin
skip-slave-start
innodb_flush_log_at_trx_commit = 1
innodb_buffer_pool_size =128M
innodb_log_buffer_size = 16M
innodb_log_file_size =8M
innodb_file_per_table
innodb_status_file
innodb_thread_concurrency= 32
query_cache_size=512M
query_cache_limit=2M
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
#[myisamchk]
#key_buffer = 20M
#sort_buffer_size = 20M
#read_buffer = 2M
#write_buffer = 2M

Manager : 10.4.6.224
[root@mfx224 ~]# cat /etc/ndbconfig.ini
# file "config.ini" - 2 data nodes and 2 SQL nodes
# This file is placed in the startup directory of ndb_mgmd (the management
# server)
# The first MySQL Server can be started from any host. The second can be started
# only on the host mysqld_5.mysql.com

[NDBD DEFAULT]
NoOfReplicas=1
MaxNoOfConcurrentOperations=  100000
MaxNoOfLocalOperations     =  110000
#MaxNoOfConcurrentTransactions default 4096,
#MaxNoOfConcurrentTransactions =
#    (maximum number of tables accessed in any single transaction + 1)
#    * number of cluster SQL nodes
MaxNoOfConcurrentTransactions=40960
#DataMemory= 1280M
#IndexMemory= 256M
DataMemory= 640M
IndexMemory= 128M
StringMemory=25  ##use in ndb62
RedoBuffer=128M
DataDir=/usr/local/mysql/cluster
TimeBetweenWatchDogCheck= 30000
#Default ConcurrentScan.......
   
MaxNoOfConcurrentScans=256
MaxNoOfLocalScans=256
    # Default BatchSize
BatchSizePerLocalScan=64
    MaxNoOfOrderedIndexes= 1024
    #   REDO logs of 16X128M=2G.
NoOfFragmentLogFiles=16
FragmentLogFileSize=128M ## use in ndb62
    # Default 1000
MaxNoOfAttributes=80000
    # Default 128,limit 1600..
MaxNoOfTables=1500
    # Default 64.
MaxNoOfUniqueHashIndexes=3500
    #Default is 768 ..
MaxNoOfTriggers=1000
TransactionDeadlockDetectionTimeout=20000
    #yunfei test
TransactionInactiveTimeout=16000

#This parameter defines the interval between synchronisation epochs
#for MySQL Cluster Replication. The default value is 100 milliseconds.
#TimeBetweenEpochs is part of the implementation of micro-GCPs,
#which can be used to improve the performance of MySQL Cluster Replication.
TimeBetweenEpochs=20 ## use in ndb62
BackupDataDir=/usr/local/mysql/BACKUP
#yunfei test
LockPagesInMainMemory=1
[ndb_mgmd default]
DataDir=/usr/local/mysql/cluster

[TCP default]
SendBufferMemory=2M
ReceiveBufferMemory=2M
[NDB_MGMD]
Hostname= 10.4.6.224
logDestination=FILE:filename=cluster.log,maxsize=100000,maxfiles=6
[NDBD]
HostName= 10.4.6.223
[MYSQLD default]
BatchByteSize=64k
BatchSize=128
[MYSQLD]
HostName= 10.4.6.220
[MYSQLD]
HostName= 10.4.6.226
[MYSQLD]
HostName= 10.4.6.227
[MYSQLD]
[MYSQLD]
完 。。。



本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u1/33594/showart_1360118.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章