MySQL高可用探索之orchestrator

2023-11-20 23:40

本文主要是介绍MySQL高可用探索之orchestrator,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

摘要:使用orchestrator实现mysql主从自动切换、故障转移、拓扑管理。

部署MySQL环境(一主两从)

IP:端口角色版本
192.168.30.113:4406masterPercona 5.7.24-27-log CentOS Linux release 7.4.1708 (Core) 3.10.0-693.el7.x86_64
192.168.30.118:4406slavePercona 5.7.24-27-log CentOS Linux release 7.4.1708 (Core) 3.10.0-693.el7.x86_64
192.168.30.119:4406slavePercona 5.7.24-27-log CentOS Linux release 7.4.1708 (Core) 3.10.0-693.el7.x86_64

安装MySQL(略)

创建复制用户(三台mysql上面都创建)

GRANT REPLICATION SLAVE ON . TO repluser@’192.168.30.%’ IDENTIFIED BY ‘rep_2019’;
set global slave_net_timeout=8; 缩短从库感知主库宕机的等待时间

创建复制关系

在118和119上执行:

 

change master to master_host='192.168.30.113',master_port=4406,master_user='repluser',master_password='rep_2019',master_auto_position=1,MASTER_HEARTBEAT_PERIOD=2,MASTER_CONNECT_RETRY=1, MASTER_RETRY_COUNT=86400;

start slave;

 

以119为例,实操:

 

mysql> change master to master_host='192.168.30.113',master_port=4406,master_user='repluser',master_password='rep_2019',master_auto_position=1,MASTER_HEARTBEAT_PERIOD=2,MASTER_CONNECT_RETRY=1, MASTER_RETRY_COUNT=86400;

Query OK, 0 rows affected, 2 warnings (0.01 sec)

mysql> show warnings \G;

*************************** 1. row ***************************

Level: Note

Code: 1759

Message: Sending passwords in plain text without SSL/TLS is extremely insecure.

*************************** 2. row ***************************

Level: Note

Code: 1760

Message: Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.

2 rows in set (0.00 sec)

ERROR:

No query specified

mysql> start slave;

Query OK, 0 rows affected (0.00 sec)

mysql> show slave status \G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.30.113

Master_User: repluser

Master_Port: 4406

Connect_Retry: 1

Master_Log_File: mysql-bin.000024

Read_Master_Log_Pos: 588

Relay_Log_File: mysqld-relay-bin.000002

Relay_Log_Pos: 665

Relay_Master_Log_File: mysql-bin.000024

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 588

Relay_Log_Space: 873

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 1134406

Master_UUID: 9b8d01ee-081d-11e9-94a1-005056a99b7f

Master_Info_File: mysql.slave_master_info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set: 9b8d01ee-081d-11e9-94a1-005056a99b7f:1

Executed_Gtid_Set: 3db33b36-0e51-409f-a61d-c99756e90155:1-31:1000007,

7b8d01ee-081d-11e9-94a1-005056a99b7f:1-3,

8b8d01ee-081d-11e9-94a1-005056a99b7f:1-2,

9b8d01ee-081d-11e9-94a1-005056a99b7f:1

Auto_Position: 1

Replicate_Rewrite_DB:

Channel_Name:

Master_TLS_Version:

1 row in set (0.00 sec)

ERROR:

No query specified

 

在113上查看slave信息:

 

mysql> show slave hosts;

+-----------+----------------+------+-----------+--------------------------------------+

| Server_id | Host | Port | Master_id | Slave_UUID |

+-----------+----------------+------+-----------+--------------------------------------+

| 1194406 | 192.168.30.119 | 4406 | 1134406 | 8b8d01ee-081d-11e9-94a1-005056a99b7f |

| 1184406 | 192.168.30.118 | 4406 | 1134406 | 7b8d01ee-081d-11e9-94a1-005056a99b7f |

+-----------+----------------+------+-----------+--------------------------------------+

2 rows in set (0.00 sec)

 

一主两从搭建完毕。

安装orchestrator

下载并解压

下载地址:https://github.com/github/orchestrator/releases/download/v3.0.14/orchestrator-3.0.14-linux-amd64.tar.gz
将解压出来的orchestrator目录拷贝到/usr/local/,将/usr/local/orchestrator加入环境变量(3台都装)
[root@mysql2 src]# tar xvf orchestrator-3.0.14-linux-amd64.tar.gz
[root@mysql2 src]# cp -r ./usr/local/orchestrator/ /usr/local/

