mysql innodb cluster(生产环境部署)

https://dev.mysql.com/doc/refman/5.7/en/mysql-innodb-cluster-working-with-production-deployment.html
https://dev.mysql.com/doc/refman/5.7/en/mysql-innodb-cluster-limitations.html

install (3 nodes)

yum install https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm -y
yum install mysql-community-server -y
yum install mysql-shell -y
yum install mysql-router -y

[xzx@cloud4ourself-kube1 ~]$ mysql --version
mysql Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using EditLine wrapper
[xzx@cloud4ourself-kube1 ~]$ mysqlrouter --version
MySQL Router v2.1.3 on Linux (64-bit) (GPL community edition)
[xzx@cloud4ourself-kube1 ~]$ mysqlsh --version
MySQL Shell Version 1.0.9

configure (3 nodes)

service mysqld start
grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
mysql> set global validate_password_policy = 0;
mysql> set password=PASSWORD('myrootpwd');
mysql> set global validate_password_policy = 0;

CREATE USER myuser IDENTIFIED BY 'new_password';
GRANT RELOAD, SHUTDOWN, PROCESS, FILE, SUPER, REPLICATION SLAVE, REPLICATION CLIENT, CREATE USER ON *.* TO myuser;
GRANT SELECT ON performance_schema.* TO myuser;
GRANT SELECT, INSERT, UPDATE, DELETE ON mysql.* TO myuser;
GRANT ALL PRIVILEGES ON mysql_innodb_cluster_metadata.*  TO myuser WITH GRANT OPTION;
GRANT REPLICATION SLAVE ON *.*  TO myuser WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.*  TO myuser;

/etc/my.cnf (3 nodes )

server_id = 1  # 2 , 3
enforce_gtid_consistency = ON
gtid_mode = ON
log_bin = 1
log_slave_updates = ON
master_info_repository = TABLE
relay_log_info_repository = TABLE
transaction_write_set_extraction = XXHASH64
binlog_checksum = NONE
validate_password_policy = 0

cluster

mysqlsh --log-level=DEBUG3
mysql-js> dba.checkInstanceConfiguration('myuser@10.9.5.91:3306')
mysql-js> dba.checkInstanceConfiguration('myuser@10.9.5.90:3306')
mysql-js> dba.checkInstanceConfiguration('myuser@10.9.5.71:3306')


mysql-js> shell.connect('myuser@10.9.5.91:3306')
mysql-js> var cluster = dba.createCluster('myCluster')

mysql-js> cluster.checkInstanceState('myuser@10.9.5.91:3306')
mysql-js> cluster.checkInstanceState('myuser@10.9.5.90:3306')
mysql-js> cluster.checkInstanceState('myuser@10.9.5.71:3306')


mysql-js>  cluster.checkInstanceState('myuser@10.9.5.90:3306')
Please provide the password for 'myuser@10.9.5.90:3306':
Analyzing the instance replication state...

The instance '10.9.5.90:3306' is valid for the cluster.
The instance is new to Group Replication.

{
    "reason": "new",
    "state": "ok"
}

mysql-js>  cluster.checkInstanceState('myuser@10.9.5.71:3306')
Please provide the password for 'myuser@10.9.5.71:3306':
Analyzing the instance replication state...

The instance '10.9.5.71:3306' is valid for the cluster.
The instance is new to Group Replication.

{
    "reason": "new",
    "state": "ok"
}
cluster.status()

cluster.addInstance('myuser@10.9.5.90:3306')
cluster.addInstance('myuser@10.9.5.71:3306')


mysql-js> cluster.status()
{
    "clusterName": "myCluster",
    "defaultReplicaSet": {
        "name": "default",
        "primary": "10.9.5.91:3306",
        "status": "OK",
        "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
        "topology": {
            "10.9.5.71:3306": {
                "address": "10.9.5.71:3306",
                "mode": "R/O",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            },
            "10.9.5.90:3306": {
                "address": "10.9.5.90:3306",
                "mode": "R/O",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            },
            "10.9.5.91:3306": {
                "address": "10.9.5.91:3306",
                "mode": "R/W",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            }
        }
    }
}

mysql router

[root@cloud4ourself-kube1 ~]# mysqlrouter --bootstrap myuser@10.9.5.91:3306 --user=root
Please enter MySQL password for myuser:

Reconfiguring system MySQL Router instance...
MySQL Router  has now been configured for the InnoDB cluster 'myCluster'.

The following connection information can be used to connect to the cluster.

Classic MySQL protocol connections to cluster 'myCluster':
- Read/Write Connections: localhost:6446
- Read/Only Connections: localhost:6447

X protocol connections to cluster 'myCluster':
- Read/Write Connections: localhost:64460
- Read/Only Connections: localhost:64470

Existing configurations backed up to /etc/mysqlrouter/mysqlrouter.conf.bak

