The most complete and detailed Java project deployment guide on the Internet (recommended collection)

Directory

  • 1. Server requirements
    • 1. Server specifications
      • 1.1 Server configuration
      • 1.2 Server selection
        • From the perspective of server purchase cost
        • From the perspective of data security
        • From the perspective of post-service
        • From the perspective of ease of use of the software
    • 2. Network
      • 2.1 Network selection
      • 2.2 Network bandwidth
      • 3. Graphical tools
  • 2. System deployment specifications
    • 1. System environment
      • Linux installation environment
        • 1. jdk installation
        • 2. redis installation
        • 3. nginx installation
      • Docker installation environment
        • 1. docker installation
        • 2. docker compose installation
        • 3. Prepare the environment required for docker
    • 2. Domain name application
    • 3. Apply for SSL certificate
    • 4. Security group activation
      • 1. Security group activation
      • 2. Turn on the firewall
    • 5. Mini program deployment
  • 3. Deployment matters
    • 1. Anti-virus
      • 1.1 Cloud server
      • 1.2 Linux
    • 2. Prevent power outage
      • 2.1 Auto-start at boot
        • Windows self-starting jar package
        • centos self-starting jar package
        • docker self-starting
        • nginx starts automatically
      • 2.2 Database backup
        • 1. Manual backup
        • 2. Automatic backup
          • 1. Linux local backup
          • 2. Linux multi-machine backup
          • 3. Windows local backup
          • 4. Windows multi-machine backup
    • 3. Controllable
    • 4. Server training
      • 1. Development
        • 1.1 Maintain project documents
          • 1. Project and environment structure
          • 2. Connection method, such as Sunflower or cloud server
          • 3. Account and password of the remote project administrator
          • 4. Project address
          • 5. Development project branch
          • 6. The port of the project, such as mengshi-9083.jar
          • 7. Environment address, such as the mounting directory and backup directory of mysql
          • 8. Deployment operations
          • 9. Front-end deployment address
      • 2. Implementation
        • 1.1 The cloud server needs to determine whether the server has expired
        • 1.2 Determine whether the Linux computer is powered on or powered off
        • 1.3 Make sure there are no above problems and contact the development

1. Server requirements

1. Server specifications

1.1 Server Configuration

For example, it is recommended to configure 4 cores 16G, and the minimum configuration is 2 cores 4G (select according to the configuration required for system deployment and the number of deployment projects)

1.2 Server selection

From the perspective of server purchase cost

The cloud server storage model requires purchasing cloud servers from cloud platform providers (Alibaba Cloud, Tencent Cloud, etc.). And you need to pay the fee every year, otherwise the system will not be usable

To store local system data locally, you need to purchase server hardware, usually a computer host, and the cost is low. If there are no problems with the use of the hardware, no other fees will be incurred later and it is not subject to the service provider. But one thing that needs to be mentioned is that the local server needs to be maintained by dedicated personnel, including hardware repair and network connection.

From the perspective of data security

Cloud server storage form: All data is stored in the cloud server, and a professional cloud platform provider is responsible for hosting and maintenance. In addition to their own maintenance, suppliers of software products are also responsible for maintaining cloud servers to ensure the data security of customer data. Similarly, in addition to supporting real-time synchronization and backup of data, the cloud server can also support manual backup. The backup data is also stored in the cloud, providing double protection for data security.

Data is stored on the local server: The data is stored on the local hard disk. Except for artificial copying, viruses, etc., there is basically no problem of data leakage. It can be accessed without being connected to the Internet, and others cannot steal or copy the data through remote means or any other means. However, this storage method has high requirements on server hardware. If the local server is damaged or the data is lost, it cannot be retrieved.

From the perspective of post-service services

Cloud server: Provide exclusive after-sales service personnel, including online consultation, telephone communication, remote demonstration and other multi-channel methods to handle problems. In terms of efficiency, online feedback can be responded to in a timely manner. There is no need to rush to the customer site. Causes can be directly identified and processed through customer feedback.

Local server: basically no follow-up services are involved, and no maintenance fees are incurred. Of course, if the product needs to be upgraded or maintained, a maintenance fee will be charged.

In terms of ease of use of the software

Software products relying on cloud servers do not require downloading and installation, just visit the dedicated website. You don’t have to worry about setting matching problems when changing computers, which may cause the system to become unavailable. At the same time, the use of the software system is not subject to geographical restrictions, and can be used on business trips or working from home. This type of software product can quickly add projects, and is more suitable for enterprises with multiple projects and remote collaborative office needs.

