序号 | 主机 | 系统 | 角色 | 备注 |
1 | stu1:192.168.3.81 | rockylinux8.6最小化安装 | 管理节点 | |
2 | stu2:192.168.3.82 | rockylinux8.6最小化安装 | 数据节点 | |
3 | stu3:192.168.3.83 | rockylinux8.6最小化安装 | 数据节点 | |
4 | stu4:192.168.3.84 | rockylinux8.6最小化安装 | sql节点 | |
5 | stu5:192.168.3.85 | rockylinux8.6最小化安装 | sql节点 | |
6 | des6:192.168.3.86 | rockylinux8.6最小化安装 | client |
一、基础环境(管理节点、数据节点、sql节点)
1、下载mysql安装包,如下:
mysql-cluster-commercial-common-8.0.30-1.1.el8.x86_64.rpm
mysql-cluster-commercial-icu-data-files-8.0.30-1.1.el8.x86_64.rpm
mysql-cluster-commercial-client-plugins-8.0.30-1.1.el8.x86_64.rpm
mysql-cluster-commercial-libs-8.0.30-1.1.el8.x86_64.rpm
mysql-cluster-commercial-client-8.0.30-1.1.el8.x86_64.rpm
mysql-cluster-commercial-server-8.0.30-1.1.el8.x86_64.rpm
mysql-cluster-commercial-data-node-8.0.30-1.1.el8.x86_64.rpm
mysql-cluster-commercial-management-server-8.0.30-1.1.el8.x86_64.rpm
2、关闭selinux及防火墙,并重启系统
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl disable firewalld
systemctl stop firewalld
init 6
3.更新Yum源
rm -rf * /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
5、安装需求包
yum install -y perl net-tools vim wget
6、卸载冲突软件包
rpm -e postfix;rpm -e mariadb-libs
7、安装软件包
rpm -ivh mysql-cluster-commercial-common-8.0.30-1.1.el8.x86_64.rpm
rpm -ivh mysql-cluster-commercial-icu-data-files-8.0.30-1.1.el8.x86_64.rpm
rpm -ivh mysql-cluster-commercial-client-plugins-8.0.30-1.1.el8.x86_64.rpm
rpm -ivh mysql-cluster-commercial-libs-8.0.30-1.1.el8.x86_64.rpm
rpm -ivh mysql-cluster-commercial-client-8.0.30-1.1.el8.x86_64.rpm
rpm -ivh mysql-cluster-commercial-server-8.0.30-1.1.el8.x86_64.rpm
二、安装mysql-cluster集群
1、数据节点(stu2、stu3)
rpm -ivh mysql-cluster-commercial-data-node-8.0.30-1.1.el8.x86_64.rpm
cat >> /etc/my.cnf << EOF
ndbcluster #启动ndb引擎
ndb-connectstring=192.168.3.81 #管理节点IP地址
[mysql_cluster]
ndb-connectstring=192.168.3.81 #管理节点IP地址
EOF
2、sql节点(stu4、stu5)
cat >> /etc/my.cnf << EOF
ndbcluster #启动ndb引擎
ndb-connectstring=192.168.3.81 #管理节点IP地址
[mysql_cluster]
ndb-connectstring=192.168.3.81 #管理节点IP地址
EOF
3、管理节点(stu1)
rpm -ivh mysql-cluster-commercial-management-server-8.0.30-1.1.el8.x86_64.rpm
mkdir /usr/mysql-cluster
cat > /usr/mysql-cluster/config.ini << EOF
[ndbd default]
NoOfReplicas=2 #数据写入数量(数据节点的数量)
DataMemory=2G #配置数据存储可使用的内存(根据系统内存写)
[ndb_mgmd]
nodeid=1
datadir=/var/lib/mysql #管理结点的日志(日志文件路径)
HostName=192.168.3.81 #管理结点的IP地址。本机IP
###### data node options: #存储结点
[ndbd]
HostName=192.168.3.82
DataDir=/var/lib/mysql #mysql数据存储路径
nodeid=2
[ndbd]
HostName=192.168.3.83
DataDir=/var/lib/mysql #mysql数据存储路径
nodeid=3
###### SQL node options: #关于SQL结点
[mysqld]
HostName=192.168.3.84
nodeid=4
[mysqld]
HostName=192.168.3.85
nodeid=5
EOF
启动管理节点stu1
ndb_mgmd --ndb_nodeid=1 --initial -f /usr/mysql-cluster/config.ini
启动数据节点stu2 stu3
ndbd --initial
启动sql节点stu4 stu5
systemctl start mysqld
管理节点验证
netstat -natup | grep ndb
ndb_mgm
show
三、数据测试
1、sql节点(stu4、stu5)
grep password /var/log/mysqld.log
mysql -uroot -p'iV?l/*g9i7jf'
alter user root@'localhost' identified by 'Admin@123';
exit
mysql -uroot -pAdmin@123
create user cluster@'192.168.3.%' identified with mysql_native_password by 'Admin@123';
grant all privileges on *.* to cluster@'192.168.3.%';
exit
2、客户端
yum install -y mariadb
mysql -ucluster -pAdmin@123 -h192.168.3.85 -e'show databases'
mysql -ucluster -pAdmin@123 -h192.168.3.84 -e'show databases'
mysql -ucluster -pAdmin@123 -h192.168.3.84
create database testdb;
use testdb
create table emp (empno numeric(4) not null,ename varchar(10),job varchar(9),mgr numeric(4),hiredate datetime,sal numeric(7, 2),comm numeric(7, 2),deptno numeric(2))engine=ndb;
insert into emp values (7369, 'SMITH', 'CLERK', 7902, '1980-12-17', 800, null, 20);
select * from testdb.emp;
exit
mysql -ucluster -pAdmin@123 -h192.168.3.85
select * from testdb.emp;
注: 数据已同步
3、模拟故障
sql节点 stu5
systemctl stop mysqld
客户端
mysql -ucluster -pAdmin@123 -h192.168.3.85
mysql -ucluster -pAdmin@123 -h192.168.3.84
管理节点
ndb_mgm
show
关闭集群
ndb_mgm
shutdown