0及伊始化错误管理

 

 

Document

注:
初稿地址:http://severalnines.com/blog/mysql-docker-containers-understanding-basics

Preface

Preface

 

$ docker run –detach –name=test-mysql
–env=”MYSQL_ROOT_PASSWORD=mypassword” –publish 6603:3306
–volume=/root/docker/test-mysql/conf.d:/etc/mysql/conf.d
–volume=/storage/docker/mysql-datadir:/var/lib/mysql mysql

 

 
  

An image is a lightweight, stand-alone, executable package that
includes everything needed to run a piece of software, including the
code, a runtime, libraries, environment variables, and config files.

MySQL Docker Containers: Understanding the basics
Docker is quickly becoming mainstream, as a method to package and deploy
self-sufficient applications in primarily stateless Linux containers.
But for a stateful service like a database, this might be bit of a
headache. How do we best configure MySQL in a container environment?
What can go wrong? Should we even run our databases in a container
environment? How does performance compare with e.g. running on virtual
machines or bare-metal servers? How do we manage replicated or clustered
setups, where multiple containers need to be created, upgraded and made
highly available?
So, welcome to our new blog series – “MySQL on Docker”. We will touch
upon swarms, shared volumes, data-only-containers, security and
configuration management, multi-host networking, service discovery and
implications on monitoring when we move from host-centric to
role-centric services with shorter life cycles.

    We
commonly use VMware or VirtualBox to install our Virtual Machines
before.For the sake of creating a
simple testing environment with less resources.I consider to implement a
MySQL db server relies on docker which can help you saving your time
when developing code or something else.

    Several
days ago,I’ve implement a docker environmnet,I’m gonna Install a MySQL
8.0 version on it.Let’s see the detail of it.

 

997755.com澳门葡京 1

 

 

container is a runtime instance of an image—what the image becomes
in memory when actually executed. It runs completely isolated from the
host environment by default, only accessing host files and ports if
configured to do so.

In our first blog post, we are going to cover some basics around running
MySQL in a container. We are going to use the term ‘Docker’ as the
container platform throughout the blog series.
MySQL Docker Containers
Think about a container as a “lightweight virtual machine”. Unlike
virtual machines though, containers do not require an entire operating
system, all required libraries and the actual application binaries. The
same Linux kernel and libraries can be shared between multiple
containers running on the host. Docker makes it easy to package Linux
software in self-contained images, where all software dependencies are
bundled and deployed in a repeatable manner. An image will have exactly
the same software installed, whether we run it on a laptop or on a
server. The key benefit of Docker is that it allows users to package an
application with all of its dependencies into a standardized unit
(container). Running many containers allows each one to focus on a
specific task; multiple containers then work in concert to implement a
distributed system.
The traditional way to run a MySQL database is to install the MySQL
packages on a host (bare-metal, virtual machine, cloud instance), and
applications would just have to connect to the listening port. Most of
the management tasks, for example, configuration tuning, backup,
restore, database upgrade, performance tweaking, troubleshooting and so
on have to be executed on the database host itself. You would expect to
have several ports accessible for connection, for example port TCP 22
for SSH, TCP 3306 for MySQL or UDP 514 for syslog.
In a container, think of MySQL as one single unit that only serve MySQL
related stuff on port 3306. Most of the operation should be performed
under this single channel. Docker works great in packaging your
application/software into one single unit, which you can then deploy
anywhere as long as Docker engine is installed. It expects the package,
or image to be run as a single process per container. With Docker,
the flow would be you (or someone) build a MySQL image using a specific
version and vendor, package the image and distribute to anybody who
wants to quickly fire a MySQL instance.
Let’s get it running
Let’s familiarize ourselves with a MySQL container running on Docker.
We’ll take a ‘break/fix’ approach, so expect to see some errors pop up
here and there. We’ll look at the errors and see why they happen. We are
going to use the official MySQL
image
created and maintained by Docker.
To begin with, we must have a host. It can be any type of hosts
(physical or virtual) running on Linux, Mac OS X or Windows. Please
refer to Docker’s installation
guide
for details. You can also use
docker-machine
to provision hosts on a supported cloud provider like DigitalOcean and
AWS EC2 Container Service, but we will cover that in another blog post.
Here, we are going to use Ubuntu 14.04 as our machine host and use
standard command line for deployment and management.
Next, find a container image that you want from the Docker registry. It
can be a public registry like 0及伊始化错误管理。Docker
Hub or a private
registry, where you host the containers’ image on-premises, within your
own network. If you can’t find the image that fits you, you can build
your own.
There are many MySQL container images available in the Docker Hub
registry. The following screenshot shows some examples:

Introduce

Procedure

Containers run apps natively on the host machine’s kernel. They have
better performance characteristics than virtual machines that only get
virtual access to host resources through a hypervisor. Containers can
get native access, each one running in a discrete process, taking no
more memory than any other executable.

997755.com澳门葡京 2

 

 

997755.com澳门葡京 3   
997755.com澳门葡京 4

Firing up a MySQL container
First, you have to install Docker. In the Linux box:
1
2

    What’s docker?There’re two concept you
should first try to understand,image & container(like an iso file,put
all kinds of different tools in it,then manage the by containner).You’re
supposed to package your applications(or indispensable software in your
dev environment) to a container.Whenever you need a second evironment to
install same softwares or dependent packages,only one thing that you
migrate the image to it is neccessary.It’s rather simple and efficient
by using docker.

Check and
run docker container again.

 

$sudo apt-get install docker.io

 

 1 [root@docker vagrant]# docker images
 2 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
 3 centos7             latest              7d0b68af5a06        10 days ago         694MB
 4 [root@docker vagrant]# docker run -d -v /vagrant/mysql_soft:/opt/mysql -v /vagrant/data1:/data -v /etc/hosts:/etc/hosts -p2222:22 --cap-add=NET_ADMIN --name c1 -h docker centos7
 5 fbf17e3f6aa8324b8d494aa0211122f5d735bf6f648a99b6632ae2be5be996da
 6 [root@docker vagrant]# docker ps -a
 7 CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                  NAMES
 8 fbf17e3f6aa8        centos7             "/usr/bin/supervisor…"   5 seconds ago       Up 3 seconds (healthy)     0.0.0.0:2222->22/tcp   c1
 9 103f318448c9        centos7             "/usr/bin/supervisor…"   25 minutes ago      Exited (0) 3 minutes ago                          node1
10 [root@docker vagrant]# docker rm container 103f318448c9
11 103f318448c9
12 Error: No such container: container
13 [root@docker vagrant]# docker ps
14 CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                    PORTS                  NAMES
15 fbf17e3f6aa8        centos7             "/usr/bin/supervisor…"   32 seconds ago      Up 30 seconds (healthy)   0.0.0.0:2222->22/tcp   c1
16 [root@docker vagrant]# ssh root@172.17.0.2
17 root@172.17.0.2's password: 
18 Last login: Wed Jun 13 00:18:11 2018 from 172.17.0.1
19 [root@docker ~]# df -h
20 Filesystem                                                                                          Size  Used Avail Use% Mounted on
21 /dev/mapper/docker-253:0-16777839-60de86a769f75e2e96c849e76f1b3de10ac8c8d9985597ff3f758070edada54d   10G  682M  9.4G   7% /
22 tmpfs                                                                                                64M     0   64M   0% /dev
23 tmpfs                                                                                               497M     0  497M   0% /sys/fs/cgroup
24 none                                                                                                612G  242G  370G  40% /data
25 /dev/mapper/centos-root                                                                             8.4G  2.1G  6.3G  26% /etc/hosts
26 shm                                                                                                  64M     0   64M   0% /dev/shm
27 tmpfs                                                                                               497M     0  497M   0% /proc/scsi
28 tmpfs                                                                                               497M     0  497M   0% /sys/firmware

 

Ubuntu/Debian

$ yum install docker

Procedure

 

building an app the Docker way.

RedHat/CentOS

Then, use the following basic command to run a MySQL container:
1

$ docker run –name=test-mysql mysql

Yeap, that’s it. Just two steps. Here is what the second command line
does:
run – Run a command in a new container.
–name – Give a name to the container. If you don’t specify this, Docker
will generate a random name.
mysql – The image name as stated on the Docker Hub page. This is the
simplest image name. The standard is “username/image_name:tag”, for
example “severalnines/mysql:5.6”. In this case, we specified “mysql”,
which means it has no username (the image is built and maintained by
Docker, therefore no username), the image name is “mysql” and the tag is
latest (default). If the image does not exist, it will pull it first
from Docker Hub into the host, and then run the container.

You should then see the following lines:
1
2
3

Status: Downloaded newer image for mysql:latest
error: database is uninitialized and password option is not specified

You need to specify one of MYSQL_ROOT_PASSWORD,
MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD

It looks like the container deployment failed. Let’s verify with the
following command if there is any running container:
1

$ docker ps
There is no running container. Let’s show all containers (including the
non-running ones):
1
2
3

$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

80b4914976a2 mysql:latest “docker-entrypoint.s 6 minutes ago Exited (1)
6 minutes ago test-mysql

Under the ‘STATUS’ column, you can see the status was “Exited (1) 6
minutes ago”. If a program ended while returning a non-zero value, it
means that the program was terminated with some kind of error. So, what
happened? The MySQL image was successfully downloaded but Docker failed
to run it as container because the environment is not properly set up.
This is stated in the error lines.
Let’s try to fix this by specifying one of the environment variables:
1
2

$ docker run –name=test-mysql
–env=”MYSQL_ROOT_PASSWORD=mypassword”
mysql

