使用官方mysql镜像即可
docker pull index.alauda.cn/library/mysql
镜像中核心文件备注
/var/lib/mysql # 镜像中数据文件
/etc/mysql/conf.d #镜像中配置文件
全量my.cnf文件
[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]
skip-host-cache
skip-name-resolve
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
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 0.0.0.0
#log-error = /var/log/mysql/error.log
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-bin=mylog
server_id=37
docker启动
38,39主机上分别启动mysql
docker run -d --net=host --name mysql-m -v /my/mysql/conf:/etc/mysql/conf.d \
-v /my/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=pwd1 --privileged=true 192.168.2.39:5000/mysql
docker run -d --net=host --name mysql38 -v /my/mysql:/etc/mysql/conf.d \
-v /my/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=pwd2 --privileged=true 192.168.2.39:5000/mysql
在mysql-master上新增客户
-- 该用户提供给slave连接
create user repu@'%' identified by 'repu?!13';
GRANT REPLICATION SLAVE ON *.* TO repu@'%' IDENTIFIED BY 'repu?!13';
flush privileges;
-- 在master上看
show master status;
-- 在slave上处理连接到master
stop slave ;
change master to master_host='mysql-m.marathon.mesos',master_port=3306,master_user='repu',master_password='repu?!13',master_log_file='mylog.000003',master_log_pos=826;
start slave;
安装到mesos
curl -XPOST 'http://192.168.2.45:8080/v2/apps' -H 'Content-Type: application/json' -d '{
"id": "mysql-m",
"env": {
"MYSQL_ROOT_PASSWORD": "pwd1"
},
"container": {
"docker": {
"privileged": true,
"image": "192.168.2.39:5000/mysql",
"network": "BRIDGE",
"portMappings": [
{
"containerPort": 3306,
"protocol": "tcp"
}
]
},
"type": "DOCKER",
"volumes": [
{
"hostPath": "/my/mysql/conf",
"containerPath": "/etc/mysql/conf.d",
"mode": "RW"
},
{
"hostPath": "/my/mysql/data",
"containerPath": "/var/lib/mysql",
"mode": "RW"
}
]
},
"cpus": 3,
"mem": 4096,
"instances": 1,
"constraints": [
[
"db",
"CLUSTER",
"m"
]
]
}'
## 从
curl -XPOST 'http://192.168.2.45:8080/v2/apps' -H 'Content-Type: application/json' -d '{
"id": "mysql-s",
"env": {
"MYSQL_ROOT_PASSWORD": "pwd1"
},
"container": {
"docker": {
"privileged": true,
"image": "192.168.2.39:5000/mysql",
"network": "BRIDGE",
"portMappings": [
{
"containerPort": 3306,
"protocol": "tcp"
}
]
},
"type": "DOCKER",
"volumes": [
{
"hostPath": "/my/mysql/conf",
"containerPath": "/etc/mysql/conf.d",
"mode": "RW"
},
{
"hostPath": "/my/mysql/data",
"containerPath": "/var/lib/mysql",
"mode": "RW"
}
]
},
"cpus": 1,
"mem": 2048,
"instances": 1,
"constraints": [
[
"db",
"CLUSTER",
"s"
]
]
}'