MySQL多執行個體安裝部署

來源:互聯網
上載者:User

標籤:完成後   mys   安裝   匯入   tmp   目錄   tar zxvf   rom   pat   

  • 解壓 MySQL 5.7 二進位包到指定目錄
    [[email protected] ~]# tar zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local/

  • 建立 MySQL 軟連結
    [[email protected] ~]#mv /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql

  • 建立 MySQL 使用者
    [[email protected] ~]#groupadd -r mysql
    [[email protected] ~]# useradd -r -g mysql -s /bin/false -M mysql

  • 在 MySQL 二進位包目錄中建立 mysql-files 目錄 [MySQL 資料匯入/匯出資料專放目錄]
    [[email protected] ~]# mkdir -v /usr/local/mysql/mysql-files
    mkdir: created directory `/usr/local/mysql/mysql-files‘

  • 建立多執行個體資料目錄
    [[email protected] ~]# mkdir -vp /data/mysql_data{1..4}
    mkdir: created directory /data‘ <br/>mkdir: created directory/data/mysql_data1‘
    mkdir: created directory /data/mysql_data2‘ <br/>mkdir: created directory/data/mysql_data3‘
    mkdir: created directory `/data/mysql_data4‘

  • 修改 MySQL 二進位包目錄的所屬使用者與所屬組
    1 [[email protected] ~]# chown root.mysql -R /usr/local/mysql

  • 修改 MySQL 多執行個體資料目錄與 資料匯入/匯出專放目錄的所屬使用者與所屬組
    [[email protected] ~]# chown mysql.mysql -R /usr/local/mysql/mysql-files /data/mysql_data{1..4}

  • 配置 MySQL 設定檔 /etc/my.cnf
    [mysqld_multi]
    mysqld = /usr/local/mysql/bin/mysqld
    mysqladmin = /usr/local/mysql/bin/mysqladmin
    log = /tmp/mysql_multi.log
  • [mysqld1]
    # 設定資料目錄 [多執行個體中一定要不同]
    datadir = /data/mysql_data1
    # 設定sock存放檔案名稱 [多執行個體中一定要不同]
    socket = /tmp/mysql.sock1
    # 設定監聽開放連接埠 [多執行個體中一定要不同]
    port = 3306
    # 設定運行使用者
    user = mysql
    # 關閉監控
    performance_schema = off
    # 設定innodb 緩衝大小
    innodb_buffer_pool_size = 32M
    # 設定監聽IP地址
    bind_address = 0.0.0.0
    # 關閉DNS 反向解析
    skip-name-resolve = 0 **

    [mysqld2]
    datadir = /data/mysql_data2
    socket = /tmp/mysql.sock2
    port = 3307
    user = mysql
    performance_schema = off
    innodb_buffer_pool_size = 32M
    bind_address = 0.0.0.0
    skip-name-resolve = 0

    [mysqld3]
    datadir = /data/mysql_data3
    socket = /tmp/mysql.sock3
    port = 3308
    user = mysql
    performance_schema = off
    innodb_buffer_pool_size = 32M
    bind_address = 0.0.0.0
    skip-name-resolve = 0

    [mysqld4]
    datadir = /data/mysql_data4
    socket = /tmp/mysql.sock4
    port = 3309
    user = mysql
    performance_schema = off
    innodb_buffer_pool_size = 32M
    bind_address = 0.0.0.0
    skip-name-resolve = 0

    • 初始化各個執行個體 [ 初始化完成後會內建隨機密碼在輸出日誌中 ]
      [[email protected] ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data1
      [[email protected] ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data2
      [[email protected] ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data3
      [[email protected] ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data4

    • 各執行個體開啟 SSL 串連
      [[email protected] ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data1
      [[email protected] ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data2
      [[email protected] ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data3
      [[email protected] ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data4

    *修改環境變數
    echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
    source /etc/profile

    • 複製多執行個體指令碼到服務管理目錄下 [ /etc/init.d/ ]
      [[email protected] ~]# cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multi

    • 添加指令碼執行許可權
      [[email protected] ~]# chmod +x /etc/init.d/mysqld_multi

    • 添加進service服務管理
      [[email protected] ~]# chkconfig --add mysqld_multi
    1. 啟動測試
      • 查個多執行個體狀態
        [[email protected] ~]# /etc/init.d/mysqld_multi report
        Reporting MySQL servers
        MySQL server from group: mysqld1 is not running
        MySQL server from group: mysqld2 is not running
        MySQL server from group: mysqld3 is not running
        MySQL server from group: mysqld4 is not running
    • 啟動多執行個體
      [[email protected] ~]# /etc/init.d/mysqld_multi start

    • 查看多執行個體狀態
      Reporting MySQL servers
      MySQL server from group: mysqld1 is running
      MySQL server from group: mysqld2 is running
      MySQL server from group: mysqld3 is running
      MySQL server from group: mysqld4 is running

    • 查看執行個體監聽連接埠
      [[email protected] ~]# netstat -lntp | grep mysqld
      tcp 0 0 0.0.0.0:3306 0.0.0.0: LISTEN 2673/mysqld
      tcp 0 0 0.0.0.0:3307 0.0.0.0:
      LISTEN 2676/mysqld
      tcp 0 0 0.0.0.0:3308 0.0.0.0: LISTEN 2679/mysqld
      tcp 0 0 0.0.0.0:3309 0.0.0.0:
      LISTEN 2682/mysqld
    1. 串連測試

    MySQL多執行個體安裝部署

    相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.