程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> 實用心得:MySQL群集雙機模擬方案

實用心得:MySQL群集雙機模擬方案

編輯:關於MYSQL數據庫

普通PC server * 2 (最小集群環境需要4台服務器)

模擬環境

red hat Linux9 for x86 (or red hat AS 2以上版本),glibc-2.2, static, gcc

MySQL版本4.1.12 binares

MySQL-max binary版本目前只支持Linux、max os x和solaris

本方案不涉及從源代碼編譯安裝。

主機                        IP地址                用途
ndb1_mgmd_sqld            192.168.1.100      Ndb node1+mgmd node1+sqld node1
ndb2_sqld2                192.168.1.200      Ndb node2+sqld node2
Mgmd:management server
sqld:mySQL Server
ndb:storaged node (share-nothing,base in memory)

安裝

從http://dev.mysql.com/downloads/MySQL/4.1.Html下載MySQL-max-4.1.12-pc-Linux-gnu-i686.tar.gz到/var/tmp

Storage and SQL Node Installation

在兩台主機上執行如下過程:

shell>;groupadd mysql
shell>;useradd -g mysql mysql
shell>;tar zxfv mysql-max-4.1.12-pc-linux-gnu-i686.tar.gz
shell>;cp -vr mysql-max-4.1.12-pc-linux-gnu-i686 /usr/local/mysql-max-4.1.12-pc-linux-gnu-i686
shell>;cd /usr/local
shell>;ln -s mysql-max-4.1.12-pc-Linux-gnu-i686 mysql
shell>;cd mysql;scripts/mysql_install_db –user=mysql
shell>;chown -R root .;chown -R mysql data;chgrp -R mysql .
shell>;cp support-files/mysql.server /etc/rc.d/init.d/
shell>;chmod +x /etc/rc.d/init.d/mysql.server
shell>;chkconfig --add mysql.server
shell>;chkconfig –level 3 MySQL.server off

Management Node Installation

在主機ndb1_mgmd_sqld1上執行如下過程:

shell>;cd /var/tmp
shell>;tar -zxvf mysql-max-4.1.12a-pc-Linux-gnu-i686.tar.gz /usr/local/bin '*/bin/ndb_mgm*'
Configuration
Configuring the Storage and SQL Nodes
在兩台主機上執行如下過程:
shell>;vi /etc/my.cnf
[MYSQLD]                                        # Options for mysqld process:
ndbcluster                                             # run NDB engine
ndb-connectstring=192.168.1.100          # location of MGM node

[MYSQL_CLUSTER]                                # Options for ndbd process:
ndb-connectstring=192.168.1.100          # location of MGM node

Configuring the Management Node
在主機ndb1_mgmd_sqld1上執行如下過程
shell>;mkdir /var/lib/mysql-cluster
shell>;cd /var/lib/mysql-cluster
shell>;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]

[NDB_MGMD]                       # Management process options:
hostname=192.168.1.100        # Hostname or IP address of MGM node
datadir=/var/lib/mysql-cluster          # Directory for MGM node logfiles

[NDBD]                                         # Options for data node "A":
                            # (one [NDBD] section per data node)
HostName=192.168.1.100                   # Hostname or IP address
DataDir=/usr/local/mysql/data           # Directory for this data node's datafiles

[NDBD]                                         # Options for data node "B":
hostname=192.168.1.200                   # Hostname or IP address
datadir=/usr/local/mysql/data           # Directory for this data node's datafiles

[MYSQLD]                                # SQL node options:
hostname=192.168.1.100                 # Hostname or IP address
                                # Directory for SQL node's datafiles
                                # (additional mysqld connections can be
                                # specifIEd for this node for various
                                # purposes such as running ndb_restore)

[MYSQLD]                        # SQL node options:
hostname=192.168.1.200                 # Hostname or IP address
                                # Directory for SQL node's datafiles
                                 # (additional MySQLd connections can be
                                 # specifIEd for this node for various
                                 # purposes such as running ndb_restore)

第一次啟動

在主機ndb1_mgmd_sqld1上執行如下過程:

shell>; ndb_mgmd -f /var/lib/MySQL-cluster/config.ini

在兩台主機上執行如下過程

shell>;ndbd –initial (note:--initial選項只能在第一次啟動的時候使用)

shell>;/etc/init.d/MySQL.server start

測試

在主機ndb1_mgmd_sqld1上執行如下過程:

shell>; ndb_mgm
-- NDB Cluster -- Management ClIEnt --
ndb_mgm>; show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.0.100  (Version: 4.1.12, Nodegroup: 0, Master)
id=3    @192.168.0.200  (Version: 4.1.12, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.0.100  (Version: 4.1.12)

[MySQLd(SQL)]   1 node(s)
id=4   (Version: 4.1.12)

出現如上信息則表示MySQL群集安裝成功。

數據抽樣測試

在主機ndb1_mgmd_sqld1上執行如下過程:

shell>;/usr/local/mysql/bin/mysql -u root test
MySQL>;DROP TABLE IF EXISTS City;
CREATE TABLE City (
ID int(11) NOT NULL auto_increment,
Name char(35) NOT NULL default '',
CountryCode char(3) NOT NULL default '',
District char(20) NOT NULL default '',
Population int(11) NOT NULL default '0',
PRIMARY KEY  (ID)
) ENGINE=NDBCLUSTER;

MySQL>;INSERT INTO City VALUES (1,'Kabul','AFG','Kabol',1780000);
INSERT INTO City VALUES (2,'Qandahar','AFG','Qandahar',237500);
INSERT INTO City VALUES (3,'Herat','AFG','Herat',186800);

在主機ndb2_sqld2上執行如下過程:

shell>;/usr/local/mysql/bin/mysql -u root MySQL

MySQSL>;select * from City;

如果成功顯示數據信息,則表示集群已經成功啟動。

Safe Shutdown and Restart

在主機ndb1_mgmd_sqld1上執行如下過程:

shell>;ndb_mgm -e shutdown (關閉集群服務器,storage node也會自動被關閉。)

在兩台主機上執行如下過程:

shell>;/etc/init.d/MySQL.server stop

重新啟動集群(順序不能弄錯)

在主機ndb1_mgmd_sqld1上執行如下過程:

shell>; ndb_mgmd -f /var/lib/MySQL-cluster/config.ini

在兩台主機上執行如下過程:

shell>;/usr/local/MySQL/bin/ndbd

啟動完ndbd進程後啟動sqld進程:

shell>;/etc/init.d/MySQL.server start

附:

config.ini中各部分解釋:

[COMPUTER]: 定義群集主機.

[NDBD]: 定義群集數據節點.

[MySQLD]: 定義SQL Server節點.

[MGM|NDB_MGMD]: Defines the management server node in the cluster.

[TCP]: Defines TCP/IP connections between nodes in the cluster, with TCP/IP being the default connection protocol.

[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. 下一頁:
Copyright © 程式師世界 All Rights Reserved