Note: because the deployment is my own project, so some tools are for my own use, do not need to install.

Environments and Plug-ins

  • Operating system: Ubuntu 18.04
  • The JDK: 1.8
  • Docker: 19.03.13
  • Redis: 6.0.9
  • Mysql: 5.7
  • Nginx: 1.10
  • wkhtmltopdf
  • Separation of front and rear ends: Front end: Vue Back end: Spring Boot

Docker

Update apt package index

sudo apt-get update
Copy the code

Install apt dependencies to get repositories over HTTPS

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
Copy the code

Add Docker’s official GPG key

curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
Copy the code

Set up the stable release repository

sudo add-apt-repository \
   "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
  $(lsb_release -cs) \
  stable"
Copy the code

Update APT source index

sudo apt-get update
Copy the code

Install the latest versions of Docker engine-Community and Containerd, or go to the next step to install specific versions:

sudo apt-get install docker-ce docker-ce-cli containerd.io
Copy the code
  1. To install a specific version of Docker Engine-Community, list the available versions in the repository and select an installation. List the versions available in your repository:
apt-cache madison docker-ce
Copy the code

2. Install a specific version using the version string in the second column, for example 5:19.03.12 to 3-0 to Ubuntu-bionic

sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
Copy the code

Test whether Docker is installed successfully

sudo docker run hello-world
Copy the code

If the following information is displayed, the installation is successful

Check the version

docker -v
Copy the code

Install the JDK

Download the.gz package from the official website

Official website download address

Unpack the

sudo mkdir /usr/local/java
sudo tar -zxvf jdk-8u271-linux-x64.tar.gz -C /usr/local/java
Copy the code

The environment variable

sudo vim /etc/profile
Copy the code

export JAVA_HOME=/usr/local/java/jdk

export CLASSPATH=.:${JAVA_HOME}/lib

export PATH=${JAVA_HOME}/bin:$PATH

Effective immediately

source /etc/profile
Copy the code

Check the installation

java -version
Copy the code

Docker installed Redis

Check out the Redis source

docker search redis
Copy the code

Pull the mirror

Docker pull redis: 6.0.9Copy the code

Creating a Mapping File

Redis. Conf: download from the official website

Modifying a configuration file:

Bind 127.0.0.1: # comment out this section, which restricts Redis to only access daemonize locally: Appendonly yes: #redis persistent requirepass foobared: # change the password

mkdir /alidata/docker/redis
vim /alidata/docker/redis/redis.conf
Copy the code

Create a container

docker run -p 6379:6379 --name redis -v /alidata/docker/redis/redis.conf:/etc/redis/redis.conf -v / alidata/docker/redis/data: / data - d redis: 6.0.9 redis server/etc/redis/redis conf - appendonly yesCopy the code

Command description:

-p 6379:6379: port mapping: indicates the host part before, and indicates the container part after.

–name redis: Specifies the name of the container, which is easy to view and operate.

-v: indicates the mount directory. The rule is the same as that of port mapping.

Why mount directory: I think Docker is a sandbox isolation level container, this is its characteristics and security mechanism, can not casually access external (host) resource directory, so need this mount directory mechanism.

-d redis:6.0.9: indicates that the background redis is enabled

Redis server/etc/redis/redis conf: in order to start the redis configuration file and load the container the conf file, eventually found is mounted directory/alidata/docker/redis/redis. Conf

test

Docker Mysql installation

Pull the mirror

Docker pull mysql: 5.7Copy the code

Creating a Mapping File

mkdir /alidata/docker/mysql/data
mkdir /alidata/docker/mysql/logs
vim /alidata/docker/mysql/conf/my.cnf
Copy the code

Create a container

docker run \ -p 3306:3306 \ --name mysql \ -v /alidata/docker/mysql/conf/my.cnf:/etc/mysql/my.cnf \ -v /alidata/docker/mysql/logs:/logs \ -v /alidata/docker/mysql/data:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=root \ -d Mysql: 5.7Copy the code

Command description:

-e MYSQL_ROOT_PASSWORD=root Sets the login password

Into the container

docker exec -it mysql bash
Copy the code

Enter the mysql

Mysql -u root -p ##Copy the code

Mysql > alter database

IP address to connect to the host, specifying port 3306

A remote connection problem occurred

  1. MySQL > select * from user where host = ‘%’
mysql> SELECT user, host FROM mysql.user;
Copy the code

The figure above is abnormal.

mysql> update user set host = '%' where user = 'root';
mysql> flush privileges;
Copy the code
  1. Check whether port 3306 is enabled