配置

首先在orchestrator管理数据库的实例上创建账号:orch自用

 

root@(none) 04:11:09>create database orchestrator;

Query OK, 1 row affected (0.02 sec)

root@(none) 04:13:49>CREATE USER 'orchestrator'@'192.168.1.3' IDENTIFIED BY '123456';

Query OK, 0 rows affected (0.00 sec)

root@(none) 04:13:58>GRANT ALL ON orchestrator.* TO 'orchestrator'@'192.168.1.3';

Query OK, 0 rows affected (0.00 sec)

 

然后再在被管理的MySQL实例上创建账号(只在主库113执行即可,从库会复制过去):

 

mysql> GRANT SELECT, RELOAD, PROCESS, SUPER, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'orchestrator'@'192.168.30.%' identified by 'abc123';

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show warnings;

+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Level | Code | Message |

+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Warning | 1287 | Using GRANT statement to modify existing user's properties other than privileges is deprecated and will be removed in future release. Use ALTER USER statement for this operation. |

+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

 

编辑配置文件
https://github.com/github/orchestrator/blob/master/docs/configuration-sample.md
使用官网的配置文件模板,修改一下数据源即可:

 

[root@mysql-113 ~]# cat /usr/local/orchestrator/orchestrator.conf.json

{

"Debug": true,

"EnableSyslog": false,

"ListenAddress": ":3000",

"MySQLTopologyUser": "orchestrator",

"MySQLTopologyPassword": "abc123",

"MySQLTopologyCredentialsConfigFile": "",

"MySQLTopologySSLPrivateKeyFile": "",

"MySQLTopologySSLCertFile": "",

"MySQLTopologySSLCAFile": "",

"MySQLTopologySSLSkipVerify": true,

"MySQLTopologyUseMutualTLS": false,

"MySQLOrchestratorHost": "192.168.1.3",

"MySQLOrchestratorPort": 3306,

"MySQLOrchestratorDatabase": "orchestrator",

"MySQLOrchestratorUser": "orchestrator",

"MySQLOrchestratorPassword": "123456",

... ...

"RaftEnabled": true,

"BackendDB": "mysql",

"RaftBind": "192.168.30.113",

"RaftDataDir": "/var/lib/orchestrator",

"DefaultRaftPort": 10008,

"RaftNodes": [

"192.168.30.113",

"192.168.30.118",

"192.168.30.119"

],

"ConsulAddress": "",

"ConsulAclToken": ""

}

 

启动

 

root@:mysql-113:/usr/local/orchestrator$./orchestrator --config=./orchestrator.conf.json http

2019-02-26 16:21:50 INFO starting orchestrator

2019-02-26 16:21:50 INFO Read config: ./orchestrator.conf.json

2019-02-26 16:21:50 DEBUG Initializing orchestrator

2019-02-26 16:21:50 DEBUG Migrating database schema

2019-02-26 16:22:25 DEBUG Migrated database schema to version [1.5.7]

2019-02-26 16:22:25 DEBUG Connected to orchestrator backend: orchestrator:?@tcp(127.0.0.1:3306)/orchestrator?timeout=1s

2019-02-26 16:22:25 DEBUG Orchestrator pool SetMaxOpenConns: 128

2019-02-26 16:22:25 INFO Starting Discovery

2019-02-26 16:22:25 INFO Registering endpoints

2019-02-26 16:22:25 INFO Starting continuous discovery

2019-02-26 16:22:25 INFO Starting HTTP listener on :3000

2019-02-26 16:22:26 DEBUG outdated keys: []

2019-02-26 16:22:27 DEBUG outdated keys: []

2019-02-26 16:22:28 DEBUG outdated keys: []

2019-02-26 16:22:29 DEBUG outdated keys: []

2019-02-26 16:22:30 DEBUG outdated keys: []

2019-02-26 16:22:31 DEBUG outdated keys: []

访问WEB

http://192.168.30.113:3000
web1
查看主从拓扑:
web2
查看orchestrator状态:
web3

命令行操作

将/usr/local/orchestrator/resources/bin目录加入path环境变量

列出集群(含别名)

 

[root@mysql-119 ~]# orchestrator-client -c clusters-alias

mysql-113:4406,cluster_dev

mysql2:3306,trotdb_test

发现实例

 

[root@mysql-119]# orchestrator -c discover -i mysql1:3306