[root@cloud4ourself-kube1 ~]# mysqlrouter &
[1] 7524

error

mysql-js> cluster.addInstance('myuser@10.9.5.90:3306')
A new instance will be added to the InnoDB cluster. Depending on the amount of
data on the cluster this might take from a few seconds to several hours.

Please provide the password for 'myuser@10.9.5.90:3306':
Adding instance to the cluster ...

Cluster.addInstance: ERROR:
Group Replication join failed.
ERROR: Group Replication plugin failed to start. Server error log contains the following errors:
 2017-05-04T09:08:59.075925Z 0 [ERROR] Plugin group_replication reported: 'This member has more executed transactions than those present in the group. Local transactions: cff92742-3097-11e7-a452-fa163ecea498:1-2 > Group transactions: 7738d877-30a8-11e7-a7c6-fa163e72ab1f:1-17,
2017-05-04T09:08:59.075977Z 0 [ERROR] Plugin group_replication reported: 'The member contains transactions not present in the group. The member will now exit the group.'

ERROR: Error joining instance to cluster: '10.9.5.90@3306' - Query failed. 3092 (HY000): The server is not configured properly to be an active member of the group. Please see more details on error log.. Query: START group_replication (RuntimeError)

fix

mysql> set global group_replication_allow_local_disjoint_gtids_join=ON;
Query OK, 0 rows affected (0.01 sec)

貌似 cluster.rejoinInstance('myuser@10.9.5.71:3306') 此方法存在bug,其使用root去连目标数据库,因此建议还是使用root用户做操作。

test

  • create table
mysql-js> \sql
Switching to SQL mode... Commands end with ;
mysql-sql> create database b;
Query OK, 1 row affected (0.08 sec)
mysql-sql> use b;
Query OK, 0 rows affected (0.00 sec)
mysql-sql> create table a (c int);
Query OK, 0 rows affected (0.29 sec)
mysql-sql> insert into a values(1);
ERROR: 3098 (HY000): The table does not comply with the requirements by an external plugin.
mysql-sql> alter table a add column a_id int(4);
Query OK, 0 rows affected (0.81 sec)
mysql-sql> alter table a add primary key pk (a_id);
Query OK, 0 rows affected (0.30 sec)
mysql-sql> insert into a values (1,2);
Query OK, 1 row affected (0.06 sec)
  • check mysql slave nodes
mysql> select * from b.a;
+------+------+
| c    | a_id |
+------+------+
|    1 |    2 |
+------+------+
1 row in set (0.00 sec)
  • stop one of mysql slave nodes
[root@cloud4ourself-kube3 ~]# service mysqld stop
Redirecting to /bin/systemctl stop  mysqld.service
  • check cluster status
        "topology": {
            "10.9.5.71:3306": {
                "address": "10.9.5.71:3306",
                "mode": "R/O",
                "readReplicas": {},
                "role": "HA",
                "status": "(MISSING)"
            },
            "10.9.5.90:3306": {
                "address": "10.9.5.90:3306",
                "mode": "R/O",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            },
            "10.9.5.91:3306": {
                "address": "10.9.5.91:3306",
                "mode": "R/W",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            }
        }
  • insert one recode
mysql-sql> insert into a values (2,3);
Query OK, 1 row affected (0.05 sec)

# and the online slave node 

mysql> select * from b.a;
+------+------+
| c    | a_id |
+------+------+
|    1 |    2 |
|    2 |    3 |
+------+------+
2 rows in set (0.00 sec)

  • start 10.9.5.71:3306 and check the table
mysql> select * from b.a;
+------+------+
| c    | a_id |
+------+------+
|    1 |    2 |
+------+------+
1 row in set (0.00 sec)
  • rejoininstance 10.9.5.71:3306
mysql-sql> \js
Switching to JavaScript mode...
mysql-js> cluster.rejoinInstance('root@10.9.5.71:3306')
Rejoining the instance to the InnoDB cluster. Depending on the original
problem that made the instance unavailable, the rejoin operation might not be
successful and further manual steps will be needed to fix the underlying
problem.

Please monitor the output of the rejoin operation and take necessary action if
the instance cannot rejoin.

Please provide the password for 'root@10.9.5.71:3306':
Rejoining instance to the cluster ...

The instance 'root@10.9.5.71:3306' was successfully rejoined on the cluster.

The instance '10.9.5.71:3306' was successfully added to the MySQL Cluster.
  • check 10.9.5.71:3306 again
mysql> select * from b.a;
+------+------+
| c    | a_id |
+------+------+
|    1 |    2 |
|    2 |    3 |
+------+------+
2 rows in set (0.00 sec)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,743评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,296评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,285评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,485评论 1 283
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,581评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,821评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,960评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,719评论 0 266
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,186评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,516评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,650评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,329评论 4 330
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,936评论 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,757评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,991评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,370评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,527评论 2 349

推荐阅读更多精彩内容