###### []( )3.4 本地运行`blogserver`项目在`IntelliJ IDEA中`以Debug模式运行`blogserver`项目![debug](https://img-blog.csdnimg.cn/20210525004130234.png#pic_center) 控制台出现如下日志信息表明后端服务启动成功:
2021-05-23 21:40:06.768 INFO 9400 — [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService ‘taskScheduler’
2021-05-23 21:40:06.846 INFO 9400 — [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with context path ‘’
2021-05-23 21:40:06.849 INFO 9400 — [ main] org.sang.BlogserverApplication : Started BlogserverApplication in 4.025
###### []( )3.5 本地运行`vueblog`项目`vueblog`项目是一个前端vue项目。进入到vueblog目录中,鼠标右键->执行Git Bash Here命令在控制台中行依次输入如下命令:
安装依赖
npm install
在 localhost:8080 启动项目
npm run dev
项目的作者**江南一点雨**在`vueblog`项目中已经配置了端口转发,将数据转发到`SpringBoot`上,因此项目启动之后,在浏览器中输入`http://localhost:8080`就可以访问我们的前端项目了,所有的请求通过端口转发将数据传到`SpringBoot`中(注意此时不要关闭`SpringBoot`项目)。这时候在浏览器中输入http://localhost:8080就能进入项目的登录页面了![本地开发环境登录页面](https://img-blog.csdnimg.cn/20210525004216947.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlc2hlbmdmdTEyMTE=,size_16,color_FFFFFF,t_70#pic_center)##### []( )5 部署到Linux服务器###### []( )5.1 后端`blogserver`项目打包部署(1) 在`blogserver`项目所在文件夹 鼠标点击右键->Git Bash Here, 在控制台中执行`mvn clean package`命令把项目达成一个jar包,在控制台日志中看到如下信息表明打包成功
[INFO] — maven-jar-plugin:3.1.2:jar (default-jar) @ blogserver —
[INFO] Building jar: D:\SpringBootProject\VBlog\blogserver\target\blogserver-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] — spring-boot-maven-plugin:2.2.7.RELEASE:repackage (repackage) @ blogserver —
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.271 s
[INFO] Finished at: 2021-05-23T22:15:44+08:00
[INFO] ------------------------------------------------------------------------
此时进入`blogserver`项目的target目录下可以看到生成了一个jar包格式的文件:`blogserver-0.0.1-SNAPSHOT.jar`(2)使用`XShell6` ssh客户端连接软件登录自己的Linux云服务器,执行`cd /usr/local`命令进入`/usr/local`目录(3)执行 `mkdir vueblog` 命令创建`vueblog`文件夹,使用`XShell6`自带的`Xftp`文件传输工具将`blogserver-0.0.1-SNAPSHOT.jar`文件上传到`/usr/local/vueblog`目录下(4) 执行`cd ./vueblog` 命令进入`/usr/local/vueblog`目录后执行`mkdir logs`命令创建日志文件夹(5) 在当前目录执行`vim startup.sh`命令创建项目的启动bash脚本文件`startup.sh`文件内容如下:
#!/bin/bash
jar_name=blogserver-0.0.1-SNAPSHOT.jar
port=8081
log_path=./logs
ID=ps -ef | grep $port | grep -v "grep" | awk '{print $2}'
echo $ID
if [ {$ID} ]; then
echo ‘App is Running,Kill the Proccess!’
kill -9 $ID
echo ‘Stop Success!’
fi
rm -rf $log_path
mkdir $log_path
echo ‘Start to Running the Application!’
nohup java -jar -Dlogging.path=$log_path -Dspring.profiles.active=prod j a r n a m e > jar_name> jarname>log_path/catalina.out 2>&1 &
tail -f $log_path/catalina.out
编辑完成后按`esc`键的同时输入":"号,然后输入`wq`命令回车保存退出(6) 在当前目录执行`vim stop.sh`命令创建项目的关闭bash脚本文件`stop.sh`文件内容如下:
#!/bin/bash
port=8081
ID=ps -ef | grep $port | grep -v "grep" | awk '{print $2}'
if [ ${ID} ]; then
echo ‘the application process id is $ID’
echo ‘kill the prcocess!’
kill -9 $ID
echo ‘stopped the application success!’
else
echo ‘the application is already stopped!’
fi
编辑完成后以保存`startup.sh`相同的方式保存退出(7) 给项目启动和关闭bash脚本文件授予读、写和执行权限
chmod 775 startup.sh stop.sh
(8) 执行启动脚本启动`blogserver`服务
./startup.sh
当控制台中出现如下日志信息时表明项目启动成功:
LOGBACK: No context given for c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy@1748225580
. ____ _ __ _ _
/\ / _’ __ _ () __ __ _ \ \ \ \
( ( )___ | '_ | '| | ’ / _` | \ \ \ \
\/ _)| |)| | | | | || (| | ) ) ) )
’ || .__|| ||| |__, | / / / /
=|_|======|/=////
:: Spring Boot :: (v2.2.7.RELEASE)
2021-05-22 18:59:30.899 INFO 24260 — [ main] org.sang.BlogserverApplication : Starting BlogserverApplication v0.0.1-SNAPSHOT on VM_0_10_centos with PID 24260 (/usr/local/vueblog/blogserver-0.0.1-SNAPSHOT.jar started by root in /usr/local/vueblog)
2021-05-22 18:59:30.901 INFO 24260 — [ main] org.sang.BlogserverApplication : The following profiles are active: prod
2021-05-22 18:59:34.055 INFO 24260 — [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
2021-05-22 18:59:34.080 INFO 24260 — [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-05-22 18:59:34.080 INFO 24260 — [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.34]
2021-05-22 18:59:34.233 INFO 24260 — [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-05-22 18:59:34.233 INFO 24260 — [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3197 ms
###### []( )5.3 前端`vueblog`项目部署(1) 修改配置文件修改`vueblog/config`目录下的`index.js`文件中build配置项中的`assetsPublicPath`属性的值为 `'/vueBlog/'`![assetPublicPath](https://img-blog.csdnimg.cn/20210525004445703.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hlc2hlbmdmdTEyMTE=,size_16,color_FFFFFF,t_70#pic_center)(2) 修改路由配置修改`vueblog/src/router`目录下的`index.js`文件,在`Router`对象中增加base和mode属性配置![routerBaseMode](https://img-blog.csdnimg.cn/20210525004407216.png#pic_center) base的值为`'/vueBlog/'`,mode的属性值为`'history'`(3) 打生产包修改完成后,在`vueblog`项目的根目录下鼠标右键->Git Bash Here 在控制台中执行`npm run build` 命令完成打包。控制台出现如下日志表明打包成功:
Build complete.
Tip: built files are meant to be served over an HTTP server.
Opening index.html over file:// won’t work.
(4) 修改`Nginx`服务配置文件在 `Xshell6`连接的Linux云服务客户端中执行`cd /usr/local/nginx/html` 切换到`nginx`服务的安装目录下的`html`文件夹执行 `mkdir vueBlog` 创建新的文件夹`vueBlog`执行 `cd ../`命令回退到`/usr/local/nginx`目录,先执行`./sbin/nginx -s stop` 命令关停`nginx`,然后执行`vim ./conf/nginx.conf` 命令修改`nginx.conf`配置文件修改后的配置文件 如下:
#user nobody;
worker_processes 1;
#error_log logs/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;sendfile on;keepalive_timeout 65;gzip on;server {listen 80;server_name www.javahsf.club;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;proxy_pass http://127.0.0.1:7200;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header Host $http_host;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header X-Real-IP $remote_addr; proxy_buffering off; sendfile off; proxy_max_temp_file_size 0; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_temp_file_write_size 64k; proxy_http_version 1.1; proxy_request_buffering off; }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;}}server {listen 3000;server_name www.javahsf.club;location / {root html;index index.html index.htm;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}
}
server {listen 8886;server_name javahsf.club www.javahsf.club;location /vueBlog {alias html/vueBlog;index index.html index.htm;try_files $uri $uri/ /vueBlog/index.html; }location / {