FATA[0000] Error response from daemon: Conflict. The name
“test-mysql” is already in use by container 80b4914976a2. You have to
delete (or rename) that container to be able to reuse that name.

Oops, another error occurred. We were trying to run a new container with
the same name as an existing container. Let’s remove the created
container and run the command again:
1
2

$ docker rm test -mysql

$ docker run –name=test-mysql
–env=”MYSQL_ROOT_PASSWORD=mypassword”
mysql

You should see lots of lines appear. That’s MySQL initialization when
starting up as newly installed software. You should see MySQL is ready
to accept connections:
1
2

2016-06-01T12:06:59.543352Z 0 [Note] mysqld: ready for connections.
Version:’5.7.12′
socket:’/var/run/mysqld/mysqld.sock’
port: 3306 MySQL Community Server (GPL)

Looks good. Our MySQL container is now running. However, you are now
stuck in the terminal and can’t do anything because the container is
running in attach mode (running in foreground). This is so inconvenient.
We would expect MySQL to run as a service instead. Let’s consider this
as a failed deployment and stop the current container. In another
terminal, stop the running container and run it again in detach mode
(running as background):
1
2
3
4

$ docker stop test -mysql

$ docker rm test-mysql

$ docker run –detach –name=test-mysql
–env=”MYSQL_ROOT_PASSWORD=mypassword” mysql

a6b09a8d332a16e008cb3035ffd36bcd664886b79c9d2533c3dc1d47026a33a0
You will get an output of the container ID, indicating the container is
successfully running in the background. Let’s verify the status of the
container:
1
2
3

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

83285aa548ba mysql:latest “docker-entrypoint.s 4 minutes ago Up 4
minutes 3306/tcp test-mysql

MySQL container is now running and accessible on port 3306 of that
container. Since it was running in the background, we could not see what
was happening during the MySQL startup. Use the following command to see
what happened during the container startup:
1

$ docker logs test-mysql

Connecting to the Container
Next, we retrieve the IP address of that container in order to access
it. Run the inspect command:
1

$ docker inspect test-mysql

We can see lots of low-level information of that container. Lookup the
“IPAddress” line:1″IPAddress”:”172.17.0.20″,

From the physical host, we can now access the MySQL server. Ensure the
MySQL client package is installed beforehand:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

$ apt-get install mysql-client
$ mysql -uroot -pmypassword -h 172.17.0.20 -P 3306

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.12 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and /or
its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and /or its
affiliates. Other names may be trademarks of their respective
owners.

Type’help;’or’\h’forhelp. Type’\c’toclear the current input statement.

mysql>
Voila! We now have a MySQL instance running in a container. However,
this port is only accessible within the Docker network. If you have
another Docker container for your application, you can connect with them
directly via IP address 172.17.0.20 on port 3306, as illustrated in the
following diagram:

997755.com澳门葡京 5

Docker allocates a dynamic IP address on every running container.
Whenever a container is restarted, you will get a new IP address. You
can get the IP address range from the Docker network interface in the
Linux box. Run the following command to see Docker’s network range:
1
2

$ ip a |grep docker | grep
inet

inet 172.17.42.1
/16
scope global docker0

Our container’s IP address is 172.17.0.20 which is in the range of
172.17.42.1/16. Let’s restart the container, and you should get a new IP
address being assigned by Docker:
1
2
3
4

$ docker stop
test
-mysql

$ docker start
test
-mysql

$ docker inspect
test
-mysql |
grep
IPAddress

“IPAddress”
:
“172.17.0.21”
,

Our IP address just changed to 172.17.0.21. If you had an application
that connects to this container via the old IP address, the application
would not get connected anymore. Docker introduces another way to link
your container with another container, to ensure whatever IP address
assigned to it will get updated in the linked container. Let’s say we
deploy a WordPress application (which has no MySQL installed on that
image), and want to link with our existing MySQL container,
test-mysql. Here is what you should do:
1

$ docker run –detach –name
test
-wordpress –link
test
-mysql:mysql wordpress

In a couple of minutes, the container “test-wordpress” will be up and
running and linked to our test-mysql container:
1
2
3
4

$ docker
ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

0cb9f4152022 wordpress:latest “
/entrypoint
.sh apac 15 seconds ago Up 15 seconds 80
/tcp
test
-wordpress

0a7aa1cf196e mysql:latest “docker-entrypoint.s 16 minutes ago Up 16
minutes 3306
/tcp
test
-mysql

To verify if it’s linked correctly, enter the test-wordpress container
and look at the content of /etc/hosts:
1
2
3
4
5
6
7
8
9
10

$ docker
exec
-it
test
-wordpress
bash

root@0cb9f4152022:
/var/www/html

 

Download
and extract MySQL software.

We’ll start at the bottom of the hierarchy of such an app, which is a
container, which we cover on this page.

cat /etc/hosts

172.17.0.22 0cb9f4152022

127.0.0.1 localhost

::1 localhost ip6-localhost ip6-loopback

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

172.17.0.21 mysql 0a7aa1cf196e
test
-mysql

The application can now see an entry with IP address and hostname
related to the linked MySQL container. If you restart the MySQL
container and get another IP address, the entry will be updated by
Docker accordingly.

997755.com澳门葡京 6

You can also expose the MySQL container to the outside world by mapping
the container’s MySQL port to the host machine port using the publish
flag (as illustrated in the above diagram). Let’s re-initiate our
container and run it again with an exposed port:
1
2

$ docker
rm
-f
test
-mysql

$ docker run –detach –name=
test
-mysql —

    Let’s install docker and then
implement a MySQL server on it,here we go.

 1 [root@docker ~]# cd /vagrant/mysql_soft
 2 [root@docker mysql_soft]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
 3 [root@docker mysql_soft]# cd /opt/mysql
 4 [root@docker mysql]# ls -l
 5 total 1215644
 6 -rwxrwxrwx 1 1000 1000 641798603 Mar 18 21:32 mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
 7 -rwxrwxrwx 1 1000 1000 603019898 Jun 19 00:42 mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
 8 [root@docker mysql]# tar -zxf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz 
 9 tar: mysql-8.0.11-linux-glibc2.12-x86_64/lib/libcrypto.so: Cannot create symlink to `libcrypto.so.1.0.0': Protocol error
10 tar: mysql-8.0.11-linux-glibc2.12-x86_64/lib/libmysqlclient.so: Cannot create symlink to `libmysqlclient.so.21': Protocol error
11 tar: mysql-8.0.11-linux-glibc2.12-x86_64/lib/libmysqlclient.so.21: Cannot create symlink to `libmysqlclient.so.21.0.11': Protocol error
12 tar: mysql-8.0.11-linux-glibc2.12-x86_64/lib/libssl.so: Cannot create symlink to `libssl.so.1.0.0': Protocol error
13 tar: mysql-8.0.11-linux-glibc2.12-x86_64/lib/plugin/libssl.so.1.0.0: Cannot create symlink to `../../lib/libssl.so.1.0.0': Protocol error
14 tar: mysql-8.0.11-linux-glibc2.12-x86_64/lib/plugin/libcrypto.so.1.0.0: Cannot create symlink to `../../lib/libcrypto.so.1.0.0': Protocol error
15 tar: mysql-8.0.11-linux-glibc2.12-x86_64/lib/plugin/debug/libssl.so.1.0.0: Cannot create symlink to `../../../lib/libssl.so.1.0.0': Protocol error
16 tar: mysql-8.0.11-linux-glibc2.12-x86_64/lib/plugin/debug/libcrypto.so.1.0.0: Cannot create symlink to `../../../lib/libcrypto.so.1.0.0': Protocol error
17 tar: mysql-8.0.11-linux-glibc2.12-x86_64/bin/libssl.so.1.0.0: Cannot create symlink to `../lib/libssl.so.1.0.0': Protocol error
18 tar: mysql-8.0.11-linux-glibc2.12-x86_64/bin/libcrypto.so.1.0.0: Cannot create symlink to `../lib/libcrypto.so.1.0.0': Protocol error
19 tar: Exiting with failure status due to previous errors

Above this level is a service, which defines how containers behave in
production, covered in Part
3.

env

“MYSQL_ROOT_PASSWORD=mypassword”
–publish 6603:3306 mysql

Verify if the container is correctly mapped:
1
2
3

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

8d97b70658a9 mysql:latest “docker-entrypoint.s 3 seconds ago Up 3
seconds 0.0.0.0:6603->3306
/tcp
test
-mysql

0cb9f4152022 wordpress:latest “
/entrypoint
.sh apac 15 minutes ago Up 15 minutes 80
/tcp
test
-wordpress

At this point, we can now access the MySQL container directly from the
machine’s port 6603.
Configuration management
The container comes with a standard MySQL 5.7 configuration options
inside /etc/mysql/my.cnf. Let’s say our application that connects to
this MySQL server requires more max_connections (default is 151) during
startup, so we need to update the MySQL configuration file. The best way
to do this in a container is to create alternative configuration files
in a directory on the host machine and then mount that directory
location as /etc/mysql/conf.dinside the mysql container.
On the host machine, create a directory and a custom MySQL configuration
file:
1
2

$
mkdir
-p
/root/container/test-mysql/conf
.d

$ vim
/root/container/test-mysql/conf
.d
/my-custom
.cnf

And add the following lines:
1
2

[mysqld]

max_connections=200

Then, we have to re-initiate the MySQL container (remove and run) by
mapping the volume path as shown in the following command (the long
command is trimmed to make it more readable):
1
2
3
4
5
6
7

