mysql-cluster8.0.30+rockylinux8.6

序号主机系统角色备注
1stu1:192.168.3.81rockylinux8.6最小化安装管理节点
2stu2:192.168.3.82rockylinux8.6最小化安装数据节点
3stu3:192.168.3.83rockylinux8.6最小化安装数据节点
4stu4:192.168.3.84rockylinux8.6最小化安装sql节点
5stu5:192.168.3.85rockylinux8.6最小化安装sql节点
6des6:192.168.3.86rockylinux8.6最小化安装client

一、基础环境(管理节点、数据节点、sql节点)

1、下载mysql安装包,如下:

MySQL :: MySQL Downloads

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值