MySQL Cluster三机集群+HA高可用+负载均衡配置手册(3)

检查集群工作状态
在db1或者db2任意一台服务器上启动管理终端:
[root@db2 mysql]# ndb_mgm -e show
Connected to Management Server at: 172.16.1.78:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2    @172.16.1.74  (mysql-5.5.31 ndb-7.2.13, Nodegroup: 0, Master)
id=3    @172.16.1.75  (mysql-5.5.31 ndb-7.2.13, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @172.16.1.78  (mysql-5.5.31 ndb-7.2.13)

[mysqld(API)]  4 node(s)
id=4 (not connected, accepting connect from any host)
id=5 (not connected, accepting connect from any host)
id=6 (not connected, accepting connect from any host)
id=7 (not connected, accepting connect from any host)
id=8 (not connected, accepting connect from any host)
id=9 (not connected, accepting connect from any host)
如果上面没有问题,现在开始加入mysqld(API)
六、启动SQL节点
在db1 中:
[root@db1 sbin]# mysqld_safe --ndb_nodeid=4 --user=mysql &
[1] 12495
[root@db1 sbin]# 131030 10:26:00 mysqld_safe Logging to '/var/log/mysqld.log'.
131030 10:26:00 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data/
在db2 中:
[root@db2 mysql]# mysqld_safe --ndb_nodeid=6 --user=mysql &
[1] 11756
[root@db2 sbin]#131030 10:18:56 mysqld_safe Logging to '/var/log/mysqld.log'.
131030 10:18:57 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data/

出现131110  0:37:19 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
错误时怎样解决问题
/usr/bin/mysql_install_db --user=mysql --datadir=/var/lib/mysql/data/

再次检查集群工作状态,看SQL节点是否加入成功,出现下面的提示信息表示添加成功
[root@db1 sbin]# ndb_mgm -e show
Connected to Management Server at: 172.16.1.78:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2    @172.16.1.74  (mysql-5.5.31 ndb-7.2.13, Nodegroup: 0, Master)
id=3    @172.16.1.75  (mysql-5.5.31 ndb-7.2.13, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @172.16.1.78  (mysql-5.5.31 ndb-7.2.13)

[mysqld(API)]  4 node(s)
id=4    @172.16.1.74  (mysql-5.5.31 ndb-7.2.13)
id=5    @172.16.1.74  (mysql-5.5.31 ndb-7.2.13)
id=6    @172.16.1.75  (mysql-5.5.31 ndb-7.2.13)
id=7    @172.16.1.75  (mysql-5.5.31 ndb-7.2.13)
id=8 (not connected, accepting connect from any host)
id=9 (not connected, accepting connect from any host)

此步也可以通过执行mysql服务器启动命令来代替
[root@db1 mysql-cluster]# service mysql start
Starting MySQL.......................[确定]......................

设置开机自动启动
将一下内容加入到/etc/rc.d/rc.local文件的最后一行,就可以使得ndb_mgmd和ndbd开机自动启动了
管理节点服务器172.16.1.78上添加ndb_mgmd -f /var/lib/mysql-cluster/config.ini
数据和SQL节点服务器172.16.1.74、172.16.1.75上添加ndbd
注:mysqld服务会自动重启,不需要添加

七、设置数据库的用户名和密码
执行如下命令:
./bin/mysqladmin -u root password 'huawei'
./bin/mysqladmin -u root -h db2 password 'huawei'
新增一个webapp用户,并且配置权限
mysql>GRANT ALL ON *.* TO 'webapp'@'%' IDENTIFIED BY 'huawei';
mysql>GRANT ALL ON *.* TO 'webapp'@'localhost' IDENTIFIED BY 'huawei';
mysql>GRANT ALL ON *.* TO 'webapp'@'db1' IDENTIFIED BY 'huawei';
mysql>GRANT ALL ON *.* TO 'webapp'@'db2' IDENTIFIED BY 'huawei';

八、功能测试
到管理节点查看下相关服务状态
# ndb_mgm
ndb_mgm> show
Connected to Management Server at: 172.16.1.78:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2    @172.16.1.74  (mysql-5.5.31 ndb-7.2.13, Nodegroup: 0, Master)
id=3    @172.16.1.75  (mysql-5.5.31 ndb-7.2.13, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @172.16.1.78  (mysql-5.5.31 ndb-7.2.13)

[mysqld(API)]  6 node(s)
id=4    @172.16.1.74  (mysql-5.5.31 ndb-7.2.13)
id=5    @172.16.1.74  (mysql-5.5.31 ndb-7.2.13)
id=6    @172.16.1.75  (mysql-5.5.31 ndb-7.2.13)
id=7    @172.16.1.75  (mysql-5.5.31 ndb-7.2.13)
id=8 (not connected, accepting connect from any host)
id=9 (not connected, accepting connect from any host)
可以看到这里的数据节点、管理节点、sql节点都是正常的。现在我们在其中一个数据节点上进行相关数据库的创建,然后到另外一个数据节点上看看数据是否同步。
[root@db2 usr]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.31-ndb-7.2.13-cluster-gpl MySQL Cluster Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/e6d08f24de9c8aafe351cad59d812345.html