2019-03-11 07:12:45 FATAL Orchestrator configured to run raft ("RaftEnabled": true). All access must go through the web API of the active raft node. You may use the orchestrator-client script which has a similar interface to the command line invocation. You may override this with --ignore-raft-setup

报错说在启用raft模式上禁止使用orchestrator客户端,建议使用orchestrator-client,orchestrator-client可以安装在没有orchestrator上的服务器。

要使用orchestrator-client需要先安装jq,否则会报错:orchestrator-client[18537]: cannot find jq

[root@mysql-119]# yum install jq -y

[root@mysql-119]# orchestrator-client -c discover -i mysql1:3306

mysql1:3306

查看拓扑

 

[root@mysql-119 ~]# orchestrator-client -c topology -i mysql-113:4406

mysql-113:4406 [0s,ok,5.7.24-27-log,rw,ROW,>>,GTID,P-GTID]

+ mysql-119:4406 [0s,ok,5.7.24-27-log,rw,ROW,>>,GTID,P-GTID]

+ mysql-118:4406 [0s,ok,5.7.24-27-log,rw,ROW,>>,GTID]

[root@mysql-119 ~]#

返回列表格式:

[root@mysql-119 ~]# orchestrator-client -c topology-tabulated -i mysql-113:4406

mysql-113:4406 |0s|ok|5.7.24-27-log|rw|ROW|>>,GTID,P-GTID

+ mysql-119:4406 |0s|ok|5.7.24-27-log|rw|ROW|>>,GTID,P-GTID

+ mysql-118:4406|0s|ok|5.7.24-27-log|rw|ROW|>>,GTID

忘记实例

 

[root@mysql-119 ~]# orchestrator-client -c forget -i mysql-118:4406

查看拓扑可以发现没有了mysql-118:

[root@mysql-119 ~]# orchestrator-client -c topology-tabulated -i mysql-113:4406

mysql-113:4406 |0s|ok|5.7.24-27-log|rw|ROW|>>,GTID,P-GTID

+ mysql-119:4406|0s|ok|5.7.24-27-log|rw|ROW|>>,GTID,P-GTID

重新发现mysql-118:

[root@mysql-119 ~]# orchestrator-client -c discover -i mysql-118:4406

mysql-118:4406

[root@mysql-119 ~]# orchestrator-client -c topology-tabulated -i mysql-113:4406

mysql-113:4406 |0s|ok|5.7.24-27-log|rw|ROW|>>,GTID,P-GTID

+ mysql-119:4406 |0s|ok|5.7.24-27-log|rw|ROW|>>,GTID,P-GTID

+ mysql-118:4406|0s|ok|5.7.24-27-log|rw|ROW|>>,GTID

查看API接口

 

[root@mysql-119 ~]# orchestrator-client -c which-api

http://localhost:3000/api

调用API

 

[root@mysql-119 ~]# orchestrator-client -c api -path clusters

[ "mysql-113:4406", "mysql2:3306" ]

[root@mysql-119 ~]# orchestrator-client -c api -path leader-check

"Not leader"

[root@mysql-119 ~]# orchestrator-client -c api -path status

{ "Code": "OK", "Message": "Application node is healthy", "Details": { "Healthy": true, "Hostname": "mysql-119", "Token": "3bfe4deae671a528477bb3caa281b4d50b7aae33b052dd421d2b8655c8220864", "IsActiveNode": false, "ActiveNode": { "Hostname": "192.168.30.118:10008", "Token": "", "AppVersion": "", "FirstSeenActive": "", "LastSeenActive": "", "ExtraInfo": "", "Command": "", "DBBackend": "", "LastReported": "0001-01-01T00:00:00Z" }, "Error": null, "AvailableNodes": [ { "Hostname": "mysql-113", "Token": "30a4dc2ab18b3fce1f66b518a3c87f5f8c9351bcf43e09e10718390392bb64aa", "AppVersion": "3.0.14", "FirstSeenActive": "2019-03-05 14:04:02", "LastSeenActive": "2019-03-11 19:36:14", "ExtraInfo": "", "Command": "", "DBBackend": "192.168.1.3:3306", "LastReported": "0001-01-01T00:00:00Z" }, { "Hostname": "mysql-118", "Token": "b8e7dea2b6bf2a7117f0ba6258633f7ad677675530d499462d51473bffd6e54b", "AppVersion": "3.0.14", "FirstSeenActive": "2019-03-05 13:58:53", "LastSeenActive": "2019-03-11 19:36:13", "ExtraInfo": "", "Command": "", "DBBackend": "192.168.1.3:3306", "LastReported": "0001-01-01T00:00:00Z" }, { "Hostname": "mysql-119", "Token": "3bfe4deae671a528477bb3caa281b4d50b7aae33b052dd421d2b8655c8220864", "AppVersion": "3.0.14", "FirstSeenActive": "2019-03-05 14:01:55", "LastSeenActive": "2019-03-11 19:36:14", "ExtraInfo": "", "Command": "", "DBBackend": "192.168.1.3:3306", "LastReported": "0001-01-01T00:00:00Z" } ], "RaftLeader": "192.168.30.118:10008", "IsRaftLeader": false, "RaftLeaderURI": "http://192.168.30.118:3000", "RaftAdvertise": "192.168.30.119", "RaftHealthyMembers": null } }

