1. Preparation
Cluster:
192.168.1.191 Management Node
192.168.1.192 Management Node
192.168.1.193 Data Node and API Node
192.168.1.194 Data Node and API Node
Installation package: mysql-cluster-gpl-7.5.5-linux-glibc2.5-x86_64.tar.gz
2. Installation
Install mysql management node
cd mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64/ sudo cp bin/ndb_mgm* /usr/local/bin
cd /usr/local/bin
sudo mkdir /var/lib/mysql-cluster
sudo mkdir /usr/local/mysql
sudo vi /var/lib/mysql-cluster/config.ini
sudo chmod -r 777 /var/lib/mysql-cluster/
sudo chmod -R 777 /usr/local/mysql/
config.ini is as follows:
[ndbd default] NoOfReplicas = 2 DataMemory = 512M IndexMemory=18M [ndb_mgmd] HostName=192.168.1.191 DataDir=/var/lib/mysql-cluster
[ndb_mgmd]
HostName=192.168.1.192
DataDir=/var/lib/mysql-cluster
[ndbd] HostName=192.168.1.193 DataDir=/var/lib/mysql-cluster [ndbd] HostName=192.168.1.194 DataDir=/var/lib/mysql-cluster
Execute on 191: /usr/local/bin/ndb_mgmd -f / var /lib/mysql-cluster/config.ini --initial
Execute on 192: /usr/local/bin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini
Success is as follows:
test:
cd /usr/local/bin
ndb_mgm
show #In
order to ensure the communication between the data node and the management node, you need to open port 1186
Install mysql data node
192.168.1.193 Data Node
192.168.1.194 Data Node
sudo groupadd mysql sudo useradd -g mysql -s /bin/false mysql
sudo mv mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64/ /usr/local/mysql
sudo mkdir /var/lib/mysql-cluster
sudo chown root:mysql /var/lib/mysql-cluster
sudo chmod -R 777 /var/lib/mysql-cluster/
sudo vi /etc/my.cnf
The content of my.cnf is as follows:
[client]
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
ndbcluster
ndb-connectstring=192.168.1.191
ndb-connectstring=192.168.1.192
[mysql_cluster]
ndb-connectstring=192.168.1.191
ndb-connectstring=192.168.1.192
cd /usr/local/mysql/
bin/ndbd --initial #Data node initialization
Test: on the management node
cd /usr/local/bin
ndb_mgm
show
Install the API (mysqld) node
initialize mysql
cd /usr/local/mysql/
./bin/mysqld --initialize
will generate a temporary password, remember the temporary password, you need to use it later
support-files/mysql.server start #Start mysql
support-files/mysql.server status #View mysql status
Test: on the management node
cd /usr/local/bin
ndb_mgm
show
Final setup: on the management node
cd /usr/local/bin ndb_mgm
shutdown #Turn off the services of the management node and data node
cd /usr/local/ mysql
. /bin/mysql -u root -p #Then enter the password The password is the temporary random password generated before
Modify the root password, change the remote access, and open port 3306 when connecting externally.
SET PASSWORD = PASSWORD('your new password'); use mysql; update user set host = '%' where user = 'root'; #Then change remote accessFLUSH
PRIVILEGES;
Start the cluster:
ps: Do not start the API cluster until the data nodes are all started
#Start the management node /usr/local/bin/ ndb_mgmd #start datanode cd /usr/loca/mysql/ ./bin/ndbd #Start api node cd /usr/loca/mysql/ ./support-files/mysql.server start
test:
The test synchronization succeeded, but the test01 synchronization failed
The default database is automatically synchronized. When creating a table, the data engine is mainly selected and ndbcluster is selected to be synchronized.