Mysql-cluster Environment Configuration Hardware environment
4 Sets of machines
192.168.1.10 Management Node
192.168.1.11 Storage Node SQL node
192.168.1.12 storage nodes, SQL nodes
192.168.1.13 SQL node
Software Environment:
Operating system: CentOS 6.5 (64-bit)
MySQL version: Mysql-cluster-gpl-7.3.5-1.el6.x86_64.rpm-bundle.tar
Mysql-cluster-gpl-7.3.5-linux-glibc2.5-x86_64.tar.gz (requires two of these files)
Installation Preparation:
1. Unzip the Mysql-cluster-gpl-7.3.5-1.el6.x86_64.rpm-bundle.tar:
Distributing the extracted mysql-cluster-server-gpl-7.3.5-1.el6.x86_64.rpm to each machine;
Distributing the extracted mysql-cluster-client-gpl-7.3.5-1.el6.x86_64.rpm to the SQL node;
2. Clean up the old MySQL installation:
Yum-y Remove MySQL
Rpm-qa | grep mysql*
For the 1 remaining MySQL packages found, please follow the following command format to delete:
RPM-E--nodeps mysql-libs-5.1.61-4.el6.x86_64
3. Install dependent libraries:
Yum-y Install Libaio
Install MySQL Cluster:
Create a folder (3 classes below to create the corresponding folder)
Storage node: Mkdir/var/lib/mysql/data
Management node: Mkdir/var/lib/mysql-cluster SQL Node: No folder authorization is available
Process Dir:mkdir/var/run/mysqld
Use the following command to change permission guarantees to write:
Chmod-r 1777/var/lib/mysql
Chmod-r 1777/var/run/mysqld
Chmod-r 1777/var/lib/mysql-cluster
1. Install the mysql-cluster-server-gpl-7.3.5-1.el6.x86_64.rpm on each machine
Execute command: RPM-UVH mysql-cluster-server-gpl-7.3.5-1.el6.x86_64.rpm
After installation, you will be prompted for the default password to be stored in the/root/.mysql_secret file (sometimes not prompted)
2. Install mysql-cluster-client-gpl-7.3.5-1.el6.x86_64.rpm on the SQL node
Execute command: RPM-UVH mysql-cluster-client-gpl-7.3.5-1.el6.x86_64.rpm
To configure the management node:
- Unzip the mysql-cluster-gpl-7.3.5-linux-glibc2.5-x86_64.tar.gz and enter its
The Mysql-cluster-gpl-7.3.5-linux-glibc2.5-x86_64\bin directory finds NDB_MGM and NDB_MGMD, copies it to the/usr/local/bin of the Management node,
These two files are then made executable:
Cd/usr/local/bin
chmod +x ndb_mgm*
- Execute on the management node:
Cd/var/lib/mysql-cluster
VI Config.ini
The contents are as follows:
[NDBD Default]
noofreplicas=2
datamemory=80m
indexmemory=20m
[NDB_MGMD]
# Management Process Options:
HOSTNAME=192.168.1.10 # hostname or IP address of MGM node
Datadir=/var/lib/mysql-cluster # Directory for MGM node log files
[NDBD]
hostname=192.168.1.11
Datadir=/var/lib/mysql/data
[NDBD]
hostname=192.168.1.12
Datadir=/var/lib/mysql/data
[Mysqld]
hostname=192.168.1.11
[Mysqld]
hostname=192.168.1.12
[Mysqld]
hostname=192.168.1.13
Configure storage nodes and SQL nodes:
To establish a configuration file on all storage nodes and SQL nodes:
Vi/etc/my.cnf
The contents are as follows:
[Client]
Socket=/var/lib/mysql/mysql.sock
[Mysqld]
max_connections=100
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
Ndbcluster
ndb-connectstring=192.168.1.10
[Mysqld_safe]
Log-error=/var/log/mysqld.log
Pid-file=/var/run/mysqld/mysqld.pid
[Mysql_cluster]
ndb-connectstring=192.168.1.10
~
To start each node:
Note the order.
- Start the Management node: Ndb_mgmd-f/var/lib/mysql-cluster/config.ini
(It needs to be performed on the management node, which creates a directory/usr/local/mysql/mysql-cluster, which, if not, can create an error by manually creating a
Mkdir/usr/local/mysql
Mkdir/usr/local/mysql/mysql-cluster)
2. Start the storage node: NDBD--initial
(Need to execute on the storage node) need to add--initial parameter at first boot, only need to execute NDBD later;
3. Start the SQL node: Nohup mysqld_safe--explicit_defaults_for_timestamp &
(Need to execute on SQL node)
Before you start, you need to check that its 3306 ports are occupied, sudo netstat-anp | grep 3306 to see if Port 3306 is occupied
If it's occupied, kill it and start again.
Check that all nodes are starting normally:
Execute NDB_MGM in the Management node to enter the cluster Management console, using the show command to list all node information:
You can see that the SQL node did not start successfully, workaround:
Cd/var/lib/mysql
Ls
Rm-f ib* (remove the file that starts with lb)
With command: sudo netstat-anp | grep 3306 to see if Port 3306 is occupied
If it's occupied kill kills
Then reboot to perform the above actions to see
Common commands:
1) NDB_MGMD Management command: NDB_MGM
After execution is the management console, inside can continue to enter the command.
View the status of all nodes inside the cluster: show
2) Stop the Cluster Server command: NDB_MGM-E shutdown
If the cluster configuration is updated: Rm/usr/mysql-cluster/ndb_1_config.bin.1
3) command to stop SQL node: Mysqladmin-uroot shutdown
4) Connect mysql:mysql-u Root–ppassword on SQL node
After the execution is the MySQL console, inside can continue to enter the command.
To modify the root user password:
Execute in each SQL node:
mysqladmin-u root-poldpassword password ' newpassword '
Where OldPassword is generated for/root/.mysql_secret:
Cat/root/.mysql_secret (view randomly generated passwords)
# The random password set for the root user at Tue Apr 11:08:59 (local time): Nnqn0u1mrcpxkmue
Test cluster: Log on to 192.168.1.12
Mysql-u Root–ppassword
mysql> CREATE DATABASE transenly;
Query OK, 1 row affected (0.06 sec)
mysql> use transenly;
Database changed
Mysql> CREATE TABLE Ctest2 (i INT) engine=ndb; (You must add the following engine=ndb when creating the table, otherwise the data synchronization is unsuccessful)
Query OK, 0 rows affected (0.38 sec)
Sign in on 192.168.1.11
Mysql-u Root–ppassword
You can see both the database and the data table, indicating that the data synchronization was successful
Data import using SQL file Import
Place the SQL file in a local location, such as/var/lib/mysql/data/
The engine= InnoDB in the SQL file needs to be modified to engine-ndb to ensure that the data is synchronized
In which a random SQL node is logged in
Mysql-u Root–ppassword
Use transenly; (the database used, provided the database is created first)
Source/var/lib/mysql/data/transenly.sql
A query OK appears, and 0 rows affected (0.00 sec) indicate that the import was successful
Then show tables; see if all three SQL nodes are created successfully
The project is not connected to the database:
Need to modify permissions, is the server can easily access
Mysql> Grant all privileges on * * to [e-mail protected] '% ' identified by ' MySQL ' with GRANT option;
Give any host access to data
3. Mysql>flush Privileges//modification takes effect
4. Mysql>exit//exit MySQL server