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

改動對應的port號:

[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.    改動數據庫rootpassword

[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  創建用戶

登錄port號為3306的mysql 服務【作為Fabric后台數據存儲】

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

【注】上面登錄時須要加主機名。由於一台server安裝了多個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



奮斗的路很幸苦。部署到此介紹,再接再厲。

。。

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM