docker 中 安装配置 mysqlcluster(arm)
1:创建两个docker container
这里我使用给指定 container ip的形式创建:
查看容器网络
docker network ls
创建一个新的bridge网络
docker network create --driver bridge --subnet=172.0.12.0/16 --gateway=172.0.1.1 mytestnet
查看网络详情
docker network inspect mytestnet
创建容器,并指定ip
docker run -e TZ="Asia/Shanghai" --privileged -itd -h node1 --name mysqlnode1 --network=mytestnet --ip 172.0.12.1 docker.io/centos docker run -e TZ="Asia/Shanghai" --privileged -itd -h node2 --name mysqlnode2 --network=mytestnet --ip 172.0.12.2 docker.io/centos
node1 作为一个管理节点 SQL、NDB服务器
node2 作为一个 SQL 、NDB服务器
分别进入 docker 容器
docker attach <container_id>
2:contianer中安装一些依赖:
yum -y install make git gcc-c++ cmake bison-devel ncurses-devel perl per-devel ncurses-devel bison libaio-devel java autoconf vim wget net-tools
检查有没有安装过mysql和mariadb,有的话先卸载,关闭防火墙,selinux (该镜像不涉及忽略)
3:下载安装mysqlcluster
3.1:编译准备
下载tar包
wget -c http://mirrors.sohu.com/mysql/MySQL-Cluster-7.4/mysql-cluster-gpl-7.4.25.tar.gz tar -zxvf mysql-cluster-gpl-7.4.25.tar.gz
创建数据存放目录
mkdir -p /data/program/mysqlCluster/{bin,ndbdata,tmp}
chown -R mysql:mysql /data/program/mysqlCluster
新建mysql用户及用户组
groupadd mysql useradd -g mysql -s /usr/sbin/nologin mysql
进入解压文件中,替换文件(原安装包不支持arm)
分别替换
./storage/ndb/memcache/extra/libevent/epoll_sub.c ./storage/ndb/src/kernel/vm/mt-asm.h
https://pan.baidu.com/s/1ZGY8r0crBHLOLaa4DKIgWA 58uu
https://pan.baidu.com/s/1AGjGklu8SF97X5x2wcYEqA 2t48
3.3 编译
执行下列代码:
cmake -DBUILD_CONFIG=mysql_release \ -DCMAKE_BUILD_TYPE=debug \ -DCMAKE_INSTALL_PREFIX=/data/program/mysqlCluster \ -DMYSQL_UNIX_ADDR=/data/program/mysqlCluster/tmp/mysql-cluster.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DMYSQL_DATADIR=/data/program/mysqlCluster/ndbdata \ -DMYSQL_USER=mysql \ -DMYSQL_TCP_PORT=3306
make && make install
添加环境变量:
export PATH=$PATH:/data/program/mysqlCluster/bin
3.4 安装
cd /data/program/mysqlCluster/
ln -s bin/mysqld-debug bin/mysqld
cp support-files/mysql.server /etc/init.d/mysqld
chmod –R 755 /etc/init.d/mysqld
按理说mysql添加到/etc/init.d目录后就可以启动了,但是要启动集群,还需要配置管理节点和数据节点,mysql暂缓启动。
(启动 mysqlcluster --> Management Node > Data Node > SQL Node)
3.5:管理节点配置(mysqlnode1)
创建配置文件
mkdir -p /data/program/mysqlCluster/etc vim /data/program/mysqlCluster/etc/config.ini
写入配置
[ndb_mgmd default] datadir=/data/program/mysqlCluster/ndbdata [ndbd default] NoOfReplicas = 2 DataMemory = 200M IndexMemory = 20M datadir=/data/program/mysqlCluster/ndbdata [ndb_mgmd] NodeId = 1 HostName=172.0.12.1 datadir=/data/program/mysqlCluster/ndbdata [ndbd] NodeId = 11 HostName=172.0.12.1 datadir=/data/program/mysqlCluster/ndbdata [ndbd] NodeId=12 HostName=172.0.12.2 datadir=/data/program/mysqlCluster/ndbdata [mysqld] NodeId = 21 HostName=172.0.12.1 [mysqld] NodeId=22 HostName=172.0.12.2 [mysqld] [mysqld] [mysqld]
启动管理节点
ndb_mgmd -f /data/program/mysqlCluster/etc/config.ini --initial (--initial 首次加载/data/program/mysqlCluster/etc/config.ini文件有改变,其它时候不要加,除非是在备份、恢复或配置变化后重启时,其他时候不要加,不然数据就清空)
#如果有改动要加上
rm -rf /data/program/mysqlCluster/mysql-cluster/ndb_1_config.bin.1 ndb_mgmd -f /data/program/mysqlCluster/etc/config.ini
查看集群状态:
ndb_mgm ndb_mgm> show
关闭管理节点 ndb_mgm> shutdown
3.6 数据节点配置 (mysqlnode1 mysqlnode2)
配置数据节点
cp /data/program/mysqlCluster/support-files/ my-default.cnf /etc/my.cnf
vim /etc/my.cnf sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES ndbcluster ndb-connectstring=172.0.12.1 [mysql_cluster] ndb-connectstring=172.0.12.1
启动数据节点
ndbd --initial (--initial 首次加载)
3.7 sql节点配置(node1 node2)
vim /etc/my.cnf [mysqld] basedir =/data/program/mysqlCluster datadir =/data/program/mysqlCluster/ndbdata socket=/data/program/mysqlCluster/tmp/mysql-cluster.sock ndbcluster ndb-connectstring = 172.0.12.1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [client] default-character-set = utf8 [mysqld] character_set_server=utf8 [mysql_cluster] ndb-connectstring = 172.0.12.1 [NDB_MGM] connect-string=172.0.12.1
启动sql节点(可以启动mysql了)
/etc/init.d/mysqld {start stop restart }
设置密码
mysql -u root -p (登录无密码) mysql> SET PASSWORD = PASSWORD('123456'); mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
至此配置完成!
test
1 从node1数据节点登陆MYSQL
mysql> create database zxztest ;
Query OK, 1 row affected (0.03 sec)
mysql> use zxztest;
Database changed
mysql> create table test1(id int,name varchar(10)) engine=ndb ;
Query OK, 0 rows affected (0.15 sec)
mysql> insert into test1 values(1,'XYT');
Query OK, 1 row affected (0.02 sec)
mysql> select * from test1 ;
+------+------+
| id | name |
+------+------+
| 1 | XYT |
+------+------+
1 row in set (0.00 sec)
2 登陆node2数据结点,进行验证
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| ndbinfo |
| performance_schema |
| test |
| zxztest |
+--------------------+
6 rows in set (0.04 sec)
mysql> use zxztest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from test1 ;
+------+------+
| id | name |
+------+------+
| 1 | XYT |
+------+------+
1 row in set (0.00 sec)
————————————————
参考:https://blog.csdn.net/xiayutai1/article/details/51933234