二箕宙、MySQL部署

圖片來(lái)自網(wǎng)絡(luò)

文/Bruce.Liu1

1.安裝簡(jiǎn)介

MySQL安裝在網(wǎng)上的帖子再多不過(guò)了,但是真正能將網(wǎng)上的文章無(wú)縫的使用在生產(chǎn)環(huán)境中的寥寥無(wú)幾逾苫,并且網(wǎng)上的文章一般都是局限于都一個(gè)知識(shí)點(diǎn)卿城,并沒(méi)有一個(gè)系統(tǒng)整體性的文章,本文即系統(tǒng)的講解MySQL各種方式安裝規(guī)劃及步驟铅搓;首先我們先了解一下MySQL常見(jiàn)的安裝方式:

  • 源碼編譯安裝方式

與二進(jìn)制發(fā)行版本相比瑟押,如果我們選擇了通過(guò)源代碼進(jìn)行安裝,那么在安裝過(guò)程中我們能夠?qū)ySQL所做的調(diào)整將會(huì)更多更靈活一些星掰。

優(yōu)點(diǎn):

  1. 針對(duì)自己的硬件平臺(tái)選用合適的編譯器來(lái)優(yōu)化編譯后的二進(jìn)制代碼多望;
  2. 根據(jù)不同的軟件平臺(tái)環(huán)境調(diào)整相關(guān)的編譯參數(shù);
  3. 針對(duì)我們特定應(yīng)用場(chǎng)景選擇性地對(duì)組件進(jìn)行裁剪氢烘;
  4. 根據(jù)我們的所需要存儲(chǔ)的數(shù)據(jù)內(nèi)容選擇只安裝我們需要的字符集怀偷;
  5. 等等其他一些可以根據(jù)特定應(yīng)用場(chǎng)景所作的各種調(diào)整。

缺點(diǎn):

  1. 對(duì)編譯參數(shù)的不夠了解造成編譯參數(shù)使用不當(dāng)可能使編譯出來(lái)的二進(jìn)制代碼不夠穩(wěn)定播玖;
  2. 對(duì)自己的應(yīng)用環(huán)境把握失誤而使用的優(yōu)化參數(shù)可能反而使系統(tǒng)性能更差椎工;
  3. 還有一個(gè)并不能稱之為隱患的小問(wèn)題就是源碼編譯安裝將使安裝部署過(guò)程更為復(fù)雜,所花費(fèi)的時(shí)間更長(zhǎng)蜀踏;

建議:如果沒(méi)有對(duì)編譯器维蒙、glibc、系統(tǒng)API有足夠的了解果覆,不建議大家使用源碼編譯安裝颅痊。因?yàn)榫幾g安裝、編譯器局待、編譯參數(shù)優(yōu)化斑响、兼容性等工作是MySQL開(kāi)發(fā)部門(mén)的一個(gè)Team完成的。據(jù)傳言通過(guò)源碼編譯安裝能夠大部分提升性能的話題钳榨,我就不加以評(píng)論了恋捆。

  • 通用二進(jìn)制安裝方式

二進(jìn)制安裝方式,是剛才我們提到的重绷,MySQL開(kāi)發(fā)團(tuán)隊(duì)將源代碼進(jìn)行編譯安裝后的一個(gè)發(fā)行格式,這種發(fā)行格式中又分為兩種:

  • Linux二進(jìn)制通用版本:

由于Linux的分支過(guò)多膜毁,每個(gè)Linux軟件包的管理方式也各有不同:常見(jiàn)的RHEL昭卓、CentOS是RPM包管理方式、Ubuntu是DEB的管理方式瘟滨,有的同學(xué)就會(huì)問(wèn)了候醒,那SUSE Linux也是RPM包管理方式,和RHEL是否通用呢杂瘸? 答案是:肯定不可以倒淫,因?yàn)榧词故荝PM包后綴名一致,但這些開(kāi)源軟件在不同的linux中的軟件本身版本败玉、編譯環(huán)境以及編譯參數(shù)都各有不同敌土。MySQL想要在這么多不同的Linux版本中做一個(gè)通用的二進(jìn)制格式镜硕,即解壓就能用的就是Linux二進(jìn)制通用版本;類(lèi)似于windows上的綠色免安裝的軟件返干。

  • Linux\Unix發(fā)行商訂制版本:

以上二進(jìn)制通過(guò)版本雖然好兴枯,但卻做不到向源代碼方式一樣萬(wàn)能,因?yàn)槎M(jìn)制版本所在的編譯環(huán)境是適合于大部分平臺(tái)矩欠,但總有不兼容的平臺(tái)财剖,因此MySQL還為不同平臺(tái)定制化了專(zhuān)屬自己格式的軟件,常見(jiàn)的版本如:

圖片來(lái)自原創(chuàng)
  1. Red Hat Enterprise Linux / Oracle Linux /CentOS Linux
  2. Ubuntu Linux
  3. Debian Linux
  4. SUSE Linux
  5. FreeBSD 10.0
  6. Windows

2. MySQL安裝

2.1.源碼編譯安裝(5.6)

2.1.1.軟件參考文檔

參考文檔:https://dev.mysql.com/doc/refman/5.7/en/source-installation.html
編譯參數(shù):https://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

軟件下載:
https://downloads.mysql.com/archives/get/file/mysql-5.6.12.tar.gz
http://www.cmake.org/files/v2.8/cmake-2.8.11.1.tar.gz
http://ftp.gnu.org/gnu/bison/bison-2.7.tar.gz
http://ftp.gnu.org/gnu/m4/m4-1.4.16.tar.gz

2.1.2.系統(tǒng)環(huán)境介紹
  • 系統(tǒng)版本
    CentOS release 6.5 (Final) x86_64

  • MySQL版本
    mysql-5.6.12.-x86_64(源代碼包)

2.1.3.安裝系統(tǒng)要求
2.1.3.1.系統(tǒng)基本庫(kù)
  • ncurses-devel
    用于終端操作的開(kāi)發(fā)包癌淮。

  • zlib
    MySQL使用zlib進(jìn)行壓縮

  • libxml
    用于XML輸入輸出方式的支持躺坟。

  • openssl
    使用openssl安全套接字方式通信。

  • dtrace
    用于診斷MySQL問(wèn)題乳蓄。

2.1.3.2.必要的編譯環(huán)境
  • gcc/g++
    MySQL 5.6開(kāi)始咪橙,需要使用g++進(jìn)行編譯。

  • cmake
    MySQL 5.5開(kāi)始栓袖,使用cmake進(jìn)行工程管理匣摘,cmake需要2.8以上版本。

  • bison
    MySQL語(yǔ)法解析器需要使用bison進(jìn)行編譯裹刮。

  • m4
    或預(yù)處理器一般用作文本替換工具音榜。

2.1.4.安裝基礎(chǔ)環(huán)境
  • 檢查基礎(chǔ)包
# rpm -qa | grep gcc-c++
# rpm -qa | grep gcc
# rpm -qa | grep zlib
# rpm -qa | grep ncurses-devel
# rpm -qa | grep libxml 
# rpm -qa | grep openssl
  • 安裝cmake編譯器
# cd /usr/local/src
# tar -xvf cmake-2.8.11.1.tar.gz
# cd cmake-2.8.11.1
# ./bootstrap
# make && make install
  • 安裝m4
# cd /usr/local/src
# tar -xvf m4-1.4.16.tar.gz
# cd m4-1.4.16
# ./configure && make && make install
  • 安裝bison
