Tars docker simple deployment

Docker deployment service development environment

2.1 creating docker virtual network

In order to facilitate the deployment of dockers in various environments such as virtual machines, Mac and Linux hosts, in this example, first create a virtual network to simulate the real LAN Intranet environment (note that dockers are still on the same machine, but the virtual ip of dockers is different, simulating multiple machines)

# Create a bridge virtual network named tars, with gateway 172.25.0.1 and network segment 172.25.0.0
docker network create -d bridge --subnet=172.25.0.0/16 --gateway=172.25.0.1 tars

2.2 start MySQL

  • Provide MySQL services for framework operation. If the host or existing MySQL is used, you can skip this step. It is recommended that the framework and application use different MySQL services.
  • Note the IP and root passwords of MySQL, which need to be used in subsequent builds
docker run -d -p 3306:3306 \
    --net=tars \
    -e MYSQL_ROOT_PASSWORD="123456" \
    --ip="172.25.0.2" \
    -v /data/framework-mysql:/var/lib/mysql \
    -v /etc/localtime:/etc/localtime \
    --name=tars-mysql \
    mysql:5.6

2.3 deployment framework using tarscloud/framework

  1. Pull image

Latest version

docker pull tarscloud/framework:latest

Specify version:

docker pull tarscloud/framework:v{x.y.z}

Use the specified version, such as v2 4.0, which is convenient for the deployment of development and production environment. If you need to upgrade later, you can choose the updated version tag. Before upgrading, please check the changelog of GitHub to avoid losses caused by upgrading to incompatible versions.

  1. Start the image (at present, only linux is considered, and the time is synchronized with the local machine)
# The mounted / etc/localtime is used to set the time zone of the container. If not, it can be removed
# 3000 port is a web program port
# Port 3001 is a service port related to web authorization (docker > = v2.4.7 can not expose this port)
docker run -d \
    --name=tars-framework \
    --net=tars \
    -e MYSQL_HOST="172.25.0.2" \
    -e MYSQL_ROOT_PASSWORD="123456" \
    -e MYSQL_USER=root \
    -e MYSQL_PORT=3306 \
    -e REBUILD=false \
    -e INET=eth0 \
    -e SLAVE=false \
    --ip="172.25.0.3" \
    -v /data/framework:/data/tars \
    -v /etc/localtime:/etc/localtime \
    -p 3000:3000 \
    -p 3001:3001 \
    tarscloud/framework:v2.4.0

After installation, visit http://${your_machine_ip}:3000 to open the web management platform

  1. Catalog description

When creating, the docker directory / data/tars will be mapped to the host directory / data/framework. After starting docker, please check the host Directory: / data/tars. Under normal circumstances, the following directories will be created:

  • app_ Log: the log directory of the tar service
  • Tarsnode data: tarsnode / data directory (storing the business services published to docker) to ensure that docker is restarted without data loss
  • web_ Log: the log of the tars node web module in the web (only for the host)
  • demo_ Log: the log of the tars user system module in the web (only for the host), (docker > = v2.4.7)
  • Patches: uploaded release package (only for the host)

If you don't have a few directories, you can restart them manually

  1. Parameter interpretation

MYSQL_ ip: the ip address of MySQL database

MYSQL_ ROOT_ Password: the root password of MySQL database

INET: the name of the network card (ifconfig, such as eth0), which indicates that the framework binds to the local IP. Note that it cannot be 127.0.0.1

REBUILD: whether to REBUILD the database, usually false. If there is an error in the intermediate installation and you want to reset the database, you can set it to true

SLAVE: whether it is a SLAVE node. Multiple machines can be deployed, usually one master and multiple slaves

MYSQL_USER: mysql user. The default is root

MYSQL_PORT: mysql port

  1. Start frame slave node

If you want multi node deployment, just execute docker run... On different machines. Pay attention to parameter settings!

