MySQL cluster installation and configuration article directory[Hide]
- One, MySQL cluster installation
- Second, node configuration
- Third, start the node for the first time
- Iv. Testing the service is normal
- V. Secure shutdown and restart
MySQL Cluster is a high-utility, high-redundancy version of MySQL suitable for distributed computing environments. It employs the NDB Cluster storage engine, allowing multiple MySQL servers to run in 1 Cluster. MySQL Cluster is able to configure the NDB storage engine with multiple failover and load balancing options, but this is easiest to do on the storage engine at the Cluster level. Below we briefly describe how MySQL cluster is installed and configured.
Basic settings
Management (MGM) node: 192.168.0.111
MySQL server (SQL) node: 192.168.0.110
Data (NDBD) node "A": 192.168.0.112
Data (NDBD) node "B": 192.168.0.113
One, MySQL cluster installation
MySQL cluster installation can be three ways, one is to directly download binary use, the second is to use the RPM installation, the third is the source code compilation. We use the first installation here.
1, each node do the same operation
- Cd/tmp
- wget http://cdn.mysql.com/Downloads/MySQL-Cluster-7.2/mysql-cluster-gpl-7.2.8-linux2.6-i686.tar.gz
- Tar xzf mysql-cluster-gpl-7.2.8-linux2.6-i686.tar.gz
- MV Mysql-cluster-gpl-7.2.8-linux2.6-i686/usr/local/mysql
Note: This download is a 32-bit binary package, if your system is 64-bit, you need to download the 64-bit package.
2. Storage node and SQL node installation
- Groupadd MySQL
- useradd-g MySQL MySQL
- /usr/local/mysql/scripts/mysql_install_db--basedir=/usr/local/mysql--datadir=/usr/local/mysql/data--user=mysql
- Chown-r Root/usr/local/mysql
- Chown-r Mysql/usr/local/mysql/data
- Chgrp-r Mysql/usr/local/mysql
- Cp/usr/local/mysql/support-files/my-medium.cnf/etc/my.cnf
Second, node configuration
1. Configuring storage nodes and SQL nodes
- Vi/etc/my.cnf
- Similar to:
- # Options for MYSQLD process:
- [MYSQLD]
- Ndbcluster # run NDB engine
- ndb-connectstring=198.168.0.111 # Location of MGM node
- # Options for NDBD process:
- [Mysql_cluster]
- ndb-connectstring=198.168.0.111 # Location of MGM node
2. Configuration Management node
- Mkdir/var/lib/mysql-cluster
- Cd/var/lib/mysql-cluster
- VI Config.ini
- The config.ini file should resemble the following:
- # Options affecting NDBD processes on all data nodes:
- [NDBD DEFAULT]
- noofreplicas=2 # 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 on 500KB, this should is more than enough for
- # This example Cluster setup.
- # TCP/IP options:
- [TCP DEFAULT]
- portnumber=2202 # this default; However, you can use any
- # port that's free for all the hosts in cluster
- # Note:it is recommended beginning with MySQL 5.0 that
- # Specify the portnumber at all and simply allow
- # The default value to be used instead
- # Management Process Options:
- [NDB_MGMD]
- HOSTNAME=198.168.0.111 # hostname or IP address of MGM node
- Datadir=/var/lib/mysql-cluster # Directory for MGM node logfiles
- # Options for Data node "A":
- [NDBD]
- # (one [NDBD] section per data node)
- HOSTNAME=198.168.0.112 # hostname or IP address
- Datadir=/usr/local/mysql/data # Directory for this data node ' s datafiles
- # Options for Data node "B":
- [NDBD]
- HOSTNAME=198.168.0.113 # hostname or IP address
- Datadir=/usr/local/mysql/data # Directory for this data node ' s datafiles
- # SQL Node Options:
- [MYSQLD]
- HOSTNAME=198.168.0.110 # hostname or IP address
- # (Additional mysqld connections can be
- # specified for this node for various
- # purposes such as running Ndb_restore)
Third, start the node for the first time
1. Start the Management node
- /USR/LOCAL/MYSQL/BIN/NDB_MGMD--configdir=/var/lib/mysql-cluster-f/var/lib/mysql-cluster/config.ini
2. Start the Data node
The first boot requires the--initial parameter initialization, which is not required for the next boot.
- /USR/LOCAL/MYSQL/BIN/NDBD--initial
3. Start the SQL node
- /usr/local/mysql/bin/mysqld_safe &
4. Check the status
If everything is OK, execute the command/usr/local/mysql/bin/ndb_mgm-e show should output similar information:
[Email protected] mysql-cluster]#/USR/LOCAL/MYSQL/BIN/NDB_MGM-E Show
Connected to Management Server at:localhost:1186
Cluster Configuration
---------------------
[NDBD (NDB)] 2 node (s)
id=2 @192.168.0.112 (mysql-5.5.27 ndb-7.2.8, nodegroup:0, Master)
Id=3 @192.168.0.113 (mysql-5.5.27 ndb-7.2.8, nodegroup:0)
[NDB_MGMD (MGM)] 1 node (s)
Id=1 @192.168.0.111 (mysql-5.5.27 ndb-7.2.8)
[Mysqld (API)] 1 node (s)
Id=4 @192.168.0.110 (mysql-5.5.27 ndb-7.2.8)
Iv. Testing the service is normal
Perform the following database operations on the SQL node:
- /usr/local/mysql/bin/mysql-uroot-p
- Mysql> CREATE database Clusterdb;use Clusterdb;
- Mysql> CREATE TABLE simples (ID int not NULL primary key) Engine=ndb;
- mysql> INSERT into simples values (1), (2), (3), (4);
- Mysql> select * from Simples;
If it appears:
+----+
| ID |
+----+
| 1 |
| 2 |
| 4 |
| 3 |
+----+
Indicates that it is working correctly.
V. Secure shutdown and restart
1, close the MySQL cluster, you can execute the following command in the management node:
- /USR/LOCAL/MYSQL/BIN/NDB_MGM-E shutdown
2. Restart the Management node
- /USR/LOCAL/MYSQL/BIN/NDB_MGMD--configdir=/var/lib/mysql-cluster-f/var/lib/mysql-cluster/config.ini
3. Restart the data node
- /usr/local/mysql/bin/ndbd
Reference: http://dev.mysql.com/doc/refman/5.1/zh/ndbcluster.html
Reprint please indicate the article source: "Https://www.centos.bz/2012/11/mysql-cluster-install-configure/"
MySQL cluster installation and configuration