# cd /usr/local/src
# tar -xvf bison-2.7.tar.gz
# cd bison-2.7
# ./configure && make && make install
2.1.5.編譯安裝MySQL
2.1.5.1.創(chuàng)建用戶及目錄
# /usr/sbin/groupadd mysql
# /usr/sbin/useradd -g mysql mysql
# mkdir /usr/local/mysql
# chown -R mysql:mysql /usr/local/mysql
# mkdir /var/run/mysqld
# chown -R mysql:mysql /var/run/mysqld
2.1.5.2.編譯MySQL
# cd /usr/local/src
# tar -xvf mysql-5.6.12.tar.gz 
# export C_FLAGS="-fPIC -Wall -Wextra -Wformat-security -Wwrite-strings -Wdeclaration-after-statement -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF -DMY_PTHREAD_FASTMUTEX=1 -I/export/home/pb2/build/sb_0-14808650-1427302228.24/release/include -I/export/home/pb2/build/sb_0-14808650-1427302228.24/mysql-5.6.24/include -I/export/home/pb2/build/sb_0-14808650-1427302228.24/mysql-5.6.24/sql -I/export/home/pb2/build/sb_0-14808650-1427302228.24/mysql-5.6.24/regex -I/export/home/pb2/build/sb_0-14808650-1427302228.24/mysql-5.6.24/zlib -I/export/home/pb2/build/sb_0-14808650-1427302228.24/mysql-5.6.24/extra/yassl/include -I/export/home/pb2/build/sb_0-14808650-1427302228.24/mysql-5.6.24/extra/yassl/taocrypt/include -I/export/home/pb2/build/sb_0-14808650-1427302228.24/release/sql    -DHAVE_YASSL -DYASSL_PREFIX -DHAVE_OPENSSL -DMULTI_THREADED"
# export C_DEFINES="-DHAVE_CONFIG_H -DMYSQL_SERVER -DHAVE_EVENT_SCHEDULER"
# export CXX_FLAGS="-fPIC -Wall -Wextra -Wformat-security -Woverloaded-virtual -Wno-unused-parameter -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF -DMY_PTHREAD_FASTMUTEX=1 -I/export/home/pb2/build/sb_0-14808650-1427302228.24/release/include -I/export/home/pb2/build/sb_0-14808650-1427302228.24/mysql-5.6.24/include -I/export/home/pb2/build/sb_0-14808650-1427302228.24/mysql-5.6.24/sql -I/export/home/pb2/build/sb_0-14808650-1427302228.24/mysql-5.6.24/regex -I/export/home/pb2/build/sb_0-14808650-1427302228.24/mysql-5.6.24/zlib -I/export/home/pb2/build/sb_0-14808650-1427302228.24/mysql-5.6.24/extra/yassl/include -I/export/home/pb2/build/sb_0-14808650-1427302228.24/mysql-5.6.24/extra/yassl/taocrypt/include -I/export/home/pb2/build/sb_0-14808650-1427302228.24/release/sql    -DHAVE_YASSL -DYASSL_PREFIX -DHAVE_OPENSSL -DMULTI_THREADED"
# export CXX_DEFINES="-DHAVE_CONFIG_H -DMYSQL_SERVER -DHAVE_EVENT_SCHEDULER"
# cd mysql-5.6.12
# cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_EXTRA_CHARSETS=utf8,gbk \
> -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
> -DWITH_FEDERATED_STORAGE_ENGINE=1 \
> -DWITH_PARTITION_STORAGE_ENGINE=1\
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
> -DMYSQL_DATADIR=/usr/local/mysql/data \
> -DWITH_SSL=bundled \
> -DENABLED_LOCAL_INFILE=1 \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DENABLE_DOWNLOADS=1 
# make && make install
2.1.6.初始化MySQL實(shí)例

準(zhǔn)備一個(gè)默認(rèn)的my.cnf配置文件

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
user=mysql
# port=13306
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

初始化MySQL實(shí)例(注意初始化是否成功)

# cd /usr/local/mysql/
# ./scripts/mysql_install_db --defaults-file=/etc/my.cnf

......
2017-08-03 16:02:46 29894 [Note] InnoDB: 5.6.12 started; log sequence number 0
2017-08-03 16:02:46 29894 [Note] Binlog end
2017-08-03 16:02:46 29894 [Note] InnoDB: FTS optimize thread exiting.
2017-08-03 16:02:46 29894 [Note] InnoDB: Starting shutdown...
2017-08-03 16:02:48 29894 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2017-08-03 16:02:48 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-08-03 16:02:48 29917 [Note] InnoDB: The InnoDB memory heap is disabled
2017-08-03 16:02:48 29917 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-08-03 16:02:48 29917 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-08-03 16:02:48 29917 [Note] InnoDB: Using CPU crc32 instructions
2017-08-03 16:02:48 29917 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-08-03 16:02:48 29917 [Note] InnoDB: Completed initialization of buffer pool
2017-08-03 16:02:48 29917 [Note] InnoDB: Highest supported file format is Barracuda.
2017-08-03 16:02:48 29917 [Note] InnoDB: 128 rollback segment(s) are active.
2017-08-03 16:02:48 29917 [Note] InnoDB: Waiting for purge to start
2017-08-03 16:02:48 29917 [Note] InnoDB: 5.6.12 started; log sequence number 1625977
2017-08-03 16:02:48 29917 [Note] Binlog end
2017-08-03 16:02:48 29917 [Note] InnoDB: FTS optimize thread exiting.
2017-08-03 16:02:48 29917 [Note] InnoDB: Starting shutdown...
2017-08-03 16:02:49 29917 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
......
2.1.7.啟動(dòng)數(shù)據(jù)庫(kù)
# /usr/local/mysql/bin/mysqld_safe &
# mysql -S /var/lib/mysql/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.12 Source distribution

