Huawei Cloud Yaoyun Server L Instance Evaluation | Best Practices for Enterprise Projects: Docker Deployment and Application (7)

Huawei Cloud Yaoyun Server L instance evaluation | Enterprise project best practice series:

Huawei Cloud Yaoyun Server L Instance Evaluation|Introduction to Cloud Server Best Practices for Enterprise Projects (1)
Huawei Cloud Yaoyun Server L Instance Evaluation|Best Practices for Enterprise Projects Huawei Cloud Introduction (2)
Huawei Cloud Yaoyun Server L Instance Evaluation | Enterprise Project Best Practices Huawei Cloud Yaoyun Server L Instance Introduction (3)
Huawei Cloud Yaoyun Server L Instance Evaluation | Best Practices for Enterprise Projects: Yunyao Cloud Server L Instance Purchase (4)
Huawei Cloud Yaoyun Server L Instance Evaluation | Evaluation of Best Practices for Enterprise Projects Use Case (5)
Huawei Cloud Yaoyun Server L Instance Evaluation|Enterprise Project Best Practice Package Management Tool Installation Software (6)
Huawei Cloud Yaoyun Server L instance evaluation | Enterprise project best practices for docker deployment and application (7)
Huawei Cloud Yaoyun Server L instance evaluation | Enterprise project best practices for private library construction verdaccio (8) a>
Huawei Cloud Yaoyun Server L Instance Evaluation|Enterprise Project Best Practices for Starting the Pet Reservation Project (9)
Huawei Cloud Yaoyun Server L Instance Evaluation|Enterprise Project Best Practice Best Practices of Scheduled Tasks and Queue Queue Practice (10)
Huawei Cloud Yaoyun Server L Instance Evaluation | Best Practices of Enterprise Projects Stress Test (11)
Huawei Cloud Yaoyun Server L instance evaluation | Suggestions and summary of best practices for enterprise projects (12)


8. Huawei Cloud Server L instance docker and docker-compose installation and deployment of MySQL and Redis applications:

With the development of cloud native, containerization, microservices, K8S and other technologies, the container docker is gradually being used extensively in the practice of enterprise teams. It can provide a set of standardized solutions, which greatly improves the efficiency of deployment, release, operation and maintenance.

The following is the K8S cloud server cluster currently used by a business line cluster of the company:

Insert image description here
K8S related deployment files:
Insert image description here


1. What is a container:

Containers are built-in capabilities of the operating system kernel. They are lightweight, high-performance resource isolation mechanisms based on the Linux kernel. Docker is one of the container technologies. The core is to realize the overall packaging of applications and operating environments and the unification of packaging formats. Docker uses Linux Container technology. Packaging turns an app into a standardized, portable, self-managing component.

Insert image description here

Container key value:
①. Rapid delivery and deployment: one-stop deployment/operation and maintenance of container applications, one-click rolling upgrade.
②. Improve resource utilization: divide resources in a more fine-grained manner to improve resource utilization.
③. Ensure high business availability: elastic expansion within seconds and quick response to concurrency peaks.
④. Simple management of complex systems: A single heavy-duty application is decoupled and split into multiple lightweight modules. Each module is more flexible in upgrading and scaling, and can easily respond to market changes.

2. Typical application scenarios of Docker:

Insert image description here


3. Install docker:

Check that docker is not installed by default. Here we directly use the official command to install docker. You can see that the network address of Huawei Cloud is also used, and the installation speed is very fast.

# 安装docker程序
sudo apt-get install -y docker.io

Insert image description here

After docker is installed, you can check the docker version and whether it runs normally using simple docker commands.

# 查看docker的版本
docker -v
# 查看当前docker运行的容器
docker ps
# 查看当前docker下载的镜像image
docker images

Insert image description here


4. Docker builds MySQL 5.7 container:

Insert image description here

# 拉取mysql镜像
docker pull mysql:5.7
# 启动一个mysql容器
docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7 --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
# 查看正在运行的容器
docker ps
# 查看所有的镜像
docker images

Insert image description here


5. Docker builds Redis container:

Insert image description here

# 拉取redis镜像
docker pull redis
# 启动一个redis容器
docker run --name redis-server -p 6379:6379 -d redis
# 查看正在运行的容器
docker ps
# 查看所有的镜像
docker images
# 进入redis容器
docker exec -it 容器id /bin/bash

Insert image description here


6. Install docker-compose:

docker-compose is a docker tool used to define a docker tool for running complex applications. This tool can be used to manage containers easily and efficiently. Multiple docker containers can be managed through a configuration file.

