MySQL Cluster build details (three node separation)

Source: Internet
Author: User
Tags iptables

This article will build the most streamlined MySQL cluster system, and all of the commands in the configuration method are run as root accounts. This MySQL cluster contains a management node, two data nodes, two SQL nodes, each of the five nodes installed on five virtual machines, the name and IP of the virtual machine are as follows:
Manage nodes Mysql-mgm 192.168.124.141
data node   1 mysql-ndbd-1 192.168.124.142
data node   2 mysql-ndbd-2 192.168.124.143
sql  knot 1 mysql-sql-1 192.168.124.144
SQL node 2 Mysql-sql-2 192.168.124.145
First, public configurationConfigure the configuration items here separately on three virtual machines. 1. Install the virtual machineThe virtual machine operating system installs the x86_64 version of CentOS 6.4, uses a NAT network, and also installs the Vmware-tools, which is not detailed here. 2. copy mysql clusterDownload the following version of MYSQL-CLUSTER:HTTP://CDN.MYSQL.COM/DOWNLOADS/MYSQL-CLUSTER-7.3/ Mysql-cluster-gpl-7.3.4-linux-glibc2.5-x86_64.tar.gz the downloaded compressed package to the/root/downloads directory of the virtual machine, and then run the following command in the shell:
Cd/root/downloads TAR-XVZF mysql-cluster-gpl-7.3.4-linux-glibc2.5-x86_64.tar.gz MV Mysql-cluster-gpl-7.3.4-linux-glibc2.5-x86_64/usr/local/mysql
3. Turn off security policyClose the Iptables firewall (or open the 1186, 3306 port of the firewall) and run the following command in the shell:
Chkconfig--level iptables off
Close SELinux and run the following command in the shell:
Gedit/etc/selinux/config
To change the SELinux entry in config file to disabled, the contents of the modified config file are as follows:
# This file controls the state of the SELinux on the system. # selinux= can take one of the these three values: # Enforcing-selinux Security policy is enforced. # Permissive-selinux Prints warnings instead of enforcing. # disabled-no SELinux policy is loaded.     Selinux=disabled # selinuxtype= can take one of these values: # targeted-targeted processes is protected, # Mls-multi level Security protection. selinuxtype=targeted
Final reboot System Second, Configuration Management node (192.168.124.141) 1. Configuring the Config.ini configuration fileRun the following command in the shell:
Mkdir/var/lib/mysql-clustercd/var/lib/mysql-clustergedit Config.ini
The configuration file Config.ini content is as follows:
[NDBD Default] noofreplicas=2 datamemory=80m indexmemory=18m
[NDB_MGMD] Nodeid=1 hostname=192.168.124.141 Datadir=/var/lib/mysql-cluster
[NDBD] nodeid=2 hostname=192.168.124.142 datadir=/usr/local/mysql/data[ndbd] nodeid=3 hostname=192.168.124.143 datadir=/ USR/LOCAL/MYSQL/DATA[MYSQLD] nodeid=4 hostname=192.168.124.144 [mysqld] nodeid=5 hostname=192.168.124.145
2. Install the Management nodeInstalls the Management node, does not need the mysqld binary file, only needs the MySQL Cluster Server program (NDB_MGMD) and listens the client program (NDB_MGM). Run the following command in the shell:
cp/usr/local/mysql/bin/ndb_mgm*/usr/local/bin cd/usr/local/bin chmod +x ndb_mgm*
third, configuration Data node (192.168.124.142, 192.168.124.143) 1. Adding MySQL groups and usersRun the following command in the shell:
Groupadd MySQL useradd-g mysql MySQL
2. Configuring the MY.CNF configuration fileRun the following command in the shell:
Gedit/etc/my.cnf
The contents of the configuration file my.cnf are as follows:
[Mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/usr/local/mysql/sock/mysql.sock user=mysql # Disabling Symbolic-links is recommended to prevent assorted security risks symbolic-links=0
[Mysqld_safe] Log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
[Mysql_cluster] ndb-connectstring=192.168.124.141
3. Create a system databaseRun the following command in the shell:
Cd/usr/local/mysql mkdir sock scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir=/usr/local/ Mysql/data
4. Set the Data directoryRun the following command in the shell:
Chown-r Root. Chown-r mysql.mysql/usr/local/mysql/data chown-r mysql.mysql/usr/local/mysql/sock chgrp-r MySQL.
5. Configure the MySQL serviceRun the following command in the shell:
CP support-files/mysql.server/etc/rc.d/init.d/chmod +x/etc/rc.d/init.d/mysql.server chkconfig--add mysql.server
iv. Configuring SQL nodes (192.168.124.144, 192.168.124.145) 1. Adding MySQL groups and usersRun the following command in the shell:
Groupadd MySQL useradd-g mysql MySQL
2. Configuring the MY.CNF configuration fileRun the following command in the shell:
Gedit/etc/my.cnf
The contents of the configuration file my.cnf are as follows:
[Client] Socket=/usr/local/mysql/sock/mysql.sock
[Mysqld] Ndbcluster datadir=/usr/local/mysql/data socket=/usr/local/mysql/sock/mysql.sock ndb-connectstring= 192.168.124.141
[Mysql_cluster] ndb-connectstring=192.168.124.141
3. Create a system databaseRun the following command in the shell:
Cd/usr/local/mysql mkdir sock scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir=/usr/local/ Mysql/data
4. Set the Data directoryRun the following command in the shell:
Chown-r Root. Chown-r mysql.mysql/usr/local/mysql/data chown-r mysql.mysql/usr/local/mysql/sock chgrp-r MySQL.
5. Configure the MySQL serviceRun the following command in the shell:
CP support-files/mysql.server/etc/rc.d/init.d/chmod +x/etc/rc.d/init.d/mysql.server chkconfig--add mysql.server
Five, cluster environment startNote The boot order: the first is the management node, then the data node, and finally the SQL node. 1. Start the Management nodeRun the following command in the shell:
Ndb_mgmd-f/var/lib/mysql-cluster/config.ini
You can also use NDB_MGM to listen to clients, as follows:
Ndb_mgm
2. Start the Data nodeThe first time you start, you need to add the--initial parameter for the initialization of the NDB node. You cannot add this parameter during a later boot process, otherwise the NDBD program clears all data files and log files that were previously established for recovery.
/USR/LOCAL/MYSQL/BIN/NDBD--initial
If it is not the first time, execute the following command.
/usr/local/mysql/bin/ndbd
3. Start the SQL nodeIf the MySQL service is not running, run the following command in the shell:
/usr/local/mysql/bin/mysqld_safe--user=mysql &
4. Start the testTo view the management node, start successfully: VI. Cluster testing 1. Test aNow we create the relevant database on one of the SQL nodes and then go to another SQL node to see if the data is synchronized. Execute on SQL Node 1 (192.168.124.144):
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; You must specify that the engine for the database table is NDB, otherwise the synchronization fails mysql> INSERT into Ctest2 () VALUES (1); Mysql> SELECT * from Ctest2;
And then on SQL Node 2 to see whether the data synchronized over the test, the non-master to create data, you can sync to master on the view table is the engine is ndb,>show create table table name; 2. Test twoClose a data node, write input on another node, turn on the closed node, and see if the data is synchronized. First, the Data node 1 restarts, and then add data on Node 2 on the SQL Node 2 (192.168.124.145) operation as follows:
mysql> CREATE DATABASE BB; mysql> use BB; Mysql> CREATE TABLE ctest3 (i INT) engine=ndb; mysql> use AA; Mysql> INSERT into Ctest2 () VALUES (3333); Mysql> SELECT * from Ctest2;
Data node 1 start, Start Data node 1 service
#/usr/local/mysql/bin/ndbd--initial#service mysqld Start
Then log in to view the data
#/usr/local/mysql/bin/mysql-u Root–p
You can see that the data has been synced, indicating that the data can be synchronized in two directions. Vii. shutting down the cluster1. To close the management node and the data node, simply execute it in the Management node (clustermgm--134):
Shell>/usr/local/mysql/bin/ndb_mgm-e shutdown
Show
Connected to Management Server at:localhost:1186 2 NDB Cluster node (s) has shutdown. Disconnecting to allow Management Server to shutdown.
2. Then close the SQL node (135,136) and run it in 2 nodes, respectively:
Shell>/etc/init.d/mysql.server stop shutting down MySQL ... success!
Note: To start the cluster again, follow the start step of part five, but do not add the "-initial" parameter when starting the data node.

MySQL Cluster build details (three node separation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.