`
crabdave
  • 浏览: 1295182 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

centos 7 部署docker mysql 5.6 容器主从服务

 
阅读更多

centos 7  部署docker mysql 5.6 容器主从服务

 

 

yum install -y wget docker

yum upgrade

 

给当前目录授权以便挂载到容器

mkdir -p /data/mysql

chcon -Rt svirt_sandbox_file_t /data/mysql

 

在宿主机上安装mysql client 

下载 mysql client 

wget http://cdn.mysql.com//Downloads/MySQL-5.6/MySQL-client-5.6.33-1.rhel5.x86_64.rpm

 

需要安装 perl 

yum install perl

 

rpm -ivh MySQL-client-5.6.33-1.rhel5.x86_64.rpm

 

必要时清理当前实验机器上的所有docker容器

docker stop `docker ps -a -q`

docker rm `docker ps -a -q`

 

拉取mysql5.6镜像

docker pull mysql:5.6

 

编写mysql主从服务的配置文件

/conf/my-m.cnf

# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL Community Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock

[mysqld_safe]
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp

innodb_buffer_pool_size=8M

log-bin = mysql-bin 
server-id = 1 

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address   = 127.0.0.1

#log-error  = /var/log/mysql/error.log

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

 

innodb_buffer_pool_size=8M  

log-bin = mysql-bin   

server-id = 1 

 

/conf/my-s.cnf

# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL Community Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock

[mysqld_safe]
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp

innodb_buffer_pool_size=8M

log-bin = mysql-bin 
server-id = 2

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address   = 127.0.0.1

#log-error  = /var/log/mysql/error.log

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

 

innodb_buffer_pool_size=8M  

log-bin = mysql-bin   

server-id = 2  

 

启动容器

master:

docker run -p 3307:3306 --name mysql-master -v $PWD/conf/my-m.cnf:/etc/mysql/my.cnf -v $PWD/logs-master:/logs -v $PWD/data-master:/mysql_data -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6

 

 

slave:

docker run -p 3308:3306 --name mysql-slave -v $PWD/conf/my-s.cnf:/etc/mysql/my.cnf -v $PWD/logs-slave:/logs -v $PWD/data-slave:/mysql_data -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6

 

 

命令说明:

  ● -p 3306:3306:将容器的3306端口映射到主机的3306端口

  ● -v $PWD/conf/my.cnf:/etc/mysql/my.cnf:将主机当前目录下的conf/my.cnf挂载到容器的/etc/mysql/my.cnf

  ● -v $PWD/logs:/logs:将主机当前目录下的logs目录挂载到容器的/logs

  ● -v $PWD/data:/mysql_data:将主机当前目录下的data目录挂载到容器的/mysql_data

  ● -e MYSQL_ROOT_PASSWORD=123456:初始化root用户的密码

 

查看容器的IP地址

master:

docker inspect  c290eb923d6a

slave:

docker inspect  7ffeb7add7ba

 

从宿主机登录master

 

mysql -uroot -p123456 -h172.17.0.2 -P 3306

登录后执行

GRANT REPLICATION SLAVE ON *.* to 'backup'@'%' identified by '123456';

show master status;

得到结果

mysql-bin.000004 | 312 

 

 

从宿主机登录slave:

mysql -uroot -p123456 -h172.17.0.3 -P 3306

change master to master_host='172.17.0.2',master_user='backup',master_password='123456',

master_log_file='mysql-bin.000004',master_log_pos=312,master_port=3306;

 

 

start slave;

show slave status;

 

如果看到Waiting for master send event.. 什么的就成功了,你现在在主库上的修改,都会同步到从库上

 

 

需要的时候stop slave;

 

参考:

http://blog.csdn.net/qq362228416/article/details/48569293

分享到:
评论

相关推荐

    centos7下mysql 5.6离线安装包,附操作手册

    在Linux系统中,CentOS 7是一个非常流行的服务器操作系统,而MySQL 5.6则是一个广泛应用的关系型数据库管理系统。在没有网络的情况下,离线安装MySQL是必要的,这通常涉及到RPM包的处理。本篇文章将详细讲解如何在...

    CentOS6.5一键安装Mysql5.6

    总结,CentOS 6.5上的一键安装MySQL 5.6涉及了系统更新、依赖安装、MySQL仓库配置、服务安装、配置优化以及安全设置等多个环节。每个步骤都需要仔细操作,确保系统的稳定性和数据库的安全性。通过这个过程,你不仅...

    centos7下mysql5.6主从配置

    仅供学习使用,希望能对大家有所帮助,

    centos6 安装mysql5.6.x版本

    在Linux系统中,CentOS 6是一个非常流行的发行版,而MySQL 5.6.x是其常用的关系型数据库管理系统。本教程将详细讲解如何在CentOS 6上安装MySQL 5.6.x版本,并涉及如何自定义安装路径,以满足特定的需求。 1. **准备...

    centos7上mysql5.6 安装配置(包含主从配置和双击热备)

    文档包含mysql下载链接,包含mysql安装配置,初学者可立即入门安装,包含主从配置和双击互呗配置,全手动安装过程分享

    centos安装mysql5.6.docx

    CentOS 6 安装 MySQL 5.6 MySQL 是一个流行的开源关系数据库管理系统,广泛应用于 Web 应用程序中。 CentOS 6 是一个基于 Linux 的操作系统,本文将指导您如何在 CentOS 6 上安装 MySQL 5.6。 关闭 SELinux ...

    CentOS7 源码安装MySQL5.6

    ### CentOS7 源码安装 MySQL 5.6 详细步骤及知识点解析 #### 一、准备工作:安装必要的依赖包 在正式安装 MySQL 5.6 之前,我们需要确保系统中已经安装了一些编译工具和其他必备组件。这些工具主要用于帮助我们...

    CentOS5安装Mysql5.6.txt

    CentOS5下安装Mysql5.6.txt

    centos7 安装mysql5.6

    2. 卸载centos 7自带的MariaDB数据库(mysql的分支) a) rpm -qa | grep mariadb b) rpm -e --nodeps mariadb-libs-5.5.41-2.el7_0.x86_64 3. 安装mysql(如果安装过请卸载掉再安装) a) 解压安装包 双击wget ...

    centos7下mysql5.6的主从复制详解

    【MySQL主从复制详解】 MySQL主从复制是一种数据库高可用性的解决方案,允许数据在多个服务器之间实时同步。这种技术在大型分布式系统中尤其重要,它实现了读写分离,提高了系统的并发处理能力,同时也提供了数据...

    arm架构centos7安装docker

    安装步骤参考:https://blog.csdn.net/chkai123/article/details/126229727 docker离线安装 arm架构下离线安装docker docker centos7离线安装docekr 离线安装docker arm架构下安装docker arm架构centos7安装docker

    CentOS7安装mysql5.7.19&mysql5;.7.19主从配置(CentOS7)

    在本教程中,我们将深入探讨如何在CentOS7操作系统上安装MySQL 5.7.19并设置主从复制配置。MySQL的主从复制是一种常用的技术,它允许数据从一个服务器(主服务器)同步到另一个服务器(从服务器),从而实现数据备份...

    Linux环境基于CentOS7 搭建部署Docker容器.pdf

    Linux环境基于CentOS7 搭建部署Docker容器

    Centos6 64位一键傻瓜安装mysql5.6.xx

    总结,"Centos6 64位一键傻瓜安装mysql5.6.xx"简化了在CentOS 6上部署MySQL的过程,特别是对于不熟悉Linux或MySQL管理的新手来说,这是一个非常实用的工具。然而,理解其工作原理和后续的维护步骤仍然是至关重要的,...

    CentOS7下Docker桥接网络配置

    本文将详细介绍如何在CentOS 7环境下配置Docker的桥接网络,并实现容器与外部网络的有效通信。 #### 二、基础知识回顾 在深入了解CentOS 7下Docker桥接网络配置之前,我们先来回顾一些基础概念: 1. **Docker容器...

    CentOS6.3源码安装mysql5.6方法.pdf

    CentOS6.3源码安装mysql5.6方法.pdf

    MySQL5.6 数据库主从同步安装与配置详解(Master/Slave)

    MySQL5.6 数据库主从同步安装与配置详解(Master/Slave) 本篇文章主要介绍了MySQL5.6 数据库主从同步安装与配置详解,具有一定的参考价值,有兴趣的可以了解一下。 安装环境 操作系统 :CentOS 6.5 数据库版本:...

Global site tag (gtag.js) - Google Analytics