The stand-alone version of the software that the local server relies on needs to download the installation package, and it needs to be downloaded again when changing the computer. And it can only work within the local area network. However, this has a relatively limited impact on companies that have single-project management, do not involve business trips, or whose leaders do not like to view reports.

2. Network

2.1 Network selection

wired network:

  • Need to be close to the router
  • increased security
  • greater control

Wi-Fi:

  • more free (within scope)
  • flexibility
  • Security Risk

To determine network cable specifications, etc.

2.2 Network bandwidth

Understand the network bandwidth and the bandwidth supported by the server, whether it is a Gigabit network or a 100M network, whether a switch is required, etc.

3. Graphical tools

Determine whether it is a Linux system. If it is determined that the Centos7 version needs to be installed, determine whether the graphical tool is installed on the server. If not, it needs to be installed.

2. System deployment specifications

1. System environment

  • Java SE 1.8 various versions jdk api: http://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html
  • Mysql download address: https://dev.mysql.com/downloads/mysql/
  • Nginx download address: https://nginx.org/en/download.html
  • Redis download address: http://download.redis.io/releases/
[root@izbp14rfm2unhhkkc0bpgwz ~]# java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)


[root@izbp14rfm2unhhkkc0bpgwz ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5501
Server version: 5.7.26 MySQL Community Server (GPL)


[root@izbp14rfm2unhhkkc0bpgwz nginx]# sbin/nginx -v
nginx version: nginx/1.17.5


[root@izbp14rfm2unhhkkc0bpgwz nginx]# cd /usr/local/redis/bin/
[root@izbp14rfm2unhhkkc0bpgwz bin]# ./redis-server -v
Redis server v=5.0.5 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=73d8617d1a0599be


[root@izbp14rfm2unhhkkc0bpgwz bin]# docker version
Client:
 Version: 1.13.1
 API version: 1.26
 Package version: docker-1.13.1-204.git0be3e21.el7.x86_64
 Go version: go1.10.3
 Git commit: 0be3e21/1.13.1
 Built: Fri Mar 19 13:57:09 2021
 OS/Arch: linux/amd64

Server:
 Version: 1.13.1
 API version: 1.26 (minimum version 1.12)
 Package version: docker-1.13.1-204.git0be3e21.el7.x86_64
 Go version: go1.10.3
 Git commit: 0be3e21/1.13.1
 Built: Fri Mar 19 13:57:09 2021
 OS/Arch: linux/amd64
 Experimental: false

Linux installation environment

1. jdk installation
//1. Create jdk directory
mkdir -p /usr/local/java
cd /usr/local/java

//2. Decompress
tar -zxvf jdk-8u144-linux-x64.tar.gz

//3. Configure environment variables
vim /etc/profile

export JAVA_HOME=/usr/local/java/jdk1.8.0_144
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
//save
:wq

//4. Reload the configuration file
source /etc/profile

//5. Test
java-version
2. redis installation
#1. Official website download
https://redis.io/download/
#2. Use xftp to put the compressed package into linux
#3. Unzip the compressed package
tar -zxvf redis.tar.gz

#4. Enter the directory and install the required gcc environment.
yum install gcc-c++
make

#5. Enter the /usr/local/bin directory, place the redis.conf file in your own directory, and start it with your own configuration file.
cp /usr/local/redis/redis.conf bconfig/

#6. Redis does not start in the background by default. Modify the configuration file.
Change daemonize no to yes

#7. Start the redis service
redis-server bconfig/redis.conf
redis-cli -p 6379

#8. Test
ping

#End the redis process
shutdown
exit

#set password
config set requirepass [dtsum123456]
3. nginx installation
# 1. Download the installation package
https://nginx.org/en/download.html

# 2. Unzip the installation package
tar -zxvf nginx-1.20.0.tar.gz

# 3. Install the dependencies required by nginx
yum install -y gcc-c++
yum install pcre-devel zlib zlib-devel openssl openssl-devel

# 4. Enter the nginx directory and execute the configure file
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --user=nginx --group=nginx

# 5. Install nginx
make
make install

# 6. Modify the port of the configuration file
vim /usr/local/nginx/conf/nginx.conf

# 7. If there is no logs file, you need to add a logs folder and authorize it.
mkdir logs
chmod 700 logs

# 8. Enter sbin and start nginx
./nginx

# 9. Test
curl localhost:[corresponding port]

Docker installation environment

1. Docker installation
# Installation steps
# 1. Uninstall the old version of docker
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest\
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
                  
# 2. Docker environment installation
yum install -y yum-utils device-mapper-persistent-data lvm2

# 3. Set up the image warehouse (Alibaba Cloud)
    yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# Update yum package index
yum makecache fast

# 4. Install docker engine
yum install docker-ce docker-ce-cli containerd.io

# 5. Start test docker
systemctl start docker
docker run hello-world

#6. If the image pull is too slow
# Modify daemon.json, if the file does not exist, create it
sudo vim /etc/docker/daemon.json
# Add registry-mirrors
{<!-- -->
 "registry-mirrors": ["https://registry.docker-cn.com","https://hub-mirror.c.163.com","https://docker.m.daocloud.io" ]
}
2. Docker compose installation
//docker-compose installation
//1. Download the latest version of docker-compose file
sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker- compose

//2. Add executable permissions
sudo chmod +x /usr/local/bin/docker-compose

//3. Test
docker-compose --version
3. Prepare the environment required for docker
//1. Create a folder
mkdir -p /docker/mysql/data
mkdir -p /docker/mysql/logs
mkdir -p /docker/mysql/conf
touch /docker/mysql/conf/my.cnf

mkdir -p /docker/redis/data
mkdir -p /docker/redis/conf
touch /docker/redis/conf/redis.conf

mkdir -p /docker/rabbitmq/conf
mkdir -p /docker/rabbitmq/data

mkdir -p /docker/nginx/logs
mkdir -p /docker/nginx/conf
touch /docker/nginx/conf/nginx.conf
touch /docker/nginx/conf/default.conf
mkdir -p /docker/nginx/www/

//2. Pull the image
docker pull mysql:5.7
docker pull nginx:latest
docker pull redis:latest
docker pull rabbitmq:latest

//3. Write docker-compose.yml
vim /docker/docker-compose.yml

version: '3'
services:
  mysql:
    image: mysql:5.7
    restart: always
    container_name: mysql57
    environment:
      MYSQL_ROOT_PASSWORD: 123456
      MYSQL_DATABASE: database
      TZ: Asia/Shanghai
    ports:
      - 3306:3306
    volumes:
      -/docker/mysql/data:/var/lib/mysql
      - /docker/mysql/logs:/var/log/mysql
      - /docker/mysql/conf/my.cnf:/etc/mysql/my.cnf
    command:
      --default-time-zone=' + 8:00'
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --max_connections=1000
      --lower_case_table_names=1
      --max_allowed_packet=128M
      --innodb_lock_wait_timeout=500
  redis:
    image: redis:latest
    restart: always
    ports:
      - 6379:6379
    networks:
      -front-ms
    privileged: true
    environment:
      - "TZ=Asia/Shanghai"
    container_name: redis
    volumes:
      - /docker/redis/data:/data
      - /docker/redis/conf/redis.conf:/etc/redis/redis.conf
    command: redis-server --requirepass 123456 --appendonly yes
    logging:
      driver:json-file
      options:
        max-size: "100m"
        max-file: "2"
  rabbitmq:
    restart: always
    image: rabbitmq:latest
    container_name: rabbitmq
    hostname: rabbit
    ports:
      - 5672:5672
      - 15672:15672
    environment:
      TZ: Asia/Shanghai
      RABBITMQ_DEFAULT_USER: guest
      RABBITMQ_DEFAULT_PASS: guest
    volumes:
      - /docker/rabbitmq/data:/var/lib/rabbitmq
      - /docker/rabbitmq/conf:/etc/rabbitmq
  nginx:
    image: nginx:latest
    restart: always
    container_name: nginx
    privileged: true
    ports:
      - 18080:80
      - 443:443
    volumes:
      - /docker/nginx/logs:/var/log/nginx/
      - /docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
      - /docker/nginx/www/:/usr/share/nginx/html/
    command: /bin/bash -c "nginx -g 'daemon off;'"
    logging:
      driver:json-file
      options:
        max-size: "100m"
        max-file: "2"
# Connect to external network
networks:
  front-ms:
    driver: bridge


//4. mysql configuration file
vim /docker/mysql/conf/my.cnf

[mysqld]
datadir=/var/lib/mysql

default-storage-engine=INNODB
character_set_server=utf8

symbolic-links=0

pid-file=/var/run/mysqld/mysqld.pid

sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

default-time_zone = ' + 8:00' #Solve time zone issues

# Set query packet size to 50M
max_allowed_packet=104857600
# Table names are not case sensitive
lower_case_table_names=1
#join buffer buffer
join_buffer_size=32M

[client]
default-character-set=utf8
 
[mysql]
default-character-set=utf8

//5. redis configuration file
vim /docker/redis/conf/redis.conf

//Only selected some important configurations for explanation
#bind 127.0.0.1 //Comment out, otherwise redis can only be accessed locally
requirepass 123456
protected-mode no //The default is yes, the protected mode is turned on and can only be accessed locally.
daemonize yes //Default no, change to yes to start as a daemon process, can run in the background, unless the process is killed, changing to yes will cause the configuration file to start redis failure
databases 16 //Number of databases (optional), I modified this just to see if it takes effect
dir ./ //Enter the local redis database storage folder (optional)
port 6379
appendonly yes //redis persistence (optional)

//6. nginx configuration file (only http is written, https needs to obtain nginx’s ssl certificate)
vim /docker/nginx/conf/nginx.conf

worker_processes 1;

events {<!-- -->
    worker_connections 1024;
}


http {<!-- -->
    include mime.types;
    default_type application/octet-stream;


    sendfile on;

    keepalive_timeout 65;


    # Enable dynamic compression
    gzip on;
    gzip_min_length 2k;
    gzip_disable msie6;
    gzip_types text/css text/javascript application/javascript image/png image/jpeg image/gif;



    #web
server {<!-- -->
listen 80;
server_name 192.168.1.1;

#Backend service configuration. Once this location is configured, it can be accessed through http://domain name/jeecg-boot/xxxx
location ^~ /jinta {<!-- -->
# Nginx solves browser cross-domain issues
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,PATCH,OPTIONS;
\t          
proxy_pass http://127.0.0.1:8086/jeecg-boot/;
proxy_set_header Host 127.0.0.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 1024m;
}
\t    
\t    
#Solve the problem that in Router(mode: 'history') mode, the page cannot be found when refreshing the routing address
location / {<!-- -->
root /usr/share/nginx/html/dist/;
index index.html index.htm;
if (!-e $request_filename) {<!-- -->
rewrite ^(.*)$ /index.html?s=$1 last;
break;
}
# Nginx solves browser cross-domain issues
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,PATCH,OPTIONS;
}

error_page 502 500 503 504 /50x.html;
\t    
location = /50x.html {<!-- -->
root /usr/share/nginx/html;
}
}

}

//7. Start docker
cd /docker
docker-compose up -d

2. Domain name application

1.1 Enter the domain name console

1.2 View existing domain names

1.3 Domain name resolution
[image]

1.4 Get all http resolution domain names
[image]

1.5 Added http domain name

3. Apply for SSL certificate



4. Security group activation

1. Security group activation


2. Firewall activation

#View port opening status
#Check the opened ports. If it is Alibaba Cloud, you need to configure security group rules.
firewall-cmd --list-ports
# Check firewall service status
systemctl status firewalld
# Open port
firewall-cmd --zone=public --add-port=80/tcp --permanent
# Restart the firewall service to make the opened ports effective
systemctl restart firewalld.service

#Check the port occupancy. If there is no input, it is not occupied.
lsof -i:[port]
netstat -tunlp - View all ports
netstat -tunlp | grep [port number] - Check port occupancy
#Difference: netstat has no permission control, lsof has permission control, and can only see this user

5. Mini program deployment

Before developing a mini program, you need to register a mini program account.
WeChat mini program: https://mp.weixin.qq.com/

3. Deployment matters

1. Anti-virus

1.1 Cloud Server

If it is on the customer’s cloud server, the customer needs to be reminded to purchase a protection package.

1.2 Linux

If you are on the public Internet, you need to download anti-virus software such as ClamAV to protect Linux servers.
If it is on an intranet, these problems are not likely to occur

2. Prevent power outage

2.1 Auto-start at boot

After the server is turned on, it is necessary to automatically start the project, automatically enable the project environment, etc.

Windows self-starting jar package

I have written this before, the link is as follows:
https://blog.csdn.net/weixin_52796198/article/details/132580922

centos self-starting jar package

I have already written about this, the link is as follows:
https://blog.csdn.net/weixin_52796198/article/details/132578266

Docker starts automatically
systemctl enable docker.service
nginx starts automatically
vim /etc/rc.d/rc.local

//Add the following line
/usr/local/nginx/sbin/nginx

//Modify executable permissions after saving
chmod +x /etc/rc.d/rc.local

2.2 Database backup

1. Manual backup

2. Automatic backup
1. Linux local backup

After taking a look, I have written about this before, the link is as follows:
https://blog.csdn.net/weixin_52796198/article/details/131216811

2. Linux multi-machine backup
#1. Add ssh public key on main server A
ssh-keygen-trsa
#Press Enter until completed, two files will be generated in the user directory/root/.ssh/: id_rsa, id_rsa.pub

#2. Copy the contents of the id_rsa.pub file to /root/.ssh/authorized_keys of backup server B
#vim /root/.ssh/id_rsa.pub
scp /root/.ssh/id_rsa.pub [email protected]:/root/.ssh/authorized_keys
#After completing this step, no password is required when copying from server A to server B.

#3. Create the transferred directory on backup server B
mkdir -p /backup/sanlong/mysql

#4. Enter a directory to write a script for backing up mysql (put it as close to the backup file as possible, so it is easier to find)
cd /docker/mysql/backupsql

#5. Create backup sh
vim backup.sh

#The following is the script content, you can modify it according to the server
#!/bin/bash
#Backup path
BACKUP=/docker/mysql/backup/sql
#current time
DATETIME=$(date + %Y-%m-%d)
echo "====Backup starts==="
echo "The backup file is stored in ${BACKUP}/$DATABASE-$DATETIME.sql"
#Database address
HOST=localhost
#database username
DB_USER=root
#Database password
DB_PW=123456
#Create backup directory
#[ ! -d "${BACKUP}/$DATETIME" ] & amp; & amp; mkdir -p "${BACKUP}/$DATETIME"

#Backend system database
DATABASE=dtsum-boot
echo $DATABASE-$DATETIME
#mysqldump -u${DB_USER} -p${DB_PW} --single-transaction --host=$HOST -q -R --databases $DATABASE | gzip > ${BACKUP}/$DATABASE-$DATETIME.sql. gz
docker exec mysql57 mysqldump -h localhost -u${DB_USER} -p${DB_PW} ${DATABASE} | gzip > /${BACKUP}/$DATABASE-$DATETIME.sql.gz

echo "===Export successful, start transmission==="
#Compress into tar.gz package
cd $BACKUP
#tar -zcvf $DATETIME.tar.gz $DATETIME
#Back up to server B
scp $DATABASE-$DATETIME.sql.gz [email protected]:/backup/sanlong/mysql
#Delete backup directory
#rm -rf ${BACKUP}/$DATETIME

#Delete the data backed up 10 days ago, you can change it yourself here
#find $BACKUP -mtime + 10 -name "*.gz" -exec rm -rf {} \;
echo "===Database backup to server successful==="
#6. Save sh
:wq

#7. Write cron script
crontab -e

#Input content (this represents backup at 0 o'clock every day)
0 0 * * * sh /docker/mysql/backupsql/backup.sh

#8. Save cron
:wq

#9. Restart the cron service
servicecrond restart
#or
/bin/systemctl restart crond.service

3. Windows local backup

①Create a backup directory somewhere and create backup.bat

②Edit backup.bat

@echo off
set "Ymd=?te:~,4%?te:~5,2%?te:~8,2%" #Use date as file name
set "host=127.0.0.1%"
set "port=3306"
set "username=root"
set "password=root"
set "database=vhr"
set "route=e:\backup"

mysqldump -h%host% -P%port% -u%username% -p%password% ?tabase% > %route%\?tabase%-%Ymd%.sql
@echo on

③Start the scheduled task and search for taskschd.msc

④Create basic tasks


⑤Select trigger frequency
.
⑥Select the script you wrote and complete

4. Windows multi-machine backup

① Perform multi-machine backup based on the completion of Windows local backup
②Set the sharing permissions of the backup computer

③Enable file sharing and turn off password requirements



④Set the mysql backup directory as a shared folder


⑤Try to access the shared folder on other computers. After clicking share, a box will pop up to copy it.

//If there is no copy, assume that my IP is 192.168.1.1 and access it directly
\192.168.1.1\backup can be accessed

⑥Choose a directory on the new computer to store the backup information

//1. I selected d:\backup\mysql as an example.

//2. Write a script in the d:\backup directory and create copy.bat
@echo off

xcopy \192.168.1.1\backup D:\backup\mysql /y /e /i /q

@echo on

⑦ Timing to create copy script
Search and enter taskschd.msc, and follow the previous steps to create a scheduled task. Here, you need to pay attention to the start time to ensure that it is after the SQL backup. For example, start the backup at 5 o’clock, and wait until 5:05 to complete the backup before copying it.

3. Controllable

Determine system expiration dates for customer systems

4. Server training

1. Development

1.1 Maintain project documents

The client server you are responsible for must write maintenance documents and place them in the project maintenance documents.

1. Project and environment structure

It must be written clearly in the document

2. Connection method, such as Sunflower or cloud server
3. Account and password of the remote project administrator
4. Project address
5. Development project branch
6. The port of the project, such as mengshi-9083.jar
7. Environment address, such as the mounting directory and backup directory of mysql
8. Deployment operation
9. Front-end deployment address

2. Implementation

1.1 The cloud server needs to determine whether the server has expired
1.2 Determine whether the Linux computer is powered on or powered off
1.3 Make sure there are no above problems and contact the developer