1. 程式人生 > >mysql cluster步驟基本取自官方文件,測試忘記參考哪裡了^_^

mysql cluster步驟基本取自官方文件,測試忘記參考哪裡了^_^

系統Centos6.5
下載mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz
下載地址:http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.3/mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz


參考文獻:http://dev.mysql.com/doc/refman/5.6/en/mysql-cluster-installation.html
官網安裝教程:http://dev.mysql.com/doc/refman/5.6/en/mysql-cluster-install-linux-binary.html
官網初始化教程:http://dev.mysql.com/doc/refman/5.6/en/mysql-cluster-install-configuration.html




本文結構
安裝--初始化(配置檔案)--開啟服務--測試功能--關閉叢集




SQL nodes. 


On each of the machines designated to host SQL nodes, perform the following steps as the system root user:


Check your /etc/passwd and /etc/group files (or use whatever tools are provided by your operating system for managing users and groups) to see whether there is already a mysql group and mysql user on the system. Some OS distributions create these as part of the operating system installation process. If they are not already present, create a new mysql user group, and then add a mysql user to this group:


shell> groupadd mysql
shell> useradd -g mysql mysql
The syntax for useradd and groupadd may differ slightly on different versions of Unix, or they may have different names such as adduser and addgroup.


Change location to the directory containing the downloaded file, unpack the archive, and create a symbolic link named mysql to the mysql directory. Note that the actual file and directory names vary according to the MySQL Cluster version number.




shell> tar -C /usr/local -xzvf mysql-cluster-gpl-7.4.3-linux2.6.tar.gz
shell> ln -s /usr/local/mysql-cluster-gpl-7.4.3-linux2.6-i686 /usr/local/mysql
Change location to the mysql directory and run the supplied script for creating the system databases:


shell> cd /usr/local/mysql
shell> scripts/mysql_install_db --user=mysql
Set the necessary permissions for the MySQL server and data directories:


shell> chown -R root .
shell> chown -R mysql data
shell> chgrp -R mysql .
Copy the MySQL startup script to the appropriate directory, make it executable, and set it to start when the operating system is booted up:


shell> cp support-files/mysql.server /etc/init.d/
shell> chmod +x /etc/init.d/mysql.server
shell> chkconfig mysql.server on


















Data nodes. 


 Installation of the data nodes does not require the mysqld binary. Only the MySQL Cluster data node executable ndbd (single-threaded) or ndbmtd (multi-threaded) is required. These binaries can also be found in the .tar.gz archive. Again, we assume that you have placed this archive in /var/tmp.


As system root (that is, after using sudo, su root, or your system's equivalent for temporarily assuming the system administrator account's privileges), perform the following steps to install the data node binaries on the data node hosts:


Change location to the /var/tmp directory, and extract the ndbd and ndbmtd binaries from the archive into a suitable directory such as /usr/local/bin:


shell> cd /var/tmp
shell> tar -zxvf mysql-5.6.21-ndb-7.4.3-linux-i686-glibc23.tar.gz
shell> cd mysql-5.6.21-ndb-7.4.3-linux-i686-glibc23
shell> cp bin/ndbd /usr/local/bin/ndbd
shell> cp bin/ndbmtd /usr/local/bin/ndbmtd
(You can safely delete the directory created by unpacking the downloaded archive, and the files it contains, from /var/tmp once ndb_mgm and ndb_mgmd have been copied to the executables directory.)


Change location to the directory into which you copied the files, and then make both of them executable:


shell> cd /usr/local/bin
shell> chmod +x ndb*












Management nodes.


  Installation of the management node does not require the mysqld binary. Only the MySQL Cluster management server (ndb_mgmd) is required; you most likely want to install the management client (ndb_mgm) as well. Both of these binaries also be found in the .tar.gz archive. Again, we assume that you have placed this archive in /var/tmp.


As system root, perform the following steps to install ndb_mgmd and ndb_mgm on the management node host:


Change location to the /var/tmp directory, and extract the ndb_mgm and ndb_mgmd from the archive into a suitable directory such as /usr/local/bin:


shell> cd /var/tmp
shell> tar -zxvf mysql-5.6.21-ndb-7.4.3-linux2.6-i686.tar.gz
shell> cd mysql-5.6.21-ndb-7.4.3-linux2.6-i686
shell> cp bin/ndb_mgm* /usr/local/bin
(You can safely delete the directory created by unpacking the downloaded archive, and the files it contains, from /var/tmp once ndb_mgm and ndb_mgmd have been copied to the executables directory.)


Change location to the directory into which you copied the files, and then make both of them executable:


shell> cd /usr/local/bin
shell> chmod +x ndb_mgm*












