文章目录
  1. 1. MySQL Frabric 环境部署
    1. 1.1. 构建环境
      1. 1.1.1. 实例准备
      2. 1.1.2. 复制结构
      3. 1.1.3. 创建用户,配置fabric对应user权限
      4. 1.1.4. 配置fabric
      5. 1.1.5. 初始化fabric环境
      6. 1.1.6. 启动 fabric
  2. 2. 结束

MySQL Frabric 环境部署

一步一步的构建fabric的部署环境,时间仓促,大致把命令list做了罗列,很多地方都有很多可以剖析的地方,今天就不多说了,后续会补上…

构建环境

实例准备

我在本地机器搭建了7个实例分别为 :3306实例作为back store database。省下三组主备以后用来作为sharding group的实例,M代表主库,S代表slave备库。对应的端口如下

3306
3310 [M] <---->  3311 [S] 
3312 [M] <---->  3313 [S] 
3314 [M] <---->  3315 [S] 

看一下如下命令:

ps -ef | grep mysqld | grep mysqld_safe

输出:

1
2
3
4
5
6
7
74  6488  5534   0  9:16下午 ttys000    0:00.86 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql/ --datadir=/data/mysql3306/data --plugin-dir=/usr/local/mysql//lib/plugin --user=mysql --log-error=/data/mysql3306/log/alert.log --pid-file=/data/mysql3306/run/mysqld.pid --socket=/data/mysql3306/run/mysql.sock --port=3306
74 7464 6509 0 9:17下午 ttys000 0:00.78 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql/ --datadir=/data/mysql3310/data --plugin-dir=/usr/local/mysql//lib/plugin --user=mysql --log-error=/data/mysql3310/log/alert.log --pid-file=/data/mysql3310/run/mysqld.pid --socket=/data/mysql3310/run/mysql.sock --port=3310
74 8424 7465 0 9:17下午 ttys000 0:00.76 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql/ --datadir=/data/mysql3311/data --plugin-dir=/usr/local/mysql//lib/plugin --user=mysql --log-error=/data/mysql3311/log/alert.log --pid-file=/data/mysql3311/run/mysqld.pid --socket=/data/mysql3311/run/mysql.sock --port=3311
74 9380 8425 0 9:17下午 ttys000 0:00.81 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql/ --datadir=/data/mysql3312/data --plugin-dir=/usr/local/mysql//lib/plugin --user=mysql --log-error=/data/mysql3312/log/alert.log --pid-file=/data/mysql3312/run/mysqld.pid --socket=/data/mysql3312/run/mysql.sock --port=3312
74 10336 9381 0 9:18下午 ttys000 0:00.80 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql/ --datadir=/data/mysql3313/data --plugin-dir=/usr/local/mysql//lib/plugin --user=mysql --log-error=/data/mysql3313/log/alert.log --pid-file=/data/mysql3313/run/mysqld.pid --socket=/data/mysql3313/run/mysql.sock --port=3313
74 11292 10337 0 9:18下午 ttys000 0:00.84 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql/ --datadir=/data/mysql3314/data --plugin-dir=/usr/local/mysql//lib/plugin --user=mysql --log-error=/data/mysql3314/log/alert.log --pid-file=/data/mysql3314/run/mysqld.pid --socket=/data/mysql3314/run/mysql.sock --port=3314
74 12248 11293 0 9:18下午 ttys000 0:00.80 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql/ --datadir=/data/mysql3315/data --plugin-dir=/usr/local/mysql//lib/plugin --user=mysql --log-error=/data/mysql3315/log/alert.log --pid-file=/data/mysql3315/run/mysqld.pid --socket=/data/mysql3315/run/mysql.sock --port=3315

复制结构

 ruiayLinSunnydeMacBook-Pro-2:gtidtest root# mysqlrplshow --master=root:root@localhost:3310 --discover-slaves-login=root:root -vv
# master on localhost: ... connected.
# Finding slaves for master: localhost:3310
# Replication Topology Graph
localhost:3310 (MASTER)
   |
   +--- localhost:3311 [IO: Yes, SQL: Yes] - (SLAVE)

ruiayLinSunnydeMacBook-Pro-2:gtidtest root# mysqlrplshow --master=root:root@localhost:3312 --discover-slaves-login=root:root -vv
 # master on localhost: ... connected.
# Finding slaves for master: localhost:3312
# Replication Topology Graph
localhost:3312 (MASTER)
   |
   +--- localhost:3313 [IO: Yes, SQL: Yes] - (SLAVE)

ruiayLinSunnydeMacBook-Pro-2:gtidtest root# mysqlrplshow --master=root:root@localhost:3314 --discover-slaves-login=root:root -vv
# master on localhost: ... connected.
# Finding slaves for master: localhost:3314
# Replication Topology Graph
localhost:3314 (MASTER)
   |
   +--- localhost:3315 [IO: Yes, SQL: Yes] - (SLAVE)

创建用户,配置fabric对应user权限

1
2
3
4
5
CREATE USER 'fabric'@'localhost' IDENTIFIED BY 'secret';
GRANT ALL ON fabric.* TO 'fabric'@'localhost';
GRANT ALL ON fabric.* TO 'fabric'@'127.0.0.1';
SET PASSWORD FOR 'fabric'@'localhost' = PASSWORD('secret');
SET PASSWORD FOR 'fabric'@'127.0.0.1' = PASSWORD('secret');

配置fabric

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
[DEFAULT]
prefix =
sysconfdir = /etc
logdir = /var/log

[storage]
address = localhost:3306
user = fabric
password =secret
database = fabric
unix_socket=/data/mysql3306/run/mysql.sock
auth_plugin = mysql_native_password
connection_timeout = 6
connection_attempts = 6
connection_delay = 1

[servers]
user = fabric
password =secret
[protocol.xmlrpc]
address = localhost:32274
threads = 5
user = admin
password =admin
disable_authentication = no
realm = MySQL Fabric
ssl_ca =
ssl_cert =
ssl_key =

[executor]
executors = 5
[logging]
level = INFO
url = file:///var/log/fabric.log

[sharding]
mysqldump_program =/usr/local/mysql/bin/mysqldump
mysqlclient_program = /usr/local/mysql/bin/mysql
[statistics]
prune_time = 3600

[failure_tracking]
notifications = 300
notification_clients = 50
notification_interval = 60
failover_interval = 0
detections = 3
detection_interval = 6
detection_timeout = 1
prune_time = 3600

[connector]
ttl = 1
[client]
password =

初始化fabric环境

运行 mysqlfabric manage setup –param=storage.user=fabric –param=storage.password=secret 看到如下输出

1
2
3
4
5
ruiayLinSunnydeMacBook-Pro-2:mysql root# mysqlfabric manage setup --param=storage.user=fabric --param=storage.password=secret
[INFO] 1402714453.490616 - MainThread - Initializing persister: user (fabric), server (localhost:3306), database (fabric).
[INFO] 1402714456.262460 - MainThread - Initial password for admin/xmlrpc set
Password set for admin/xmlrpc from configuration file.
[INFO] 1402714456.280574 - MainThread - Password set for admin/xmlrpc from configuration file.

初始化完毕后可以登录store db ,也就是mysql3306 实例,use fabric ; show tables ; 可以看到如下表:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
root@fabric 10:54:41>show tables ;
+-------------------+
| Tables_in_fabric |
+-------------------+
| checkpoints |
| error_log |
| group_replication |
| group_view |
| groups |
| log |
| permissions |
| proc_view |
| role_permissions |
| roles |
| servers |
| shard_maps |
| shard_ranges |
| shard_tables |
| shards |
| user_roles |
| users |
+-------------------+
17 rows in set (0.00 sec)

至此 fabric 环境已经准备好了。 可以启动fabric后台进程了。

启动 fabric

终端执行:mysqlfabric manage start ,当然还有很多参数可以添加,比如 Deamon 选项和指定日志文件选项

1
2
3
4
5
6
7
8
9
10
11
ruiayLinSunnydeMacBook-Pro-2:mysql root#  mysqlfabric manage start
[INFO] 1402714611.474464 - MainThread - Initializing persister: user (fabric), server (localhost:3306), database (fabric).
[INFO] 1402714611.478876 - MainThread - Loading Services.
[INFO] 1402714611.495904 - MainThread - Fabric node starting.
[INFO] 1402714611.497266 - MainThread - Starting Executor.
[INFO] 1402714611.497345 - MainThread - Setting 5 executor(s).
[INFO] 1402714611.497697 - Executor-0 - Started.
[INFO] 1402714611.498002 - Executor-1 - Started.
[INFO] 1402714611.498457 - Executor-2 - Started.
[INFO] 1402714611.498768 - Executor-3 - Started.
[INFO] 1402714611.499371 - Executor-4 - Started.

结束

环境已经配置完成, 接下来就可以配置 group 和 shards,接下来会补充另一篇文章来介绍fabric的sharding以及对于的HA方案,Thanks

文章目录
  1. 1. MySQL Frabric 环境部署
    1. 1.1. 构建环境
      1. 1.1.1. 实例准备
      2. 1.1.2. 复制结构
      3. 1.1.3. 创建用户,配置fabric对应user权限
      4. 1.1.4. 配置fabric
      5. 1.1.5. 初始化fabric环境
      6. 1.1.6. 启动 fabric
  2. 2. 结束