0

我的目标是让 Percona XtraDB 安装在 Docker 容器中运行。为此,我编写了以下配置。

Dockerfile:

FROM ubuntu:wily
ENV DEBIAN_FRONTEND noninteractive
#
# ENVIRONMENT INSTALL
#
RUN apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get install -y wget curl netcat python-dev python-setuptools python-software-properties vim
RUN easy_install j2cli
COPY my.cnf.j2 /templates/
COPY docker-entrypoint.sh /
RUN chmod +x docker-entrypoint.sh /
#
# PERCONA XTRADB CLUSTER INSTALL
#
RUN echo "deb http://repo.percona.com/apt wily main" >>     /etc/apt/sources.list.d/percona.list
RUN echo "deb-src http://repo.percona.com/apt wily main" >>     /etc/apt/sources.list.d/percona.list
RUN apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
RUN apt-get update && apt-get install -y percona-xtradb-cluster-56
ENTRYPOINT ["/docker-entrypoint.sh"]

码头入口点.sh

#!/bin/bash -e
j2 /templates/my.cnf.j2 > /etc/mysql/my.cnf
exec bash

我的.cnf.j2

[mysqld]
user=mysql
default_storage_engine=InnoDB
basedir=/usr
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
innodb_autoinc_lock_mode=2
log_queries_not_using_indexes=1
max_allowed_packet=128M
binlog_format=ROW
wsrep_provider=/usr/lib/libgalera_smm.so
wsrep_node_address={{node_ip}}
wsrep_cluster_name="mycluster"
wsrep_cluster_address=gcomm://
wsrep_node_name={{node_name}}
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="test:test"

!includedir /etc/mysql/conf.d/

wsrep_cluster_address=gcomm:// 通常包含 3 个节点 WAN-IP 的列表,由于隐私,我删除了它们。

构建图像非常好用:

docker build --rm -t test .

开始工作也很好:

docker run --name Test1 -e "node_ip=127.0.0.1" -e "node_name=Test1" -p 3306:3306 -p 4567:4567 -p 4444:4444 -p 4568:4568 -i -t test

变量 node_ip 指向我服务器的 WAN-IP,出于隐私原因,我将其设置为 127.0.0.1。

但是当我尝试在容器中引导 mysql 时:

/etc/init.d/mysql bootstrap-pxc

我收到此错误:

2016-03-28 09:24:09 354 [Note] Server hostname (bind-address): '*'; port: 3306
2016-03-28 09:24:09 354 [Note] IPv6 is available.
2016-03-28 09:24:09 354 [Note]   - '::' resolves to '::';
2016-03-28 09:24:09 354 [Note] Server socket created on IP: '::'.
2016-03-28 09:24:09 354 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
160328 09:24:09 mysqld_safe mysqld from pid file /var/lib/mysql/8605688929d8.pid ended

我该如何解决这个问题才能让 XtraDB 在我的容器中运行?

4

2 回答 2

1

mysql_install_db chown mysql.mysql -R /var/lib/mysql service mysql start

以上似乎没有问题,请测试一下。

于 2016-03-29T10:44:13.223 回答
0

可能是权限问题。FROM尝试在您的陈述后添加以下内容:

RUN useradd mysql \
    && mkdir /var/lib/mysql \
    && chown -R mysql:mysql /var/lib/mysql
于 2016-03-28T13:05:44.347 回答