Front-end forwarding and separated deployment of springboot project

ready:

①Cloud server

②Source code package: https://cloud.189.cn/t/FfaUjiyUfIjq (Access code: 19nt)

③Close the firewall and selinux, and release the ports 3306 8081 8085 6379 in the security group, etc.

④Important note: Create the database vhr before maven compilation and packaging; import the data in V1__vhr.sql after compilation and packaging and before the project runs

1. Upload source code package, maven, jdk package, install maven and jdk

# 1.安装maven
tar  -zxvf  apache-maven-3.6.3-bin.tar.gz

# 安装到/usr/local下,重命名maven
mv   apache-maven-3.6.3   /usr/local/maven

# 2.安装jdk
tar  -zxvf jdk-8u11-linux-x64.tar.gz

mv  jdk1.8.0_11/   /usr/local/

# 3.配置环境变量
vim /etc/profile

# 保存、退出后刷新环境变量
.  /etc/profile

# 查看安装是否成功,查看maven版本
mvn  -version

# 查看jdk是否安装成功,查看版本
java  -version

Two, install mariadb, rabbitmq, redis, nginx

2.1 Install mariadb

yum  install mariadb  mariadb-server  -y

systemctl  start  mariadb
 
mysql_secure_installation
 
mysql  -uroot  -p
 
# 下边命令在mariadb中执行
grant  all on  *.*  to root@'%'  identified by "123456";
 
create database  vhr;

2.2 Install rabbitmq 

yum install rabbitmq-server

systemctl  start rabbitmq-server

systemctl  status  rabbitmq-server

# 添加rabbitMQ用户,设置用户名
rabbitmqctl add_user vhruser vhrpasswd

# 查看用户
rabbitmqctl list_users

 

2.3 Install redis 

yum install redis

# 修改redis密码
vim /etc/redis.conf

systemctl  start redis

systemctl  status  redis

 2.4 Install nginx

yum install nginx

systemctl  start nginx

systemctl  status  nginx

Three, project packaging and deployment

3.1 Modify project related configuration parameters

# 修改项目的相关配置
cd  /root/app/vhr/vhrserver/vhr-web/src/main/resources/
vim  application.yml
# application.yml配置数据库、rabbitmq、redis、nginx相关信息
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    username: root
    password: 123456
    url: jdbc:mysql://localhost:3306/vhr?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
  rabbitmq:
    username: vhruser
    password: vhrpasswd
    host: 127.0.0.1
    publisher-confirms: true
    publisher-returns: true
  redis:
    host: 127.0.0.1
    database: 0
    port: 6379
    password: vhrpasswd
  cache:
   cache-names: menus_cache
server:
  port: 8081
  compression:
    enabled: true
fastdfs:
  nginx:
    host: http://你的nginx所在IP/

3.2 Compile and package

# 切换到pom.xml下打包编译
cd  /root/app/vhr/vhrserver

# 编译、打包
mvn clean && mvn compile && mvn package

3.3 Create a new configuration file under the nginx configuration folder, configure front and back forwarding separation

vim /etc/nginx/conf.d/mynginx.conf

# 配置后一定要重启
systemctl  restart  nginx

systemctl  status  nginx
upstream  vhrtest   {
           server   127.0.0.1:8081;
}

# nginx开放端口8085
server {
        listen       8085;
        server_name  localhost;
        client_max_body_size 1024M;
        
        # 当访问路径 http://ip:8085/index.html,转发到http://127.0.0.1:8081
        location / {
            proxy_pass http://vhrtest;
            # proxy_set_header Host $host:$server_port;
            proxy_redirect  default;
       }
       
       # 当访问是静态文件(括号中)类型,直接访问/root/app/static/
       location ~ .*\.(js|css|ico|png|jpg|eot|svg|ttf|woff|html)$ {
            root /root/app/static/;
            expires  30d;  #缓存
        }
}

 

3.4 mysql import the required data of the site

# 不登录数据库导入数据
mysql  -uroot -p  vhr  <  /root/app/V1__vhr.sql

# 也可以登录数据库后用如下命令导入
source  /root/app/V1__vhr.sql

3.5 Run the project

Find the jar package: the location is prompted when compiling and packaging (the figure in section 3.2), generally in the target directory under the project path

cd  /root/app/vhr/vhrserver/vhr-web/target/

ls   -lh

# 后台启动项目,输入日志到/root/log.out下
nohup java  -jar  vhr-web-0.0.1-SNAPSHOT.jar  >  /root/log.out  &

# 查看日志
tail  -f  /root/log.out

3.6 Test visit http://ip:8085/index.html

403 error, showing a message like nginx, check the nginx log

# 查看nginx日志,出现了大量的权限被拒绝
tail  -f  /var/log/nginx/error.log

 

# 查看nginx进程
ps  -aux  | grep nginx

The working user and the startup user are inconsistent. Access denied is likely to be the reason. Modify the nginx working user and restart

# 修改nginx配置文件
vim /etc/nginx/nginx.conf

#配置修改后要重启nginx
systemctl  restart nginx

Visit again

Guess you like

Origin blog.csdn.net/qq_29644709/article/details/110921586