时间:2021-07-01 10:21:17 帮助过:8人阅读
‘2‘
services:
m1:
build:
./master
container_name:
m1
volumes:
-
/home/ssab/config/mysql-master/
:/etc/mysql/:ro
-
/etc/localtime:/etc/localtime:ro
-
/home/ssab/config/hosts:/etc/hosts:ro
ports:
-
"3309:3306"#暴露mysql的端口
networks:
mysql:
ipv4_address:
172.18
.
0.
2
ulimits:
nproc:
65535
hostname:
m1
mem_limit:
1024
m
restart:
always
environment:
MYSQL_ROOT_PASSWORD:
m1test
s1:
build:
./s1
container_name:
s1
volumes:
-
/home/ssab/config/mysql-s1/
:/etc/mysql/:ro
-
/etc/localtime:/etc/localtime:ro
-
/home/ssab/config/hosts:/etc/hosts:ro
ports:
-
"3307:3306"
networks:
mysql:
ipv4_address:
172.18
.
0.
3
links:
- m1
ulimits:
nproc:
65535
hostname:
s1
mem_limit:
1024
m
restart:
always
environment:
MYSQL_ROOT_PASSWORD:
s1test
s2:
build:
./s2
container_name:
s2
volumes:
-
/home/ssab/config/mysql-s2/
:/etc/mysql/:ro
-
/etc/localtime:/etc/localtime:ro
-
/home/ssab/config/hosts:/etc/hosts:ro
ports:
-
"3308:3306"
links:
- m1
networks:
mysql:
ipv4_address:
172.18
.
0.
4
ulimits:
nproc:
65535
hostname:
s2
mem_limit:
1024
m
restart:
always
environment:
MYSQL_ROOT_PASSWORD:
s2test
mycat:
# 设置mycat
build:
./mycat
container_name:
mycat
volumes:
-
/home/ssab/config/mycat/:/mycat/conf/:ro# mycat配置文件
-
/home/ssab/config/mycat-logs/
:/mycat/logs/:rw# mycat日志文件
-
/etc/localtime:/etc/localtime:ro
-
/home/ssab/config/hosts:/etc/hosts:ro
ports:
-
"8066:8066"# 暴露mycat服务端口
-
"9066:9066"# 暴露mycat管理端口
links:
# mycat可以连接m1 s1 s2
- m1
- s1
- s2
networks:
mysql:
ipv4_address:
172.18
.
0.
5
ulimits:
nproc:
65535
hostname:
mycat
mem_limit:
1024
m
restart:
always
networks:
mysql:
driver:
bridge
ipam:
driver:
default
config:
-
subnet:172.18
.
0.
0/
24
gateway:
172.18
.
0.
1
mysql的Dockerfile样例:
FROMmysql:5.7.17
MAINTAINER<
ssabwork_wjj@163.com>
EXPOSE 3306
CMD ["mysqld"]
mycat的Dockerfile样例:
FROM java:
8-jre
MAINTAINER
<ssab work_wjj@
163.com
>
LABEL Description
="使用mycat做mysql数据库的读写分离"
ENV mycat
-versionMycat
-server-1.6-RELEASE-20161028204710-linux.tar
.gz
USER root
COPY
./Mycat
-server-1.6-RELEASE-20161028204710-linux.tar
.gz
/
RUN tar
-zxf/Mycat
-server-1.6-RELEASE-20161028204710-linux.tar
.gz
ENV MYCAT_HOME
=/mycat
ENV PATH
=$PATH:
$MYCAT_HOME/bin
WORKDIR
$MYCAT_HOME/bin
RUN chmod u
+x
./mycat
EXPOSE
80669066
CMD
["./mycat",
"console"]
docker-compose.yml样例(mysql主从+mycat读写分离)
标签:work 使用 读写 java lease ima code service compose