$ docker run \

–detach \

–name=
test
-mysql \

997755.com澳门葡京 ,–

 

 

Finally, at the top level is the stack, defining the interactions of all
the services, covered in Part
5.

env

“MYSQL_ROOT_PASSWORD=mypassword”
\

–publish 6603:3306 \

–volume=
/root/docker/test-mysql/conf
.d:
/etc/mysql/conf
.d \

mysql

This will start a new container test-mysql where the MySQL instance
uses the combined startup settings from the default /etc/mysql/my.cnf
and /etc/mysql/conf.d/my-custom.cnf, with settings from the latter
taking precedence.

997755.com澳门葡京 7

Verify the new setting is loaded from the machine host:
1
2
3
4
5
6

$ mysql -uroot -pmypassword -h127.0.0.1 -P6603 -e
‘show global variables like “max_connections”‘
;

+—————–+——-+

| Variable_name | Value |

+—————–+——-+

| max_connections | 200 |

+—————–+——-+

Many configuration options can also be passed as flags to mysqld. This
will give you the flexibility to customize the container without needing
a custom .cnf file. For example, if you want to change the max
connections similar to the above and collation for all tables to use
UTF-8 (utf8mb4), just run the following:
1
2
3
4
5
6
7
8
9

$ docker run \

–detach \

