docker数据库主从复制到读写分离(mycat)

docker笔记

1.安装docker: sudo apt-get install -y docker.io

2.安装sshserver: sudo apt-get install openssh-server

3.连接用工具putty或xshell连接server.

4.ufw disable (关闭防火墙)

5. uname – a  查看系统版本号

6.ru root 切换用户

7.docker –version 查看版本号

8.sudo docker search mysql :查找镜像地址

配置master

9.创建文件夹:

mkdir /usr/local/mysqlData/master/cnf –p

mkdir /usr/local/mysqlData/master/data -p

cd  /usr/loal/mysqlData/master/cnf/

vim mysql.cnf

创建mysql.cnf 添加

 

[mysqld]

pid-file    =/var/run/mysqld/mysqld.pid

socket    =/var/run/mysqld/mysqld.sock

datadir    =/var/lib/mysql

 

symbolic-links=0

 

character-set-server = utf8  

#skip-networking 

innodb_print_all_deadlocks = 1

max_connections = 2000 

max_connect_errors = 6000 

open_files_limit = 65535 

table_open_cache = 128  

max_allowed_packet = 4M 

binlog_cache_size = 1M 

max_heap_table_size = 8M 

tmp_table_size = 16M 

 

read_buffer_size = 2M 

read_rnd_buffer_size = 8M 

sort_buffer_size = 8M 

join_buffer_size = 28M 

key_buffer_size = 4M 

 

thread_cache_size = 8 

 

query_cache_type = 1 

query_cache_size = 8M 

query_cache_limit = 2M 

 

ft_min_word_len = 4 

 

log-bin = mysql-bin    #主要是这两行

server-id = 1

binlog_format = mixed 

 

performance_schema = 0 

explicit_defaults_for_timestamp 

 

#lower_case_table_names = 1 

 

interactive_timeout = 28800 

wait_timeout = 28800 

 

# Recommended in standard MySQL setup 

 

sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES  

 

[mysqldump] 

quick 

max_allowed_packet = 16M 

 

[myisamchk]

key_buffer_size = 8M

sort_buffer_size = 8M

read_buffer = 4M

write_buffer = 4M

 

10.启动MySQL 容器

 

docker run -itd-p 3306:3306 --name master -v /usr/local/mysqlData/master/cnf:/etc/mysql/conf.d-v /usr/local/mysqlData/master/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root7d83a47ab2d2

7d83a47ab2d2(镜像地址id)root自己定义密码

11.进入MySQL容器

docker exec -it b8bd1f75f91a/bin/bash

942c2253509c 为 docker ps 中container ID

12.连接MySQL

mysql -uroot-h127.0.0.1 -P3306 –p

13.授权:

GRANT ALLPRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

解释对所有用户,所有ip都不做限制

14.刷新权限配置:flush  privileges;

15.退出容器:ctrl+d

配置slave:

15.创建文件:(可以配置多个从)

mkdir /usr/local/mysqlData/slave/cnf  -p

mkdir /usr/local/mysqlData/slave/data -p

cd  /usr/loal/mysqlData/master/cnf/

vim mysql.cnf

 

 

16.创建容器:

docker run -itd-p 3307:3306 –name slave -v /usr/local/mysqlData/slave/cnf:/etc/mysql/conf.d -v/usr/local/mysqlData/slave/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root 7d83a47ab2d2

 

17.进入master:

docker exec -it942c2253509c /bin/bash

mysql -uroot-h127.0.0.1 -P3306 –p

18.show master status ;

记录 file position

19.切换到slave

change master tomaster_host='192.168.1.109',master_user='root',master_password='root',master_log_file='mysql-bin.000003',master_log_pos=604;

20.切换到slave01

change master tomaster_host='192.168.1.109',master_user='root',master_password='root',master_log_file='mysql-bin.000003',master_log_pos=604;

21.在master 创建测试数据库,表数据。

 

 

Docker 安装目录: /var/lib /docker

 

 

Dockerfile:

FROMregistry.cn-hangzhou.aliyuncs.com/dthan/debian-wget:1.6

 

# install jre

RUN cd /usr/local && wget --no-cookies--no-check-certificate --header"Cookie:gpw_e24=http%3a%2f%2fwww.oracle.com%2ftechnetwork%2fjava%2fjavase%2fdownloads%2fjdk7-downloads-1880260.html;oraclelicense=accept-securebackup-cookie"http://download.oracle.com/otn-pub/java/jdk/8u152-b16/aa0333dd3019491ca4f6ddbe78cdb6d0/server-jre-8u152-linux-x64.tar.gz&& tar -zxvf server-jre-8u152-linux-x64.tar.gz && rm -fserver-jre-8u152-linux-x64.tar.gz

 

ENV JAVA_HOME /usr/local/jdk1.8.0_152

ENV CLASSPATH ${JAVA_HOME}/lib/dt.jar:$JAVA_HOME/lib/tools.jar

ENV PATH $PATH:${JAVA_HOME}/bin

 

# install mycat

ADDhttp://dl.mycat.io/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz/usr/local/

RUN cd /usr/local && tar -zxvfMycat-server-1.6-RELEASE-20161028204710-linux.tar.gz && rm -fMycat-server-1.6-RELEASE-20161028204710-linux.tar.gz

 

VOLUME /usr/local/mycat/conf

EXPOSE 8066 9066

CMD ["/usr/local/mycat/bin/mycat","console"]

 

docker build -t syn/mycat :v1 .

 

 

 

docker create --name mycat --net multihost   \

-v/home/skc/workspace/graduate_design/docker_data/mycat/conf:/usr/local/mycat/conf  \

-v/home/skc/workspace/graduate_design/docker_data/mycat/logs:/usr/local/mycat/logs\

-p 8066:8066 -p 9066:9066  \

syn/mycat -mycat:v1

 

 

docker run -d -p 8066:8066 --name docker_mycat–link master:db_mysql  dcloud/mycat:v1

 

 

注意:--linkdocker-mysql:db_mysql     docker-mysqlmysql的容器名,db_mysql 为连接名,mycat中配置的mysql连接地址的ip该处db_mysql

docker 文件地址

ls /var/lib/docker/aufs/diff/ -l

vim/var/lib/docker/aufs/diff/4b95ec997fa3cd73166cca65efa8dd7074fda2cab91f0c9e1df6e4cdf5b2a585/usr/local/mycat/conf/schema.xml

 

 

 

杀死所有running状态的容器

?

1

docker kill $(docker ps -q)

删除所有已经停止的容器

?

1

docker rm $(docker ps -a -q)

删除所有\'untagged/dangling\' ()状态的镜像

?

1

docker rmi $(docker images -q -f dangling=true)

删除所有镜像:

?

1

docker rmi $(docker images -q)

 

连接mycat

mysql -uroot -p -hmysql-mycat -P8066
查找
 
find ./ -name 'server.xml'

 未完待续。。。。。

你可能感兴趣的:(docker数据库主从复制到读写分离(mycat))