This is the 11th day of my participation in the August Wenwen Challenge.More challenges in August

preface

Simple recently learned some knowledge on the deployment environment, so precipitation, this article combines the practice and experience summary, can deploy to some small white reference, this tutorial is a partial basis, many are close to the principle of operation, so learn to, no matter what type of environment deployment can quick learning, know principle is so invincible.

To prepare

1. Springboot + Maven +mysql project

2. Prepare a server

Maven, maven, nginx, mysql

practice

1, first to a server, you can install a virtual machine or buy a server is also very convenient.
2. Install JDk1.8, Maven, nginx, and mysql, configure environment variables, and check whether the configuration is successful. I won’t go into that here, because there are many online tutorials.
Get the server’s git public key and add it to github Settings, assuming that the code is maintained on Github.

ssh-keygen -t rsa -C “xxxxx”

SSH file will be generated in the home directory. Open the file to see the key file, copy the contents, and add them to github’s public key.

4. Pull the code to the server

Go to a directory where all your projects are stored.

git clone [email protected]

Git pull, pull the latest code.

Git is something to learn.

5. Write Java shell scripts to package and start services

Two scripts are used here

compile.sh
/home/app/code/testdemo/git pull MVN clean package -dmaven.test. skip=true -dskiptests =true cp /home/app/code/testDemo/testDemo-service-center/target/testDemo-center-dev.jar /home/app/package/testDemo-center.jar #sh  remote_restart_issue.shCopy the code
remote_restart_issue.sh
CD /home/app/package if [! -n "$(pgrep -f testdemo-center)"]; then echo "process is not exist!" else echo $(pgrep -f testDemo-center) pkill -f testDemo-center fi OLD_BUILD_ID=$BUILD_ID BUILD_ID=dontKillMe nohup /usr/bin/java -jar testDemo-center.jar & BUILD_ID=$OLD_BUILD_ID echo $(pgrep -f testDemo-center)Copy the code
6. Modify some configuration information

The log address, database IP and port, and location of the referenced external JAR package are the same as in the code.

7. Run the shell script to start the service

sh compile.sh

sh remote_restart_issue.sh

Nginx configure reverse proxy
location /test {
proxy_pass http://localhost:9900/test;
}
Copy the code

Restart the nginx

9. Start invoking the service

The end of the