MySQL Fabric部署

架构描述:

一台主机上安装4个MySQL 服务,其中一个MySQL服务用于存储MySQL Fabric后台数据;另外3个MySQL服务用于主从架构测试。一个主+两个从。

 

 

第一部分:二进制方式安装MySQL 5.6.19

1.        操作系统

CentOS release 6.2 (Final)

 

2.        创建用户和组

[root@mymaster1 ~]# groupadd mysql

[root@mymaster1 ~]# useradd -r -g mysqlmysql

 

3.        解压安装包(解压到你想存储数据库数据的地方)

[root@mymaster1 ~]# cd /data

[root@mymaster1 data]# tar -xzvf/root/mysql_soft/mysql-5.6.19-linux-glibc2.5-x86_64.tar.gz

[root@mymaster1 data]# ln -smysql-5.6.19-linux-glibc2.5-x86_64 mysql

 

4.        查看解压情况

[root@mymaster1 data]# ll

总用量 20

lrwxrwxrwx.  1 root root   34  6 27 15:31 mysql -> mysql-5.6.19-linux-glibc2.5-x86_64

drwxr-xr-x. 13 rootroot  4096  6 27 15:31 mysql-5.6.19-linux-glibc2.5-x86_64

 

5.        修改文件夹所属用户和组为mysql:

[root@mymaster1 data]# cd mysql

[root@mymaster1 mysql]# chown -R mysql:mysql.

 

6.        安装数据库

[root@mymaster1 mysql]#scripts/mysql_install_db --user=mysql --basedir=/data/mysql--datadir=/data/mysql/data

WARNING: The host'mymaster1.localdomain' could not be looked up with /data/mysql/bin/resolveip.

This probably means thatyour libc libraries are not 100 % compatible

with this binary MySQLversion. The MySQL daemon, mysqld, should work

normally with theexception that host name resolving will not work.

This means that youshould use IP addresses instead of hostnames

when specifying MySQLprivileges !

 

当出现上面警告时,解决方法是:在/etc/hosts配置文件中增加IP地址和主机名的映射

[root@mymaster1 Packages]# cat /etc/hosts

127.0.0.1  localhost localhost.localdomain localhost4 localhost4.localdomain4

::1        localhost localhost.localdomain localhost6 localhost6.localdomain6

IP地址  mymaster1.localdomain

 

正确的提示信息如下:

[root@mymaster1 mysql]#scripts/mysql_install_db --user=mysql --basedir=/data/mysql--datadir=/data/mysql/data

Installing MySQL system tables...2014-06-2716:02:45 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated.Please use --explicit_defaults_for_timestamp server option (see documentationfor more details).

2014-06-27 16:02:45 2134 [Note] InnoDB:Using atomics to ref count buffer pool pages

2014-06-27 16:02:45 2134 [Note] InnoDB: TheInnoDB memory heap is disabled

2014-06-27 16:02:45 2134 [Note] InnoDB:Mutexes and rw_locks use GCC atomic builtins

2014-06-27 16:02:45 2134 [Note] InnoDB:Compressed tables use zlib 1.2.3

2014-06-27 16:02:45 2134 [Note] InnoDB:Using Linux native AIO

2014-06-27 16:02:45 2134 [Note] InnoDB:Using CPU crc32 instructions

2014-06-27 16:02:45 2134 [Note] InnoDB:Initializing buffer pool, size = 128.0M

2014-06-27 16:02:45 2134 [Note] InnoDB:Completed initialization of buffer pool

2014-06-27 16:02:45 2134 [Note] InnoDB: Thefirst specified data file ./ibdata1 did not exist: a new database to becreated!

2014-06-27 16:02:45 2134 [Note] InnoDB:Setting file ./ibdata1 size to 12 MB

2014-06-27 16:02:45 2134 [Note] InnoDB:Database physically writes the file full: wait...

2014-06-27 16:02:45 2134 [Note] InnoDB:Setting log file ./ib_logfile101 size to 48 MB

2014-06-27 16:02:46 2134 [Note] InnoDB:Setting log file ./ib_logfile1 size to 48 MB

2014-06-27 16:02:46 2134 [Note] InnoDB:Renaming log file ./ib_logfile101 to ./ib_logfile0

2014-06-27 16:02:46 2134 [Warning] InnoDB:New log files created, LSN=45781