–name=
test
-mysql \

  1 ###Create a docker host named "docker" by vagrant.###
  2 $ vagrant up docker
  3 Bringing machine 'docker' up with 'virtualbox' provider...
  4 ==> docker: Importing base box 'CentOS7'...
  5 Progress: 30%
  6 ==> docker: Matching MAC address for NAT networking...
  7 ==> docker: Setting the name of the VM: Vagrant_docker_1529333111553_95525
  8 ==> docker: Clearing any previously set forwarded ports...
  9 ==> docker: Clearing any previously set network interfaces...
 10 ==> docker: Preparing network interfaces based on configuration...
 11     docker: Adapter 1: nat
 12     docker: Adapter 2: hostonly
 13 ==> docker: Forwarding ports...
 14     docker: 22 (guest) => 2222 (host) (adapter 1)
 15 ==> docker: Running 'pre-boot' VM customizations...
 16 ==> docker: Booting VM...
 17 ==> docker: Waiting for machine to boot. This may take a few minutes...
 18     docker: SSH address: 127.0.0.1:2222
 19     docker: SSH username: vagrant
 20     docker: SSH auth method: private key
 21     docker:
 22     docker: Vagrant insecure key detected. Vagrant will automatically replace
 23     docker: this with a newly generated keypair for better security.
 24     docker:
 25     docker: Inserting generated public key within guest...
 26     docker: Removing insecure key from the guest if it's present...
 27     docker: Key inserted! Disconnecting and reconnecting using new SSH key...
 28 ==> docker: Machine booted and ready!
 29 ==> docker: Checking for guest additions in VM...
 30     docker: The guest additions on this VM do not match the installed version of
 31     docker: VirtualBox! In most cases this is fine, but in rare cases it can
 32     docker: prevent things such as shared folders from working properly. If you see
 33     docker: shared folder errors, please make sure the guest additions within the
 34     docker: virtual machine match the version of VirtualBox you have installed on
 35     docker: your host and reload your VM.
 36     docker:
 37     docker: Guest Additions Version: 4.3.28
 38     docker: VirtualBox Version: 5.1
 39 ==> docker: Setting hostname...
 40 ==> docker: Configuring and enabling network interfaces...
 41     docker: SSH address: 127.0.0.1:2222
 42     docker: SSH username: vagrant
 43     docker: SSH auth method: private key
 44 ==> docker: Mounting shared folders...
 45     docker: /vagrant => E:/Vagrant
 46 
 47 [root@docker ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
 48 -- Omitted.
 49 
 50 Installed:
 51   yum-utils.noarch 0:1.1.31-45.el7                                                                                                                   
 52 
 53 Dependency Installed:
 54   libxml2-python.x86_64 0:2.9.1-6.el7_2.3            python-chardet.noarch 0:2.2.1-1.el7_1            python-kitchen.noarch 0:1.1.1-5.el7           
 55 
 56 Updated:
 57   device-mapper-persistent-data.x86_64 0:0.7.3-3.el7                                   lvm2.x86_64 7:2.02.177-4.el7                                  
 58 
 59 Dependency Updated:
 60   device-mapper.x86_64 7:1.02.146-4.el7          device-mapper-event.x86_64 7:1.02.146-4.el7     device-mapper-event-libs.x86_64 7:1.02.146-4.el7    
 61   device-mapper-libs.x86_64 7:1.02.146-4.el7     libxml2.x86_64 0:2.9.1-6.el7_2.3                lvm2-libs.x86_64 7:2.02.177-4.el7                   
 62   python-urlgrabber.noarch 0:3.10-8.el7          rpm.x86_64 0:4.11.3-32.el7                      rpm-build-libs.x86_64 0:4.11.3-32.el7               
 63   rpm-libs.x86_64 0:4.11.3-32.el7                rpm-python.x86_64 0:4.11.3-32.el7               yum.noarch 0:3.4.3-158.el7.centos
 64 
 65 ###Add repo of docker of aliyun.###
 66 [root@docker ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
 67 Loaded plugins: fastestmirror
 68 adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
 69 grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
 70 repo saved to /etc/yum.repos.d/docker-ce.repo
 71 [root@docker ~]# 
 72 
 73 ###Create metadata cache.###
 74 [root@docker ~]# yum makecache fast
 75 Loaded plugins: fastestmirror
 76 base                                                                                                                          | 3.6 kB  00:00:00     
 77 docker-ce-stable                                                                                                              | 2.9 kB  00:00:00     
 78 extras                                                                                                                        | 3.4 kB  00:00:00     
 79 updates                                                                                                                       | 3.4 kB  00:00:00     
 80 docker-ce-stable/x86_64/primary_db                                                                                            |  13 kB  00:00:00     
 81 Loading mirror speeds from cached hostfile
 82  * base: mirrors.shu.edu.cn
 83  * extras: ftp.sjtu.edu.cn
 84  * updates: mirrors.shu.edu.cn
 85 Metadata Cache Created
 86 
 87 ###Install docker from repo.###
 88 [root@docker ~]# yum -y install docker-ce
 89 Loaded plugins: fastestmirror
 90 Loading mirror speeds from cached hostfile
 91  * base: mirrors.shu.edu.cn
 92  * extras: ftp.sjtu.edu.cn
 93  * updates: mirrors.shu.edu.cn
 94 Resolving Dependencies
 95 --> Running transaction check
 96 ---> Package device-mapper-persistent-data.x86_64 0:0.4.1-2.el7 will be updated
 97 ---> Package device-mapper-persistent-data.x86_64 0:0.7.3-3.el7 will be an update
 98 ---> Package lvm2.x86_64 7:2.02.115-3.el7 will be updated
 99 ---> Package lvm2.x86_64 7:2.02.177-4.el7 will be an update
100 --> Processing Dependency: lvm2-libs = 7:2.02.177-4.el7 for package: 7:lvm2-2.02.177-4.el7.x86_64
101 --> Processing Dependency: libdevmapper.so.1.02(DM_1_02_97)(64bit) for package: 7:lvm2-2.02.177-4.el7.x86_64
102 --> Processing Dependency: libdevmapper.so.1.02(DM_1_02_141)(64bit) for package: 7:lvm2-2.02.177-4.el7.x86_64
103 --> Processing Dependency: libdevmapper.so.1.02(DM_1_02_138)(64bit) for package: 7:lvm2-2.02.177-4.el7.x86_64
104 --> Processing Dependency: libdevmapper.so.1.02(DM_1_02_135)(64bit) for package: 7:lvm2-2.02.177-4.el7.x86_64
105 --> Processing Dependency: libdevmapper.so.1.02(DM_1_02_133)(64bit) for package: 7:lvm2-2.02.177-4.el7.x86_64
106 --> Processing Dependency: libdevmapper.so.1.02(DM_1_02_128)(64bit) for package: 7:lvm2-2.02.177-4.el7.x86_64
107 --> Processing Dependency: libdevmapper.so.1.02(DM_1_02_113)(64bit) for package: 7:lvm2-2.02.177-4.el7.x86_64
108 --> Processing Dependency: libdevmapper.so.1.02(DM_1_02_110)(64bit) for package: 7:lvm2-2.02.177-4.el7.x86_64
109 --> Processing Dependency: libdevmapper.so.1.02(DM_1_02_107)(64bit) for package: 7:lvm2-2.02.177-4.el7.x86_64
110 --> Processing Dependency: libdevmapper.so.1.02(DM_1_02_104)(64bit) for package: 7:lvm2-2.02.177-4.el7.x86_64
111 --> Processing Dependency: libdevmapper.so.1.02(DM_1_02_103)(64bit) for package: 7:lvm2-2.02.177-4.el7.x86_64
112 --> Processing Dependency: libdevmapper.so.1.02(DM_1_02_101)(64bit) for package: 7:lvm2-2.02.177-4.el7.x86_64
113 --> Processing Dependency: libdevmapper.so.1.02(DM_1_02_100)(64bit) for package: 7:lvm2-2.02.177-4.el7.x86_64
114 ---> Package yum-utils.noarch 0:1.1.31-45.el7 will be installed
115 
116 -- Omitted.
117 
118 Installed:
119   docker-ce.x86_64 0:18.03.1.ce-1.el7.centos -- The lastest version of docker CE is 18.03.1 
120 
121 Dependency Installed:
122   audit-libs-python.x86_64 0:2.8.1-3.el7                checkpolicy.x86_64 0:2.5-6.el7             container-selinux.noarch 2:2.55-1.el7            
123   libcgroup.x86_64 0:0.41-15.el7                        libseccomp.x86_64 0:2.3.1-3.el7            libsemanage-python.x86_64 0:2.5-11.el7           
124   libtool-ltdl.x86_64 0:2.4.2-22.el7_3                  lz4.x86_64 0:1.7.5-2.el7                   pigz.x86_64 0:2.3.3-1.el7.centos                 
125   policycoreutils-python.x86_64 0:2.5-22.el7            python-IPy.noarch 0:0.75-6.el7             setools-libs.x86_64 0:3.3.8-2.el7                
126 
127 Updated:
128   centos-release.x86_64 0:7-5.1804.el7.centos.2              dracut.x86_64 0:033-535.el7              initscripts.x86_64 0:9.49.41-1.el7             
129 
130 Dependency Updated:
131   audit.x86_64 0:2.8.1-3.el7                 audit-libs.x86_64 0:2.8.1-3.el7                 dracut-config-rescue.x86_64 0:033-535.el7               
132   dracut-network.x86_64 0:033-535.el7        glib2.x86_64 0:2.54.2-2.el7                     kmod.x86_64 0:20-21.el7                                 
133   libgudev1.x86_64 0:219-57.el7              libselinux.x86_64 0:2.5-12.el7                  libselinux-devel.x86_64 0:2.5-12.el7                    
134   libselinux-python.x86_64 0:2.5-12.el7      libselinux-ruby.x86_64 0:2.5-12.el7             libselinux-utils.x86_64 0:2.5-12.el7                    
135   libsemanage.x86_64 0:2.5-11.el7            libsepol.x86_64 0:2.5-8.1.el7                   libsepol-devel.x86_64 0:2.5-8.1.el7                     
136   policycoreutils.x86_64 0:2.5-22.el7        selinux-policy.noarch 0:3.13.1-192.el7_5.3      selinux-policy-targeted.noarch 0:3.13.1-192.el7_5.3     
137   systemd.x86_64 0:219-57.el7                systemd-libs.x86_64 0:219-57.el7                systemd-sysv.x86_64 0:219-57.el7                        
138 
139 Complete!
140 
141 ###Check docker detail version.###
142 [root@docker ~]# docker version
143 Client:
144  Version:      18.03.1-ce
145  API version:  1.37
146  Go version:   go1.9.5
147  Git commit:   9ee9f40
148  Built:        Thu Apr 26 07:20:16 2018
149  OS/Arch:      linux/amd64
150  Experimental: false
151  Orchestrator: swarm
152 Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
153 [root@docker ~]# 
154 
155 ###Create a docker daemon config file.###
156 [root@docker docker]# pwd
157 /etc/docker
158 [root@docker docker]# vim daemon.json
159 [root@docker docker]# cat daemon.json 
160 {
161 "registry-mirrors": [ "https://registry.docker-cn.com"]
162 }
163 
164 ###Start docker service and list infomations.###
165 [root@docker docker]# systemctl start docker
166 [root@docker docker]# docker info
167 Containers: 0
168  Running: 0
169  Paused: 0
170  Stopped: 0
171 Images: 0
172 Server Version: 18.03.1-ce
173 Storage Driver: devicemapper
174  Pool Name: docker-253:0-16777839-pool
175  Pool Blocksize: 65.54kB
176  Base Device Size: 10.74GB
177  Backing Filesystem: xfs
178  Udev Sync Supported: true
179  Data file: /dev/loop0
180  Metadata file: /dev/loop1
181  Data loop file: /var/lib/docker/devicemapper/devicemapper/data
182  Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
183  Data Space Used: 11.8MB
184  Data Space Total: 107.4GB
185  Data Space Available: 7.6GB
186  Metadata Space Used: 581.6kB
187  Metadata Space Total: 2.147GB
188  Metadata Space Available: 2.147GB
189  Thin Pool Minimum Free Space: 10.74GB
190  Deferred Removal Enabled: true
191  Deferred Deletion Enabled: true
192  Deferred Deleted Device Count: 0
193  Library Version: 1.02.146-RHEL7 (2018-01-22)
194 Logging Driver: json-file
195 Cgroup Driver: cgroupfs
196 Plugins:
197  Volume: local
198  Network: bridge host macvlan null overlay
199  Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
200 Swarm: inactive
201 Runtimes: runc
202 Default Runtime: runc
203 Init Binary: docker-init
204 containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
205 runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
206 init version: 949e6fa
207 Security Options:
208  seccomp
209   Profile: default
210 Kernel Version: 3.10.0-229.el7.x86_64
211 Operating System: CentOS Linux 7 (Core)
212 OSType: linux
213 Architecture: x86_64
214 CPUs: 1
215 Total Memory: 993.6MiB
216 Name: docker
217 ID: 4GY3:Q2FL:P4DD:HOFN:WFJZ:RDAV:GMJA:RDFF:VTAS:VW6D:TSC6:LCSC
218 Docker Root Dir: /var/lib/docker
219 Debug Mode (client): false
220 Debug Mode (server): false
221 Registry: https://index.docker.io/v1/
222 Labels:
223 Experimental: false
224 Insecure Registries:
225  127.0.0.0/8
226 Registry Mirrors:
227  https://registry.docker-cn.com/
228 Live Restore Enabled: false
229 
230 WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use.
231          Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
232 WARNING: bridge-nf-call-iptables is disabled
233 WARNING: bridge-nf-call-ip6tables is disabled
234 
235 ###Load image of CentOS7.###
236 [root@docker docker]# docker image
237 
238 Usage:    docker image COMMAND
239 
240 Manage images
241 
242 Options:
243 
244 
245 Commands:
246   build       Build an image from a Dockerfile
247   history     Show the history of an image
248   import      Import the contents from a tarball to create a filesystem image
249   inspect     Display detailed information on one or more images
250   load        Load an image from a tar archive or STDIN
251   ls          List images
252   prune       Remove unused images
253   pull        Pull an image or a repository from a registry
254   push        Push an image or a repository to a registry
255   rm          Remove one or more images
256   save        Save one or more images to a tar archive (streamed to STDOUT by default)
257   tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
258 
259 Run 'docker image COMMAND --help' for more information on a command.
260 [root@docker docker]# docker images
261 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
262 [root@docker docker]# cd /vagrant
263 [root@docker vagrant]# ls -l
264 total 1887022
265 -rwxrwxrwx 1 vagrant vagrant 498180608 Mar 13 16:19 centos-7.0-x86_64.box
266 -rwxrwxrwx 1 vagrant vagrant     15080 Mar 21 18:42 epel-release-latest-7.noarch.rpm
267 drwxrwxrwx 1 vagrant vagrant      4096 Mar 18 16:42 masterha
268 -rwxrwxrwx 1 vagrant vagrant     87119 Nov  7  2014 mha4mysql-manager-0.56-0.el6.noarch.rpm
269 -rwxrwxrwx 1 vagrant vagrant    113914 Nov  7  2014 mha4mysql-manager-0.56.tar.gz
270 -rwxrwxrwx 1 vagrant vagrant    118521 Mar 11 18:36 mha4mysql-manager-0.57.tar.gz
271 -rwxrwxrwx 1 vagrant vagrant     36326 Nov  7  2014 mha4mysql-node-0.56-0.el6.noarch.rpm
272 -rwxrwxrwx 1 vagrant vagrant     50172 Nov  4  2014 mha4mysql-node-0.56.tar.gz
273 -rwxrwxrwx 1 vagrant vagrant     54484 Mar 11 18:36 mha4mysql-node-0.57.tar.gz
274 drwxrwxrwx 1 vagrant vagrant      4096 Jun  2 16:23 MyFlash-master
275 -rwxrwxrwx 1 vagrant vagrant   2339403 Jun  1 16:15 MyFlash-master.zip
276 drwxrwxrwx 1 vagrant vagrant      8192 May  3 17:22 MySQL
277 -rwxrwxrwx 1 vagrant vagrant 641798603 Mar 18 14:32 mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
278 drwxrwxrwx 1 vagrant vagrant      4096 Jun  8 15:57 mysqlbinlog_flashback-master
279 -rwxrwxrwx 1 vagrant vagrant    299829 Jun  8 15:41 mysqlbinlog_flashback-master.zip
280 -rwxrwxrwx 1 vagrant vagrant   4720640 Jun  8 16:57 pip-10.0.1.tar
281 -rwxrwxrwx 1 vagrant vagrant     74297 Jun  8 17:06 PyMySQL-0.8.1.tar.gz
282 -rwxrwxrwx 1 vagrant vagrant  59238400 Jun  8 16:17 Python-2.6.9.tar
283 drwxrwxrwx 1 vagrant vagrant      4096 Jun  8 17:18 setuptools-39.2.0
284 -rwxrwxrwx 1 vagrant vagrant    851112 Jun  8 17:17 setuptools-39.2.0.zip
285 -rwxrwxrwx 1 vagrant vagrant      4140 Jun 18 16:43 Vagrantfile
286 -rwxrwxrwx 1 vagrant vagrant    540672 Apr 19 14:21 zabbix-3.0.16.tar.gz
287 -rwxrwxrwx 1 vagrant vagrant 723758592 Jun 13 17:08 zst_centos7-201806.tar
288 [root@docker vagrant]# docker image load < zst_centos7-201806.tar 
289 129b697f70e9: Loading layer [==================================================>]  205.1MB/205.1MB
290 e17a43dfd99e: Loading layer [==================================================>]  20.09MB/20.09MB
291 81230abc4426: Loading layer [==================================================>]  2.802MB/2.802MB
292 a70f1502766b: Loading layer [==================================================>]  3.584kB/3.584kB
293 4c4dfc844006: Loading layer [==================================================>]  6.656kB/6.656kB
294 49fde8c22696: Loading layer [==================================================>]  6.144kB/6.144kB
295 3fe67ade2cc6: Loading layer [==================================================>]  3.072kB/3.072kB
296 eeb315c508b1: Loading layer [==================================================>]  77.82kB/77.82kB
297 0439f8e04051: Loading layer [==================================================>]  8.704kB/8.704kB
298 ec476b61f06f: Loading layer [==================================================>]  13.82kB/13.82kB
299 9f752899cdce: Loading layer [==================================================>]  5.632kB/5.632kB
300 027f1ff8b124: Loading layer [==================================================>]  3.584kB/3.584kB
301 f9b50836c42f: Loading layer [==================================================>]   5.12kB/5.12kB
302 2f68f3a1869a: Loading layer [==================================================>]   89.6kB/89.6kB
303 61f05bc1691a: Loading layer [==================================================>]  495.2MB/495.2MB
304 24d441f4dab8: Loading layer [==================================================>]  191.5kB/191.5kB
305 Loaded image ID: sha256:7d0b68af5a06e04c2713dab89a293dc1b1dff5ccbaab8235e97cbc9cff7db2cb
306 [root@docker vagrant]# docker images
307 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
308 <none>              <none>              7d0b68af5a06        5 days ago          694MB
309 
310 ###Add a tag for repository.###
311 [root@docker vagrant]# docker tag 7d0b68af5a06 CentOS7
312 Error parsing reference: "CentOS7" is not a valid repository/tag: invalid reference format: repository name must be lowercase
313 [root@docker vagrant]# docker tag 7d0b68af5a06 centos7 - Change the repository name into lowercase.
314 [root@docker vagrant]# docker images
315 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
316 centos7             latest              7d0b68af5a06        6 days ago          694MB
317 [root@docker vagrant]#
318 
319 ###Check whether there're running containers.###
320 [root@docker vagrant]# docker ps -a
321 CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
322 [root@docker vagrant]#
323 
324 ###Start a container with dependency of directory themselves.###
325 [root@docker vagrant]# mkdir mysql_soft
326 [root@docker vagrant]# mkdir data1
327 [root@docker vagrant]# docker run -d -v /vagrant/mysql_soft:/opt/mysql -v /vagrant/data1:/data -v /etc/hosts:/etc/hosts -p2222:22  --cap-add=NET_ADMIN  --name node1 -h docker centos7
328 9ff260da9643d7b8243668699760d7a64d3f797a1cd2a9bc2562f11e9790dcc7
329 [root@docker vagrant]# df -h
330 Filesystem               Size  Used Avail Use% Mounted on
331 /dev/mapper/centos-root  8.4G  2.1G  6.3G  26% /
332 devtmpfs                 488M     0  488M   0% /dev
333 tmpfs                    497M     0  497M   0% /dev/shm
334 tmpfs                    497M  6.7M  491M   2% /run
335 tmpfs                    497M     0  497M   0% /sys/fs/cgroup
336 /dev/sda1                497M  118M  379M  24% /boot
337 none                     612G  243G  369G  40% /vagrant
338 tmpfs                    100M     0  100M   0% /run/user/0
339 /dev/dm-3                 10G  682M  9.4G   7% /var/lib/docker/devicemapper/mnt/fe5e6b5cf3f15ebcd2a1d0805919d1858b789b37a2f5d1c31af771072e812334
340 shm                       64M     0   64M   0% /var/lib/docker/containers/9ff260da9643d7b8243668699760d7a64d3f797a1cd2a9bc2562f11e9790dcc7/mounts/shm
341 [root@docker vagrant]# docker ps -a
342 CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                    PORTS                  NAMES
343 9ff260da9643        centos7             "/usr/bin/supervisor…"   14 seconds ago      Up 13 seconds (healthy)   0.0.0.0:2222->22/tcp   node1
344 
345 ###Check the IP of docker "node1".###
346 [root@docker vagrant]# docker inspect node1 | grep IPAddress
347             "SecondaryIPAddresses": null,
348             "IPAddress": "172.17.0.2",
349                     "IPAddress": "172.17.0.2",
350 
351 ###Login docker "node1".###
352 [root@docker vagrant]# ssh root@172.17.0.2
353 The authenticity of host '172.17.0.2 (172.17.0.2)' can't be established.
354 ECDSA key fingerprint is 1c:3a:48:00:26:63:1f:5b:6d:82:bf:0a:4d:df:03:cc.
355 Are you sure you want to continue connecting (yes/no)? yes
356 Warning: Permanently added '172.17.0.2' (ECDSA) to the list of known hosts.
357 root@172.17.0.2's password: 
358 Last login: Wed Jun 13 00:18:11 2018 from 172.17.0.1
359 [root@docker ~]# df -h
360 Filesystem                                                                                          Size  Used Avail Use% Mounted on
361 /dev/mapper/docker-253:0-16777839-fe5e6b5cf3f15ebcd2a1d0805919d1858b789b37a2f5d1c31af771072e812334   10G  682M  9.4G   7% /
362 tmpfs                                                                                                64M     0   64M   0% /dev
363 tmpfs                                                                                               497M     0  497M   0% /sys/fs/cgroup
364 none                                                                                                612G  243G  369G  40% /data
365 /dev/mapper/centos-root                                                                             8.4G  2.1G  6.3G  26% /etc/hosts
366 shm                                                                                                  64M     0   64M   0% /dev/shm
367 tmpfs                                                                                               497M     0  497M   0% /proc/scsi
368 tmpfs                                                                                               497M     0  497M   0% /sys/firmware

Check
absent “libxxx.so” then install them untill there’re no “not found”
results.

  • Stack
  • Services
  • Container (you are here)

env

“MYSQL_ROOT_PASSWORD=mypassword”
\

–publish 6603:3306 \

mysql \

–max-connections=200 \

–character-
set
-server=utf8mb4 \

–collation-server=utf8mb4_unicode_ci

Data Storage
There are several ways to store data used by MySQL that run in Docker
containers. Docker can manage the storage of your database’s data by
writing the database files to disk on the host system, using its own
internal volume management. If you run the inspect command, look at the
“Volumes” directive and you should notice by default MySQL data
directory (/var/lib/mysql) is mounted into Docker’s internal volume:
1
2
3
4
5
6

$ docker inspect
test
-mysql

“Volumes”
: {

“/etc/mysql/conf.d”
:
“/root/docker/test-mysql/conf.d”
,

“/var/lib/mysql”
:
“/var/lib/docker/vfs/dir/4d437e2fe5ab2f71ffeea2590d72a417a9ca88607c130b46f5ad819d0a5b68cd”

}

This is the easiest way and fairly transparent to the user. The downside
is that the files may be hard to locate for tools and applications that
run directly on the host system, i.e. outside containers.
The other way is to create a data directory on the host system (outside
the container) and mount this to a directory visible from inside the
container. This places the database files in a known location on the
host system, and makes it easy for tools and applications on the host
system to access the files. The downside is that the user needs to make
sure that the directory exists, and that e.g. directory permissions and
other security mechanisms on the host system are correctly set up.
Create a data directory on a suitable volume on your host system, e.g.
/storage/docker/mysql-datadir:
1

$
mkdir
-p
/storage/docker/mysql-datadir

Start your mysql container like this:
1
2
3
4
5
6
7
8

$ docker run –detach –name=test-mysql
–env=”MYSQL_ROOT_PASSWORD=mypassword”
–publish 6603:3306
–volume=/root/docker/test-mysql/conf.d:
/etc/mysql/conf
.d

–volume=
/storage/docker/mysql-datadir
:
/var/lib/mysql
\

mysql

The ”–volume=/storage/docker/mysql-datadir:/var/lib/mysql“ part of the
command mounts the/storage/docker/mysql-datadir directory from the
underlying host system as /var/lib/mysql inside the container, where
MySQL by default will write its data files, as illustrated in the
following diagram:

997755.com澳门葡京 8

When inspecting the container, you should see the following lines:
1
2
3
4
5
6

$ docker inspect test-mysql

“Volumes”
: {
“/etc/mysql/conf.d”
:
“/root/docker/test-mysql/conf.d”
,
“/var/lib/mysql”
:
“/storage/docker/mysql-datadir”
}

Which is now clearer for you to see the directory and files on the
machine host created by this container:
1
2
3
4
5
6
7
8
9
10
11
12
13

$ls -al /storage/docker/mysql-datadir/

total 188452

drwxr-xr-x 5 999 999 4096 Jun 3 10:13 .

drwxr-xr-x 3 root root 4096 Jun 3 10:06 ..

-rw-r—– 1 999 999 56 Jun 3 10:13 auto.cnf

-rw-r—– 1 999 999 1329 Jun 3 10:13 ib_buffer_pool

-rw-r—– 1 999 999 79691776 Jun 3 10:13 ibdata1

-rw-r—– 1 999 999 50331648 Jun 3 10:13 ib_logfile0

-rw-r—– 1 999 999 50331648 Jun 3 10:13 ib_logfile1

-rw-r—– 1 999 999 12582912 Jun 3 10:13 ibtmp1

drwxr-x— 2 999 999 4096 Jun 3 10:13 mysql

drwxr-x— 2 999 999 4096 Jun 3 10:13 performance_schema

drwxr-x— 2 999 999 12288 Jun 3 10:13 sys

Note that restarting or removing the container does not remove the MySQL
data directory. When you restart a MySQL container by using “stop” and
“start” command, it would be similar to restarting the MySQL service in
a standard installation:
1
2

$ docker stop test-mysql

$ docker start test -mysql

If you remove the MySQL container, the data in the mounted volumes will
still be intact and you can run a new instance, mounting the same volume
as data directory:
1
2

$ docker rm -f test-mysql

$ docker run -d –name=new-mysql -p 6604:3306
-v/storage/docker/mysql-datadir:/var/lib/mysql mysql

*If a MySQL container runs on top of an existing MySQL datadir, the
$MYSQL_ROOT_PASSWORD variable should be omitted from the “run” command
line; it will in any case be ignored, and the pre-existing database will
not be changed in any way.
However, only one running (active) container is allowed to access the
MySQL data directory at a time. Running another container mounting the
same datadir volume will cause MySQL startup error on the later
container:
1
2
3
4
5
6
7
8
9

$ docker run -d –name=another-new-mysql -p 6605:3306
-v/storage/docker/mysql-datadir:/var/lib/mysql mysql

$ docker logs another-new-mysql

2016-06-10T07:16:59.538635Z 0 [Note] InnoDB: Completed initialization
of buffer pool

2016-06-10T07:16:59.540373Z 0 [Note] InnoDB: If the mysqld execution
user is authorized, page cleaner thread priority can be changed. See
the
man
page of setpriority().

2016-06-10T07:16:59.551646Z 0 [ERROR] InnoDB: Unable to lock .
/ibdata1
error: 11

2016-06-10T07:16:59.551656Z 0 [Note] InnoDB: Check that you
do
not already have another mysqld process using the same InnoDB data or
log files.

2016-06-10T07:16:59.551659Z 0 [Note] InnoDB: Retrying to lock the
first data
file

2016-06-10T07:17:00.552294Z 0 [ERROR] InnoDB: Unable to lock .
/ibdata1
error: 11

2016-06-10T07:17:00.552364Z 0 [Note] InnoDB: Check that you
do
not already have another mysqld process using the same InnoDB data or
log files.

This is expected since a MySQL process must exclusively own the MySQL
data directory to avoid any potential conflicts. Having more than one
mysqld process connecting to the same data directory is just not
feasible. That’s why MySQL horizontal scaling can only be achieved via
replication.
That concludes this blog. Do share your experience in managing MySQL
containers in the comments section below.

 

 1 [root@docker mysql]# ldd /usr/local/mysql/bin/mysqld.sh
 2 ldd: /usr/local/mysql/bin/mysqld.sh: No such file or directory
 3 [root@docker mysql]# ldd /usr/local/mysql/bin/mysqld
 4     linux-vdso.so.1 =>  (0x00007fff57cca000)
 5     libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f57bc85d000)
 6     libaio.so.1 => not found
 7     libnuma.so.1 => not found
 8     libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f57bc625000)
 9     libssl.so.1.0.0 => not found
