Docker stack deployment MySQL 5.6

Source: Internet
Author: User
Tags docker ps docker swarm

===============================================

2018/7/1_ the 1th time to modify Ccb_warlock

===============================================

MySQL has a very tight relationship as a common relational database and project. Because of the frequent need to build temporary MySQL services, and the temporary build mostly just to temporarily checkpoint data, and normal Yum or Apt-get installation needs to download a lot of time, and also need to roll back the cleanup environment from the perspective of the virtual machine snapshot. The recent attempt to use Docker for rapid deployment has made it feel very lightweight and clean for non-stress-loaded environments through Docker mode.

Due to technical capabilities and company business constraints, did not try to container MySQL load capacity, according to some feedback that the performance of the MySQL container itself is far less than the cloud server vendors provide MySQL services (here I understand that the individual is only the MySQL container but did not do all aspects of optimization, Performance is far from meeting the requirements of the production environment, so the container deployment of MySQL is only for internal use, not enough capacity to optimize or not rush to the production environment.

MySQL By default is to turn off remote access, recently did not have time to test the deployment of direct remote access, the current tutorial also need to connect to the MySQL container inside to configure, late in the empty I will fill in the missing content.

I. Pre-conditions

    • Docker Swarm (http://www.cnblogs.com/straycats/p/8978135.html) has been deployed in the environment
    • Preferably also deployed Portainer (http://www.cnblogs.com/straycats/p/8978201.html)
    • Server ip:192.168.12.11 for default deployment
    • The default swarm creates Network:myswarm-net

Ii. deployment of MySQL containers (5.6)

2.1 Creating a mapping Directory

Mkdir-p/usr/docker-vol/mysql/data

2.2 Configuring MYSQL-STACK.YML

# Edit Mysql-stack.yml

Vi/root/mysql-stack.yml

# Add the following content to Mysq-stack.yml, Wq save

Version: ' 3.6' Services:mysql:image:mysql:5.6.40Environment:#set the time zone to Asia/shanghai-tz=asia/Shanghai-mysql_root_password=123456volumes:-/usr/docker-vol/mysql/data:/var/lib/MySQL Deploy:replicas:1restart_policy:condition:any Resources:limits:cpus:"0.2"memory:512m update_config:parallelism:1#Update 1 copies at a timeDelay:5s#each update intervalMonitor:10s#how long a single update does not end to determine that the update failedmax_failure_ratio:0.1#maximum failure rate that can be tolerated when updatingOrder:start-first#Update order for new task start priorityPorts:-3,306:3,306Networks:-myswarm-Netnetworks:myswarm-net:external:true

2.3 Deployment of service stacks

1) Command mode

Cddocker Stack deploy-c mysql-stack.yml mysql-stack

2) Portainer interface mode (recommended)

Login Portainer (if the Portainer is deployed according to the tutorial above, the browser accesses http://Host ip:9000 to add the contents of the Mysql-stack.yml file in the stack)

Third, configure MySQL to allow remote IP access

The official image and installation in Linux configuration, the initial only allow local services to access MySQL, need to adjust the configuration of MySQL to achieve the purpose of remote connection. (as stated earlier, the current scenario is not very reasonable and will need to be optimized in the future)

# Get Container ID

Docker PS

Find Mysql-stack _mysql.******************* 's container ID (I'm here for 0d66abc8ce32)

# Enter the container

Docker exec-it 0d66abc8ce32/bin/bash

# Log in to MySQL

Mysql-uroot-p

Enter the initialized root password 123456 login.

# Enter MySQL Library

mysql> use MySQL;

# settings allow root user to access MySQL via any IP

Mysql> Grant all privileges  "123456";

# make the configuration take effect immediately

mysql> flush Privileges;

# quit MySQL

Mysql> exit

# Exit Container

Exit

Then use the Navicat connection 192.168.12.11:3306, username/password: root/123456, the connection is successful, indicating that the MySQL container is ready to use.

Docker stack deployment MySQL 5.6

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.