docker run -d \
    --name=tars-framework-slave \
    --net=tars \
    -e MYSQL_HOST="172.25.0.2" \
    -e MYSQL_ROOT_PASSWORD="123456" \
    -e MYSQL_USER=root \
    -e MYSQL_PORT=3306 \
    -e REBUILD=false \
    -e INET=eth0 \
    -e SLAVE=true \
    --ip="172.25.0.4" \
    -v /data/framework-slave:/data/tars \
    -v /etc/localtime:/etc/localtime \
    docker.tarsyun.com/tarscloud/framework:v2.4.0

Note: SLAVE parameters are different

2.4 Docker deploying Tars application node

The Tars application node image defaults to the image of the collection environment (Java+GoLang+NodeJs+PHP). If necessary, you can log in to the Docker Hub to view the relevant tag s of each language

  1. Pull image

Latest version:

docker pull tarscloud/tars-node:latest
  1. Start node (at present, only linux is considered, and the time is synchronized with the local machine)

Latest version:

docker run -d \
    --name=tars-node \
    --net=tars \
    -e INET=eth0 \
    -e WEB_HOST="http://172.25.0.3:3000" \
    --ip="172.25.0.5" \
    -v /data/node:/data/app \
    -v /etc/localtime:/etc/localtime \
    -p 9000-9010:9000-9010 \
    tarscloud/tars-node:latest
  • 9000 ~ 9010 ports are initially opened for use. If they are not enough, they can be added by themselves
  • After the Node is started, it will automatically register with the framework 172.25.0.3. After the deployment is completed, you can see that the Node with IP 172.25.0.5 is started in the operation and maintenance management Node management of the framework

Note that if you use – net=host on the same machine and start the framework and tar node image at the same time, it is not possible, because the framework also contains a tar node, which will lead to port conflict and fail to start

3. Docker deployment service production environment

Summary:

  • tarscloud/framework:v{x.y.y} deploy one master and multiple slaves
  • tarscloud/framework:v{x.y.y} starts in the form of – net=host, that is, the same network as the host
  • The node application server uses tarscloud / tars node: latest and also starts in the mode of – net=host
  • Tarscloud / tars node has several different labels as follows:
    • Tarscloud / tars node: stable, tarscloud / tars node: latest, tarscloud / tars node: full. The runtime environment of JDK, PHP and nodejs has been installed
    • Tarscloud / tars node: CPP, running cpp/go service
    • Tarscloud / tars node: Java with jdk installed
    • Tarscloud / tars node: nodejs. Nodejs is installed
    • Tarscloud / tars node: php. php is installed

If you want to build your own image, please refer to: https://github.com/TarsCloud/TarsDocker

3.1 Docker deploys Tars framework services

# The mounted / etc/localtime is used to set the time zone of the container. If not, it can be removed
# --net=host represents that docker uses the host network
# INET=eth0 eth0 is the name of the network card. The tars script will obtain the IP according to the name of the network card and bind the service to the obtained IP
docker run -d \
    --name=tars-framework \
    --net=host \
    -e MYSQL_HOST="Host IP For MySQL Service" \
    -e MYSQL_ROOT_PASSWORD="Your Root Password" \
    -e MYSQL_USER=root \
    -e MYSQL_PORT=3306 \
    -e REBUILD=false \
    -e SLAVE=false \
    -e INET=eth0 \
    -v /etc/localtime:/etc/localtime \
    -v /tmp/test/data:/data/tars \
    tarscloud/framework:v2.4.0

3.2 Docker deploying Tars application node

# The mounted / etc/localtime is used to set the time zone of the container. If not, it can be removed
# --net=host represents that docker uses the host network
# INET=eth0 eth0 is the name of the network card. The tars script will obtain the IP according to the name of the network card and bind the service to the obtained IP
docker run -d \
    --name=tars-node \
    --net=host \
    -e INET=eth0 \
    -e WEB_HOST="The Accessible Http Address and Port Of Your Tars Framework" \
    -v /data/tars:/data/app \
    -v /etc/localtime:/etc/localtime \
    tarscloud/tars-node:latest

