更換mysql_Docker搭建MySQL主從復制

Docker搭建MySQL主從復制

  1. 主從服務器上分別安裝Docker

    1.1 Docker 要求 CentOS 系統的內核版本高于 3.10

    [root@localhost ~]# uname -r
    3.10.0-693.el7.x86_64

    1.2 確保 yum 包更新到最新。

    [root@localhost ~]# sudo yum update
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile* base: mirrors.cqu.edu.cn* extras: mirrors.cqu.edu.cn* updates: mirrors.cqu.edu.cn
    base                                                                                                                                             | 3.6 kB  00:00:00     
    docker-ce-stable                                                                                                                                 | 3.5 kB  00:00:00     
    extras                                                                                                                                           | 2.9 kB  00:00:00     
    updates                                                                                                                                          | 2.9 kB  00:00:00

    1.3 安裝需要的軟件包, yum-util 提供yum-config-manager功能,另外兩個是devicemapper驅動依賴的

    [root@localhost ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile* base: mirrors.cqu.edu.cn* extras: mirrors.cqu.edu.cn* updates: mirrors.cqu.edu.cn
    Package yum-utils-1.1.31-52.el7.noarch already installed and latest version
    Package device-mapper-persistent-data-0.8.5-1.el7.x86_64 already installed and latest version
    Package 7:lvm2-2.02.185-2.el7_7.2.x86_64 already installed and latest version
    Nothing to do

    1.4 設置yum源

    [root@localhost ~]# sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    Loaded plugins: fastestmirror, langpacks
    adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
    grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
    repo saved to /etc/yum.repos.d/docker-ce.repo

    1.5 安裝docker

    [root@localhost ~]#  sudo yum install docker-ce
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile* base: mirrors.cqu.edu.cn* extras: mirrors.cqu.edu.cn* updates: mirrors.cqu.edu.cn
    Package 3:docker-ce-19.03.8-3.el7.x86_64 already installed and latest version
    Nothing to do

    1.6 啟動docker并設置docker自動啟動

    [root@localhost ~]# sudo systemctl start docker
    [root@localhost ~]# sudo systemctl enable docker

    1.7 檢測docker是否安裝成功

    [root@localhost ~]# docker version
    Client: Docker Engine - CommunityVersion:           19.03.8API version:       1.40Go version:        go1.12.17Git commit:        afacb8bBuilt:             Wed Mar 11 01:27:04 2020OS/Arch:           linux/amd64Experimental:      falseServer: Docker Engine - CommunityEngine:Version:          19.03.8API version:      1.40 (minimum version 1.12)Go version:       go1.12.17Git commit:       afacb8bBuilt:            Wed Mar 11 01:25:42 2020OS/Arch:          linux/amd64Experimental:     falsecontainerd:Version:          1.2.13GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429runc:Version:          1.0.0-rc10GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dddocker-init:Version:          0.18.0GitCommit:        fec3683
    
  2. docker更換國內阿里倉庫,并下載安裝MySQL

    2.1 docker更換國內阿里倉庫

    sudo mkdir -p /etc/docker
    sudo tee /etc/docker/daemon.json <<-'EOF'
    {"registry-mirrors": ["https://rdwyjupq.mirror.aliyuncs.com"]
    }
    EOF
    sudo systemctl daemon-reload
    sudo systemctl restart docker

    2.2 安裝MySQL

    ? 2.2.1 下載MySQL

    [root@localhost ~]# docker pull mysql
    Using default tag: latest
    latest: Pulling from library/mysql
    c499e6d256d6: Pull complete 
    22c4cdf4ea75: Pull complete 
    6ff5091a5a30: Pull complete 
    2fd3d1af9403: Pull complete 
    0d9d26127d1d: Pull complete 
    54a67d4e7579: Pull complete 
    fe989230d866: Pull complete 
    3a808704d40c: Pull complete 
    826517d07519: Pull complete 
    69cd125db928: Pull complete 
    b5c43b8c2879: Pull complete 
    1811572b5ea5: Pull complete 
    Digest: sha256:b69d0b62d02ee1eba8c7aeb32eba1bb678b6cfa4ccfb211a5d7931c7755dc4a8
    Status: Downloaded newer image for mysql:latest
    docker.io/library/mysql:latest

    ? 2.2.2 查看MySQL鏡像

    [root@localhost ~]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    mysql               latest              9228ee8bac7a        4 days ago          547MB

    ? 2.2.3 創建MySQL的掛載文件目錄(日志、數據、配置)

    [root@localhost ~]# mkdir -p /root/mysql/data /root/mysql/logs /root/mysql/conf

    ? 2.2.4 先啟動容器(為了復制配置文件)(這種做法顯得多余,但是Docker不是很精通的我沒想到更好的辦法,請各位大神指導)

    [root@localhost conf]# docker run -d -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD="123456" mysql
    05d161e69f3b2e3e4ebaa50f822934599a31e7ade330e1440a68aec9e404f7ae

    ? 2.2.5 復制配置文件

    [root@localhost conf]# docker cp mysql:/etc/mysql/my.cnf /root/mysql/conf/

    ? 2.2.6 停止并刪容器

    [root@localhost conf]# docker stop mysql
    mysql
    [root@localhost conf]# docker rm mysql
    mysql

    ? 2.2.7 重新啟動容器(加上掛載)

    [root@localhost conf]# docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 --mount type=bind,src=/root/mysql/conf/my.cnf,dst=/etc/mysql/my.cnf --mount ty
    pe=bind,src=/root/mysql/data,dst=/var/lib/mysql --mount type=bind,src=/root/mysql/logs,dst=/logs --restart=on-failure:3 -d mysql64824c7e84ceb3513b65a375c55f2c53bc653f95b119008296122b13ff632ba1

    ? 2.2.8 進入MySQL查詢現有字符集,結果都是utf8mb4

    show variables like '%char%';

    ? 2.2.9 在掛載的配置文件更改字符集

    character-set-server=utf8default-character-set=utf8default-character-set=utf8

    ? 2.2.10 重啟docker容器,并查看字符集已經更改,證明掛載的配置文件有效

8b33d894dcd45b567d7e6eced2f5be89.png
  1. 搭建主從復制數據庫

    3.1 配置主Master庫

    ? 3.1.1 進入主庫掛載配置文件my.cnf,加入以下配置并重啟docker容器

    [mysqld]
    ## 同一局域網內注意要唯一
    server-id=100  
    ## 開啟二進制日志功能,可以隨便取(關鍵)
    log-bin=mysql-bin

    ? 3.1.2 在主Master庫執行語句

    CREATE USER 'slave'@'%' IDENTIFIED BY '123456';
    GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%';

    ? 為防止后面出現報錯[Authentication plugin 'caching_sha2_password' cannot be loaded],執行下面語句

    ALTER USER 'slave'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;   #修改加密規則 
    ALTER USER 'slave'@'%' IDENTIFIED WITH mysql_native_password BY 'password';   #更新一下用戶的密碼 
    FLUSH PRIVILEGES;
    alter user 'slave'@'%' identified by '123456';

    最后執行語句獲取File, Position

    show master status;

    3.2 配置從Slave庫

    ? 3.2.1 進入從庫掛載配置文件my.cnf,加入以下配置并重啟docker容器

    [mysqld]
    ## 設置server_id,注意要唯一
    server-id=101  
    ## 開啟二進制日志功能,以備Slave作為其它Slave的Master時使用
    log-bin=mysql-slave-bin   
    ## relay_log配置中繼日志
    relay_log=edu-mysql-relay-bin  

    ? 3.2.2 鏈接主從庫,在從庫執行語句

    change master to master_host='192.168.47.128', master_user='slave', master_password='123456', master_port=3306, master_log_file='mysql-bin.000001', master_log_pos= 5938, master_connect_retry=30;

    master_host :Master的地址

    master_port:Master的端口號,指的是容器的端口號

    master_user:用于數據同步的用戶

    master_password:用于同步的用戶的密碼

    master_log_file:指定 Slave 從哪個日志文件開始復制數據,即上文中提到的 File 字段的值

    master_log_pos:從哪個 Position 開始讀,即上文中提到的 Position 字段的值

    master_connect_retry:如果連接失敗,重試的時間間隔,單位是秒,默認是60秒

    ? 3.2.3 查看主從同步狀態

    show slave status ;

undefined_b.jpg

? 正常情況下,SlaveIORunning 和 SlaveSQLRunning 都是No,因為我們還沒有開啟主從復制過程。

  3.2.4 開啟主從復制
   start slave;

重新查看主從同步狀態, 這時SlaveIORunning 和 SlaveSQLRunning 都是Yes,如果你的SlaveIORunning 和 SlaveSQLRunning 其中一個是Connecting或者No,就證明配置有錯,查看Last_IO_Error報錯的詳細信息

通過下面命令,刪除已經配置的主從鏈接信息,重新進行配置

   stop slave;reset master;
     3.2.5 測試主從復制,最簡單的方式是在主庫建立個新庫,這時,從庫會自動同步

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389094.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389094.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389094.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

dll文件的c++制作dll文件的c++制作

dll文件的c制作1、首先用vs2005建立一個c的dll動態鏈接庫文件&#xff0c;這時&#xff0c;// DllTest.cpp : 定義 DLL 應用程序的入口點。//#include "stdafx.h"//#include "DllTest.h"#ifdef _MANAGED#pragma managed(push, off)#endifBOOL APIENTRY Dll…

理解ConstraintLayout 對性能的好處

自從在17年GoogleI/O大會宣布了Constraintlayout,我們持續提升了布局的穩定性和布局編輯的支持。我們還為ConstraintLayout添加了一些新特性支持創建不同類型的布局&#xff0c;添加這些新特性&#xff0c;可以明顯的提升性能&#xff0c;在這里&#xff0c;我門將討論Contrain…

數據湖 data lake_在Data Lake中高效更新TB級數據的模式

數據湖 data lakeGOAL: This post discusses SQL “UPDATE” statement equivalent for a data lake (object) storage using Apache Spark execution engine. To further clarify consider this, when you need to perform conditional updates to a massive table in a relat…

如何理解運維

運維工程師&#xff08;運營&#xff09;&#xff0c;負責維護并確保整個服務的高可用性&#xff0c;同時不斷優化系統架構提升部署效率&#xff0c;優化資源利用率提高整體的投資回報率。運維工程師面對的最大挑戰是大規模集群的管理問題&#xff0c;如何管理好幾十萬臺服務器…

advanced installer更換程序id_好程序員web前端培訓分享kbone高級-事件系統

好程序員web前端培訓分享kbone高級-事件系統&#xff1a;1、用法&#xff0c;對于多頁面的應用&#xff0c;在 Web 端可以直接通過 a 標簽或者 location 對象進行跳轉&#xff0c;但是在小程序中則行不通&#xff1b;同時 Web 端的頁面 url 實現和小程序頁面路由也是完全不一樣…

ai對話機器人實現方案_顯然地引入了AI —無代碼機器學習解決方案

ai對話機器人實現方案A couple of folks from Obviously.ai contacted me a few days back to introduce their service — a completely no-code machine learning automation tool. I was a bit skeptical at first, as I always am with supposedly fully-automated solutio…

網絡負載平衡的

網絡負載平衡允許你將傳入的請求傳播到最多達32臺的服務器上&#xff0c;即可以使用最多32臺服務器共同分擔對外的網絡請求服務。網絡負載平衡技術保證即使是在負載很重的情況下它們也能作出快速響應。 網絡負載平衡對外只須提供一個IP地址&#xff08;或域名&#xff09;。 如…

透明狀態欄導致windowSoftInputMode:adjustResize失效問題

當我們通過下面代碼&#xff1a; getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); 設置狀態欄透明&#xff0c;當界面存在EditText時&#xff0c;在activity里面設置windowSoftInputMode:…

[TimLinux] JavaScript 元素動態顯示

1. css的opacity屬性 這個屬性用于&#xff1a;設置元素的不透明級別&#xff0c;取值范圍&#xff1a;從 0.0 &#xff08;完全透明&#xff09;到 1.0&#xff08;完全不透明&#xff09;&#xff0c;元素所在的文本流還在。這個屬性的動態變化可以用來設置元素的淡入淡出效果…

神經網絡 CNN

# encodingutf-8import tensorflow as tfimport numpy as npfrom tensorflow.examples.tutorials.mnist import input_datamnist input_data.read_data_sets(MNIST_data, one_hotTrue)def weight_variable(shape): initial tf.truncated_normal(shape, stddev0.1) # 定義…

圖片中的暖色或冷色濾色片是否會帶來更多點擊? —機器學習A / B測試

A/B test on ads is the art of choosing the best advertisement that optimizes your goal (number of clicks, likes, etc). For example, if you change a simple thing like a filter in your pictures you will drive more traffic to your links.廣告的A / B測試是一種選…

3d制作中需要注意的問題_淺談線路板制作時需要注意的問題

PCB電路板是電子設備重要的基礎組裝部件&#xff0c;在制作PCB電路板時&#xff0c;只有將各個方面都考慮清楚&#xff0c;才能保證電子設備在使用時不會出現問題。今天小編就與大家一起分享線路板制作時需要注意的問題&#xff0c;歸納一下幾點&#xff1a;1、考慮制作類型電路…

冷啟動、熱啟動時間性能優化

用戶希望應用程序能夠快速響應并加載。 一個啟動速度慢的應用程序不符合這個期望&#xff0c;可能會令用戶失望。 這種糟糕的體驗可能會導致用戶在應用商店中對您的應用進行糟糕的評價&#xff0c;甚至完全放棄您的應用。 本文檔提供的信息可幫助您優化應用的啟動時間。 它首先…

python:lambda、filter、map、reduce

lambda 為關鍵字。filter&#xff0c;map&#xff0c;reduce為內置函數。 lambda&#xff1a;實現python中單行最小函數。 g lambda x: x * 2 #相當于 def g(x):return x*2print(g(3))# 6 注意&#xff1a;這里直接g(3)可以執行&#xff0c;但沒有輸出的&#xff0c;前面的…

集群

原文地址&#xff1a;http://www.microsoft.com/china/MSDN/library/windev/COMponentdev/CdappCEnter.mspx?mfrtrue 本文假設讀者熟悉 Windows 2000、COM、IIS 5.0 摘要 Application Center 2000 簡化了從基于 Microsoft .NET 的應用程序到群集的部署&#xff0c;群集是一組…

Myeclipes連接Mysql數據庫配置

相信大家在網站上也找到了許多關于myeclipes如何連接mysql數據庫的解決方案&#xff0c;雖然每一步都按照他的步驟來&#xff0c;可到最后還是提示連接失敗&#xff0c;有的方案可能應個人設備而異&#xff0c;配置環境不同導致。經過個人多方探索終于找到一個簡單便捷的配置方…

cnn圖像二分類 python_人工智能Keras圖像分類器(CNN卷積神經網絡的圖片識別篇)...

上期文章我們分享了人工智能Keras圖像分類器(CNN卷積神經網絡的圖片識別的訓練模型)&#xff0c;本期我們使用預訓練模型對圖片進行識別&#xff1a;Keras CNN卷積神經網絡模型訓練導入第三方庫from keras.preprocessing.image import img_to_arrayfrom keras.models import lo…

圖卷積 節點分類_在節點分類任務上訓練圖卷積網絡

圖卷積 節點分類This article goes through the implementation of Graph Convolution Networks (GCN) using Spektral API, which is a Python library for graph deep learning based on Tensorflow 2. We are going to perform Semi-Supervised Node Classification using C…

[微信小程序] 當動畫(animation)遇上延時執行函數(setTimeout)出現的問題

小程序中當動畫animation遇上setTimeout函數內部使用this.setData函數&#xff0c;通常情況下會出現報錯。本文先告訴解決方法&#xff0c;后分析報錯原因 1.解決方法&#xff1a; 在 setTimeout() 函數的同級加上 const that this; &#xff0c;然后將this.setData換成that…

關于使用pdf.js預覽pdf的一些問題

手機應用中pdf展示使用非常廣泛&#xff0c; 一些pdf由于特殊的內容比如文字、電子簽章必須使用復雜的解析器來解析&#xff0c;當使用MultiPdf 這個庫加載&#xff0c;會使得包變得非常龐大&#xff0c; 這里我們考慮使用pdf.js 來解析pdf. 引用非常簡單&#xff0c;只需要把…