Copyright (c) 2009-2016 Percona LLC and/or its affiliates
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>

關(guān)閉數(shù)據(jù)庫(kù)

# mysqladmin  -S /var/lib/mysql/mysql.sock shutdown
  • 添加$PATH環(huán)境變量
# vi /etc/profile

......    ......
export PATH=$PATH:/usr/local/mysql/bin

2.2.通用二進(jìn)制安裝(5.7)

2.2.1.軟件參考文檔

參考文檔:https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
軟件下載:https://downloads.mysql.com/archives/get/file/mysql-5.7.17-linux-glibc2.5-x86_64.tar

圖片來(lái)自網(wǎng)絡(luò)
2.2.2.系統(tǒng)環(huán)境介紹
  • 系統(tǒng)版本
    CentOS release 6.5 (Final) x86_64

  • MySQL版本
    mysql-5.7.17-linux-glibc2.5-x86_64(Linux - Generic)

2.2.3.安裝系統(tǒng)要求

MySQL依賴異步IO

# rpm -qa | grep libaio
2.2.4.安裝MySQL
2.2.4.1.創(chuàng)建用戶目錄
# groupadd mysql
# useradd -r -g mysql -s /bin/false mysql
2.2.4.2.創(chuàng)建軟連接
# cd /opt
# tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
# cd /usr/local/
# ln -s /opt/mysql-5.7.17-linux-glibc2.5-x86_64 mysql
2.2.4.3.創(chuàng)建目錄授權(quán)
# cd mysql
# mkdir mysql-files
# chmod 750 mysql-files
# chown -R mysql .
# chgrp -R mysql .
2.2.4.4.初始化數(shù)據(jù)庫(kù)

準(zhǔn)備一個(gè)my.cnf配置文件

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
user=mysql
# port=13306
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

包含MySQL 5.7.5之前使用該命令初始化數(shù)據(jù)庫(kù):bin/mysql_install_db --user=mysql
5.7.6以后初始化被集成到mysqld命令中bin/mysqld --initialize --user=mysql

# bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
2017-08-03T08:56:23.581602Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-08-03T08:56:23.885630Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-08-03T08:56:23.940039Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-08-03T08:56:23.998870Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a0827f27-7829-11e7-ba31-549f350fdab8.
2017-08-03T08:56:23.999501Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-08-03T08:56:24.000670Z 1 [Note] A temporary password is generated for root@localhost: hk)V!i*t(2AN
# bin/mysql_ssl_rsa_setup 
Generating a 2048 bit RSA private key
................................................................+++
.......................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
...............................+++
..+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
..................................................................+++
.........+++
writing new private key to 'client-key.pem'
-----
2.1.4.5.啟動(dòng)MySQL
# bin/mysqld_safe &
  • 可選(將MySQL服務(wù)腳本放到/etc/init.d下.)
# cp -p support-files/mysql.server  /etc/init.d/mysql

3.多實(shí)例部署

隨著硬件層面的發(fā)展,linux系統(tǒng)多核已經(jīng)是普通趨勢(shì)捧弃,而mysql是單進(jìn)程多線程赠叼,所以先天上對(duì)多進(jìn)程的利用不是很高,雖然5.6版本已經(jīng)在這方面改進(jìn)很多违霞,但是也沒(méi)有達(dá)到100%嘴办,所以為了充分的利用系統(tǒng)資源,mysql有自己的補(bǔ)充买鸽,那就是可以部署多實(shí)例涧郊,一個(gè)實(shí)例一個(gè)端口。

  • MySQL多實(shí)例也有兩種方式:
  1. 基于mysqld_safe程序分散管理
  2. 基于mysqld_multi程序統(tǒng)一管理

3.1.mysqld_multi多實(shí)例方式

多實(shí)例安裝方式和單機(jī)稍微有些調(diào)整眼五,為避免環(huán)境造成混亂妆艘,我們從頭開(kāi)始部署。并且我們要實(shí)現(xiàn)用mysqld_multi程序同時(shí)管理5.6看幼、5.7數(shù)據(jù)庫(kù)批旺。

3.1.1.軟件參考文檔

5.6參考文檔:https://dev.mysql.com/doc/refman/5.6/en/binary-installation.html
5.7參考文檔:https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html

軟件下載:
https://downloads.mysql.com/archives/get/file/mysql-5.6.24-linux-glibc2.5-x86_64.tar.gz
https://downloads.mysql.com/archives/get/file/mysql-5.7.9-linux-glibc2.5-x86_64.tar

3.1.2.系統(tǒng)環(huán)境介紹
  • 系統(tǒng)版本
    CentOS release 6.5 (Final) x86_64

  • MySQL版本
    mysql-5.6.24.-x86_64(二進(jìn)制通用版)
    mysql-5.7.9.-x86_64(二進(jìn)制通用版)

3.1.3.創(chuàng)建用戶目錄
# groupadd mysql
# useradd -r -g mysql -s /bin/false mysql
3.1.4.創(chuàng)建軟連接
  • 5.6
# tar -zxvf mysql-5.6.24-linux-glibc2.5-x86_64.tar.gz
# ln -s /opt/mysql-5.6.24-linux-glibc2.5-x86_64 /usr/local/mysql5.6
  • 5.7
# tar -zxvf mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz
# ln -s /opt/mysql-5.7.9-linux-glibc2.5-x86_64 /usr/local/mysql
3.1.5.創(chuàng)建目錄授權(quán)
  • 5.6
# chown -R mysql:mysql /usr/local/mysql5.6
# chown -R mysql:mysql /usr/local/mysql5.6/
  • 5.7
# cd /usr/local/mysql
# mkdir mysql-files
# chmod 750 mysql-files
# chown -R mysql .
# chgrp -R mysql .
3.1.6.初始化數(shù)據(jù)庫(kù)
3.1.6.1.準(zhǔn)備/etc/my.cnf
  • mysql5.6標(biāo)簽用于抒寫(xiě)5.6和5.7不兼容的參數(shù)
[mysqld]
# GENERAL #
user                           = mysql
port                           =3306
default_storage_engine         = InnoDB
socket                         = /data1/db3306/my3306.sock
pid_file                       = /data1/db3306/mysql.pid
#read-only =0
tmpdir                  = /data1/tmp
#key_buffer_size                = 128M
max_allowed_packet             = 32M
max_connect_errors             = 1000000
datadir          = /data1/db3306/
log_bin = 133063306-bin
relay-log=  133063306-relay-bin
expire_logs_days               = 7
#sync_binlog                    = 0
tmp_table_size                 = 32M
max_heap_table_size            = 32M
max_connections                = 5000
thread_cache_size              = 512
table_definition_cache         = 4096
table_open_cache               = 4096
wait_timeout            = 28800
interactive_timeout     = 28800
transaction-isolation = READ-COMMITTED
binlog-format=row
character-set-server=utf8
skip-name-resolve
back_log=1024
explicit_defaults_for_timestamp=true
server_id=133063306

# INNODB #
innodb_flush_method            = O_DIRECT
#innodb_data_home_dir = /data1/db3306
innodb_data_file_path = ibdata1:100M:autoextend
#redo log
#innodb_log_group_home_dir=./
innodb_log_files_in_group      = 3
innodb_log_file_size           = 128M
#innodb performance
innodb_flush_log_at_trx_commit = 0
innodb_file_per_table          = 1
innodb_buffer_pool_instances   = 8
innodb_io_capacity             = 2000
innodb_lock_wait_timeout       = 30
binlog_error_action = ABORT_SERVER
innodb_buffer_pool_size        = 128M
innodb_max_dirty_pages_pct=90
innodb_file_format=Barracuda
innodb_support_xa=0
innodb_buffer_pool_dump_at_shutdown = 1
innodb_buffer_pool_load_at_startup = 1

log_error                      = error.log
#log_queries_not_using_indexes = 1
slow_query_log                 = 1
slow_query_log_file            = slow-queries.log
long_query_time=2
gtid_mode=ON
enforce-gtid-consistency
log-slave-updates
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync_master_info = 10000
slave_sql_verify_checksum=1
skip-slave-start
init-connect='SET NAMES utf8'
character-set-server=utf8
skip-character-set-client-handshake
bind-address=0.0.0.0
skip-external-locking
slave-parallel-workers=6

[mysql5.6]
myisam_recover                 = FORCE,BACKUP
3.1.6.2.創(chuàng)建數(shù)據(jù)目錄
# mkdir /data1/db3306
# mkdir /data1/tmp
# chown -R mysql:mysql /data1/*
3.1.6.3.初始化5.7數(shù)據(jù)庫(kù)
# bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
# bin/mysql_ssl_rsa_setup 
Generating a 2048 bit RSA private key
.......+++
....+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
........+++
...................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
..+++
............+++
writing new private key to 'client-key.pem'
-----
3.1.6.5.配置環(huán)境變量
# vim /etc/profile

export PATH=/usr/local/mysql/bin:$PATH
3.1.6.6.啟動(dòng)數(shù)據(jù)庫(kù)
# cp support-files/mysql.server  /etc/init.d/mysql
# service mysql start
Starting MySQL...                                          [  OK  ]
3.1.7.配置5.7版本多實(shí)例
3.1.7.1.添加/etc/my.cnf參數(shù)
  • mysqld_multi標(biāo)簽用于mysqld_multi程序啟動(dòng)時(shí)初始化的參數(shù)
    默認(rèn)不加mysqld參數(shù),那么mysqld_mulit程序不會(huì)使用mysqld_safe啟動(dòng)數(shù)據(jù)庫(kù)
  • mysql3307屬于mysqld_mulit程序子標(biāo)簽,一般用于配置多實(shí)例在配置文件中不同的參數(shù)
    如:端口、數(shù)據(jù)文件目錄等
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
log = /var/log/mysqld_multi.log

[mysqld3307]
port = 3307
datadir = /data1/db3307/
socket = /data1/db3307/my3307.sock
pid_file = /data1/db3307/mysql.pid
3.1.7.2.創(chuàng)建目錄
# mkdir /data1/db3307
# chown -R mysql:mysql /data1/db3307/
3.1.7.3.初始化數(shù)據(jù)庫(kù)
# bin/mysqld --initialize --user=mysql --datadir=/data1/db3307
3.1.7.4.啟動(dòng)多實(shí)例
# mysqld_multi  report
Reporting MySQL servers
MySQL server from group: mysqld3307 is not running
# mysqld_multi start 3307
# mysqld_multi  report
Reporting MySQL servers
MySQL server from group: mysqld3307 is running
3.1.8.配置5.6版本多實(shí)例
3.1.8.1.添加/etc/my.cnf參數(shù)

注意:現(xiàn)在是不同版本诵姜,所以要加上參數(shù)basedir汽煮,讓5.7mysqld_multi程序去以5.6的軟件去加載5.6的數(shù)據(jù)庫(kù)

[mysqld3308]
port = 3308
basedir = /usr/local/mysql5.6/
datadir = /data1/db3308/
socket = /data1/db3308/my3308.sock
pid_file = /data1/db3308/mysql.pid
3.1.8.2.創(chuàng)建目錄
# mkdir /data1/db3308
# chown -R mysql:mysql /data1/db3308
3.1.8.3.初始化數(shù)據(jù)庫(kù)
# cd /usr/local/mysql5.6/
# ./scripts/mysql_install_db --user=mysql --datadir=/data1/db3308
3.1.8.4.啟動(dòng)多實(shí)例
# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3307 is running
MySQL server from group: mysqld3308 is not running
# mysqld_multi start 3308
# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3307 is running
MySQL server from group: mysqld3308 is running

# ps -ef | grep mysql | grep 3308
root       9023      1  0 23:57 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --port=3308 --basedir=/usr/local/mysql5.6/ --datadir=/data1/db3308/ --socket=/data1/db3308/my3308.sock --pid_file=/data1/db3308/mysql.pid
mysql      9924   9023  5 23:57 pts/1    00:00:04 /usr/local/mysql5.6/bin/mysqld --basedir=/usr/local/mysql5.6/ --datadir=/data1/db3308/ --plugin-dir=/usr/local/mysql5.6//lib/plugin --user=mysql --log-error=/data1/db3308//error.log --pid-file=/data1/db3308/mysql.pid --socket=/data1/db3308/my3308.sock --port=3308
3.1.9.mysqld_multi常用命令
3.1.9.1.查看多實(shí)例狀態(tài)
# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3307 is running
MySQL server from group: mysqld3308 is running
3.1.9.2.關(guān)閉mysql實(shí)例
  • mysqld_multi程序也是調(diào)用mysqladmin去關(guān)閉數(shù)據(jù)庫(kù),由于5.7有密碼,所以我們要將mysqld_multi所管理的所有數(shù)據(jù)庫(kù)改成統(tǒng)一密碼

  • 修改多實(shí)例密碼
    5.7改密碼

# cat /data1/db3307/error.log | grep temp
2017-08-07T15:40:48.714494Z 1 [Note] A temporary password is generated for root@localhost: 82u_G(K?M933

# mysql -S /data1/db3307/my3307.sock -p"82u_G(K?M933"
mysql> set password='123';

5.6改密碼

# mysql -S /data1/db3308/my3308.sock -e "set password=password('123')"
  • 將用戶名/密碼信息配置到mysqld_multi標(biāo)簽中
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
log = /var/log/mysqld_multi.log
user=root
pass=123
  • 驗(yàn)證
# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3307 is running
MySQL server from group: mysqld3308 is running
# mysqld_multi stop
# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3307 is not running
MySQL server from group: mysqld3308 is not running

補(bǔ)充:
由于是mysqld_multi程序管理不同版本的多實(shí)例暇赤,最好還是將每個(gè)多實(shí)例的basedir指定一下心例。

附錄my.cnf

[mysqld]
# GENERAL #
user                           = mysql
port                           =3306
default_storage_engine         = InnoDB
socket                         = /data1/db3306/my3306.sock
pid_file                       = /data1/db3306/mysql.pid
#read-only =0
tmpdir                  = /data1/tmp
#key_buffer_size                = 128M
max_allowed_packet             = 32M
max_connect_errors             = 1000000
datadir          = /data1/db3306/
log_bin = 133063306-bin
relay-log=  133063306-relay-bin
expire_logs_days               = 7
#sync_binlog                    = 0
tmp_table_size                 = 32M
max_heap_table_size            = 32M
max_connections                = 5000
thread_cache_size              = 512
table_definition_cache         = 4096
table_open_cache               = 4096
wait_timeout            = 28800
interactive_timeout     = 28800
transaction-isolation = READ-COMMITTED
binlog-format=row
character-set-server=utf8
skip-name-resolve
back_log=1024
explicit_defaults_for_timestamp=true
server_id=133063306

# INNODB #
innodb_flush_method            = O_DIRECT
#innodb_data_home_dir = /data1/db3306
innodb_data_file_path = ibdata1:100M:autoextend
#redo log
#innodb_log_group_home_dir=./
innodb_log_files_in_group      = 3
innodb_log_file_size           = 128M
#innodb performance
innodb_flush_log_at_trx_commit = 0
innodb_file_per_table          = 1
innodb_buffer_pool_instances   = 8
innodb_io_capacity             = 2000
innodb_lock_wait_timeout       = 30
binlog_error_action = ABORT_SERVER
innodb_buffer_pool_size        = 128M
innodb_max_dirty_pages_pct=90
innodb_file_format=Barracuda
innodb_support_xa=0
innodb_buffer_pool_dump_at_shutdown = 1
innodb_buffer_pool_load_at_startup = 1

log_error                      = error.log
#log_queries_not_using_indexes = 1
slow_query_log                 = 1
slow_query_log_file            = slow-queries.log
long_query_time=2
gtid_mode=ON
enforce-gtid-consistency
log-slave-updates
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync_master_info = 10000
slave_sql_verify_checksum=1
skip-slave-start
init-connect='SET NAMES utf8'
character-set-server=utf8
skip-character-set-client-handshake
bind-address=0.0.0.0
skip-external-locking
slave-parallel-workers=6


[mysql5.6]
myisam_recover                 = FORCE,BACKUP

[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
log = /var/log/mysqld_multi.log
user=root
pass=123

[mysqld3307]
port = 3307
basedir=/usr/local/mysql/
datadir = /data1/db3307/
socket = /data1/db3307/my3307.sock
pid_file = /data1/db3307/mysql.pid

[mysqld3308]
port = 3308
basedir = /usr/local/mysql5.6/
datadir = /data1/db3308/
socket = /data1/db3308/my3308.sock
pid_file = /data1/db3308/mysql.pid

4.Docker部署

依賴系統(tǒng)基礎(chǔ)庫(kù)

bridge-utils
libcgroup
rsync

阿里的yum下載docker

rpm -Uvh http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum -y install docker-io

找到dockermysql鏡像

docker run hello-world
docker search mysql
docker search mysql:5.6
docker pull mysql:5.6

安裝

docker run --name db001 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6
docker ps

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市翎卓,隨后出現(xiàn)的幾起案子契邀,更是在濱河造成了極大的恐慌,老刑警劉巖失暴,帶你破解...
    沈念sama閱讀 206,839評(píng)論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件坯门,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡逗扒,警方通過(guò)查閱死者的電腦和手機(jī)古戴,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,543評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)矩肩,“玉大人现恼,你說(shuō)我怎么就攤上這事∈蜷荩” “怎么了叉袍?”我有些...
    開(kāi)封第一講書(shū)人閱讀 153,116評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)刽酱。 經(jīng)常有香客問(wèn)我喳逛,道長(zhǎng),這世上最難降的妖魔是什么棵里? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 55,371評(píng)論 1 279
  • 正文 為了忘掉前任润文,我火速辦了婚禮,結(jié)果婚禮上殿怜,老公的妹妹穿的比我還像新娘典蝌。我一直安慰自己,他們只是感情好头谜,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,384評(píng)論 5 374
  • 文/花漫 我一把揭開(kāi)白布骏掀。 她就那樣靜靜地躺著,像睡著了一般柱告。 火紅的嫁衣襯著肌膚如雪砖织。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 49,111評(píng)論 1 285
  • 那天末荐,我揣著相機(jī)與錄音,去河邊找鬼新锈。 笑死甲脏,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播块请,決...
    沈念sama閱讀 38,416評(píng)論 3 400
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼娜氏,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了墩新?” 一聲冷哼從身側(cè)響起贸弥,我...
    開(kāi)封第一講書(shū)人閱讀 37,053評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎海渊,沒(méi)想到半個(gè)月后绵疲,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,558評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡臣疑,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,007評(píng)論 2 325
  • 正文 我和宋清朗相戀三年盔憨,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片讯沈。...
    茶點(diǎn)故事閱讀 38,117評(píng)論 1 334
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡郁岩,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出缺狠,到底是詐尸還是另有隱情问慎,我是刑警寧澤,帶...
    沈念sama閱讀 33,756評(píng)論 4 324
  • 正文 年R本政府宣布挤茄,位于F島的核電站如叼,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏驮樊。R本人自食惡果不足惜薇正,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,324評(píng)論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望囚衔。 院中可真熱鬧挖腰,春花似錦、人聲如沸练湿。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,315評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)肥哎。三九已至辽俗,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間篡诽,已是汗流浹背崖飘。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,539評(píng)論 1 262
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留杈女,地道東北人朱浴。 一個(gè)月前我還...
    沈念sama閱讀 45,578評(píng)論 2 355
  • 正文 我出身青樓吊圾,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親翰蠢。 傳聞我的和親對(duì)象是個(gè)殘疾皇子项乒,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,877評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容