博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql innodb cluster服务器搭建
阅读量:5824 次
发布时间:2019-06-18

本文共 4451 字,大约阅读时间需要 14 分钟。

1、限于环境,只有2台服务器,一台安装mysql + mysqlrouter,另一台安装2个mysql实例;

2、添加2台服务器的/etc/hosts文件,如下:

192.168.1.223  dbserver01192.168.1.224  dbserver02

3、准备安装包文件:

mysql-router-2.1.4-linux-glibc2.12-x86-64bit.tar.gzmysql-shell-1.0.10-linux-glibc2.12-x86-64bit.tar.gzmysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

4、解压安装包到相应目录如:/test/mysql-3306,在/test/mysql-3306目录下创建data、log目录,创建my.cnf文件

my.cnf文件内容:

[mysqld]port = 3306socket=/test/mysql-3306/mysql.sockbasedir=/test/mysql-3306datadir=/test/mysql-3306/datalog-error=/test/mysql-3306/log/mysql.logpid-file=/test/mysql-3306/mysql.pid# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0[mysqld_safe]port = 3306socket=/test/mysql-3306/mysql.sockbasedir=/test/mysql-3306datadir=/test/mysql-3306/datalog-error=/test/mysql-3306/log/mysql.logpid-file=/test/mysql-3306/mysql.pid[mysql]port = 3306socket=/test/mysql-3306/mysql.sock[mysqladmin]port = 3306socket=/test/mysql-3306/mysql.sock

5、拷贝init_3306.sh、login_3306.sh、start_3306.sh、stop_3306.sh到/test/mysql-3306目录,各文件内容如下:

init_3306.sh文件内容:

#!/bin/shbin/mysqld --defaults-file=/test/mysql-3306/my.cnf --initialize --user=root --console

login_3306.sh文件内容:

#!/bin/shbin/mysql --defaults-file=/test/mysql-3306/my.cnf -uroot -p

start_3306.sh文件内容:

#!/bin/shnohup bin/mysqld_safe --defaults-file=/test/mysql-3306/my.cnf --user=root >/dev/null 2>&1 &

stop_3306.sh文件内容:

#!/bin/shbin/mysqladmin --defaults-file=/test/mysql-3306/my.cnf shutdown -uroot -pxxxx@2017

6、执行init_3306.sh文件初始化数据库成功;

7、查看log/mysql.log文件中生成的密码;

8、执行start_3306.sh文件启动数据库成功;

9、执行login_3306.sh数据log文件中密码登录成功;

 

mysql> set sql_log_bin = 0;Query OK, 0 rows affected (0.00 sec)mysql> set password=password('xxxx@2017');Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> grant all privileges on *.* to 'root'@'%' identified by 'xxxx@2017' with grant option;Query OK, 0 rows affected, 1 warning (0.01 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> set sql_log_bin = 1;Query OK, 0 rows affected (0.00 sec)mysql> exitBye 

 

10、修改my.cnf文件,增加【mysqld】段内配置

server_id = 1gtid_mode = ONenforce_gtid_consistency = ONmaster_info_repository = TABLErelay_log_info_repository = TABLEbinlog_checksum = NONElog_slave_updates = ONlog_bin = binlogbinlog_format = ROWtransaction_write_set_extraction = XXHASH64

11、重启mysql,执行mysqlsh命令

[root@dbserver01 test]# mysqlsh MySQL Shell 1.0.10Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type '\help' or '\?' for help; '\quit' to exit.Currently in JavaScript mode. Use \sql to switch to SQL mode and execute queries.mysql-js> dba.configureLocalInstance('root@localhost:3306');Please provide the password for 'root@localhost:3306': Detecting the configuration file...Default file not found at the standard locations.                  Please specify the path to the MySQL configuration file: /test/mysql-3306/my.cnfValidating instance...The instance 'localhost:3306' is valid for Cluster usageYou can now use it in an InnoDB Cluster.{    "status": "ok"}mysql-js>

 12、创建集群实例

mysql-js> \c root@dbserver01:3306Creating a Session to 'root@dbserver01:3306'Enter password: Your MySQL connection id is 8Server version: 5.7.20-log MySQL Community Server (GPL)No default schema selected; type \use 
to set one.mysql-js> var cluster = dba.createCluster('szcluster');A new InnoDB cluster will be created on instance 'root@dbserver01:3306'.Creating InnoDB cluster 'szcluster' on 'root@dbserver01:3306'...Adding Seed Instance...Cluster successfully created. Use Cluster.addInstance() to add MySQL instances.At least 3 instances are needed for the cluster to be able to withstand up toone server failure.mysql-js> cluster.status();{ "clusterName": "szcluster", "defaultReplicaSet": { "name": "default", "primary": "dbserver01:3306", "status": "OK_NO_TOLERANCE", "statusText": "Cluster is NOT tolerant to any failures.", "topology": { "dbserver01:3306": { "address": "dbserver01:3306", "mode": "R/W", "readReplicas": {}, "role": "HA", "status": "ONLINE" } } }}mysql-js>

 13、完成另一台服务器两个实例的配置(执行到10、11步即可,无需执行12步)

 

14、mysqlrouter --bootstrap root@dbserver01:3306 --user=root

转载于:https://www.cnblogs.com/itpoorman/p/7754494.html

你可能感兴趣的文章
从微软的DBML文件中我们能学到什么(它告诉了我们什么是微软的重中之重)~目录...
查看>>
被需求搞的一塌糊涂,怎么办?
查看>>
c_数据结构_队的实现
查看>>
jquery 选择器总结
查看>>
1月10日,11日工作情况
查看>>
Qt设置背景图片
查看>>
Grunt使用心得
查看>>
【阿里云文档】常用文档整理
查看>>
iptables 配置需要保存
查看>>
.NET各种小问题
查看>>
ApkTool反编译和重新打包
查看>>
OpenState: Programming Platform-independent Stateful OpenFlow Applications Inside the Switch
查看>>
java中的Volatile关键字
查看>>
前端自定义图标
查看>>
sqlserver 取取月初月末和月份间隔
查看>>
Vagrant的一个BUG - 不支持'change_host_name'
查看>>
实验二
查看>>
MongoDB数据库迁移
查看>>
独立开发一个云(PaaS)的核心要素, Go, Go, Go!!!
查看>>
java的继承性
查看>>