MySQL叢集技術 (四台機器)

來源:互聯網
上載者:User

1、環境描述
Mysql manager 節點:192.168.0.1
MysqlServer節點:192.168.0.100
Mysql 節點:192.168.0.160
Mysql 節點:192.168.0.161
說明:至少需要四台伺服器才可以做mysql的叢集。建議5台,再增加一台MysqlServer。
2安裝mysql二進位包
2.1 安裝之前的準備工作
下載mysql-max-4.1.13-pc-linux-gnu-i686.tar.gz包
(注意:可以做叢集的mysql都是mysql-max的,下載地點www.mysql.org)
#groupadd mysql
#useradd -g mysql mysql
#cd /usr/local
#tar xfz mysql-max-4.1.13-pc-linux-gnu-i686.tar.gz
#ln -s /usr/local/mysql-max-4.1.13-pc-linux-gnu-i686 /opt/mysql4.1.13
2.2 分別在manager,server,node節點上安裝二進位的mysql包
#cd mysql4.1.13
#scripts/mysql_install_db --user=mysql (必須帶目錄執行,否則出錯)
#chown -R root /opt/mysql4.1.13
#chgrp -R mysql /opt/mysql4.1.13
#chown -R mysql.mysql /opt/mysql4.1.13/data
#cp support-files/mysql.server /etc/rc.d/init.d/ 配置mysql啟動設定
#chmod +x /etc/rc.d/init.d/mysql.server 
#chkconfig --add mysql.server
3配置server,note節點
在192.168.0.160和192.168.0.161機器上
# ./mysql –help 該命令可以查看mysql啟動時是怎麼尋找my.cnf檔案的順序。
Default options are read from the following files in the given order:
/etc/my.cnf /usr/local/mysql-max-4.1.13/data/my.cnf ~/.my.cnf 
# cp support-files/my-medium.cnf data/my.cnf 將mysql的設定檔考到data下
Vi /usr/local/mysql-max-4.1.13-pc-linux-gnu-i686/data/my.cnf
[MYSQLD]
ndbcluster
ndb-connectstring=192.168.0.1
[MYSQL_CLUSTER]
ndb-connectstring=192.168.0.1
4配置Management管理節點
在192.168.0.1機器上
#mkdir /var/lib/mysql-cluster
#cd /var/lib/mysql-cluster
#vi config.ini
[NDBD DEFAULT] # Options affecting ndbd processes on all data nodes:
NoOfReplicas=2 # Number of replicas
DataMemory=80M # How much memory to allocate for data storage
IndexMemory=52M # How much memory to allocate for index storage
# For DataMemory and IndexMemory, we have used the
# default values. Since the "world" database takes up
# only about 500KB, this should be more than enough for
# this example Cluster setup.
[TCP DEFAULT] # TCP/IP options:
portnumber=2202 # This the default; however, you can use any
# port that is free for all the hosts in cluster
# Note: It is recommended beginning with MySQL 5.0 that
# you do not specify the portnumber at all and simply allow
# the default value to be used instead
# Management process options(定義管理節點.)
[NDB_MGMD]
hostname=192.168.0.1 # 管理節點Hostname or IP address of MGM node
datadir=/var/lib/mysql-cluster # Directory for MGM node logfiles
# Options for data node "A"(定義群集資料節點.)
# (one [NDBD] section per data node)
[NDBD]
hostname=192.168.0.160 # 節點Hostname or IP address
datadir=/usr/local/mysql/data # Directory for this data node's datafiles
# Options for data node "B"(定義群集資料節點.)
[NDBD]
hostname=192.168.0.161 # 節點Hostname or IP address
datadir=/usr/local/mysql/data # Directory for this data node's datafiles

# SQL node options(定義Sql server節點.)
[MYSQLD]
hostname=192.168.0.100 # SQL節點Hostname or IP address

#datadir=/usr/local/mysql/data # Directory for SQL node's datafiles
# (additional mysqld connections can be
# specified for this node for various
# purposes such as running ndb_restore)

[NDB_MGMD]:後面不能有任何注釋資訊,否則提示:
Error line 17: [TCP] Unknown parameter: [NDB_MGMD] # Management process options
Error line 17: Could not parse name-value pair in config file.
[SHM]: Defines shared-memory connections between nodes. 在MySQL 4.1.9之前,這個功能必須使用--with-ndb-shm option編譯進去, 從MySQL 4.1.9-max版本開始, it is enabled by default 

  • 1
  • 2
  • 下一頁

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.