MySQL5.7集群搭建

今天抽出时间做一个测试,搭建一个最简单的MySQL Cluster。
准备5个虚拟机,操作系统版本Redhat6.5,MySQL版本mysql-cluster-gpl-7.5.5-linux-glibc2.5-x86_64.tar(5.7)
管理节点mgm 192.168.8.220
SQL节点1 192.168.8.221
SQL节点2     192.168.8.222
DB节点1 192.168.8.231
DB节点2
192.168.8.232
一、准备工作
关闭防火墙:
service iptables stop
chkconfig iptables off
关闭selinux:
vi /etc/selinux/config
将SELINUX=enforce改为disabled
解压mysql-cluster-gpl-7.5.5-linux-glibc2.5-x86_64.tar至/usr/local/mysql(5个节点)
二、配置管理节点
cp /usr/local/mysql/bin/ndb_mgm* /usr/local/bin
cd /usr/local/bin
chmod +x ndb_mgm*

cd /usr/local/mysql
vi config.ini
[ndbd default]
NoOfReplicas=2
DataMemory=80M
IndexMemory=18M
[ndb_mgmd]
NodeId=1
hostname=192.168.8.220
datadir=/mysql/data
[ndbd]
NodeId=2
hostname=192.168.8.231
datadir=/mysql/data
[ndbd]
NodeId=3
hostname=192.168.8.232
datadir=/mysql/data
[mysqld]
NodeId=4
hostname=192.168.8.221
[mysqld]
NodeId=5
hostname=192.168.8.222

启动mgm
ndb_mgmd -f /usr/local/mysql/config.ini 
进入mgm查看状态:
[root@mgm usr]# ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
三、配置数据节点(两个节点
修改配置文件
vi /etc/my.cnf
添加如下配置:
user=mysql
basedir=/usr/local/mysql
datadir=/mysql/data
default-storage-engine=InnoDB
#skip-grant-tables
socket=/tmp/mysqld.sock
[client]
default-character-set=utf8
socket=/tmp/mysqld.sock
[mysql]
socket=/tmp/mysqld.sock
default-character-set=utf8
[mysql_cluster]
ndb-connectstring=192.168.8.220

cd /usr/local/mysql/bin
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/data
2017-11-02 08:06:03 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-11-02 08:06:20 [WARNING] The bootstrap log isn't empty:
2017-11-02 08:06:20 [WARNING] 2017-11-02T00:06:04.435385Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2017-11-02T00:06:04.457329Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-11-02T00:06:04.457350Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
提示新版本--initialize取代了mysql_install_db,这个不影响。

/usr/local/mysql/bin/ndbd --initial
2017-11-02 08:10:11 [ndbd] INFO     -- Angel connected to '192.168.8.220:1186'
2017-11-02 08:10:11 [ndbd] INFO     -- Angel allocated nodeid: 3

四、配置SQL节点
修改配置文件
vi /etc/my.cnf
添加如下配置:
user=mysql
basedir=/usr/local/mysql
datadir=/mysql/data
default-storage-engine=InnoDB
#skip-grant-tables
socket=/tmp/mysql.sock
ndbcluster
ndb-connectstring=192.168.8.220
[client]
default-character-set=utf8
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
default-character-set=utf8
[mysql_cluster]
#ndb-connectstring=192.168.8.220

cd /usr/local/mysql/bin
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/data
2017-11-02 08:06:03 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-11-02 08:06:20 [WARNING] The bootstrap log isn't empty:
2017-11-02 08:06:20 [WARNING] 2017-11-02T00:06:04.435385Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2017-11-02T00:06:04.457329Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-11-02T00:06:04.457350Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
提示新版本--initialize取代了mysql_install_db,这个不影响。

在SQL节点启动数据库,并改root口令

五、集群测试
在SQL节点一添加database test,SQL节点2可以查询到,并进行增删改查操作。

六、启动集群
1)启动管理结点
在shell中运行以下命令:
ndb_mgmd -f /usr/local/mysql/config.ini
还可以使用ndb_mgm来监听客户端,如下:
ndb_mgm
2)启动数据结点
首次启动,则需要添加--initial参数,以便进行NDB节点的初始化工作。在以后的启动过程中,则是不能添加该参数的,否则ndbd程序会清除在之前建立的所有用于恢复的数据文件和日志文件。
/usr/local/mysql/bin/ndbd --initial
如果不是首次启动,则执行下面的命令。
/usr/local/mysql/bin/ndbd
3)启动SQL结点
若MySQL服务没有运行,则在shell中运行以下命令:
/usr/local/mysql/bin/mysqld_safe --user=mysql &

七、关闭集群
1)关闭管理节点和数据节点,只需要在管理节点(ClusterMgm--134)里执行:
shell> /usr/local/mysql/bin/ndb_mgm -e shutdown
显示
Connected to Management Server at: localhost:1186
NDB Cluster node(s) have shutdown.
Disconnecting to allow management server to shutdown.
2)然后关闭Sql节点(135,136),分别在2个节点里运行:
shell> /etc/init.d/mysql stop
Shutting down MySQL... SUCCESS!

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30135314/viewspace-2146749/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/30135314/viewspace-2146749/

你可能感兴趣的:(数据库,shell,运维)