[root@mysql-118 ~]# orchestrator-client -c api -path leader-check

"OK"

[root@mysql-113 ~]# orchestrator-client -c api -path leader-check

"Not leader"

搜索实例

 

[root@mysql-119 ~]# orchestrator-client -c search -i mysql-118

mysql-118:4406

[root@mysql-119 ~]# orchestrator-client -c search -i mysql3

mysql3:3307

查看指定实例的主库

 

[root@mysql-119 ~]# orchestrator-client -c which-master -i mysql-119:4406

mysql-113:4406

查看指定实例的从库

 

[root@mysql-119 ~]# orchestrator-client -c which-replicas -i mysql-113:4406

mysql-119:4406

[root@mysql-119 ~]# orchestrator-client -c which-replicas -i mysql2

mysql1:3306

mysql3:3307

查看指定实例名

 

[root@mysql-119 ~]# orchestrator-client -c instance -i mysql2

mysql2:3306

打印指定主实例从库异常的列表:which-broken-replicas,模拟test3的复制异常:

 

# orchestrator-client -c which-broken-replicas -i test2:3307

test3:3307

给定一个实例,列出所在集群下所有实例

 

[root@mysql-119 ~]# orchestrator-client -c which-cluster-instances -i mysql-119:4406

mysql-113:4406

mysql-118:4406

mysql-119:4406

[root@mysql-119 ~]# orchestrator-client -c which-cluster-instances -i mysql1

mysql1:3306

mysql2:3306

mysql3:3307

查看所有实例

 

[root@mysql-119 ~]# orchestrator-client -c all-clusters-masters

mysql-113:4406

mysql2:3306

[root@mysql-119 ~]# orchestrator-client -c all-instances

mysql2:3306

mysql-113:4406

mysql-119:4406

mysql1:3306

mysql3:3307

mysql-118:4406

查看可作为pt-online-schema-change操作的副本列表

 

[root@mysql-119 ~]# orchestrator-client -c which-cluster-osc-replicas -i mysql2

mysql1:3306

mysql3:3307

[root@mysql-119 ~]# orchestrator-client -c which-cluster-osc-running-replicas -i mysql2

mysql1:3306

mysql3:3307

查看集群中主实例的数据中心

 

[root@mysql-119 ~]# orchestrator-client -c dominant-dc

mysql2

将集群的主提交到KV存储

 

[root@mysql-119 ~]# orchestrator-client -c submit-masters-to-kv-stores

mysql/master/cluster_dev:mysql-113:4406

mysql/master/cluster_dev/hostname:mysql-113

mysql/master/cluster_dev/port:4406

mysql/master/cluster_dev/ipv4:192.168.30.113

mysql/master/cluster_dev/ipv6:

mysql/master/trotdb_test:mysql2:3306

mysql/master/trotdb_test/hostname:mysql2

mysql/master/trotdb_test/port:3306

mysql/master/trotdb_test/ipv4:192.168.1.173

mysql/master/trotdb_test/ipv6:

修改拓扑(迁移从库到另一个实例上)

 

[root@mysql-119 ~]# orchestrator-client -c topology -i mysql-118:4406

mysql-113:4406 [0s,ok,5.7.24-27-log,rw,ROW,>>,GTID,P-GTID]

+ mysql-119:4406 [0s,ok,5.7.24-27-log,rw,ROW,>>,GTID,P-GTID]

