1. Backend instruction deployment
Divided into war package deployment and jar package deployment
1.1 war package deployment*
Put the war package directly in Tomcat's webapps folder, and then start Tomcat to complete the deployment
1.2 jar package deployment
Divided into two deployment methods: through the instruction method, through IDEA configuration
1.2.1 Deploy the jar package by command
First, the project clean-package is packaged as a jar package, and the package is uploaded to linux
nohup is to run in the background, > mall.out is to save the log information in this file, -D is to modify the configuration
nohup java -jar -Dserver.ip=192.168.137.129 -Dspring.datasource.password=root -Dfile.dir=/home/luobei/images mall100-0.0.1-SNAPSHOT.jar > mall.out 2>&1
close process
kill -9 process id
1.2.2 Deploy the jar package through IDEA
IDEA is to configure the steps in the instruction mode, and IDEA will perform these operations
2. Front-end deployment
Project packaging (note that the url of the front-end project connected to the back-end needs to be followed by /app/ as an identifier)
npm run build
Create nginx.conf configuration file
# Run user
root with root user authority;
# Number of running program
processes worker_processes 1;events { # The maximum number of connections per process worker_connections 1024; }
http {
include mime.types;
default_type application/octet-stream;sendfile on;
keepalive_timeout 65;
server { listen 80; # nginx server ip address server_name 192.168.174.129; # static resource configuration location / { index index.html index.htm; # Note: The path /usr/local/nginx/static here refers to the nginx container The path inside is not the path of the host Linux root /usr/local/nginx/static; try_files $uri $uri/ @router; } # Solve the problem of directly entering the route in the browser address bar and reporting 404 by the refresh button location @router { rewrite ^.*$ /index.html last; } # Dynamic resource configuration, all dynamic resources start with /app, and non-/app start with static resource location ^~/app { # Delete /app/, and then forward request to the backend server
rewrite ^/app/(.*) /$1 break;
# nginx cross-domain configuration [optional]
proxy_set_header Host $http_host;
proxy_set_header x-Rea7-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header x-Forwarded-For $ proxy_add_x_forwarded_for;
# Backend server configuration
proxy_pass http://balance;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html { root html; } } # Backend server list upstream balance{ server 192.168.7.131: 8080; # If the background program is run by docker, the ip here should be the container ip
#server 127.0.0.1:8082;
}
}
Compress the generated dist file into a zip and upload it to the host
Create nginx container and mount directory
docker run -d --name nginx-mall -p 80:80 -v /home/luobei/nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/luobei/nginx/mall/:/usr/local/nginx/static nginx
3.Docker
docker common commands | |
---|---|
docker images | See which mirrors are available |
docker serach xxx | search mirror |
docker pull xxx:xxx | Pull the mirror image of the corresponding version |
docker save -o xxx.tar xxx | Export the image as a tar file |
docker load -i xxx.tar | load image |
docker rmi image/id | delete mirror |
docker exec -it container id bash | into the container |
docker rm container name/id | delete container |
docker stop container name/id | stop container |
docker start container name/id | Start the container |
docker run -d -p --name image name | Run the image to generate a container, --name specifies the container name, -p port, -d background |
docker logs container name/id | View container logs |
docker inspect container name | View container details (ip address) |
docker build -t image name: version . | Build the image according to the Dockerfile |
3.1 IDEA uses Docker
Install the docker plugin
First determine whether to install the docker plugin: File → Settings... Find plugins, search for "docker" in the middle column, install it if it is not installed, and do not need to install it again if it is already installed
Enable docker remote access on the server
Edit the docker configuration file
vi /lib/systemd/system/docker.service
Add the following
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H 0.0.0.0:2375
Restart the docker service
systemctl daemon-reload
systemctl restart docker
Open port 2375
firewall-cmd --zone=public --add-port=2375/tcp --permanent systemctl restart firewalld.service
new connection
IDEA中 File → Settings...