In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The secret of the text is that it is relevant to the topic when it comes to how to run a MySQL service in a DOCKER container. So, instead of gossiping, let's go straight to the following, and I'm sure you'll benefit from reading this article on how to run MySQL services in a DOCKER container.
The virtual machine uses VBOX,VBOX to configure two networks, one is HOST ONLY and the other is NAT, which ensures that the virtual machine can connect locally and externally at the same time.
The installation of the operating system CentOS7.5,docker is relatively simple, you can refer to the online instructions:
1. Uninstall the lower version of docker in the system first
# yum remove docker\
Docker-client\
Docker-client-latest\
Docker-common\
Docker-latest\
Docker-latest-logrotate\
Docker-logrotate\
Docker-selinux\
Docker-engine-selinux\
Docker-engine
two。 Install the necessary system tools
# yum install-y yum-utils device-mapper-persistent-data lvm2
3. Add the source of Aliyun (http is used for the address in some documents, resulting in the failure of adding the source. It should be noted that the source address is currently using https protocol)
# yum-config-manager-- add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4. Update the yum cache
# yum makecache fast
5. Install the docker-ce version
# yum-y install docker-ce
6. Configure the docker service to start itself and start the docker service
# systemctl enable docker
# systemctl start docker
7. At this point, the docker configuration is complete. Execute docker info and view the information of docker.
# docker info
Containers: 3
Running: 0
Paused: 0
Stopped: 3
Images: 3
Server Version: 18.06.1-ce
Storage Driver: overlay2
8. Download CENTOS's latest docker image
# docker search centos
# docker pull centos
[root@mysqldb ~] # docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Centos latest 75835a67d134 4 weeks ago 200MB
Let's start configuring the necessary network and directory information on the physical host.
1. Host creates a mysql directory
[root@mysqldb mysql] # cd / mysql/skydb/
[root@mysqldb skydb] # mkdir skydb1
[root@mysqldb skydb] # cd skydb1/
[root@mysqldb skydb1] # mkdir {data,log,binlog,tmp,script,etc}
two。 Host creates a container private network (you only need to create it once)
The network is created to facilitate the use of fixed IP addresses in the docker container.
[root@mysqldb] # docker network create-- subnet=172.168.56.0/16 skynet
[root@mysqldb ~] # docker network ls
3. Start the centos docker container
[root@mysqldb ~] #
Docker run-id-- name skydb1\
-v / mysql/mysql/mysql-5.7.24:/opt/mysql5.7\
-v / mysql/skydb/skydb1:/mysqldata\
-v / etc/hosts:/etc/hosts\
-- net skynet-- ip 172.168.56.10-- hostname skydb1 centos
-- name skydb1 specifies the name of the docker container
-v / etc/hosts:/etc/hosts specifies the mapping of local files to files inside the docker container
-- net skynet specifies the virtual network of docker
-- ip 172.168.56.10 fixed docker container ip address
-- hostname skydb1 specifies the hostname of the docker container
The binary installation package used by MySQL is extracted to the host and mapped to the docker container through file mapping.
The following is the download address of the installation media for 5.7 and 8.0:
Wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
Wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
4. Connect containers (connected by container name and ID)
[root@mysqldb ~] # docker exec-it skydb1 bash-c ". / root/.bash_profile & & / bin/bash"
To make the login information more eye-catching, specify banner `hostname` in / root/.bash_profile to facilitate the identification of docker container hosts.
5. Create a file link
[root@skydb1 ~] # cd / usr/local/
[root@skydb1 local] # ln-s / opt/mysql5.7/. / mysql
[root@skydb1 local] # ln-s / opt/mysql5.7/bin/mysql / usr/local/bin/mysql
[root@skydb1 script] # ln-s / mysqldata/script/my.cnf / etc/my.cnf
6. Through ldd, check whether the mysqld program contains all the dynamic libraries
[root@skydb1 ~] # ldd / usr/local/mysql/bin/mysqld
7. Docker container, install the necessary software packages
[root@skydb1 ~] # yum install libaio
[root@skydb1 ~] # yum install numactl
[root@skydb1 ~] # yum install iproute
[root@skydb1 ~] # yum install net-tools
8. Create an installation user and modify directory permissions
[root@skydb1 ~] # groupadd mysql
[root@skydb1] # useradd-g mysql-d / home/mysql-s / sbin/nologin-MN mysql
[root@skydb1 local] # cd / mysqldata/
[root@skydb1 mysqldata] # chown-R mysql:mysql. /
9. Initialize mysql in the docker container
[root@skydb1] # / usr/local/mysql/bin/mysqld-- initialize
[root@skydb1] # / usr/local/mysql/bin/mysqld &
10. View the default root password
[root@skydb1 ~] # cd / mysqldata/log
[root@skydb1 log] # cat skydb1.err | grep pass
2018-11-06T05:27:43.361600-00:00 1 [Note] A temporary password is generated for root@localhost: / dJt?sq62OlF
11. Modify root user password
[root@skydb1] # / usr/local/mysql/bin/mysql-S / mysqldata/tmp/skydb1.sock-uroot-p
Mysql > set global super_read_only=0
Mysql > set global read_only=0
Mysql > alter user user () identified by 'oracle'
Mysql > flush privileges
twelve。 Configure local automatic login
[root@skydb1 script] # cat my.cnf
[client]
Port = 3306
Socket = / mysqldata/tmp/skydb1.sock
User = root
Password = oracle
[root@skydb1 script] # mysql
13. Authorize root users to connect remotely
Root@localhost [mysql] > GRANT ALL PRIVILEGES ON *. * TO root@ "172.168.56.%" IDENTIFIED BY "oracle"
Root@localhost [mysql] > GRANT ALL PRIVILEGES ON *. * TO root@ "172.168.0.1" IDENTIFIED BY "oracle"
Root@localhost [(mysql)] > flush privileges
[root@mysqldb] # mysql-uroot-h 172.168.56.10-p
[root@mysqldb] # mycli-u root-h 172.168.56.10
14. Start, stop and log in docker container
[root@mysqldb ~] # docker ps
[root@mysqldb ~] # docker stop skydb1
[root@mysqldb ~] # docker start skydb1
[root@mysqldb ~] # docker exec-it skydb1 bash-c ". / root/.bash_profile & & / bin/bash"
Is there anything you don't understand about the above operation method of running the MySQL service in the DOCKER container? Or if you want to know more about it, you can continue to follow our industry information section.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.