MySQL Cluster 是 MySQL 适合于分布式计算环境的高实用、高冗余版本。它采用了NDB Cluster 存储引擎,允许在1个 Cluster 中运行多个MySQL服务器。在MyQL 5.0及以上的二进制版本中、以及与最新的Linux版本兼容的RPM中提供了该存储引擎
实验环境
centos7_x64
mysqladmin 192.168.10.17
mysqldata1 192.168.10.19
mysqldata2 192.168.10.18
实验软件
mysql57-community-release-el7-11.noarch.rpm
软件安装
cp -pv /etc/hosts /etc/hosts.bak
echo 192.168.10.17 mysqladmin >> /etc/hosts
echo 192.168.10.19 mysqldata1 >> /etc/hosts
echo 192.168.10.18 mysqldata2 >> /etc/hosts
hostnamectl set-hostname mysqladmin/mysqldata1/mysqldata2 mysqladmin/mysqldata1/mysqldata2
systemctl stop firewalld.service && systemctl disable firewalld.service
systemctl restart ntpd.service && systemctl enable ntpd.service mysqladmin/mysqldata1/mysqldata2
ntpdate 192.168.10.17 && clock -w
sed -i 's/https/http/g' /etc/yum.repos.d/epel.repo
sed -i 's/gpgcheck=1/gpgcheck=0/g' /etc/yum.repos.d/*.repo
yum install -y lsof pytho-scp openssh-server openssh-client axel lsof ntp
yum install -y perl perl-Class-MethodMaker perl-DBI libaio numactl
rpm -ivh /root/mysql57-community-release-el7-11.noarch.rpm
sed -i.bak "55s/0/1/g" /etc/yum.repos.d/mysql-community.repo
yum install -y mysql-cluster-community-server mysqladmin操作
systemctl restart mysqld.service && systemctl enable mysqld.service
systemctl restart ntpd.service && systemctl enable ntpd.service
ntpdate 192.168.10.17 && clock -w
yum install -y perl perl-Class-MethodMaker perl-DBI libaio numactl
sed -i.bak "55s/0/1/g" /etc/yum.repos.d/mysql-community.repo mysqldata1/mysqldata2操作
yum install -y mysql-cluster-community-server
yum install -y mysql-cluster-community-data-node
yum install -y mysql-cluster-community-management-server
systemctl restart mysqld.service && systemctl enable mysqld.service
cp -pv /etc/my.cnf /etc/my.cnf.bak
cat /etc/my.cnf
[mysqld]
skip-grant-tables 此选项适用于修改root密码
systemctl restart mysqld.service
mysql -uroot -p 密码为空
mysql> use mysql;
mysql> update user set authentication_string=password('123456') where user='root';
mysql> flush privileges;
mysql -uroot -p数据库密码
mysql> mysqladmin/mysqldata1/mysqldata2操作
sed -i "55s/0/1/g" /etc/yum.repos.d/mysql-community.repo mysqladmin操作
yum install -y perl perl-Class-MethodMaker perl-DBI libaio numactl
yum install -y mysql-cluster-community-server
yum install -y mysql-cluster-community-management-server
systemctl restar mysql.service && systemctl enable mysqld.service
sed -i "55s/0/1/g" /etc/yum.repos.d/mysql-community.repo mysqladmin操作
yum install -y perl perl-Class-MethodMaker perl-DBI libaio numactl
yum install -y mysql-cluster-community-server
yum install -y mysql-cluster-community-data-node
yum install -y mysql-cluster-community-management-server
systemctl restar mysql.service && systemctl enable mysqld.service
mkdir -pv /etc/mysql-cluster && touch /etc/mysql-cluster/config.ini mysqladmin操作
cat /etc/mysql-cluster/config.ini
[ndbd default]
NoOfReplicas=2
DataMemory=500M
IndexMemory=100M
[ndb_mgmd]
nodeid=1
datadir=/var/lib/mysql
HostName=192.168.10.17
[ndbd]
HostName=192.168.10.19
DataDir=/var/lib/mysql
nodeid=2
[ndbd]
HostName=192.168.10.18
DataDir=/var/lib/mysql
nodeid=3
[mysqld]
HostName=192.168.10.19
nodeid=4
[mysqld]
HostName=192.168.10.18
nodeid=5
cat /etc/my.cnf mysqldata1/mysqldata2操作
[mysqld]
datadir=/var/lib/mysql
ndbcluster
ndb-connectstring=192.168.10.17
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql_cluster]
ndb-connectstring=192.168.10.17
cat /etc/my.cnf mysqldata2操作
[mysqld]
ndbcluster
ndb-connectstring=192.168.10.17
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql_cluster]
ndb-connectstring=192.168.10.17
先启动:管理结点服务->数据结点服务->sql结点服务
ndb_mgmd --ndb_nodeid=1 --initial -f /etc/mysql-cluster/config.ini mysqladmin操作
ndbd --initial mysqldata1/mysqldata2操作
ndb_mgm mysqladmin操作
ndb_mgm> show
[ndbd(NDB)]2 node(s)
id=2 (not connected, accepting connect from mysqldata1)
[email protected] (mysql-5.7.30 ndb-7.5.18, starting, Nodegroup: 0)
[ndb_mgmd(MGM)]1 node(s)
[email protected] (mysql-5.7.30 ndb-7.5.18)
[mysqld(API)]2 node(s)
id=4 (not connected, accepting connect from mysqldata1)
id=5 (not connected, accepting connect from mysqldata2)
ndb_mgm>
netstat -tuplna | grep 33
tcp 0 0 192.168.10.18:33160 192.168.10.17:1186 ESTABLISHED 2229/ndbd
tcp 0 0 192.168.10.18:33164 192.168.10.17:1186 ESTABLISHED 2230/ndbd
tcp 0 0 192.168.10.18:33162 192.168.10.17:1186 ESTABLISHED 2230/ndbd
tcp6 0 0 :::3306 :::* LISTEN 986/mysqld
netstat -tuplna | grep ndb_mgmd
tcp 0 0 0.0.0.0:1186 0.0.0.0:* LISTEN 12837/ndb_mgmd
tcp 0 0 127.0.0.1:1186 127.0.0.1:45212 ESTABLISHED 12837/ndb_mgmd
tcp 0 0 192.168.10.17:1186 192.168.10.18:33164 ESTABLISHED 12837/ndb_mgmd
tcp 0 0 127.0.0.1:45212 127.0.0.1:1186 ESTABLISHED 12837/ndb_mgmd
tcp 0 0 192.168.10.17:1186 192.168.10.18:33162 ESTABLISHED 12837/ndb_mgmd
tcp 0 0 192.168.10.17:1186 192.168.10.18:33160 ESTABLISHED 12837/ndb_mgmd