+ mysql-118:4406 [0s,ok,5.7.24-27-log,rw,ROW,>>,GTID]

将mysql-118:4406改为mysql-113:4406的从库

[root@mysql-119 ~]# orchestrator-client -c relocate -i mysql-118:4406 -d mysql-113:4406

mysql-118:4406<mysql-113:4406

[root@mysql-119 ~]# orchestrator-client -c topology -i mysql-118:4406

mysql-113:4406 [0s,ok,5.7.24-27-log,rw,ROW,>>,GTID,P-GTID]

+ mysql-118:4406 [0s,ok,5.7.24-27-log,rw,ROW,>>,GTID]

+ mysql-119:4406 [0s,ok,5.7.24-27-log,rw,ROW,>>,GTID,P-GTID]

如果发生过了failover,旧主修复后只能通过手动方式将其加入复制。
如果使用orchestrator加入会报错:

 

[root@mysql-113 ~]# orchestrator-client -c relocate -i mysql-118:4406 -d mysql-113:4406

2019-03-19 08:37:10 ERROR Relocating mysql-118:4406 below mysql-113:4406 turns to be too complex; please do it manually

 

故障切换

主库宕机,自动Failover

② Detected UnreachableMaster on mysql-113:4406. Affected replicas: 2
② Detected DeadMaster on mysql-113:4406. Affected replicas: 1
③ Will recover from DeadMaster on mysql-113:4406
④ Recovered from DeadMaster on mysql-113:4406. Failed: mysql-113:4406; Promoted: mysql-118:4406
⑤ (for all types) Recovered from DeadMaster on mysql-113:4406. Failed: mysql-113:4406; Successor: mysql-118:4406

遇到问题及解决

访问WEB报:html/template: “templates/layout” is undefined

访问http://192.168.30.113:3000时报错:html/template: “templates/layout” is undefined
由于启动orchstrator时没有cd到go的项目路径,而是直接使用绝对路径启动:
/usr/local/orchestrator/orchestrator –config=/usr/local/orchestrator/orchestrator.conf.json http &
正确启动方式:
cd /usr/local/orchestrator && ./orchestrator –config=./orchestrator.conf.json http &

glibc版本太低问题

如果系统版本是centos6,运行时可能遇到如下报错:

 

[root@mysql2 ~]# orchestrator

orchestrator: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by orchestrator)

[root@mysql2 ~]# strings /lib64/libc.so.6 |grep GLIBC

GLIBC_2.2.5

GLIBC_2.2.6

GLIBC_2.3

GLIBC_2.3.2

GLIBC_2.3.3

GLIBC_2.3.4

GLIBC_2.4

GLIBC_2.5

GLIBC_2.6

GLIBC_2.7

GLIBC_2.8

GLIBC_2.9

GLIBC_2.10

GLIBC_2.11

GLIBC_2.12

GLIBC_PRIVATE

[root@mysql2 ~]#

升级glibc要非常小心,一般不建议升级。

root@:mysql_dev:~$strings /lib64/libc.so.6 |grep GLIBC

GLIBC_2.2.5

GLIBC_2.2.6

GLIBC_2.3

GLIBC_2.3.2

GLIBC_2.3.3

GLIBC_2.3.4

GLIBC_2.4

GLIBC_2.5

GLIBC_2.6

GLIBC_2.7

GLIBC_2.8

GLIBC_2.9

GLIBC_2.10

GLIBC_2.11

GLIBC_2.12

GLIBC_2.13

GLIBC_2.14

GLIBC_2.15

GLIBC_2.16

GLIBC_2.17

GLIBC_PRIVATE

root@:mysql_dev:~$orchestrator --help

Usage of orchestrator:

-alias string

cluster alias

-binlog string

Binary log file name

-c string

command, required. See full list of commands via 'orchestrator -c help'

-config string

config file name

-d string

destination instance, host_fqdn[:port] (synonym to -s)

-databaseless

EXPERIMENTAL! Work without backend database

-debug

debug mode (very verbose)

-discovery

auto discovery mode (default true)

-duration string

maintenance duration (format: 59s, 59m, 23h, 6d, 4w)

-grab-election

Grab leadership (only applies to continuous mode)

-hostname string

Hostname/fqdn/CNAME/VIP (applies for hostname/resolve related commands)

-i string

instance, host_fqdn[:port] (e.g. db.company.com:3306, db.company.com)

-noop

Dry run; do not perform destructing operations

-owner string