4. Problem inspection

If the management platform still cannot be opened after docker is running, you can check as follows:

  • Close docker. Note that you need to use docker stop To close (please search by yourself for the use of docker)
  • When starting the image, be careful not to use the - d parameter
docker --name=tars-framework \
    --net=tars \
    -e MYSQL_HOST="172.25.0.2" \
    -e MYSQL_ROOT_PASSWORD="123456" \
    -e MYSQL_USER=root \
    -e MYSQL_PORT=3306 \
    -e REBUILD=false \
    -e INET=eth0 \
    -e SLAVE=false \
    --ip="172.25.0.3" \
    -v /data/framework:/data/tars \
    -v /etc/localtime:/etc/localtime \
    -p 3000:3000 \
    -p 3001:3001 \
    tarscloud/framework:v2.4.0
  • Check the docker output for obvious problems
  • The problem check of node is consistent with the framework

If the web platform is opened, but an error is displayed, you need to check the web. You can enter docker, please refer to Check the web for problems Checking web problems in

5. Image acceleration

  • At present, the "docker" has been built tarsyun. COM / tarscloud / framework # and # docker tarsyun. Image acceleration of COM / tarscloud / tars node

This method is only applicable to linux environment

curl -sSL https://doc.tarsdoc.com/docker_set_mirror.sh | sh -s https://w1mnep2c.mirror.aliyuncs.com
systemctl restart docker

6. Development environment docker compose

  • The following is an example of using docker compose to directly pull up the development environment for learning reference only
  • . / source/Shanghai is a linux time zone setting file, which needs to be obtained by yourself
version: "3"

services:
  mysql:
    image: mysql:5.6
    container_name: tars-mysql
    ports:
      - "3307:3306"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: "123456"
    volumes:
      - ./mysql/data:/var/lib/mysql:rw
      - ./source/Shanghai:/etc/localtime
    networks:
      internal:
        ipv4_address: 172.25.1.2
  framework:
    image: tarscloud/framework:v2.4.0
    container_name: tars-framework
    ports:
      - "3000:3000"
      - "3001:3001"
    restart: always
    networks:
      internal:
        ipv4_address: 172.25.1.3
    environment:
      MYSQL_HOST: "172.25.1.2"
      MYSQL_ROOT_PASSWORD: "123456"
      MYSQL_USER: "root"
      MYSQL_PORT: 3306
      REBUILD: "false"
      INET: eth0
      SLAVE: "false"
    volumes:
      - ./framework/data:/data/tars:rw
      - ./source/Shanghai:/etc/localtime
    depends_on:
      - mysql
  node:
    image: tarscloud/tars-node:latest
    container_name: tars-node
    restart: always
    networks:
      internal:
        ipv4_address: 172.25.1.5
    volumes:
      - ./node/data:/data/app:rw
      - ./source/Shanghai:/etc/localtime
    environment:
      INET: eth0
      WEB_HOST: http://172.25.1.3:3000
    ports:
      - "9000-9010:9000-9010"
    depends_on:
      - framework
networks:
  internal:
    driver: bridge
    ipam:
      config:
        - subnet: 172.25.1.0/16

7. docker Version Description

explain:

  • docker mainly includes: https://github.com/TarsCloud/TarsFramework And https://github.com/TarsCloud/TarsWeb Our service
  • TarsFramework and TarsWeb are both linked as submodule s https://github.com/TarsCloud/Tars below.
  • Therefore, in order to better manage docker version, the version label of docker corresponds to: https://github.com/TarsCloud/Tars Tag of
  • https://github.com/TarsCloud/Tars When you click tag, it will automatically compile and push docker to docker hub

The above execution method is from tarscloud / framework: v2 Only after 4.0

 

Reprint-----------------------------------------------------------------------------------------------------------------------------------------------------

Posted by ryeman98 on Thu, 19 May 2022 09:53:00 +0300