初始化(配置檔案)
Configuring the data nodes and SQL nodes.
shell> vi /etc/my.cnf
For each data node and SQL node in our example setup, my.cnf should look like this:
[mysqld]
# Options for mysqld process:
ndbcluster                      # run NDB storage engine


[mysql_cluster]
# Options for MySQL Cluster processes:
ndb-connectstring=192.168.0.5# location of management server


Configuring the management node.  
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=18M   # 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 the cluster
                  # Note: It is recommended that you do not specify the port
                  # number at all and simply allow the default value to be used
                  # instead


[ndb_mgmd]
# Management process options:
hostname=192.168.0.5           # Hostname or IP address of MGM node
datadir=/var/lib/mysql-cluster  # Directory for MGM node log files


[ndbd]
# Options for data node "A":
                                # (one [ndbd] section per data node)
hostname=192.168.0.4           # Hostname or IP address
datadir=/usr/local/mysql/data   # Directory for this data node's data files


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


[mysqld]
# SQL node options:
hostname=192.168.0.4          # Hostname or IP address
                                # (additional mysqld connections can be
                                # specified for this node for various
                                # purposes such as running ndb_restore)


[mysqld]
# SQL node options:
hostname=192.168.0.6          # Hostname or IP address
                                # (additional mysqld connections can be
                                # specified for this node for various
                                # purposes such as running ndb_restore)







Initial Startup of MySQL Cluster開啟服務
啟用順序:管理節點--Sql節點--資料節點
On the management host:
shell> ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial
#僅初次使用--initial引數
On each of the data node hosts, run this command to start the ndbd process:
shell> ndbd --initial  
#僅初次使用--initial引數
啟動sql節點
service mysql.server start
檢驗是否成功開啟
管理節點上,如下顯示說明啟動成功
[
[email protected]
bin]# 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.4  (mysql-5.6.21 ndb-7.3.7, Nodegroup: 0, *)
id=3    @192.168.0.6  (mysql-5.6.21 ndb-7.3.7, Nodegroup: 0)


[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.0.5  (mysql-5.6.21 ndb-7.3.7)


[mysqld(API)]   2 node(s)
id=4    @192.168.0.4  (mysql-5.6.21 ndb-7.3.7)
id=5    @192.168.0.6  (mysql-5.6.21 ndb-7.3.7)




★非常重要:
1.在建表的時候一定要用ENGINE=NDB或ENGINE=NDBCLUSTER指定使用NDB叢集儲存引擎,或用ALTER TABLE選項更改表的儲存引擎。
2.NDB表必須有一個主鍵,因此建立表的時候必須定義主鍵,否則NDB儲存引擎將自動生成隱含的主鍵。
3.Sql節點的使用者許可權表仍然採用MYISAM儲存引擎儲存的,所以在一個Sql節點建立的MySql使用者只能訪問這個節點,如果要用同樣的使用者訪問別的Sql節點,需要在對應的Sql節點追加使用者。雖然在MySql Cluster7.2版本開始提供了”使用者許可權共享”.


功能測試:
1.在任意資料節點上,建立資料庫並插入資料,測試另一臺上是否能夠同步
shell> /usr/local/mysql/bin/mysql -u root -p  
mysql>show databases;  
mysql>create database aa;  
mysql>use aa;  
mysql>CREATE TABLE ctest2 (i INT) ENGINE=NDB; //這裡必須指定資料庫表的引擎為NDB,否則同步失敗  
mysql> INSERT INTO ctest2 () VALUES (1);  
mysql> SELECT * FROM ctest2;  


注意:
如果在建立資料庫時遇到如下錯誤
Access denied for user ''@'localhost' to database 'mysql  
解決方法:
首先停止mysqld服務,然後後臺執行  
shell> /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &  
shell> service mysql.server start  
再用root登入,就一切正常  
2.同樣,在另一資料節點上,執行插入資料操作,測試是否可以雙向同步。
3.關閉一個數據節點,另一個節點插入資料,然後開啟資料節點,測試是否可以自動同步




關閉叢集
1.關閉管理節點和資料節點,只需要在管理節點裡執行:
shell> /usr/local/mysql/bin/ndb_mgm -e shutdown  
顯示
Connected to Management Server at: localhost:1186  
2 NDB Cluster node(s) have shutdown.  
Disconnecting to allow management server to shutdown.  


2.然後關閉Sql節點(135,136),分別在2個節點裡執行:
shell> /etc/init.d/mysql.server stop  
Shutting down MySQL... SUCCESS!  




注意:要再次啟動叢集,就按照啟動順序重新啟動,不過再次啟動資料節點的時候就不要加”–initial”引數了。

相關推薦

no