MySQLCluster is a technology that allows you to deploy a Cluster of databases in memory in a non-shared system. Without a shared architecture, the system can use cheap hardware without special requirements for hardware and software. In addition, since each component has its own memory and disk, MySQL Cluster is a technology that allows the deployment of the "memory" database Cluster in a non-shared system. Without a shared architecture, the system can use cheap hardware without special requirements for hardware and software. In addition, since each component has its own memory and disk, there is no single point of failure. MySQL Cluster is composed of a group of computers, each of which runs a variety of processes, including MySQL servers, NDB Cluster data nodes, management servers, and (possibly) dedicated Data Access program.
The commands that both servers need to execute are not mentioned in the following section. because they are configured in the dual-management center, in fact, the two machines have different id and ip configurations. other parameter configurations are basically the same.
1. download mysql-cluster 7.3.7
Http://dev.mysql.com/downloads/cluster/
2. clean up the environment and install the mysql service that comes with CentOS6.5. I can run the first command without executing it. if not, we recommend that you run the command.
# Yum-y remove mysql # rpm-qa | grep mysql * # rpm-e-nodeps mysql-libs-5.1.71-1.el6.x86_64
2) prepare the environment
Create a folder (the following three classes are used to create the corresponding folder)
Storage node: # mkdir/var/lib/mysql/data
Management Node: # mkdir/var/lib/mysql-cluster SQL node: folder authorization is not required.
Process DIR: # mkdir/var/run/mysqld
You can use the following command to change the permission to write data:
# Chmod-R 1777/var/lib/mysql
# Chmod-R 1777/var/run/mysqld
# Chmod-R 1777/var/lib/mysql-cluster
3) install mysql-cluster
First release mysql-cluster-gpl-7.4.2-1.el6.x86_64.rpm-bundle.tar
# Tar xvf MySQL-Cluster-gpl-7.4.2-1.el6.x86_64.rpm-bundle.tar
Run the following command to install
# Rpm-ivh MySQL-Cluster-server-gpl-7.3.4-1.el6.x86_64.rpm
# Rpm-ivh MySQL-Cluster-client-gpl-7.3.4-1.el6.x86_64.rpm
Note: after the server gpl package is installed, the following message is displayed, reminding us that the first super account password after the cluster is installed exists in the/root/. mysql_secret file.
Bytes ---------------------------------------------------------------------------------------------------------------------
A random password has been set for the MySQL root USER!
You will find that password in '/root/. mysql_secret '.
You must change that password on your first connect,
No other statement but 'set password' will be accepted.
See the manual for the semantics of the 'password expired' flag.
Also, the account for the anonymous user has been removed.
In addition, you can run:
/Usr/bin/mysql_secure_installation
Which will also give you the option of removing the test database.
This is stronugly recommended for production servers.
-----------------------------------------------------------
2. configuration management node
1) execute the following command:
# Cd/var/lib/mysql-cluster
# Vi config. ini
2) configure the config. ini file, for example, the configuration file in attachment 100.218: [computer]
Mgr-server-01
HostName = 192.168.100.218
[Mgm default]
Datadir =/var/lib/mysql-cluster
[Mgm]
HostName = 192.168.100.218
NodeId = 60
ExecuteOnComputer = mgr-server-01
PortNumber = 1186
ArbitrationRank = 2
[Mgm]
HostName = 192.168.100.217
NodeId = 61
ExecuteOnComputer = mgr-server-01
PortNumber = 1186
ArbitrationRank = 2
[Ndbd default]
NoOfReplicas = 2
DataMemory = 500 M
IndexMemory = 500 M
[Ndbd]
HostName = 192.168.100.217
DataDir =/var/lib/mysql
NodeId = 1
[Ndbd]
HostName = 192.168.100.218
DataDir =/var/lib/mysql
NodeId = 2
[Mysqld]
HostName = 192.168.100.217
NodeId = 81
[Mysqld]
HostName = 192.168.100.218
NodeId = 82
Configuration file 100.217: [computer]
Mgr-server-02
HostName = 192.168.100.217
[Mgm default]
Datadir =/var/lib/mysql-cluster
[Mgm]
HostName = 192.168.100.218
NodeId = 60
ExecuteOnComputer = mgr-server-01
PortNumber = 1186
ArbitrationRank = 2
[Mgm]
HostName = 192.168.100.217
NodeId = 61
ExecuteOnComputer = mgr-server-01
PortNumber = 1186
ArbitrationRank = 2
[Ndbd default]
NoOfReplicas = 2
DataMemory = 500 M
IndexMemory = 500 M
[Ndbd]
HostName = 192.168.100.217
DataDir =/var/lib/mysql
NodeId = 1
[Ndbd]
HostName = 192.168.100.218
DataDir =/var/lib/mysql
NodeId = 2
[Mysqld]
HostName = 192.168.100.217
NodeId = 81
[Mysqld]
HostName = 192.168.100.218
NodeId = 82
In fact, there is little difference between the two files, that is, the name and id in the computer configuration.
3. SQL node and data node configuration
Modify my. add the following content to the cnf File: [client] socket =/var/lib/mysql. sock [mysqld] max_connections = 100 datadir =/var/lib/mysql socket =/var/lib/mysql. sock ndbcluster ndb-connectstring = 192.168.100.218, 192.168.100.217 [mysqld_safe] log-error =/var/log/mysqld. log # pid-file =/var/run/mysqld. pid-file =/var/lib/mysql/mysqld. pid
[Mysql_cluster] ndb-connectstring = 192.168.100.218, 192.168.100.217
4. MySQL Cluster initial startup command and user password change adjustment: (please start in strict order)
1) start mysql-cluster
Before starting the service for the first time, make sure that the firewall of the two machines is disabled (service iptables stop or set the firewall port to allow access, and the two ports are communication port 1186 and data port 3306)
Start mgt console command for the first time: ndb_mgmd-f/var/lib/mysql-cluster/config. ini
Run the "ndbd -- initial" command to start the balancing node.
Run mysqld_safe -- defaults-file =/usr/my. cnf -- explicit_defaults_for_timestamp &
My. cnf is in the etc directory in some systems
Pay attention to the need to monitor the entire console output during the startup process. if any error information is found, it should be resolved in a timely manner based on the error log content.
Bytes ---------------------------------------------------------------------------------------------------------
Run the following command to enable the Management console: ndb_mgm
Run # show
Check whether all nodes have been fully started, as shown below. each node is connected. if any node is not connected, you will see
Ndb_mgm> show
Connected to Management Server at: 192.168.100.218: 1186
Cluster Configuration
---------------------
[Ndbd (NDB)] 2 node (s)
Id = 1 @ 192.168.100.217 (mysql-5.6.21 ndb-7.4.2, node group: 0)
Id = 2 @ 192.168.100.218 (mysql-5.6.21, Nodegroup: 0 ,*)
[Ndb_mgmd (MGM)] 1 node (s)
Id = 60 @ 192.168.100.218 (mysql-5.6.21 ndb-7.4.2)
Id = 61 @ 192.168.100.217 (mysql-5.6.21 ndb-7.4.2)
[Mysqld (API)] 2 node (s)
Id = 81 @ 192.168.100.217 (mysql-5.6.21 ndb-7.4.2)
Id = 82 @ 192.168.100.218 (mysql-5.6.21 ndb-7.4.2)
If a node is not connected, as shown in the following code, id = 81 indicates no connection. check the fault point.
Ndb_mgm> show
Cluster Configuration
---------------------
[Ndbd (NDB)] 2 node (s)
Id = 1 @ 192.168.100.217 (mysql-5.6.21 ndb-7.4.2, node group: 0)
Id = 2 @ 192.168.100.218 (mysql-5.6.21, Nodegroup: 0 ,*)
[Ndb_mgmd (MGM)] 1 node (s)
Id = 60 @ 192.168.100.218 (mysql-5.6.21 ndb-7.4.2)
Id = 61 @ 192.168.100.217 (mysql-5.6.21 ndb-7.4.2)
[Mysqld (API)] 2 node (s)
Id = 81 (not connected, accepting connect from 192.168.100.217)
Id = 82 @ 192.168.100.218 (mysql-5.6.21 ndb-7.4.2)
2) change the password
After mysqld is started properly (you can use pgrep mysqld to obtain the process ID), run the following command to modify the process ID:
Mysql-u root-p;
Random password (for details, see The/root/. mysql_secret file), and then use the following command to change the password:
Set password = PASSWORD ('New password ');
However, the new password must be a hash value. Therefore, you must use the following method to obtain the hash value of the password string:
Select password ('20140901 ');
However, executing the above Command will allow you to set the password first, and then turn it back, go to mysql elsewhere and execute the following command. the hash value of 111111 is "* Reset" set password = PASSWORD ('* fd571204174ba9afe270fe62151ae967eca5e0aa'). It's depressing. after the setting, the ciphertext must be used for login. Then, use the ciphertext to log on to the system. run the following command to force the use mysql; delete from user; grant all on *. * to root @ '%' identified by "111111" with grant option; flush privileges; quit; then, you can use the plaintext password to log on.
The preceding commands must be executed on several servers with SQL data nodes;
5. after the above steps are completed, test whether the cluster works normally.
1) simple function testing
Run the following command on mysql 218:
Create database clustertest;
Use clustertest;
Create table testtable (Count INT) ENGINE = NDBCLUSTER; note: ENGINE = NDBCLUSTER; the ENGINE must use NDBCLUSTER to synchronize data; otherwise, data will not be synchronized.
Check whether the database and table are created automatically. go to mysql on mysql 217. if the database and table are created successfully, check the Environment configuration.
2) test whether data can be synchronized in the case of disaster recovery (if a database is stopped and then started, will the lost data be automatically supplemented)
Stop the mysql service on 217 and run it on 218.
Insert into testtable values (1 );
Start mysql 217 and use show to check that the database nodes of 217 are connected. run the following statement:
Select * from testtable;
If data is found, the function is complete.
6. disable Cluster: (the Cluster must be executed in strict order)
Close the data node: # mysqld stop (the SQL node can be shut down using mysqladmin shutdown or another method .)
Run # ndb_mgm-e shutdown on the management node.
Close management nodes and data nodes securely.
Run the following process detection command to check whether the system has exited:
# Pgrep mysqld
# Ps aux | grep nbdb
If not, find the corresponding pid and perform the kill operation.
Kill-9 process no.
7. restart the Cluster solution:
The order in which the entire cluster is started. Note that some statements have subtracted the initialization content:
Ndb_mgmd-f/var/lib/mysql-cluster/config. inindbd
Mysqld_safe -- defaults-file =/etc/my. cnf -- explicit_defaults_for_timestamp &
Note: 1. After mysql is installed, it will be automatically started by default. every time you start the cluster, you must first disable the mysql service, which is too troublesome, you can execute the following command (I am a little embarrassed ):
Chkconfig -- level 123456 mysql off
2. firewall problems. I am too lazy to open ports one by one. I simply shut down the firewall directly (not recommended)
Chkconfig -- level 123456 iptables off