1. Download MySQL-cluster 7.3.7
http://dev.mysql.com/downloads/cluster/
2. Environment cleanup and installation
1) Clean up the mysql service that comes with CentOS6.5. I don’t have to execute the first command. If it is not possible on other systems, it is recommended to execute it
# yum -y remove mysql # rpm -qa | grep mysql* # rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
2) Environment preparation
Create folders (divided into the following 3 categories to create corresponding folders)
存储节点:# mkdir /var/lib/mysql/data 管理节点:# mkdir /var/lib/mysql-cluster SQL节点:可不用 文件夹授权 进程DIR:# mkdir /var/run/mysqld
使用如下的命令来变更权限保证可写入: # chmod -R 1777 /var/lib/mysql # chmod -R 1777 /var/run/mysqld # chmod -R 1777 /var/lib/mysql-cluster
3) Install mysql-cluster
First unzip 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
Then execute 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
Pay special attention to when the server gpl package is installed Afterwards, the following prompt message will appear, reminding us that the first super account password after the entire cluster is installed exists in the file /root/.mysql_secret.
--------------------------------------------------------------------------------------------------------------------- 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 strongly recommended for production servers. -----------------------------------------------------------
2. Configure the management node
1) Execute the following command:
# cd /var/lib/mysql-cluster # vi config.ini
2) Configure the config.ini file
[computer] Id=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 [ndbd default] NoOfReplicas=2 DataMemory=500M IndexMemory=500M [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
3. SQL node and Data node configuration
Modify the my.cnf file and add the following content:
[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.100.218 [mysqld_safe] log-error=/var/log/mysqld.log #pid-file=/var/run/mysqld/mysqld.pid pid-file=/var/lib/mysql/mysqld.pid [mysql_cluster] ndb-connectstring=192.168.100.218
4. MySQL Cluster initial startup command and user password change adjustment: (Please start in strict accordance with the order)
1) Start mysql-cluster
Before executing the initial startup, please confirm that the firewalls of the two machines are turned off (service iptables stop or set the firewall port to be passable, the two ports are communication port 1186 and data port 3306)
Start mgt for the first time Console command: NDB_MGMD -F /VAR/Lib/mysql-Cluster/config.ini
Start Bacten Node Command: NDBD-Intial
Start Data Node Command: MySQLD_SAFE-Defaults-FILE =/ETC/My. cnf --explicit_defaults_for_timestamp &
Note that the entire console output needs to be monitored during the startup process. If any error messages are found, they need to be resolved in time and based on the error log content.
-------------------------------------------------- -------------------------------------------------- --------
If everything is normal, use the following command to open the Management console: ndb_mgm
Execute# show
Check whether each node has been fully started, as follows, each node has been connected , if there is a node that 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, Nodegroup: 0) id=2 @192.168.100.218 (mysql-5.6.21 ndb-7.4.2, Nodegroup: 0, *) [ndb_mgmd(MGM)] 1 node(s) id=60 @192.168.100.218 (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 there is a node that is not connected, as shown below, the line with id=81 means there is 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, Nodegroup: 0) id=2 @192.168.100.218 (mysql-5.6.21 ndb-7.4.2, Nodegroup: 0, *) [ndb_mgmd(MGM)] 1 node(s) id=60 @192.168.100.218 (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) Modify Password
When mysqld starts normally (you can use pgrep mysqld to obtain the process ID), we can use the following command to modify it:
mysql -u root -p;
Random password (see the /root/.mysql_secret file for details), After entering, use the following command to change the password:
SET PASSWORD = PASSWORD('新密码');
But this new password must be a hash value, so use the following method to obtain the hash value of the password string
select password('111111');
However, executing the above command will ask you to set a password first, which is frustrating, but it comes back again, so go and execute it on mysql elsewhere.
The hash value of 111111 is "*FD571203974BA9AFE270FE62151AE967ECA5E0AA"
SET PASSWORD = PASSWORD( '*FD571203974BA9AFE270FE62151AE967ECA5E0AA');
It's so depressing. After setting up, you still have to use ciphertext for login. Well, just use ciphertext to log in. After entering, use the following command to force the use of plaintext for login
use mysql; delete from user; grant all on *.* to root@'%' identified by "111111" with grant option; flush privileges; quit;
Then, you can use the clear text password to log in
Several servers equipped with SQL data nodes need to execute the above command once;
5. After the above steps are completed, test whether the cluster is working normally
1) Simple functional test
After entering mysql on 218, execute the following:
create database clustertest; use clustertest; CREATE TABLE testtable(Count INT) ENGINE=NDBCLUSTER;
Note: ENGINE=NDBCLUSTER; The engine must use NDBCLUSTER to synchronize, otherwise the synchronization will not occur
Check whether it is successful , on 217, go to mysql and check whether the database and table are automatically created. If they are created, it means success. If it fails, please check the environment configuration
2) Test whether the data can be synchronized in disaster recovery situations (one database is stopped) If it is lost, will the lost data be automatically replenished when it is restarted?)
Stop the mysql service on 217, execute
insert into testtable values (1);
on 218 to start the mysql service of 217, and use show to confirm 217 The database node has been connected. Execute the following statement
select * from testtable;
If data is found, it means the function is complete
6. Close Cluster: (need to be executed strictly in order)
Close the data node : # mysqld stop (SQL nodes can be shut down using mysqladmin shutdown or other methods. )
Execute on the management node: # ndb_mgm -e shutdown
will safely shut down the management node and data node.
After closing, use the following process detection command to check whether it exited:
# pgrep mysqld # ps aux | grep nbdb
If not, find the corresponding pid and perform the kill operation.
kill -9 process number
7, Start the Cluster plan again:
The sequence of starting the entire cluster. Note that some statements have been subtracted from the initialization content:
ndb_mgmd -f /var/lib/mysql-cluster/config.ini ndbd mysqld_safe --defaults-file=/etc/my.cnf --explicit_defaults_for_timestamp &
备注:
1、mysql安装后,默认会自动启动的,每次启动cluster的时候,都需要先把mysql的服务关闭,太麻烦,于是可以执行如下命令(我出手有点狠):
chkconfig --level 123456 mysql off
2、防火墙问题,偷个懒,我懒得去一一开放端口,干脆把防火墙直接关了
chkconfig --level 123456 mysql off
以上就是MySQL之——MySQL Cluster集群搭建详解(基于RPM安装包)的内容,更多相关内容请关注PHP中文网(www.php.cn)!