10     libcrypto.so.1.0.0 => not found
11     libdl.so.2 => /lib64/libdl.so.2 (0x00007f57bc420000)
12     librt.so.1 => /lib64/librt.so.1 (0x00007f57bc217000)
13     libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f57bbf10000)
14     libm.so.6 => /lib64/libm.so.6 (0x00007f57bbc0e000)
15     libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f57bb9f7000)
16     libc.so.6 => /lib64/libc.so.6 (0x00007f57bb62a000)
17     /lib64/ld-linux-x86-64.so.2 (0x00007f57bca7f000)
18     libfreebl3.so => /lib64/libfreebl3.so (0x00007f57bb427000)
19 [root@docker mysql]# yum install -y libaio numactl libssl libcrypto
20 -- Omitted
21 [root@docker mysql]# ldd /usr/local/mysql/bin/mysqld
22     linux-vdso.so.1 =>  (0x00007fff05f82000)
23     libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fc18aca3000)
24     libaio.so.1 => /lib64/libaio.so.1 (0x00007fc18aaa0000)
25     libnuma.so.1 => /lib64/libnuma.so.1 (0x00007fc18a894000)
26     libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fc18a65d000)
27     libssl.so.1.0.0 => not found
28     libcrypto.so.1.0.0 => not found
29     libdl.so.2 => /lib64/libdl.so.2 (0x00007fc18a458000)
30     librt.so.1 => /lib64/librt.so.1 (0x00007fc18a24f000)
31     libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fc189f48000)
32     libm.so.6 => /lib64/libm.so.6 (0x00007fc189c46000)
33     libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fc189a2f000)
34     libc.so.6 => /lib64/libc.so.6 (0x00007fc189662000)
35     /lib64/ld-linux-x86-64.so.2 (0x00007fc18aec5000)
36     libfreebl3.so => /lib64/libfreebl3.so (0x00007fc18945f000)
37 [root@docker mysql]# find / -name libssl.so.1.0.0
38 /opt/mysql/mysql-8.0.11-linux-glibc2.12-x86_64/lib/libssl.so.1.0.0
39 [root@docker mysql]# cp /opt/mysql/mysql-8.0.11-linux-glibc2.12-x86_64/lib/libssl.so.1.0.0 /usr/lib64
40 [root@docker mysql]# find / -name libcrypto.so.1.0.0
41 /opt/mysql/mysql-8.0.11-linux-glibc2.12-x86_64/lib/libcrypto.so.1.0.0
42 [root@docker mysql]# cp /opt/mysql/mysql-8.0.11-linux-glibc2.12-x86_64/lib/libcrypto.so.1.0.0 /usr/lib64
43 [root@docker mysql]# ldd /usr/local/mysql/bin/mysqld
44     linux-vdso.so.1 =>  (0x00007fff13ffe000)
45     libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f156dbc3000)
46     libaio.so.1 => /lib64/libaio.so.1 (0x00007f156d9c0000)
47     libnuma.so.1 => /lib64/libnuma.so.1 (0x00007f156d7b4000)
48     libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f156d57d000)
49     libssl.so.1.0.0 => /lib64/libssl.so.1.0.0 (0x00007f156d30d000)
50     libcrypto.so.1.0.0 => /lib64/libcrypto.so.1.0.0 (0x00007f156cf25000)
51     libdl.so.2 => /lib64/libdl.so.2 (0x00007f156cd21000)
52     librt.so.1 => /lib64/librt.so.1 (0x00007f156cb18000)
53     libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f156c811000)
54     libm.so.6 => /lib64/libm.so.6 (0x00007f156c50f000)
55     libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f156c2f8000)
56     libc.so.6 => /lib64/libc.so.6 (0x00007f156bf2b000)
57     /lib64/ld-linux-x86-64.so.2 (0x00007f156dde5000)
58     libfreebl3.so => /lib64/libfreebl3.so (0x00007f156bd28000)

 