2014-06-27 16:02:46 2134 [Note] InnoDB:Doublewrite buffer not found: creating new

2014-06-27 16:02:46 2134 [Note] InnoDB:Doublewrite buffer created

2014-06-27 16:02:46 2134 [Note] InnoDB: 128rollback segment(s) are active.

2014-06-27 16:02:46 2134 [Warning] InnoDB:Creating foreign key constraint system tables.

2014-06-27 16:02:46 2134 [Note] InnoDB:Foreign key constraint system tables created

2014-06-27 16:02:46 2134 [Note] InnoDB:Creating tablespace and datafile system tables.

2014-06-27 16:02:46 2134 [Note] InnoDB:Tablespace and datafile system tables created.

2014-06-27 16:02:46 2134 [Note] InnoDB:Waiting for purge to start

2014-06-27 16:02:46 2134 [Note] InnoDB:5.6.19 started; log sequence number 0

2014-06-27 16:02:47 2134 [Note] Binlog end

2014-06-27 16:02:47 2134 [Note] InnoDB: FTSoptimize thread exiting.

2014-06-27 16:02:47 2134 [Note] InnoDB:Starting shutdown...

2014-06-27 16:02:48 2134 [Note] InnoDB:Shutdown completed; log sequence number 1625977

OK

 

Filling help tables...2014-06-27 16:02:48 0[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use--explicit_defaults_for_timestamp server option (see documentation for moredetails).

2014-06-27 16:02:48 2157 [Note] InnoDB:Using atomics to ref count buffer pool pages

2014-06-27 16:02:48 2157 [Note] InnoDB: TheInnoDB memory heap is disabled

2014-06-27 16:02:48 2157 [Note] InnoDB:Mutexes and rw_locks use GCC atomic builtins

2014-06-27 16:02:48 2157 [Note] InnoDB:Compressed tables use zlib 1.2.3

2014-06-27 16:02:48 2157 [Note] InnoDB:Using Linux native AIO

2014-06-27 16:02:48 2157 [Note] InnoDB:Using CPU crc32 instructions

2014-06-27 16:02:48 2157 [Note] InnoDB:Initializing buffer pool, size = 128.0M

2014-06-27 16:02:48 2157 [Note] InnoDB:Completed initialization of buffer pool

2014-06-27 16:02:48 2157 [Note] InnoDB:Highest supported file format is Barracuda.

2014-06-27 16:02:48 2157 [Note] InnoDB: 128rollback segment(s) are active.

2014-06-27 16:02:48 2157 [Note] InnoDB:Waiting for purge to start

2014-06-27 16:02:48 2157 [Note] InnoDB:5.6.19 started; log sequence number 1625977

2014-06-27 16:02:48 2157 [Note] Binlog end

2014-06-27 16:02:48 2157 [Note] InnoDB: FTSoptimize thread exiting.

2014-06-27 16:02:48 2157 [Note] InnoDB:Starting shutdown...

2014-06-27 16:02:50 2157 [Note] InnoDB:Shutdown completed; log sequence number 1625987

OK

 

To start mysqld at boot time you have tocopy

support-files/mysql.server to the rightplace for your system

 

PLEASE REMEMBER TO SET A PASSWORD FOR THEMySQL root USER !

To do so, start the server, then issue thefollowing commands:

 

 /data/mysql/bin/mysqladmin -u root password 'new-password'

 /data/mysql/bin/mysqladmin -u root -h mymaster1.localdomain password'new-password'

 

Alternatively you can run:

 

 /data/mysql/bin/mysql_secure_installation

 

which will also give you the option ofremoving the test

databases and anonymous user created bydefault.  This is

strongly recommended for productionservers.

 

See the manual for more instructions.

 

You can start the MySQL daemon with:

 

  cd. ; /data/mysql/bin/mysqld_safe &

 

You can test the MySQL daemon withmysql-test-run.pl

 

  cdmysql-test ; perl mysql-test-run.pl

 

Please report any problems athttp://bugs.mysql.com/

 

The latest information about MySQL isavailable on the web at

 

 http://www.mysql.com

 

Support MySQL by buying support/licenses athttp://shop.mysql.com

 

New default config file was created as/data/mysql/my.cnf and

will be used by default by the server whenyou start it.

You may edit this file to change serversettings

 

7.        修改相关目录权限,提高安全性:

[root@mymaster1 mysql]# chown -R root .

[root@mymaster1 mysql]# chown -R mysql data

 

8.        配置MySQL服务为主机服务,即能用service mysql start启动服务

[root@mymaster1 mysql]# cpsupport-files/mysql.server /etc/init.d/mysql

[root@mymaster1 mysql]# vi +46 /etc/init.d/mysql

把下面的

basedir=

datadir=

修改为

basedir=/data/mysql

datadir=/data/mysql/data

 

【备注】另外三个mysql服务,可以在这里复制为如下形式:

[root@mymaster1 mysql]#cp support-files/mysql.server /etc/init.d/mysql.3001

[root@mymaster1 mysql]#vi +46 /etc/init.d/mysql.3001

 

 

9.        修改配置文件

[root@mysqlfabric mysql_3001]# cd/opt/mysql

[root@mysqlfabric mysql]# vi my.cnf

修改相应的端口号:

[mysqld]

character-set-server=gbk

lower_case_table_names=1

default_storage_engine=myisam

port=3306

 

gtid_mode=ON

log-bin

log-slave-updates

enforce-gtid-consistency

server_id=1 #【不同的MySQL服务,修改为不同的id

【备注】:上面的蓝色字体是用于开启GTID复制参数

 

10.    启动数据库

[root@mymaster1 mysql]# service mysql start

Starting MySQL[确定]

 

11.    修改数据库root密码

[root@mymaster1 mysql]#/data/mysql/bin/mysqladmin -u root password 'root'

[root@mymaster1 mysql]#/data/mysql/bin/mysqladmin -u root -h mymaster1.localdomain password ' root'

 

12.    修改环境变量,把mysql执行文件路径添加到环境变量中

[root@mymaster1 mysql]# vi /etc/profile

PATH=$PATH:/data/mysql/bin

export PATH

 

13.    测试登录

[root@mymaster1 mysql]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.6.19 MySQL CommunityServer (GPL)

 

Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.

 

mysql>

 

mysql> show variables like '%data%';

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

| Variable_name                 | Value                  |

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

| character_set_database        | latin1                 |

| collation_database            | latin1_swedish_ci      |

| datadir                       | /data/mysql/data/ 

 

14.    添加用于复制的用户(3001上)

mysql> CREATE USER 'repl'@'%' IDENTIFIEDBY 'repl';

Query OK, 0 rows affected (0.03 sec)

 

mysql> GRANT REPLICATION SLAVE ON *.* TO'repl'@'%';

Query OK, 0 rows affected (0.00 sec)

 

15.    开启复制(3002,3003上)

 使用change master to 命令开启复制

mysql> start slave;

 

mysql> show slave status\G


下面是重要步骤,安装Fabric


第二部分:安装MySQL Fabric

1.        安装Connector/Python

[root@mysqlfabric soft]# rpm -ivhmysql-connector-python-1.2.2-1.el6.noarch.rpm

注:MySQL Fabric使用Connector/Python来连接MySQL,所以必须安装这个连接器

 

2.        安装Fabric

由于Fabric包含在mysql-utilities,所以只需要安装mysql-utilities就可以了。

[root@mysqlfabric soft]# rpm -ivh mysql-utilities-1.4.3-1.el6.noarch.rpm

Preparing...               ########################################### [100%]

  1:mysql-utilities       ########################################### [100%]

 

3.        配置MySQL Fabric

配置MySQL Fabric需要创建MySQL用户,创建启动配置文件和安装Fabric数据存储

l  创建用户

登录端口号为3306的mysql 服务【作为Fabric后台数据存储】

[root@mysqlfabric soft]# mysql -u root -P3306 -p –h mysqlfabric.localdomain

【注】上面登录时需要加主机名,因为一台服务器安装了多个mysql服务

mysql> CREATE USER 'fabric'@'mysqlfabric.localdomain'IDENTIFIED BY 'fabric';

Query OK, 0 rows affected (0.00 sec)


mysql> GRANT ALL ON fabric.* TO'fabric'@'mysqlfabric.localdomain';

Query OK, 0 rows affected (0.00 sec)

 

l  在另外三台MySQL 服务下创建下面的用户,用于连接被管理的MySQL服务

[root@mysqlfabric mysql_3003]# mysql -uroot-P3001 -p -h mysqlfabric.localdomain


mysql> GRANT ALL ON *.* TO 'fabric'@' mysqlfabric.localdomain';

Query OK, 0 rows affected (0.00 sec)

 

mysql> SET PASSWORD FOR 'fabric'@' mysqlfabric.localdomain' = PASSWORD('fabric');

Query OK, 0 rows affected (0.00 sec)

 

[root@mysqlfabric mysql_3003]# mysql -uroot-P3002 -p -h mysqlfabric.localdomain

 

mysql> GRANT ALL ON *.* TO 'fabric'@' mysqlfabric.localdomain';

Query OK, 0 rows affected (0.00 sec)

 

mysql> SET PASSWORD FOR 'fabric'@' mysqlfabric.localdomain' = PASSWORD('fabric');

Query OK, 0 rows affected (0.00 sec)

[root@mysqlfabric mysql_3003]# mysql -uroot-P3003 -p -h mysqlfabric.localdomain

 

mysql> GRANT ALL ON *.* TO 'fabric'@' mysqlfabric.localdomain';

Query OK, 0 rows affected (0.00 sec)

 

mysql> SET PASSWORD FOR 'fabric'@' mysqlfabric.localdomain' = PASSWORD('fabric');

Query OK, 0 rows affected (0.00 sec)

 

l  配置文件

打开配置文件/etc/mysql/fabric.cfg

[root@mysqlfabric soft]# vi/etc/mysql/fabric.cfg

修改[storage]部分信息:

[storage]

auth_plugin = mysql_native_password

database = fabric

user = fabric

address = mysqlfabric.localdomain:3306

connection_delay = 1

connection_timeout = 6

password =fabric

connection_attempts = 6

 

[sharding]

mysqldump_program =/opt/mysql/bin/mysqldump

mysqlclient_program =/opt/mysql/bin/mysql

 

 

4.        填充MySQL Fabric后台存储数据(创建库和表)

[root@mysqlfabric mysql]# mysqlfabric manage setup--param=storage.user=fabric --param=storage.password=fabric

[INFO] 1404205520.480905 - MainThread -Initializing persister: user (fabric), server (mysqlfabric.localdomain:3306),database (fabric).

Finishing initial setup

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

Password for admin user is not yet set.

Password for admin/xmlrpc:

Repeat Password: admin

Password set.admin

 

 

 

5.        启动MySQL Fabric节点

[root@mysqlfabric ~]# mysqlfabric managestart

如果想在后台运行,可以加上—daemonize选项

 

停止方式:

[root@mysqlfabric ~]# mysqlfabric managestop

 

6.        配置MySQL Fabric用于主从复制

l  创建组

[root@mysqlfabric ~]# mysqlfabric groupcreate my_group

Password for admin:

Procedure :

{ uuid        = d7d4581c-a819-47c2-ad31-37c5390e93bd,

 finished    = True,

 success     = True,

 return      = True,

 activities  =

}

 

l  把MySQL服务添加到组

错误信息:

[root@mysqlfabric ~]# mysqlfabric group addmy_group mysqlfabric.localdomain:3001

Procedure :

{ uuid        = 5c373b82-d369-413d-a2e0-5b4c60d506c0,

 finished    = True,

 success     = False,

 return      = ServerError: Server (be642e20-00d3-11e4-8d96-0050568f7be4)does not have the binary log or gtid enabled.,

 activities  =

}

 

正确信息:

[root@mysqlfabric mysql_3003]#  mysqlfabricgroup add my_group mysqlfabric.localdomain:3001

Procedure :

{ uuid        = baafd4d2-dba8-4863-9a76-74a3e6153065,

 finished    = True,

 success     = True,

 return      = True,

 activities  =

}

 

[root@mysqlfabric mysql_3003]# mysqlfabric group add my_groupmysqlfabric.localdomain:3002

Procedure :

{ uuid        = 2f336426-b12d-4bd2-ab71-0b6c9d513466,

 finished    = True,

 success     = True,

 return      = True,

 activities  =

}

 

[root@mysqlfabric mysql_3003]# mysqlfabric group add my_groupmysqlfabric.localdomain:3003

Procedure :

{ uuid        = 844eba0a-a7bc-4e67-8359-3ab53d0520c7,

  finished    = True,

 success     = True,

 return      = True,

 activities  =

}

l  把组内一个MySQL服务提升为一个master:

添加MySQL服务到组后,Fabric不会意识到任何主从复制的架构,必须提升组内任何一个MySQL服务为主master,其它服务设置为slave。提升命令如下:

[root@mysqlfabric ~]# mysqlfabric grouppromote my_group

 

当组内有一个主master时,新添加到组内的新MySQL服务将自动成为slave

也可以使用同样的命令使组内的master降级为slave,另选一个slavemaster

 

l  查看my_group组Mysql服务的信息:

[root@mysqlfabric ~]# mysqlfabric grouplookup_servers my_group

Command :

{ success     = True

 return      = [{'status':'SECONDARY', 'server_uuid': 'be642e20-00d3-11e4-8d96-0050568f7be4', 'mode':'READ_ONLY', 'weight': 1.0, 'address': 'mysqlfabric.localdomain:3001'},{'status': 'SECONDARY', 'server_uuid': 'c696a608-00d5-11e4-8da3-0050568f7be4','mode': 'READ_ONLY', 'weight': 1.0, 'address': 'mysqlfabric.localdomain:3002'},{'status': 'PRIMARY', 'server_uuid': '1230c8cb-00d7-11e4-8dac-0050568f7be4','mode': 'READ_WRITE', 'weight': 1.0, 'address':'mysqlfabric.localdomain:3003'}]

 activities  =

}

 

l  查看my_group组MySQL服务健康状态信息:

[root@mysqlfabric ~]# mysqlfabric grouphealth my_group

Command :

{ success     = True

 return      ={'1230c8cb-00d7-11e4-8dac-0050568f7be4': {'status': 'PRIMARY', 'is_alive':True, 'threads': {}}, 'be642e20-00d3-11e4-8d96-0050568f7be4': {'status':'SECONDARY', 'is_alive': True, 'threads': {}},'c696a608-00d5-11e4-8da3-0050568f7be4': {'status': 'SECONDARY', 'is_alive':True, 'threads': {}}}

 activities  =

}

 

l  自动检测组内MySQL服务故障:

如果想在primary失败时,secondary能自动提升为primary,执行下面步骤:

[root@mysqlfabric ~]# mysqlfabric group activate my_group

Procedure :

{ uuid        = 4ee1bd23-0fab-46f0-a336-9e4731117370,

 finished    = True,

 success     = True,

 return      = True,

 activities  =

}

 

【备注】如果不想让fabric自动检测故障,可以取消自动监控功能:

[root@mysqlfabric ~]# mysqlfabric group deactivate my_group


7.        故障测试

[root@mysqlfabric ~]# service mysql.3003 stop

 

[root@mysqlfabric ~]# mysqlfabric group lookup_servers my_group

Command :

{ success     = True

 return      = [{'status':'SECONDARY', 'server_uuid': 'be642e20-00d3-11e4-8d96-0050568f7be4', 'mode':'READ_ONLY', 'weight': 1.0, 'address': 'mysqlfabric.localdomain:3001'}, {'status': 'PRIMARY', 'server_uuid':'c696a608-00d5-11e4-8da3-0050568f7be4', 'mode': 'READ_WRITE', 'weight': 1.0,'address': 'mysqlfabric.localdomain:3002'}, {'status': 'FAULTY','server_uuid': '1230c8cb-00d7-11e4-8dac-0050568f7be4', 'mode': 'READ_WRITE','weight': 1.0, 'address': 'mysqlfabric.localdomain:3003'}]

 activities  =

}

 

说明已经把3002提升为primary

 

8.        Mysqlfabric相关命令:

l  把一个MySQL服务移出组:

mysqlfabric group remove my_groupserver_uuid

如:

[root@mysqlfabric ~]#mysqlfabric groupremove my_group 1230c8cb-00d7-11e4-8dac-0050568f7be4

 

master不能被移出组,必须disablemaster后才可以移出:

mysqlfabric group demote my_group

 

l  删除组(组内已经没有MySQL服务)

mysqlfabric group destroy my_group

 

l  强制删除组(组内有MySQL服务)

mysqlfabric group destroy my_group --force



奋斗的路非常幸苦,部署到此介绍,再接再厉。。。。

 

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值