A, packaging,

The project is divided into two branches: Develop and Master.

When packaging, switch to the production branch, because the configuration in the production branch is different from the configuration in the development branch. The database and log paths of the development branch are local.

To do this, use the package command to go to the project directory:

 source ~/.bash_profile
 cd /Users/kaiyiwang/Code/java/quantsmart/ruoyi/

Packaging:

mvn clean package -Dmaven.test.skip=true

Pack the results:

(base) ➜ Ruoyi git:(master) qualify MVN clean package - dmaven. test. Skip= true [INFO] Scanning for projects. [the INFO] -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [INFO] Building ruoyi 2.2.0 [INFO] -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [INFO] maven - clean - plugin: 3.1.0: the clean (default-clean) @ ruoyi --- [INFO] Deleting /Users/kaiyiwang/Code/java/quantsmart/ruoyi/target [INFO] [INFO] --- Maven-resources-plugin :3.1.0:resources (default-resources) @ruoyi --... [INFO] -- maven-jar-plugin:3.1.0:jar (default-jar) @ruoyi -- [INFO] -- Building jar: / Users/kaiyiwang/Code/Java/quantsmart ruoyi/target/ruoyi. Jar [INFO] - spring - the boot - maven - plugin: 2.1.1. RELEASE: repackage  (repackage) @ ruoyi --- [INFO] Replacing main artifact with repackaged archive [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 40.379 s [INFO] Finished at: 2020-05-18T22:16:22+08:00 [INFO] Final Memory: 47M/297M [INFO] ------------------------------------------------------------------------

Second, the deployment of

It’s ready to deploy after packing. Because Spring Boot has built-in Tomcat containers, it is convenient to stop Tomcat if it is installed on the system, saving the deployment of Tomcat. We just throw the JAR package onto Linux. Here you can use the FTP tool, or use the following command line gadget, first install, we use FileZilla for uploading.

Upload directory:

/var/www/web/

Start. Sh file

#! # JVM_OPTS=" -dname =$appname-duser. timezone=Asia/Shanghai -XMS512m -XMX512m -XX:PermSize=256M -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC" APP_HOME=`pwd` LOG_PATH=$APP_HOME/logs/$AppName.log if [ "$1" = "" ]; Then the echo - e "\ [0; 31 m not input operation 033\033 [0 m \ [0; 34 m 033 {start | stop | restart | status} \ 033 [0 m" exit 1 fi if [" $AppName "=" " "\]; then the echo - e [0; 31 m not input application 033\033 [0 m" exit 1 fi function start () {PID = ` ps - ef | grep Java | grep $AppName | grep -v grep|awk '{print $2}'` if [ x"$PID" != x"" ]; then echo "$AppName is running..." else nohup java -jar $JVM_OPTS target/$AppName > /dev/null 2>&1 & echo "Start $AppName success..." fi } function stop() { echo "Stop $AppName" PID="" query(){ PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'` } query if [ x"$PID" != x"" ]; then kill -TERM $PID echo "$AppName (pid:$PID) exiting..." while [ x"$PID" != x"" ] do sleep 1 query done echo "$AppName exited." else echo "$AppName already stopped." fi } function restart() { stop sleep 2 start } function status() { PID=`ps -ef |grep java|grep $AppName|grep -v grep|wc -l` if [ $PID != 0 ];then echo "$AppName is running..." else echo "$AppName is not running..." fi } case $1 in start) start;; stop) stop;; restart) restart;; status) status;; *) esac

Another version: start_init.sh

#! /bin/sh JAR_NAME=ruoyi.jar tpid=`ps -ef|grep $JAR_NAME|grep -v grep|grep -v kill|awk '{print $2}'` if [ ${tpid} ]; then echo 'Stop Process... ' fi sleep 5 tpid=`ps -ef|grep $JAR_NAME|grep -v grep|grep -v kill|awk '{print $2}'` if [ ${tpid} ]; then echo 'Kill Process! ' kill -9 $tpid else echo 'Stop Success! ' fi tpid=`ps -ef|grep $JAR_NAME|grep -v grep|grep -v kill|awk '{print $2}'` if [ ${tpid} ]; then echo 'App is running.' else echo 'App is NOT running.' fi rm -f tpid nohup java -jar ./$JAR_NAME >/dev/null 2>&1 & echo $! > tpid echo 'Start Success! '

This script uses the grep command to see if there are any JARs running. If there are any JARs running, kill them and run them. If there are no JARs running, run them. Note that the above JAR_NAME needs to be assigned based on your JAR package name. The other most important line is to start a background thread to run the JAR via the nohup command and dump the generated nohup.out into a black hole. By the way, after saving the script, add permissions to the script:

chmod +x ry.sh

Activation:

 [root@css web]# ./start_init.sh                                                                        
Stop Success!
App is NOT running.
Start Success!

You can directly use the command to start, if the error report is easy to check, you can use the shell to start after no problem.

cd /var/www/web
java -jar ./ruoyi.jar
#./start_init.sh 

We can see that the startup has been successful. If the startup is not successful, please check the specific error information, such as whether the MySQL account permission setting is OK or whether Redis is enabled.

(has ◠ ‿ ◠) ノ ゙ start-up success ლ (´ ڡ ` ლ) ゙. -- -- -- -- -- -- --. ____ __ | _ _ \ \ \ / / | ('/') | \ _ | (_ _) o / _ () _. '| (_, _).' __ ___ (_ _) o ' | | \ \ | | | | (_ _) '| | \ `' / | ` - '/ | | \ \ /' '-' ` '-' ` -. -' 01:57:41.471 [Quartz Scheduler [Ruoyischeduler]] INFO O.Q.C.Quartz Scheduler - [Start,547] - Scheduler Ruoyischeduler _$_cssbjqnffcsvic1589824655161 started.

Third, front-end deployment

When the project is complete, just run a single command to package your application

NPM run build:stage NPM run build:stage

Once the build is packaged, the dist folder is generated in the root directory, which contains the packaged build files, usually static files such as.js,.css, index.html, and so on.

Usually the static files in the dist folder will be posted to your nginx or static server, where the index.html is the entry page for the backend service.

Nginx configuration

cd /usr/local/nginx/conf
vim nginx.conf

nginx.conf


#user  nobody;
worker_processes  1;

error_log  /var/log/nginx_error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx_access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  /var/log/nginx_access.log  main;

        location / {
            root   /var/www/web/ui/dist;
            try_files $uri $uri/ /index.html;
            index  index.html index.htm;
        }

        location /prod-api/{
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://localhost:8080/;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

Restore the Nginx configuration after modification:

/ usr/local/nginx/sbin/nginx - # s reload restart/usr/local/nginx/sbin/nginx - s stop or: nginx - # s quit stop

Open the redis:

CD /developer/redis-5.0.6/ src. /redis-server # nohup /developer/redis-5.0.6/ src. /redis-server >/dev/null >&1 &

OK, so far, the front and back end projects have been deployed OK, let’s visit the project in mind through the browser.


Relevant article: springboot packaging (jar) deployed on Linux environment (idea, maven) https://www.cnblogs.com/wuxun… https://segmentfault.com/a/11… https://vuepress.vuejs.org/