当前位置:Gxlcms > 数据库问题 > mysql-cluster 安装配置

mysql-cluster 安装配置

时间:2021-07-01 10:21:17 帮助过:22人阅读

[root@amoebe mysql]# ./bin/ndb_mgmd -f config.ini      #启动服务

MySQL Cluster Management Server mysql-5.7.18 ndb-7.5.6   #启动成功


[root@amoebe mysql]# ./bin/ndb_mgm                #进入管理程序,可以看到配置文件生效了,但因为没配置节点上的mysql,所以这里显示未连接

-- NDB Cluster -- Management Client --

ndb_mgm> show

Connected to Management Server at: localhost:1186

Cluster Configuration

---------------------

[ndbd(NDB)]2 node(s)

id=2 (not connected, accepting connect from 192.168.240.129)

id=3 (not connected, accepting connect from 192.168.240.127)


[ndb_mgmd(MGM)]1 node(s)

id=1@192.168.240.130  (mysql-5.7.18 ndb-7.5.6)


[mysqld(API)]2 node(s)

id=4 (not connected, accepting connect from 192.168.240.129)

id=5 (not connected, accepting connect from 192.168.240.128)


-------------------------------------------------------------------------------------------------------------------------------

配置节点: 192.168.240.128/192.168.240.129


[root@localhost]# useradd -s /sbin/nologin mysql

[root@localhost]# mkdir /soft/mysql

[root@localhost]# tar xf mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz 

[root@localhost]# mkdir /soft/mysql/data

[root@localhost]# chown -R mysql:mysql /soft/mysql

[root@localhost]# cd /soft/mysql

[root@localhost mysql]# yum install -y libaio*

vim support-files/mysql.server    #修改服务文件

basedir=/soft/mysql

datadir=/soft/mysql/data


[root@yaho mysql]# bin/mysqld  --initialize --user=mysql --basedir=/soft/mysql --datadir=/soft/mysql/data

./bin/mysqld --initialize --user=mysql --datadir=/soft/mysql/data      --注意自动生成的临时密码


[Note] A temporary password is generated for root@localhost: pByj>rz95OhV

----------------------------------------------------------------------------------------------------------------------------------

先更改密码:


[root@yaho mysql]# bin/mysql -u root -p‘pByj>rz95OhV‘        --登录mysql,有特殊符号,要用‘‘括起来,在这里踏坑了

mysql> use mysql;                                --必须先更改密码才可以操作

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> alter user ‘root‘@‘localhost‘ identified by ‘123456‘;

Query OK, 0 rows affected (0.00 sec)


[root@mysql]# vim /etc/my.cnf

[mysqld]

datadir=/soft/mysql/data

user=mysql

ndbcluster

lc_messages-dir=/soft/mysql/share/

ndb-connectstring=192.168.240.130

 

[mysql_cluster]

ndb-connectstring=192.168.240.130

 

[root@mysql]# bin/ndbd --initial      #第一次使用要初始化数据,下次不能加--initial,否则会清空数据库

[root@mysql]# ln -s /soft/mysql/bin /sbin/mysql

[root@mysql]# ln -s /soft/mysql/support-files/mysql.server  /sbin/mysqld


----------------------------------------------------------------------------------------------------------------------------

回到130控制台:


ndb_mgm> show

Cluster Configuration

---------------------

[ndbd(NDB)]2 node(s)

id=2@192.168.61.128  (mysql-5.7.18 ndb-7.5.6, starting, Nodegroup: 0)  --节点ndbd已连接

id=3@192.168.61.129  (mysql-5.7.18 ndb-7.5.6, starting, Nodegroup: 0) --节点ndbd已连接


[ndb_mgmd(MGM)]1 node(s)

id=1@192.168.61.130  (mysql-5.7.18 ndb-7.5.6)


[mysqld(API)]2 node(s)

[mysqld(API)]2 node(s)

id=4@192.168.61.128  (mysql-5.7.18 ndb-7.5.6)                  #小心防火墙

id=5@192.168.61.129  (mysql-5.7.18 ndb-7.5.6)                  #小心防火墙


-----------------------------------------------------------------------------------------------------------------------------

测试:

建库/建表

在192.168.61.128上登录mysql:

mysql>create databases abc charset=gbk;

Query OK, 0 rows affected (0.72 sec)

mysql>create table name(id int(5) not null primary key auto_increment,name varchar(10) not null ) engine=ndb;

Query OK, 0 rows affected (0.72 sec)

mysql>insert into name(name) values (‘张三‘),(‘李四‘);


-----------------------------------------------------------------------------------------------------------------------------

在192.168.240.128/192.168.240.129 进行查询

mysql>select * from tp.name;

+----+---------+

| id | name   |

+----+----------+

|  1 | 张三   |

|  2 | 李四   |

+----+---------+


-----------------------------------------------------------------------------------------------------------------------------

模拟192.168.240.128/192.168.240.129故障之一失效,再查询

mysql>select * from tp.name;


+----+---------+

| id | name   |

+----+----------+

|  1 | 张三   |

|  2 | 李四   |

+----+---------+

mysql>insert into name(name) values (‘长江‘),(‘黄河‘);

Query OK, 0 rows affected (0.72 sec)

mysql> select * from tp.name group by id;

+----+--------+

| id | name   |

+----+--------+

|  1 | 长江   |

|  2 | 黄河   |

|  3 | 张三   |

|  4 | 李四   |

+----+--------+

4 rows in set (0.01 sec)


经过测试总结几点:

  1. 当cluster挂了后,两个数据节点的mysql都不能访问数据库;

  2. 当cluster挂了时,两个mysql还是可以正常工作的,更新数据也会同步,但不能重启mysql服务;

2.只要不是两个mysql服务同时挂了,数据还是安全的。

3.当cluster挂掉,节点A挂掉,这时往节点B上更新数据;cluster和节点A恢复上线后会造成节点A和节点B的数据不一致。

4.当两个mysql数据不一致时,先启动cluster,再启动数据更新的数据节点和SQL节点,确保已经成功连上cluster,最后再启动另一个节点,后一个节点会自动更新最新的数据。!!启动顺序很重要!!!


-----------------------------------------------------------------------------------------------------------------------------


启动顺序:

管理节点 ndb_megd -> 数据节点 ndbd -> SQL节点 指定ndbcluster 参数的专用mysqld

     ndb_mgmd -f config.ini -> ndbd -> mysqld start 


关闭顺序:

SQL节点 指定ndbcluster 参数的专用mysqld ->  管理节点 ndb_mem

      mysqld stop --> ndb_mgm -e shutdown --> 完成



附:


1. mysqld --initialize-insecure自动生成无密码的root用户,mysqld --initialize自动生成带随机密码的root用户


2.用mysql帐号设置的话需要在 /etc/security/limits.conf 中追加下面信息,不然会提示limite限制错误:

mysql   hard   nofile   65535


3.[ERROR] Can‘t find error-message file ‘/usr/local/mysql/share/zh-cn/errmsg.sys‘. Check error-message file location and ‘lc-messages-dir‘ configuration directive.

在my.cnf里添加行:

lc_messages-dir=/soft/mysql/share/


4.启动mysql时,可能会提示:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (111)


ln -s /soft/mysql/mysql.sock  /tmp/mysql.sock             #要用绝对路径



mysql-cluster 安装配置

标签:mysql cluster

人气教程排行