operation owner

-pattern string

regular expression pattern

-pool string

Pool logical name (applies for pool-related commands)

-promotion-rule string

Promotion rule for register-andidate (prefer|neutral|must_not) (default "prefer")

-quiet

quiet

-reason string

operation reason

-s string

sibling instance, host_fqdn[:port]

-skip-unresolve

Do not unresolve a host name

-skip-unresolve-check

Skip/ignore checking an unresolve mapping (via hostname_unresolve table) resolves back to same hostname

-stack

add stack trace upon error

-statement string

Statement/hint

-strict

strict mode (more checks, slower)

-verbose

verbose

-version

Print version and exit

 

虚GTID问题

报错:2019-03-05 10:31:52 ERROR ReadTopologyInstance(mysql-113:4406) DetectPseudoGTIDQuery: Error 1146: Table ‘meta.pseudo_gtid_status’ doesn’t exist
在被管理的MySQL实例上创建Pseudo-GTID的meta库(只在主库执行即可,从库会复制过去)

 

mysql> create database meta;

Query OK, 1 row affected (0.01 sec)

mysql> source /usr/local/orchestrator/resources/pseudo-gtid/pseudo-gtid.sql;

Query OK, 1 row affected, 1 warning (0.00 sec)

Database changed

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE IF NOT EXISTS cluster (

-> anchor TINYINT NOT NULL,

-> cluster_name VARCHAR(128) CHARSET ascii NOT NULL DEFAULT '',

-> cluster_domain VARCHAR(128) CHARSET ascii NOT NULL DEFAULT '',

-> PRIMARY KEY (anchor)

-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Query OK, 0 rows affected (0.01 sec)

mysql> show tables;

+--------------------+

| Tables_in_meta |

+--------------------+

| cluster |

| pseudo_gtid_status |

+--------------------+

2 rows in set (0.00 sec)

mysql> INSERT INTO cluster (anchor, cluster_name, cluster_domain)

-> VALUES (1, CONCAT('cls_',@@hostname), @@hostname)

-> ON DUPLICATE KEY UPDATE cluster_name=VALUES(cluster_name), cluster_domain=VALUES(cluster_domain);

Query OK, 1 row affected (0.00 sec)

mysql> select * from cluster;

+--------+---------------+----------------+

| anchor | cluster_name | cluster_domain |

+--------+---------------+----------------+

| 1 | cls_mysql-113 | mysql-113 |

+--------+---------------+----------------+

1 row in set (0.00 sec)

 

hosts没配置报错

 

2019-02-27 11:28:43 DEBUG outdated keys: []

2019-02-27 11:28:44 DEBUG outdated keys: [mysql1:3306 mysql2:3306 mysql3:3307]

2019-02-27 11:28:44 ERROR dial tcp: lookup mysql3 on [::1]:53: read udp [::1]:32462->[::1]:53: read: connection refused

2019-02-27 11:28:44 ERROR ReadTopologyInstance(mysql3:3307) show variables like 'maxscale%': dial tcp: lookup mysql3 on [::1]:53: read udp [::1]:32462->[::1]:53: read: connection refused

2019-02-27 11:28:44 ERROR ReadTopologyInstance(mysql3:3307) Cleanup: dial tcp: lookup mysql3 on [::1]:53: read udp [::1]:19871->[::1]:53: read: connection refused

2019-02-27 11:28:44 WARNING discoverInstance(mysql3:3307) instance is nil in 0.009s, error=Failed ReadTopologyInstance

2019-02-27 11:28:44 DEBUG Discovered host: mysql2:3306, master: mysql1:3306, version: 5.7.20-19-log in 0.018s

2019-02-27 11:28:44 DEBUG Discovered host: mysql1:3306, master: mysql2:3306, version: 5.7.20-19-log in 0.020s

2019-02-27 11:28:45 DEBUG outdated keys: []

报错:

2019-03-05 13:31:04 DEBUG raft leader is 192.168.30.113:10008; state: Follower

2019-03-05 13:31:07 ERROR ReadTopologyInstance(mysql1:3306) show global status like 'Uptime': dial tcp: lookup mysql1 on 127.0.0.1:53: no such host

2019-03-05 13:31:07 ERROR ReadTopologyInstance(mysql3:3307) show global status like 'Uptime': dial tcp: lookup mysql3 on 127.0.0.1:53: no such host

原因:域名解析问题,配置/etc/hosts解决

解决:在orchestrator运行的机器上添加mysql的ip及对应主机名

#orchestrator

192.168.1.172 mysql1

192.168.1.173 mysql2

192.168.1.123 mysql3

report-host没设置报错

 

2019-02-26 17:15:03 DEBUG outdated keys: [mysql1:3306 mysql2:3306]

2019-02-26 17:15:03 ERROR ReadTopologyInstance(mysql2:3306) show slave hosts: ReadTopologyInstance(mysql2:3306) 'show slave hosts' returned row with <host,port>: <,3306>

2019-02-26 17:15:03 ERROR ReadTopologyInstance(mysql1:3306) show slave hosts: ReadTopologyInstance(mysql1:3306) 'show slave hosts' returned row with <host,port>: <,3306>

2019-02-26 17:15:03 DEBUG Discovered host: mysql2:3306, master: mysql1:3306, version: 5.7.20-19-log in 0.018s

2019-02-26 17:15:03 DEBUG Discovered host: mysql1:3306, master: mysql2:3306, version: 5.7.20-19-log in 0.025s

2019-02-26 17:15:04 DEBUG outdated keys: []

2019-02-26 17:15:05 DEBUG outdated keys: []

解决:

Mysql主从复制,在master上查看从的信息:show slave hosts

http://dinglin.iteye.com/blog/1255160

默认不记录从的host信息,只记录端口和Server_id信息,需要设置my.cnf 中的[mysqld] report-host=IP

正常输出:

2019-02-27 11:31:43 DEBUG outdated keys: []

2019-02-27 11:31:44 DEBUG outdated keys: [mysql1:3306 mysql2:3306 mysql3:3307]

2019-02-27 11:31:44 DEBUG Discovered host: mysql2:3306, master: mysql1:3306, version: 5.7.20-19-log in 0.019s

2019-02-27 11:31:44 DEBUG Discovered host: mysql1:3306, master: mysql2:3306, version: 5.7.20-19-log in 0.023s

2019-02-27 11:31:44 DEBUG Discovered host: mysql3:3307, master: mysql2:3306, version: 5.7.20-19-log in 0.042s

2019-02-27 11:31:45 DEBUG outdated keys: []

mysql用户权限问题

 

2019-03-05 13:58:55 ERROR ReadTopologyInstance(mysql2:3306) show global status like 'Uptime': Error 1045: Access denied for user 'orchestrator'@'192.168.30.118' (using password: YES)

2019-03-05 14:08:34 ERROR ReadTopologyInstance(mysql3:3307) show global status like 'Uptime': Error 1045: Access denied for user 'orchestrator'@'192.168.30.118' (using password: YES)

2019-03-05 14:08:34 WARNING DiscoverInstance(mysql3:3307) instance is nil in 0.017s (Backend: 0.004s, Instance: 0.013s), error=Error 1045: Access denied for user 'orchestrator'@'192.168.30.118' (using password: YES)

2019-03-05 14:08:34 ERROR ReadTopologyInstance(mysql1:3306) show global status like 'Uptime': Error 1045: Access denied for user 'orchestrator'@'192.168.30.118' (using password: YES)

2019-03-05 14:08:34 WARNING DiscoverInstance(mysql1:3306) instance is nil in 0.023s (Backend: 0.004s, Instance: 0.019s), error=Error 1045: Access denied for user 'orchestrator'@'192.168.30.118' (using password: YES)

2019-03-05 14:08:35 ERROR ReadTopologyInstance(mysql2:3306) show global status like 'Uptime': Error 1045: Access denied for user 'orchestrator'@'192.168.30.118' (using password: YES)

2019-03-05 14:08:35 WARNING DiscoverInstance(mysql2:3306) instance is nil in 0.016s (Backend: 0.008s, Instance: 0.009s), error=Error 1045: Access denied for user 'orchestrator'@'192.168.30.118' (using password: YES)

解决:由于orchestrator部署到了新的网段,需重新赋权

mysql> GRANT SELECT, RELOAD, PROCESS, SUPER, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'orchestrator'@'192.168.30.%' identified by 'abc123';

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show warnings;

+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Level | Code | Message |

+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Warning | 1287 | Using GRANT statement to modify existing user's properties other than privileges is deprecated and will be removed in future release. Use ALTER USER statement for this operation. |

+---------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

GTID错误跳过

Problem:Errant GTID
replica has gtid entries not found on its master
可以在页面上处理GTID错误:
图1
图2
图3
然后刷新下页面就没有GTID的报错了。

这篇关于MySQL高可用探索之orchestrator的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/398273

相关文章

SQL中的外键约束

外键约束用于表示两张表中的指标连接关系。外键约束的作用主要有以下三点: 1.确保子表中的某个字段(外键)只能引用父表中的有效记录2.主表中的列被删除时,子表中的关联列也会被删除3.主表中的列更新时,子表中的关联元素也会被更新 子表中的元素指向主表 以下是一个外键约束的实例展示

基于MySQL Binlog的Elasticsearch数据同步实践

一、为什么要做 随着马蜂窝的逐渐发展,我们的业务数据越来越多,单纯使用 MySQL 已经不能满足我们的数据查询需求,例如对于商品、订单等数据的多维度检索。 使用 Elasticsearch 存储业务数据可以很好的解决我们业务中的搜索需求。而数据进行异构存储后,随之而来的就是数据同步的问题。 二、现有方法及问题 对于数据同步,我们目前的解决方案是建立数据中间表。把需要检索的业务数据,统一放到一张M

如何去写一手好SQL

MySQL性能 最大数据量 抛开数据量和并发数,谈性能都是耍流氓。MySQL没有限制单表最大记录数,它取决于操作系统对文件大小的限制。 《阿里巴巴Java开发手册》提出单表行数超过500万行或者单表容量超过2GB,才推荐分库分表。性能由综合因素决定,抛开业务复杂度,影响程度依次是硬件配置、MySQL配置、数据表设计、索引优化。500万这个值仅供参考,并非铁律。 博主曾经操作过超过4亿行数据

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置

深入探索协同过滤:从原理到推荐模块案例

文章目录 前言一、协同过滤1. 基于用户的协同过滤(UserCF)2. 基于物品的协同过滤(ItemCF)3. 相似度计算方法 二、相似度计算方法1. 欧氏距离2. 皮尔逊相关系数3. 杰卡德相似系数4. 余弦相似度 三、推荐模块案例1.基于文章的协同过滤推荐功能2.基于用户的协同过滤推荐功能 前言     在信息过载的时代,推荐系统成为连接用户与内容的桥梁。本文聚焦于

MySQL数据库宕机,启动不起来,教你一招搞定!

作者介绍:老苏,10余年DBA工作运维经验,擅长Oracle、MySQL、PG、Mongodb数据库运维(如安装迁移,性能优化、故障应急处理等)公众号:老苏畅谈运维欢迎关注本人公众号,更多精彩与您分享。 MySQL数据库宕机,数据页损坏问题,启动不起来,该如何排查和解决,本文将为你说明具体的排查过程。 查看MySQL error日志 查看 MySQL error日志,排查哪个表(表空间

MySQL高性能优化规范

前言:      笔者最近上班途中突然想丰富下自己的数据库优化技能。于是在查阅了多篇文章后,总结出了这篇! 数据库命令规范 所有数据库对象名称必须使用小写字母并用下划线分割 所有数据库对象名称禁止使用mysql保留关键字(如果表名中包含关键字查询时,需要将其用单引号括起来) 数据库对象的命名要能做到见名识意,并且最后不要超过32个字符 临时库表必须以tmp_为前缀并以日期为后缀,备份

[MySQL表的增删改查-进阶]

🌈个人主页:努力学编程’ ⛅个人推荐: c语言从初阶到进阶 JavaEE详解 数据结构 ⚡学好数据结构,刷题刻不容缓:点击一起刷题 🌙心灵鸡汤:总有人要赢,为什么不能是我呢 💻💻💻数据库约束 🔭🔭🔭约束类型 not null: 指示某列不能存储 NULL 值unique: 保证某列的每行必须有唯一的值default: 规定没有给列赋值时的默认值.primary key:

MySQL-CRUD入门1

文章目录 认识配置文件client节点mysql节点mysqld节点 数据的添加(Create)添加一行数据添加多行数据两种添加数据的效率对比 数据的查询(Retrieve)全列查询指定列查询查询中带有表达式关于字面量关于as重命名 临时表引入distinct去重order by 排序关于NULL 认识配置文件 在我们的MySQL服务安装好了之后, 会有一个配置文件, 也就

Java 连接Sql sever 2008

Java 连接Sql sever 2008 /Sql sever 2008 R2 import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class TestJDBC