MySQL分片高可用集群之Fabric部署使用(2)

fabric的默认配置文件路径为/usr/local/etc/mysql/fabric.cfg,其他安装方法会是/etc/mysql/fabric.cfg(其他系统根据自己情况配置)因此为了方便后面的操作,我们还是使用这个配置文件,当然也可以用--config 参数指定配置文件。

fabric.cfg内容如下:

[DEFAULT]

prefix = /usr/local

sysconfdir = /usr/local/etc

logdir = /var/log

# storage 配置的是fabric元数据存储的数据库

[storage]

address = localhost:10000

user = fabric

password = 123456

database = fabric

auth_plugin = mysql_native_password

connection_timeout = 6

connection_attempts = 6

connection_delay = 1

[servers]

user = fabric

password = 123456

backup_user = fabric_backup

backup_password = secret

restore_user = fabric_restore

restore_password = secret

unreachable_timeout = 5

# fabric对外的协议,这里是xmlrpc协议

[protocol.xmlrpc]

address = localhost:32274

threads = 5

user = admin

password = 123456

disable_authentication = yes

realm = MySQL Fabric

ssl_ca =

ssl_cert =

ssl_key =

# fabric对外的协议,这里是mysql协议,能用mysql连接,但是不能跟普通数据库一样操作

[protocol.mysql]

address = localhost:32275

user = admin

password = 123456

disable_authentication = yes

ssl_ca =

ssl_cert =

ssl_key =

[executor]

executors = 5

[logging]

level = INFO

url = file:///var/log/fabric.log

[sharding]

mysqldump_program = /usr/bin/mysqldump

mysqlclient_program = /usr/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


配置好后,需要初始化fabric的元数据
 

$ mysqlfabric manage setup

。。。。。。

Finishing initial setup

=======================

Password for admin user is not yet set.

Password for admin/xmlrpc:                这里需要设置admin的密码

Repeat Password:                          重复输入密码

Password set.

Password set.

这时fa00这个数据库已经有了fabric的元数据,我们可以用mysql客户端查看。

然后启动

$ mysqlfabric manage start


自此虽然启动了fabric,但是还没有和前面配置的后两个业务数据库产生联系,接下来我们需要用命令行建立联系。我先看一下mysqlfabric的分组相关帮助,

$ mysqlfabric help group

Commands available in group 'group' are:

group activate group_id  [--synchronous]

group description group_id  [--description=NONE] [--synchronous]

group deactivate group_id  [--synchronous]

group create group_id  [--description=NONE] [--synchronous]

group remove group_id server_id  [--synchronous]

group add group_id address  [--timeout=NONE] [--update_only] [--synchronous]

group health group_id 

group lookup_servers group_id  [--server_id=NONE] [--status=NONE] [--mode=NONE]

group destroy group_id  [--synchronous]

group demote group_id  [--update_only] [--synchronous]

group promote group_id  [--slave_id=NONE] [--update_only] [--synchronous]

group lookup_groups  [--group_id=NONE]


我们首先需要创建一个组group-1:

$ mysqlfabric group create group-1

然后将两个业务数据库10011和10012放入这个组中:

$ mysqlfabric group add group-1 127.0.0.1:10011

$ mysqlfabric group add group-1 127.0.0.1:10012


然后可以查看这时group-1这个组的状态

$ mysqlfabric group lookup_servers group-1

Fabric UUID:  5ca1ab1e-a007-feed-f00d-cab3fe13249e

Time-To-Live: 1

server_uuid        address    status      mode weight

------------------------------------ --------------- --------- --------- ------

d4919ca2-754a-11e5-8a5e-34238703623c 127.0.0.1:10011 SECONDARY READ_ONLY    1.0

d6597f06-754a-11e5-8a5e-34238703623c 127.0.0.1:10012 SECONDARY READ_ONLY    1.0

从status 和 mode 这两个字段可以看出,这个时候刚加入的两个服务器还没有正式生效,都是作为从库只读的身份,两个库还没有建立实质的联系,我们需要将其中一个数据库提升为可写的主:

$ mysqlfabric group promote group-1

$ mysqlfabric group lookup_servers group-1

Fabric UUID:  5ca1ab1e-a007-feed-f00d-cab3fe13249e

Time-To-Live: 1

server_uuid        address    status      mode weight

------------------------------------ --------------- --------- ---------- ------

d4919ca2-754a-11e5-8a5e-34238703623c 127.0.0.1:10011 SECONDARY  READ_ONLY    1.0

d6597f06-754a-11e5-8a5e-34238703623c 127.0.0.1:10012  PRIMARY READ_WRITE    1.0

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/d43f7e11bd0b62d574a3dd16075536b2.html