Docker Compose can be used to manage containers easily and efficiently. In the configuration file, all containers are defined by services, and then the docker-compose script is used to start, stop and restart the application, the services in the application and all containers that depend on the service. With one command, you can create and start all services from the YML file configuration, which is very suitable for scenarios where multiple containers are combined for development.

Insert image description here

Pull the corresponding program from github. Many times, the network times out. If you do not have network problems, you can try the following installation solutions:

sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Insert image description here

Find other solutions and use pip to install docker-compose.

# pip安装docker-compose
sudo pip install docker-compose
# 查看版本
docker-compose -v

Insert image description here


7. docker-compose builds MySQL and Redis containers:

.env file:

MYSQL_DATABASE=huawei
MYSQL_USER=root
MYSQL_PASSWORD=123456
MYSQL_ROOT_PASSWORD=root
MYSQL_DIR=./mysql
MYSQL_PORT=3306
MYSQL_VERSION=5.7

docker-compose.yml file:

version: '3'

networks:
  node-network:
    driver: bridge

services:
  ### Reids Container #######################################
  redis:
    image: redis
    container_name: redis-docker
    ports:
      - 6379:6379
    environment:
      TZ: Asia/Shanghai
    networks:
      - node-network

  ### mysql Container ###########################
  mysql:
    restart: always
    build:
      context: ./mysql
      args:
        - MYSQL_VERSION=${
    
    MYSQL_VERSION}
    # 指定容器的名称
    container_name: mysql-docker
    # 使container内的root拥有真正的root权限,否则,container内的root只是外部的一个普通用户权限
    # 有可能数据卷可能挂载不了,启动不起
    privileged: true
    command: --innodb-use-native-aio=0
    environment:
      MYSQL_DATABASE: ${
    
    MYSQL_DATABASE}             # 指定一个数据库,在容器启动时创建.
      # 创建一个新用户,这个用户在MYSQL_DATABASE指定的数据库上拥有超级用户权限
      MYSQL_USER: ${
    
    MYSQL_USER}
      MYSQL_PASSWORD: ${
    
    MYSQL_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${
    
    MYSQL_ROOT_PASSWORD}
    volumes:
      - "${MYSQL_DIR}/data:/var/lib/mysql"           # 挂载数据目录
      - "${MYSQL_DIR}/logs:/var/lib/mysql-logs"      # 挂载日志目录
    ports:
      # 将容器的3306映射到本地3306,前面是本地端口
      - "${MYSQL_PORT}:3306"

Insert image description here
Destroy the container:Insert image description here

# 启动MySQL和Redis容器
docker-compose up -d redis mysql
# 查看容器
docker ps
# 销毁容器
docker down

8. Use "Navicat Premium" to connect to the MySQL server. There are two options for connection:

serial number Connection scheme
1 Use local SSH to connect to the Huawei Cloud Server L instance server, and then connect to the local host to connect to the MySQL server.
2 Open the server's external network port 3306 and directly use the IP + port of the Huawei Cloud Server L instance server to connect.

Insert image description here

In the security group of the Huawei Cloud Server L instance, add the rules as follows, enable the external network restriction rule of 3306, and access the internal port of the Huawei Cloud Server L instance from the external network.

Insert image description here
Insert image description here
Insert image description here


9. Connect to the Redis server using:

Redis Desktop Manager (RDM) is a graphical interface tool for managing and operating Redis databases. It provides a simple and easy-to-use interface, allowing users to easily perform various Redis database operations, and supports connections to multiple Redis servers.

In the security group, open port 6379.
Insert image description here

Use IP + port to connect to the redis instance.
Insert image description here

Perform redis key operations.

Insert image description here


10. Summary:

Docker can run containers based on different Linux distributions on a single host that shares the same kernel space. For example, if you run RHEL, CentOS, and SUSE-based containers on an Ubuntu server, only the user space is different and the kernel space is the same. You can build containers or clusters for MySQL, Redis, and Nginx.

Insert image description here

By installing docker and docker-compose on the Huawei Cloud Server L instance, and then deploying MySQL and Redis containers, no containers that did not meet the needs were found. During the installation process, the default download speed of Huawei Cloud Source was very fast. , is worth recommending.

Insert image description here

The following is a list of installed software:

Insert image description here

The following is the overall test progress of software installation and deployment:

Insert image description here

Guess you like

Origin blog.csdn.net/wanmeijuhao/article/details/133810398