Summary

 

development environment

In the past, if you were to start writing a Python app, your first order
of business was to install a Python runtime onto your machine. But, that
creates a situation where the environment on your machine has to be just
so in order for your app to run as expected; ditto for the server that
runs your app.

With Docker, you can just grab a portable Python runtime as an image, no
installation necessary. Then, your build can include the base Python
image right alongside your app code, ensuring that your app, its
dependencies, and the runtime, all travel together.

These portable images are defined by something called a Dockerfile.

 

 

Dockerfile will
define what goes on in the environment inside your container.

Access to resources like networking interfaces and disk drives is
virtualized inside this environment, which is isolated from the rest of
your system, so you have to map ports to the outside world, and be
specific about what files you want to “copy in” to that environment.
However, after doing that, you can expect that the build of your app
defined in this Dockerfile will behave exactly the same wherever it
runs.

# Use an official Python runtime as a parent image
FROM python:2.7-slim

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80

# Define environment variable
ENV NAME World

# Run app.py when the container launches
CMD ["python", "app.py"]

Proxy servers can block connections to your web app once it’s up and
running. If you are behind a proxy server, add the following lines to
your Dockerfile, using the ENV command to specify the host and port
for your proxy servers:

# Set proxy server, replace host:port with values for your servers
ENV http_proxy host:port
ENV https_proxy host:port

 

 

  • The docker has been installed
    properly.Now all the newly added container can share the contents
    and diskspace in directory “/vagrant” on host
    “docker”.
  • You don’t need to to copy MySQL db
    software to each of your node anymore now.
  • As soon as you copy a file to
    “/vagrant”,it will appear in the container’s dierctory “/opt/mysql”
    and the free diskspace depends on your diskspace of physical
    machine.
    Does it convenient?I’m afraid it
    really does.**

Make
required directory and create soft link.

The app itself

Create two more files, requirements.txt and app.py, and put them in
the same folder with the Dockerfile. This completes our app, which as
you can see is quite simple. When the above Dockerfile is built into
an image, app.py andrequirements.txt will be present because of
that Dockerfile’s ADD command, and the output from app.py will be
accessible over HTTP thanks to the EXPOSE command.

 

1 [root@docker mysql]# mkdir -p /data/mysql/mysql3306/{data,logs,tmp}
2 [root@docker mysql]# ln -sv /opt/mysql/mysql-8.0.11-linux-glibc2.12-x86_64 /usr/local/mysql
3 ‘/usr/local/mysql’ -> ‘/opt/mysql/mysql-8.0.11-linux-glibc2.12-x86_64’

