Deploy the Vue SpringBoot project to the server

Deploy the Vue SpringBoot project to the server

Mainly divided into the following steps:

  1. Install mysql (you can install it directly, or you can choose to install it in docker, this article is the latter)
  2. Install the Java compilation environment (jdk)
  3. Maven packaging (backend file packaging)
  4. Vue packaging (front-end file packaging)
  5. Install nginx and configure related files
  6. some pits

server install mysql

Here is mysql installed in Docker, the specific steps are as follows:

Docker

Docker installation (refer to the rookie tutorial "https://www.runoob.com/docker/ubuntu-docker-install.html"):

Uninstall the old version:

sudo apt-get remove docker docker-engine docker.io containerd runc

Update the apt package index:

sudo apt-get update

Install the apt dependency package for retrieving the warehouse via HTTPS:

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

Add Docker's official GPG key:

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

Verify that you now have the key with the thumbprint by searching for the last 8 characters of the thumbprint:

sudo apt-key fingerprint 0EBFCD88

Set up a stable repository:

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

Install Docker Engine-Community

Install the latest version of Docker Engine-Community and containerd:

sudo apt-get install docker-ce docker-ce-cli containerd.io

To test whether Docker is successfully installed, enter the following command and print out the following information to indicate that the installation is successful:

sudo docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete                                                                                                                                  Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
Status: Downloaded newer image for hello-world:latest


Hello from Docker!
This message shows that your installation appears to be working correctly.


To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.


To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash


Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/


For more examples and ideas, visit:
 https://docs.docker.com/get-started/

docker command:

启动:
systemctl start docker
守护进程重启:
systemctl daemon-reload
重启docker服务:
systemctl restart docker / service docker restart
关闭:
docker service docker stop / docker systemctl stop docker
开机自启:
systemctl enable docker
Docker需要用户具有sudo权限,为了避免每次都输入sudo,可以把用户加入Docker用户组
sudo usermod -aG docker $USER
查看镜像:
docker images
查看进程
docker ps
安装mysql:
docker pull mysql:5.7

Docker Alibaba Cloud image acceleration:

mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-"EOF"
>{
>   "registry-mirrors": ["https://3n4m4jry.mirror.aliyuncs.com"]
> }
> EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

Start mysql:

docker run -p 3306:3306 --name mysql \       //前面是本机端口号、后面是mysql的端口号
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7

enter mysql

//进入mysql容器:
docker exec -it [容器id] /bin/bash
//登录mysql,没有空格:
mysql -uroot -proot

Install and configure the Java environment

Upload and unzip the jdk:

tar -xzvf [文件名]

Modify the /etc/profile file

export PATH=$PATH:$JAVA_HOME/bin

export JAVA_HOME=/home/auto/jdk1.8
export CLASSPATH=$:CLASSPATH:$JAVA_HOME/lib/

Activate configuration:

source /etc/profile

Check if the installation is successful:

java -version

Maven packaging

Maven packaging: must be in the root directory of the project

mvn clean package -DskipTests

After the packaging is completed, the corresponding file will appear under the target
insert image description here
Upload the file to the server and run the jar package

java -jar [文件名]

If you want to run in the background, use the following command:

nohup java -jar springboot-0.0.1-SNAPSHOT.jar &

view log

tail -500f nohup.out
cat nohup.out

Check whether java is started

ps -ef | grep java

shutdown:

kill -9 [进程号]

Vue packaging

Vue packaging (under the front-end directory, first delete the dist directory):

npm run build

A dist directory will be generated

Install the anywhere front-end static resource server plugin:

npm install anywhere -g

Use anywhere to start static files to test whether dist is correct and available

anywhere -p [端口号]

Drag the dist directory onto the server

Install nginx and configure related files

Install dependencies:

apt-get install gcc
apt-get install libpcre3 libpcre3-dev
apt-get install zlib1g zlib1g-dev
# Ubuntu14.04的仓库中没有发现openssl-dev,由下面openssl和libssl-dev替代
#apt-get install openssl openssl-dev
sudo apt-get install openssl 
sudo apt-get install libssl-dev

Drag the installation package to the server and unzip it

tar -zxvf nginx-1.20.2.tar.gz

Configure and install:

cd nginx-1.20.2/
./configure --prefix=/home/auto/nginx
make && make install

start up:

cd sbin/
./nginx

Use ip to check whether the startup is successful:

insert image description here
vue dist nginx configuration:

cd conf/
vim nginx.conf
location / {
            root /home/auto/code_main/springserver/dist;
            index index.html index.htm;
            try_files $uri $uri/ /index.html;
        }

Restart nginx:

cd sbin/
./nginx -s reload

some pits

There may be a problem that although the backend can run successfully, other devices still cannot access it.
Possible reasons: The port number is not enabled. Open
the corresponding port number of the server:

/sbin/iptables -I INPUT -p tcp --dport 9090 -j ACCEPT

After the front-end deployment is completed, cross-domain problems may occur when using the front-end functions.
Possible reason: The url requested by the front end has not been modified, and needs to be modified and repackaged.

You're done!

Guess you like

Origin blog.csdn.net/no1xiaoqianqian/article/details/127138407