CentOS7 mysql-cluster安装与配置

目录

下载安装:

#拷贝ndb_mgm和ndb_mgmd

#创建并编辑配置文件

#初始化管理节点

安装数据节点和sql节点

#初始化mysql

#启动mysql

#登录并设置新密码

#启动ndbd节点:

#启动和停止管理节点

mysql-cluster安装与配置

下载安装:

下载工具包地址:https://dev.mysql.com/downloads/cluster/

注:以mysql-cluster-8.0.25-linux-glibc2.12-x86_64.tar.gz为例

$>wget https://downloads.mysql.com/archives/get/p/14/file/mysql-cluster-8.0.25-linux-glibc2.12-x86_64.tar.gz

$> tar -zxvf mysql-cluster-8.0.25-linux-glibc2.12-x86_64.tar.gz

#将解压的文件重命名为mysql-cluster移动到/usr/local/mysql目录下

$> mv mysql-cluster-8.0.25-linux-glibc2.12-x86_64 /usr/local/mysql/mysql-cluster

#复制到其它服务器

$> scp -r /usr/local/mysql/mysql-cluster root@192.168.106.102:/usr/local/mysql/mysql-cluster

$> scp -r /usr/local/mysql/mysql-cluster root@192.168.106.103:/usr/local/mysql/mysql-cluster

#防火墙 status查看是否开启,stop关闭

$> systemctl status firewalld

$> systemctl stop firewalld

不用执行:[root@mysql ~]# systemctl disable firewalld

#拷贝ndb_mgm和ndb_mgmd

$> cp /usr/local/mysql/mysql-cluster/bin/ndb_mgm* /usr/local/bin/

#创建并编辑配置文件

$> vi /usr/local/mysql/mysql-cluster/config.ini

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ndbd default] #ptions affecting ndbd processes on all data nodes: NoOfReplicas=2 # Number of fragment replicas DataMemory=256M # How much memory to allocate for data storage [ndb_mgmd] # Management process options: NodeId=1 HostName=192.168.106.101 # Hostname or IP address of management node default port 1186 DataDir=/usr/local/mysql/mysql-cluster # Directory for management node log files [ndbd] # Options for data node "A": # (one [ndbd] section per data node) HostName=192.168.106.102 # Hostname or IP address NodeId=2 # Node ID for this data node DataDir=/usr/local/mysql/clu_data # Directory for this data node's data files [ndbd] # Options for data node "B": HostName=192.168.106.103 # Hostname or IP address NodeId=3 # Node ID for this data node DataDir=/usr/local/mysql/clu_data # Directory for this data node's data files [mysqld] # SQL node options: NodeId=4 HostName=192.168.106.102 # Hostname or IP address # (additional mysqld connections can be # specified for this node for various # purposes such as running ndb_restore) [mysqld] # SQL node options: NodeId=5 HostName=192.168.106.103 |

#初始化管理节点

$> /usr/local/bin/ndb_mgmd -f /usr/local/mysql/mysql-cluster/config.ini --initial

ndb_mgmd是mysql cluster的管理服务器,-f:指定启动的参数配置文件

#--initial:初始化配置,修改配置文件启动时就必须加上--initial参数,不然添加的节点不会在mysql cluster中

#验证初始化管理节点是否启动成功

$> /usr/local/bin/ndb_mgm

-- NDB Cluster -- Management Client --

|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ndb_mgm> show Connected to Management Server at: 192.168.106.101:1186 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=2 @192.168.106.102 (mysql-8.0.25 ndb-8.0.25, Nodegroup: 0, *) id=3 @192.168.106.103 (mysql-8.0.25 ndb-8.0.25, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s) id=1 @192.168.106.101 (mysql-8.0.25 ndb-8.0.25) [mysqld(API)] 2 node(s) id=4 @192.168.106.102 (mysql-8.0.25 ndb-8.0.25) id=5 @192.168.106.103 (mysql-8.0.25 ndb-8.0.25) |

安装数据节点和sql节点