requirements.txt

Flask
Redis

 

app.py

from flask import Flask
from redis import Redis, RedisError
import os
import socket

# Connect to Redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)

app = Flask(__name__)

@app.route("/")
def hello():
    try:
        visits = redis.incr("counter")
    except RedisError:
        visits = "<i>cannot connect to Redis, counter disabled</i>"

    html = "<h3>Hello {name}!</h3>" \
           "<b>Hostname:</b> {hostname}<br/>" \
           "<b>Visits:</b> {visits}"
    return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80)

 we see that pip install -r requirements.txt installs the Flask and
Redis libraries for Python, and the app prints the environment
variable NAME, as well as the output of a call
to socket.gethostname(). Finally, because Redis isn’t running (as
we’ve only installed the Python library, and not Redis itself), we
should expect that the attempt to use it here will fail and produce the
error message.

 Accessing the name of the host when inside a container retrieves the
container ID, which is like the process ID for a running executable.

That’s it! You don’t need Python or anything in requirements.txt on
your system, nor will building or running this image install them on
your system. It doesn’t seem like you’ve really set up an environment
with Python and Flask, but you have.

 

 

 

Create
mysql group & user.

Build the app

We are ready to build the app. Make sure you are still at the top level
of your new directory. Here’s what ls should show:

$ ls
Dockerfile      app.py          requirements.txt

Now run the build command. This creates a Docker image, which we’re
going to tag using -t so it has a friendly name

docker build -t friendlyhello .

Where is your built image? It’s in your machine’s local Docker image
registry:

 

$ docker images

REPOSITORY            TAG                 IMAGE ID
friendlyhello         latest              326387cea398

 

 

1 [root@docker mysql]# userdel mysql
2 [root@docker mysql]# groupadd mysql
3 [root@docker mysql]# useradd -g mysql -s /sbin/nologin -d /usr/local/mysql -MN mysql

Run the app

Run the app, mapping your machine’s port 4000 to the container’s
published port 80 using -p:

docker run -p 4000:80 friendlyhello

ou should see a message that Python is serving your app
at http://0.0.0.0:80. But that message is coming from inside the
container, which doesn’t know you mapped port 80 of that container to
4000, making the correct URL http://localhost:4000.

 If you are using Docker Toolbox on Windows 7, use the Docker Machine IP
instead of localhost. For example, . To
find the IP address, use the command docker-machine ip.

You can also use the curl command in a shell to view the same content.

$ curl http://localhost:4000

<h3>Hello World!</h3><b>Hostname:</b> 8fc990912a14<br/><b>Visits:</b> <i>cannot connect to Redis, counter disabled</i>

This port remapping of 4000:80 is to demonstrate the difference
between what you EXPOSE within the Dockerfile, and what
you publish using docker run -p. In later steps, we’ll just map port
80 on the host to port 80 in the container and use http://localhost.

 

Hit CTRL+C in your terminal to quit.

On Windows, explicitly stop the container

On Windows systems, CTRL+C does not stop the container. So, first
type CTRL+C to get the prompt back (or open another shell), then
typedocker container ls to list the running containers, followed
bydocker container stop <Container NAME or ID> to stop the container.
Otherwise, you’ll get an error response from the daemon when you try to
re-run the container in the next step.

 

 run the app in the background, in detached mode:

docker run -d -p 4000:80 friendlyhello

 

You get the long container ID for your app and then are kicked back to
your terminal. Your container is running in the background. You can also
see the abbreviated container ID with docker container ls (and both
work interchangeably when running commands):

$ docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED
1fa4ab2cf395        friendlyhello       "python app.py"     28 seconds ago

You’ll see that CONTAINER ID matches what’s
on http://localhost:4000.

 

use docker container stop to end the process, using
the CONTAINER ID, like so:

docker container stop 1fa4ab2cf395

  

 

 

 

 

Share your image

how to push to registries when you want to deploy containers to
production.

upload our built image and run it somewhere else.

A registry is a collection of repositories, and a repository is a
collection of images—sort of like a GitHub repository, except the code
is already built. An account on a registry can create many repositories.
The docker CLI uses Docker’s public registry by default.

We’ll be using Docker’s public registry here just because it’s free and
pre-configured, but there are many public ones to choose from, and you
can even set up your own private registry using Docker Trusted
Registry.

Modify
directory privilege.

Log in with your Docker ID 

If you don’t have a Docker account, sign up for one
at cloud.docker.com. Make note of your
username.

Log in to the Docker public registry on your local machine.

$ docker login
1 [root@docker mysql]# cd /usr/local
2 [root@docker local]# chown -R mysql.mysql mysql

Tag the image

The notation for associating a local image with a repository on a
registry isusername/repository:tag

 The tag is optional, but recommended, since it is the mechanism that
registries use to give Docker images a version. Give the repository and
tag meaningful names for the context,

such as get-started:part2. This will put the image in
the get-started repository and tag it as part2.

put it all together to tag the image. Run docker tag image with your
username, repository, and tag names so that the image will upload to
your desired destination. The syntax of the command is:

docker tag image username/repository:tag
docker tag friendlyhello john/get-started:part2

Run docker
images to
see your newly tagged image. (You can also use docker image ls.)

$ docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
friendlyhello            latest              d9e555c53008        3 minutes ago       195MB
john/get-started         part2               d9e555c53008        3 minutes ago       195MB
python                   2.7-slim            1c7128a655f6        5 days ago          183MB
...

 

Publish the image

Upload your tagged image to the repository:

docker push username/repository:tag

Once complete, the results of this upload are publicly available. If you
log in to Docker Hub, you will see the new
image there, with its pull command.

Modify
environment variable.

Pull and run the image from the remote repository

use docker run and run your app on any machine with this command:

If the image isn’t available locally on the machine, Docker will pull it
from the repository.“

docker run -p 4000:80 username/repository:tag

$ docker run -p 4000:80 john/get-started:part2
Unable to find image 'john/get-started:part2' locally
part2: Pulling from john/get-started
10a267c67f42: Already exists
f68a39a6a5e4: Already exists
9beaffc0cf19: Already exists
3c1fe835fb6b: Already exists
4c9f1fa8fcb8: Already exists
ee7d8f576a14: Already exists
fbccdcced46e: Already exists
Digest: sha256:0601c866aab2adcc6498200efd0f754037e909e5fd42069adeff72d1e2439068
Status: Downloaded newer image for john/get-started:part2
 * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)

No matter where docker run executes, it pulls your image, along with
Python and all the dependencies from requirements.txt, and runs your
code. It all travels together in a neat little package, and the host
machine doesn’t have to install anything but Docker to run it.

 

 

 

 

docker build -t friendlyname .  # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyname  # Run "friendlyname" mapping port 4000 to 80
docker run -d -p 4000:80 friendlyname         # Same thing, but in detached mode
docker container ls                                # List all running containers
docker container ls -a             # List all containers, even those not running
docker container stop <hash>           # Gracefully stop the specified container
docker container kill <hash>         # Force shutdown of the specified container
docker container rm <hash>        # Remove specified container from this machine
docker container rm $(docker container ls -a -q)         # Remove all containers
docker image ls -a                             # List all images on this machine
docker image rm <image id>            # Remove specified image from this machine
docker image rm $(docker image ls -a -q)   # Remove all images from this machine
docker login             # Log in this CLI session using your Docker credentials
docker tag <image> username/repository:tag  # Tag <image> for upload to registry
docker push username/repository:tag            # Upload tagged image to registry
docker run username/repository:tag                   # Run image from a registry

  

1 [root@docker local]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> ~/.bash_profile
2 [root@docker local]# source ~/.bash_profile
3 [root@docker local]# echo $PATH
4 /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

 

Prepare a
suitable my.cnf in docker and then copy it to specific path.

1 [root@docker local]# cp /opt/mysql/my.cnf /data/mysql/mysql3306/my3306.cnf

 

Initialize
MySQL db.

[root@docker local]# mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf --initialize
mysqld: [Warning] World-writable config file '/data/mysql/mysql3306/my3306.cnf' is ignored.
2018-06-23T16:26:39.446641Z 0 [System] [MY-013169] [Server] mysqld (mysqld 8.0.11) initializing of server in progress as process 20451
2018-06-23T16:26:39.528638Z 0 [ERROR] [MY-010338] [Server] Can't find error-message file '/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2018-06-23T16:26:39.804315Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2018-06-23T16:26:39.804363Z 0 [ERROR] [MY-010119] [Server] Aborting
2018-06-23T16:26:40.010408Z 0 [System] [MY-010910] [Server] mysqld: Shutdown complete (mysqld 8.0.11)  MySQL Community Server - GPL.
[root@docker ~]# cd /data/mysql/mysql3306/data -- There're no files in the directory,why does it show the existent error?Let's see below.
[root@docker data]# ls -la
total 4
drwxrwxrwx 1 mysql mysql    0 Jun 19 03:24 .
drwxrwxrwx 1 mysql mysql 4096 Jun 24 00:38 ..

 

I
change the way of initialization.

