This section mainly introduces the use of docker to complete the deployment of the framework. There are two types of docker available:
First, make sure you have installed the docker environment on your service. If not, please refer to docker install
If you want the source code to compile docker by yourself, see Install
Using docker to install the tars framework, there are two images to choose from: framework / tars .
Note: the difference is whether you want to deploy the business service in the image (not recommended, not convenient for upgrading the tars framework))
First create a docker network to make sure this guide work properly on each OS platform. Tars will works exactly like it works in VM or cloud hosting machine.
# Create a bridge virtual network and set the name, subnet and gateway.
docker network create -d bridge --subnet=172.25.0.0/16 --gateway=172.25.0.1 tars
docker run -d \
--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
docker pull tarscloud/framework:stable
# Mount timezone file /etc/localtime to container. Remove it if you don't have.
# expose port 3000 for web entry
# expose port 3001 for web authorization
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:stable
You can access http://${your_machine_ip}:3000
to enter Tars web management platform.
If these directories are not created, you can create them manually and restart docker
MYSQL_IP: IP of MySQL DB instance
MYSQL_ROOT_PASSWORD: Root password for MySQL
INET: The name of the network interface (as you can see in ifconfig, such as eth0) indicates the native IP bound by the framework. Note that it cannot be 127.0.0.1
REBUILD: Whether to rebuild the database is 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: Is this a slave node
MYSQL_USER: MySQL user. Will use root as default.
MYSQL_PORT: MySQL port
If you want to deploy multiple nodes, just execute docker run... On different machines. Pay attention to the 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:stable
Attention: SLAVE environment is true
docker pull tarscloud/tars-node:stable
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/tars \
-v /etc/localtime:/etc/localtime \
-p 9000-9010:9000-9010 \
tarscloud/tars-node:stable
172.25.0.3
.You can find it in the node management part of your platform web.If the docker still cannot open the management platform after running, you can check as follows:
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:stable
If the web platform is open, but the error is displayed, you need to check the web problems. You can enter docker, please refer to check the web problems incheck the web problem
172.25.1.0/16
in case conflict with the guide in chapter 2 to 4version: "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:stable
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:stable
container_name: tars-node
restart: always
networks:
internal:
ipv4_address: 172.25.1.5
volumes:
- ./node/data:/data/: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