• centos7用docker安装mysql5.7.24后配置主从


    1)使用docker安装完成mysql5.7.24,我规划的是3台:

    192.168.0.170(Master)

    192.168.0.169(Slave)

    192.168.0.168(Slave)

    2)配置三台机器的my.cnf配置文件

    我三台机器的配置文件都是/usr/local/mysql/conf/my.cnf 

    3)设置三台主从服务器配置
    vi /usr/local/mysql/conf/my.cnf

    [mysql]
    default-character-set=utf8
    [mysqld]
    interactive_timeout = 120

    wait_timeout = 120
    max_allowed_packet = 32M
    log-bin=mysql-bin
    server-id=170

    character-set-server=utf8

    vi /usr/local/mysql/conf/my.cnf

    [mysql]
    default-character-set=utf8
    [mysqld]
    interactive_timeout = 120
    wait_timeout = 120
    max_allowed_packet = 32M
    log-bin=mysql-bin
    server-id=169
    character-set-server=utf8

    vi /usr/local/mysql/conf/my.cnf

    [mysql]
    default-character-set=utf8
    [mysqld]
    interactive_timeout = 120
    wait_timeout = 120
    max_allowed_packet = 32M
    log-bin=mysql-bin
    server-id=168

    character-set-server=utf8

    3)创建主从服务器容器

    在170,169,168上运行启动mysql

    docker run --name mysql5_7_24 -p 3306:3306 -v /usr/local/mysql/conf:/etc/mysql/conf.d -v /usr/local/mysql/log:/var/log/mysql -v /usr/local/mysql/data:/var/lib/mysql --privileged=true -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7.24

    docker run --name mysql5_7_24 -p 3306:3306 -v /usr/local/mysql/conf:/etc/mysql/conf.d -v /usr/local/mysql/log:/var/log/mysql -v /usr/local/mysql/data:/var/lib/mysql --privileged=true -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7.24

    docker run --name mysql5_7_24 -p 3306:3306 -v /usr/local/mysql/conf:/etc/mysql/conf.d -v /usr/local/mysql/log:/var/log/mysql -v /usr/local/mysql/data:/var/lib/mysql --privileged=true -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7.24


    4)登录170主服务器的mysql,查询master的状态


    170主库创建用户

    SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
    GRANT REPLICATION SLAVE ON *.* to 'backup'@'%' identified by '123456';


    5)登录169和168从服务器的mysql,设置与主服务器相关的配置参数

    SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
    change master to master_host='192.168.0.170',master_user='backup',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=439;

    master_host为docker的地址不能写127.0.0.1
    master_user是在主库创建的用户
    master_log_pos是主库show master status;查询出的Position(439是最开始查询出来的,和上面的截图22437不同)


    然后在169和168上启动服务

    start slave;

    查看服务状态

    show slave status;

    Waiting for master to send event 就是成功了
    Connecting to master 多半是连接不通

    之后主库的修改都能同步到从库了

  • 相关阅读:
    [C#] override和overload的区别
    [ASP.Net] 20141228_Dapper文章搜集
    JSP
    Ajax使用简介
    编写JAVA脚本的JSP页面
    JAVA web开发模式
    JSP基础
    过滤器
    监听会话范围内事件
    http解析
  • 原文地址:https://www.cnblogs.com/xiaohanlin/p/10021146.html
Copyright © 2020-2023  润新知