$> vi /etc/my.cnf

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [mysqld] datadir=/usr/local/mysql/clu_data basedir=/usr/local/mysql/mysql-cluster ndbcluster default-storage-engine=ndbcluster port=33062 #character config character_set_server=utf8mb4 explicit_defaults_for_timestamp=true [mysqld_safe] #log-error=/var/log/mariadb/mariadb.log log-error=/usr/local/mysql/clu_data/mysql.log #pid-file=/var/run/mariadb/mariadb.pid : [mysql_cluster] ndb-connectstring=192.168.106.101:1186 # # include all files from the config directory # !includedir /etc/my.cnf.d |

#初始化mysql

$>/usr/local/mysql/mysql-cluster/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql-cluster --datadir=/usr/local/mysql/clu_data

#启动mysql

$>/usr/local/mysql/mysql-cluster/support-files/mysql.server start

#登录并设置新密码

$> mysql -uroot -p

ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
use mysql;
update user set host = '%' where user = 'root';
flush privileges;

如果连接报错:

修改mysql的root用户的语句:alter user 'root'@'localhost' identified by 'xxx'; mysql默认使用sha_256加密,再次修改mysql账号的密码,使用其他的加密方式,如下语句:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'xxx';

flush privileges;

#启动ndbd节点:

$> cp /usr/local/mysql/mysql-cluster/bin/ndbd /usr/local/bin/ndbd

$> cp /usr/local/mysql/mysql-cluster/bin/ndbmtd /usr/local/bin/ndbmtd

$> /usr/local/mysql/mysql-cluster/bin/ndbd --initial

#首次启动数据节点时要加上--initial参数,后续启动不能添加该参数,否则ndbd程序会清除在之前建立的所有用于恢复的数据文件和日志文件

下次启动直接

$> /usr/local/mysql/mysql-cluster/bin/ndbd

#启动和停止管理节点

启动顺序:管理节点->[数据节点,sql节点]

管理节点启动:/usr/local/bin/ndb_mgmd -f /usr/local/mysql/mysql-cluster/config.ini

数据节点启动: /usr/local/bin/ndbd

SQL节点启动:/usr/local/mysql/mysql-cluster/support-files/mysql.server start

管理节点停止: /usr/local/bin/ndb_mgm -e shutdown

数据节点停止: /usr/local/bin/ndbd shutdown

SQL节点停止:/usr/local/mysql/mysql-cluster/support-files/mysql.server stop

在其中一台创建一个新的库,添加一个ndbcluster 引擎的表,其它引擎数据不会同步:

集群数据库创建表的引擎必须是:ENGINE=NDBCLUSTER or ENGINE=NDB

CREATE TABLE `test` (

`id` bigint NOT NULL AUTO_INCREMENT

) ENGINE =ndbcluster;

INSERT test(id) value(1);

异常处理:

libcrypto.so.1.1: cannot open shared object file: No such

gcc查看是否安装gcc -v

安装yum install gcc gcc-c++

openssl查看是否安装openssl version

安装yum install -y openssl openssl-devel

ALTER USER 'root'@'%' IDENTIFIED BY 'Aa123456' PASSWORD EXPIRE NEVER; #修改加密规则

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Aa123456';

flush privileges;

相关推荐
诸神黄昏EX14 分钟前
Android 分区相关介绍
android
打鱼又晒网1 小时前
【MySQL】数据库精细化讲解:内置函数知识穿透与深度学习解析
数据库·mysql
大白要努力!1 小时前
android 使用SQLiteOpenHelper 如何优化数据库的性能
android·数据库·oracle
Estar.Lee1 小时前
时间操作[取当前北京时间]免费API接口教程
android·网络·后端·网络协议·tcp/ip
Winston Wood1 小时前
Perfetto学习大全
android·性能优化·perfetto
tatasix2 小时前
MySQL UPDATE语句执行链路解析
数据库·mysql
天海华兮2 小时前
mysql 去重 补全 取出重复 变量 函数 和存储过程
数据库·mysql
武子康4 小时前
大数据-231 离线数仓 - DWS 层、ADS 层的创建 Hive 执行脚本
java·大数据·数据仓库·hive·hadoop·mysql
黑色叉腰丶大魔王4 小时前
《MySQL 数据库备份与恢复》
mysql
Ljw...4 小时前
索引(MySQL)
数据库·mysql·索引