1 [root@docker data]# mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3306/data --user=mysql --initialize
2 2018-06-23T17:04:01.792594Z 0 [System] [MY-013169] [Server] mysqld (mysqld 8.0.11) initializing of server in progress as process 12261
3 2018-06-23T17:04:01.887954Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /data/mysql/mysql3306/data/ is case insensitive
4 mbind: Operation not permitted
5 2018-06-23T17:04:12.669761Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: o/>k*hqxn1T=
6 2018-06-23T17:04:16.807974Z 0 [System] [MY-013170] [Server] mysqld (mysqld 8.0.11) initializing of server has completed
7 [root@docker etc]# ps aux | grep mysqld
8 root     13712  0.0  0.0  10692   976 pts/1    SN+  01:06   0:00 grep --color=auto mysqld

 

Start
mysqld but failed.

 1 [root@docker etc]# mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf &
 2 [1] 14145
 3 [root@docker etc]# mysqld: [Warning] World-writable config file '/data/mysql/mysql3306/my3306.cnf' is ignored.
 4 2018-06-23T17:06:54.345108Z 0 [System] [MY-010116] [Server] mysqld (mysqld 8.0.11) starting as process 14145
 5 2018-06-23T17:06:54.346090Z 0 [ERROR] [MY-010338] [Server] Can't find error-message file '/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
 6 2018-06-23T17:06:54.357718Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /data/ is case insensitive
 7 2018-06-23T17:06:54.358228Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
 8 2018-06-23T17:06:54.358263Z 0 [ERROR] [MY-010119] [Server] Aborting
 9 2018-06-23T17:06:54.362713Z 0 [System] [MY-010910] [Server] mysqld: Shutdown complete (mysqld 8.0.11)  MySQL Community Server - GPL.
10 ^C
11 [1]+  Exit 1                  mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf

 

The
my3306.cnf cannot be world-writable,so I copy it to “/tmp” and start
mysqld again.

 1 [root@docker etc]# cp /data/mysql/mysql3306/my3306.cnf /tmp
 2 [root@docker etc]# cd /tmp
 3 [root@docker tmp]# ls -l | grep my3306.cnf
 4 -rwxr-xr-x 1 root root 9672 Jun 24 01:10 my3306.cnf
 5 [root@docker tmp]# mysqld --defaults-file=/tmp/my3306.cnf &
 6 [1] 16816
 7 [root@docker tmp]# ps aux | grep mysqld
 8 root     16926  0.0  0.0  10692   976 pts/1    SN+  01:11   0:00 grep --color=auto mysqld
 9 [1]+  Exit 1                  mysqld --defaults-file=/tmp/my3306.cnf
10 [root@docker etc]# tail /data/mysql/mysql3306/data/error.log
11 2018-06-24T01:11:03.732865+08:00 0 [Warning] [MY-010086] [Server] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
12 2018-06-24T01:11:03.735145+08:00 0 [Warning] [MY-010097] [Server] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
13 2018-06-24T01:11:03.736465+08:00 0 [System] [MY-010116] [Server] mysqld (mysqld 8.0.11) starting as process 16816
14 mbind: Operation not permitted
15 2018-06-24T01:11:04.184074+08:00 1 [ERROR] [MY-012263] [InnoDB] InnoDB: The Auto-extending innodb_system data file './ibdata1' is of a different size 768 pages (rounded down to MB) than specified in the .cnf file: initial 6400 pages, max 0 (relevant if non-zero) pages!
16 2018-06-24T01:11:04.184868+08:00 1 [ERROR] [MY-012930] [InnoDB] InnoDB: Plugin initialization aborted with error Generic error.
17 2018-06-24T01:11:04.810086+08:00 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
18 2018-06-24T01:11:04.810840+08:00 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
19 2018-06-24T01:11:04.810961+08:00 0 [ERROR] [MY-010119] [Server] Aborting
20 2018-06-24T01:11:04.828841+08:00 0 [System] [MY-010910] [Server] mysqld: Shutdown complete (mysqld 8.0.11)  MySQL Community Server - GPL.

 

It
still has problem ’cause size of “./ibdata1” is incompatible with the
parameter in “my3306.cnf”.

1 [root@docker data]# ls -l ibdata1
2 -rwxrwxrwx 1 mysql mysql 12582912 Jun 24 01:04 ibdata1
3 [root@docker data]# cat /tmp/my3306.cnf | grep innodb_data_file_path
4 innodb_data_file_path                           =ibdata1:100M:autoextend    #    ibdata1:12M:autoextend
5 [root@docker data]# vim /tmp/my3306.cnf | grep innodb_data_file_path
6 [root@docker data]# cat /tmp/my3306.cnf | grep innodb_data_file_path
7 innodb_data_file_path                           =ibdata1:12M:autoextend    #    ibdata1:12M:autoextend

 

After
I started mysqld several seconds later,the process down again at
once.

 1 [root@docker etc]# mysqld --defaults-file=/tmp/my3306.cnf &
 2 [1] 4761
 3 [root@docker etc]# ps aux|grep mysqld
 4 mysql     4761 38.0  3.1 474908 32152 pts/1    SNl  01:42   0:01 mysqld --defaults-file=/tmp/my3306.cnf
 5 root      4808  0.0  0.0  10692   972 pts/1    SN+  01:42   0:00 grep --color=auto mysqld
 6 [root@docker etc]# ps aux|grep mysqld
 7 root      6964  0.0  0.0  10692   972 pts/1    SN+  01:45   0:00 grep --color=auto mysqld
 8 [root@docker etc]# 
 9 [root@docker data]# tail -10 error.log
10 2018-06-24T01:42:30.177384+08:00 0 [Warning] [MY-010097] [Server] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
11 2018-06-24T01:42:30.179005+08:00 0 [System] [MY-010116] [Server] mysqld (mysqld 8.0.11) starting as process 4761
12 mbind: Operation not permitted
13  100
14  100
15  100
16 2018-06-24T01:42:33.215591+08:00 1 [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('2').
17 2018-06-24T01:42:33.216211+08:00 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
18 2018-06-24T01:42:33.216289+08:00 0 [ERROR] [MY-010119] [Server] Aborting
19 2018-06-24T01:42:34.839683+08:00 0 [System] [MY-010910] [Server] mysqld: Shutdown complete (mysqld 8.0.11)  MySQL Community Server - GPL.

 

*The
error shows that the value is not equal between
lower_case_table_names” and dictionary.*

1 [root@docker data]# cat /opt/mysql/my.cnf|grep lower_case_table_names
2 lower_case_table_names              =1                              #    0
3 [root@docker data]# cat /tmp/my3306.cnf | grep lower_case_table_names
4 lower_case_table_names              =1                              #    0
5 [root@docker data]# vim /tmp/my3306.cnf 
6 [root@docker data]# cat /tmp/my3306.cnf | grep lower_case_table_names
7 lower_case_table_names              =2                              #    0

 

After
I’ve modified my3306.cnf,it seems no error occurs now.

 1 [root@docker data]# tail -10 error.log
 2 2018-06-24T01:53:20.035831+08:00 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.infoschema@localhost' ignored in --skip-name-resolve mode.
 3 2018-06-24T01:53:20.035971+08:00 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
 4 2018-06-24T01:53:20.036064+08:00 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
 5 2018-06-24T01:53:20.036160+08:00 0 [Warning] [MY-010315] [Server] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
 6 2018-06-24T01:53:20.036898+08:00 0 [Warning] [MY-010323] [Server] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
 7 2018-06-24T01:53:20.037083+08:00 0 [Warning] [MY-010323] [Server] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
 8 2018-06-24T01:53:20.037268+08:00 0 [Warning] [MY-010311] [Server] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
 9 2018-06-24T01:53:20.042517+08:00 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
10 2018-06-24T01:53:20.042646+08:00 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
11 2018-06-24T01:53:20.099046+08:00 0 [System] [MY-010931] [Server] mysqld: ready for connections. Version: '8.0.11'  socket: '/tmp/mysql.sock'  port: 3306  MySQL Community Server - GPL.
12 [root@docker etc]# ps aux|grep mysqld
13 mysql    11812  2.0  9.3 1148688 95244 pts/1   SNl  01:53   0:01 mysqld --defaults-file=/tmp/my3306.cnf
14 root     12514  0.0  0.0  10692   972 pts/1    SN+  01:54   0:00 grep --color=auto mysqld

 

Start
mysql client and modify the password generated by
initialization.

 1 [root@docker etc]# mysql
 2 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
 3 [root@docker etc]# mysql -p
 4 Enter password: -- Use the password which generated by initialization(here is "o/>k*hqxn1T=")
 5 Welcome to the MySQL monitor.  Commands end with ; or \g.
 6 Your MySQL connection id is 9
 7 Server version: 8.0.11
 8 
 9 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
10 
11 Oracle is a registered trademark of Oracle Corporation and/or its
12 affiliates. Other names may be trademarks of their respective
13 owners.
14 
15 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
16 
17 mysql> show databases;
18 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
19 mysql> alter user root@localhost identified by 'Passw0rd';
20 Query OK, 0 rows affected (0.11 sec)
21 
22 mysql> show databases;
23 +--------------------+
24 | Database           |
25 +--------------------+
26 | information_schema |
27 | mysql              |
28 | performance_schema |
29 | sys                |
30 +--------------------+
31 4 rows in set (0.20 sec)
32 
33 mysql>

 

Summary

  • ldd can be used to check if mysqld is
    missing “libxxx.so” file.Then you can install or copy directly into
    “/usr/lib64” directory.
  • There’re many errors in my
    installation procedure due to inappropriate parameters.
  • Because of the vagrant,all the shared
    directories in docker contains also has the 777 privilege what cause
    the world-writable issue.
  • Since MySQL 5.7,password of
    root@localhost must be changed while first login.Otherwise,you can
    do nothing at all.

 

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*
*
Website