netstat -talnp 
Copy the code

  1. If ECS is used, set security configuration rules to allow access to ports

test

Docker to install the RabbitMQ

Pull the mirror

Docker pull the rabbitmq: 3.7Copy the code

Create the container and start it

Docker run -d --name rabbit -P 15672:156772 -p 5672:5672 -p 61613:61613 rabbitmq:3.7Copy the code

Note: You need to use the STOMP plugin here, so you need to map port 61613 to the host for your personal needs

Install the STOMP plug-in

Into the container

docker exec -it rabbit bash
Copy the code

Manually enable the MQ management plug-in

rabbitmq-plugins enable rabbitmq_management
Copy the code

Manually enable the STOMP plug-in

rabbitmq-plugins enable rabbitmq_stomp
Copy the code

accesshttp://ip:15672

Install wkhtmltopdf

website

download

Wget HTTP: / / https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.xenial_amd64.debCopy the code

Download the dependent

sudo apt-get install libxfont1 xfonts-encodings xfonts-utils xfonts-base xfonts-75dpi
Copy the code

Install wkhtmltopdf

Sudo DPKG -i wkhtmltox_0. 12.6 1. Xenial_amd64. DebCopy the code

Wkhtmltopdf tool path in/usr/local/bin/wkhtmltopdf

test

wkhtmltopdf https://www.baidu.com/ test.pdf
Copy the code

Chinese garbled

Download simsun. TTC to /usr/share/fonts(available on Windows)

Docker to install Nginx

Pull the mirror

Docker pull nginx: 1.10Copy the code

Creating a Mapping File

mkdir /alidata/docker/nginx/logs
mkdir /alidata/docker/nginx/conf
Copy the code

Start the container

Docker run --name nginx-test -p 80:80 -d nginx:1.10Copy the code

access

Establish a mapping

Check the container

docker ps
Copy the code

Copy configuration file

docker cp 1c1245efec1d:/etc/nginx/nginx.conf /alidata/docker/nginx/conf
Copy the code

Create the Nginx container and map the WWW,logs,conf directory to the local directory and start

docker run -d --name nginx \ -p 8082:80 \ -v /alidata/www/histo/pcp:/usr/share/nginx/html \ -v / alidata/docker/nginx/conf/nginx. Conf: / etc/nginx/nginx. Conf \ - v/alidata/docker/nginx/logs: / var/log/nginx \ nginx: 1.10Copy the code

Parameter Description:

–name nginx: indicates the container name. -p 81:80: Indicates port mapping. Local port 81 is mapped to port 80 inside a container. -d nginx:1.10: Sets the container to always run in the background.

Create the page

/alidata/www/histo/pcp/index.html

<! DOCTYPE HTML > < HTML > <head> <meta charset=" UTF-8 "> <title> Docker build nginx</title> </head> <body> <h1>Docker build nginx</ h1> </body> </html>Copy the code

access

Docker deployment front end (more to come)

compile

Copy the compiled file to/alidata/www/histo/pcp/

Configuration niginx

Docker deploys the backend

Access to project

Git Clone project addressCopy the code

Build the project

mvn clean
mvn install
Copy the code

Write a Dockerfile file

# Author MAINTAINER [email protected] # ADD the JAR package to the container and rename it pcp.jar ADD./target/*.jar pcp.jar # The in-container application will use the container's specified port EXPOSE 10999 # to run the jar package ENTRYPOINT Java-jar pcp.jarCopy the code

Image Making Method 1

Upload the compiled project and Dockerfile to the server

# # # to upload/alidata/application/PCP/PCPCopy the code

ls

To make the mirror

docker build -t pcp .
Copy the code

Start the container

docker run -d --name pcp -p 10999:10999 pcp
Copy the code

Image Making Method 2

Ali cloud new docker image upload cloud address

This goes to ali cloud on the new, free

Configure the build.sh script

docker rmi registry.cn-shanghai.aliyuncs.com/xxx/yyy:${1} docker build -t registry.cn-shanghai.aliyuncs.com/xxx/yyy:${1}  . docker login --username=xxx --password=xxx registry.cn-shanghai.aliyuncs.com docker push registry.cn-shanghai.aliyuncs.com/xxx/xxx:${1}Copy the code

Go to your project and open Git bash

Run the build.sh script

sh build.sh {{version}}
Copy the code

Pull the mirror

docker pull registry.cn-shanghai.aliyuncs.com/xxx/yyy:{{version}}
Copy the code

Start the container

docker run -d --name pcp -p 10999:10999 pcp
Copy the code