1.安装jdk和配置
1.解压JDK源码 tar -zxvf xxxxx.tar
2.配置环境变量
vim /etc/profile
在最后面加上
export JAVA_HOME=/root/jdk1.8
export PATH=$JAVA_HOME/bin:$PATH
exprot CLASSPATH=.:JAVA_HOME/lib/dt.jar:JAVA_HOME/lib/tools.jar
3.执行指令,让配置生效
source /etc/profile
2.多环境配置,区分生产还是开发
复制application.properties 为 application-prod.properties 文件,只需要写不同的配置的代码比如mysql的配置
两个文件都会读到, application-prod.properties会复盖application.properties 的配置
在ideal中
edit configurations
environment
VM options -Dspring.profiles.action=prod
3.打包为jar文件
maven->lifecycle->install
打包成功 会在target下面生成jar文件
pom.xml
<build>
//设置打包的文件名
<finalName>${artifactId}</finalName>
//或者 设置子目录
<finalName>/dist/${artifactId}</finalName>
4.在服务器中启动
java -jar -Dspring.profiles.action=prod /home/wwwroot/wiki/wiki.jar
5.$'\r':command not found syntax error:unexpected end of file
//$'\r':command not found syntax error:unexpected end of file问题处理
//如果文件是在window写的,上传到linux,有时换行会报错,可以用以下命令来处理,
//在linux中打开文件,然后输入以下命令
:set ff=unix
6.查看最新日志和在日志中查找关键字
//看最新的100行日志 加f可以自动刷新
tail -100f trace.log
//在log文件中查找关键字
grep 关键字 trace.log
7.配置域名,反向代理到springboot项目
server{
listen 80;
# server_name 8.133.184.84;
server_name xxxxxx.com;
location / {
proxy_pass http://localhost:8880;
# 针对websocket,需要增加下面的配置
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 代理时长设置600秒,默认60秒,websocket超时会自动断开
proxy_read_timeout 600s;
}
}
8.配置html文件,vue项目,nginx配置
server{
listen 80;
# server_name 8.133.184.84;
server_name wiki.courseimooc.com;
location / {
alias /root/web/;
index index.html;
try_files $uri $uri/ /index.html;
}
}