若依项目上线(学之思开源考试系统)

学之思开源考试系统是一款 java + vue 的前后端分离的考试系统。主要优点是开发、部署简单快捷、界面设计友好、代码结构清晰。支持web端和微信小程序,能覆盖到pc机和手机等设备。 支持多种部署方式:集成部署、前后端分离部署、docker部署。

准备基础环境

(所有服务器关闭selinux、防火墙)

服务器功能 主机ip 主机名 服务名称 配置
前端服务器 10.36.192.251 nginx nginx 1C2G
后端服务器+代码打包 10.36.192.252 java java、maven、nodejs 4C8G
数据库/缓存 10.36.192.253 db mysql、redis 2C4G

Nginx

#配置Nginxyum源
[root@nginx ~]# cat /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
​
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
​
#安装Nginx
[root@nginx ~]# yum install -y nginx

java

# 上传java包到服务器
# 安装java环境
[root@java ~]# tar -xf jdk-8u211-linux-x64.tar.gz -C /usr/local/
[root@java ~]# mv /usr/local/jdk1.8.0_211/ /usr/local/java
[root@java ~]# vim /etc/profile.d/java.sh
JAVA_HOME=/usr/local/java
PATH=$PATH:$JAVA_HOME/bin
​
[root@java ~]# source /etc/profile.d/java.sh
[root@java ~]# java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)

mysql、redis

# 配置mysql yum源
# 安装mysql
[root@db ~]# yum install -y mysql-server
[root@db ~]# systemctl start mysqld
[root@db ~]# systemctl enable mysqld
[root@db ~]# grep "password" /var/log/mysqld.log
2023-11-03T19:44:26.450149Z 1 [Note] A temporary password is generated for root@localhost: rb894yRh(NUG
[root@db ~]# mysqladmin -uroot -p'rb894yRh(NUG' password 'QianFeng@123!'
[root@db ~]# mysql -uroot -p'QianFeng@123!'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.42 MySQL Community Server (GPL)
​
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
​
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
​
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
​
# 创建数据库
mysql> create database ruoyi character set utf8 collate  utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
​
#授权root用户远程登录
mysql> grant all on *.*  to 'root'@'%' identified by 'QianFeng@123!';
Query OK, 0 rows affected, 1 warning (0.00 sec)
​
#刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
​
mysql> \q
Bye
下载redis
[root@db ~]# wget http://download.redis.io/releases/redis-4.0.9.tar.gz
[root@db ~]# tar -xf redis-4.0.9.tar.gz -C /usr/local/
[root@db ~]# mv /usr/local/redis-4.0.9/ /usr/local/redis
[root@db ~]# yum install -y gcc make
[root@db ~]# cd /usr/local/redis/
[root@db redis]# make
[root@db redis]# cat redis.conf
bind 10.36.192.253
port 6379
daemonize yes
[root@db redis]# ./src/redis-server redis.conf &
[root@db redis]# ss -tlanp |grep redis
LISTEN     0      128    10.36.192.253:6379                     *:*                   users:(("redis-server",pid=4938,fd=6))

配置打包环境

配置前端打包环境

[root@java ~]# wget https://nodejs.org/dist/v12.18.4/node-v12.18.4-linux-x64.tar.xz
[root@java ~]# tar -xf node-v12.18.4-linux-x64.tar.xz -C /usr/local/
[root@java ~]# mv /usr/local/node-v12.18.4-linux-x64/ /usr/local/node
[root@java ~]# vim /etc/profile.d/node.sh
NODE_HOME=/usr/local/node
PATH=$PATH:$NODE_HOME/bin
[root@java ~]# source /etc/profile.d/node.sh
[root@java ~]# node -v
v12.18.4

配置后端打包环境

[root@java ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz --no-check-certificate
[root@java ~]# tar -xf apache-maven-3.9.5-bin.tar.gz -C /usr/local/
[root@java ~]# mv /usr/local/apache-maven-3.9.5/ /usr/local/maven
[root@java ~]# vim /etc/profile.d/mvn.sh
MAVEN_HOME=/usr/local/maven
PATH=$PATH:$MAVEN_HOME/bin
[root@java ~]# source /etc/profile.d/mvn.sh
[root@java ~]# mvn -version
Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546)
Maven home: /usr/local/maven
Java version: 1.8.0_211, vendor: Oracle Corporation, runtime: /usr/local/java/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.el7.x86_64", arch: "amd64", family: "unix"

获取代码

[root@java ~]# yum install -y git
[root@java ~]# git clone https://gitee.com/y_project/RuoYi-Vue.git
[root@java ~]# ls
anaconda-ks.cfg                node-v12.18.4-linux-x64.tar.xz
apache-maven-3.9.5-bin.tar.gz  RuoYi-Vue
jdk-8u211-linux-x64.tar.gz

前端代码打包

[root@java ~]# cd RuoYi-Vue/ruoyi-ui
#替换为国内的taobaoyuan
[root@java ruoyi-ui]# npm install --unsafe-perm --registry=https://registry.npm.taobao.org
[root@java ruoyi-ui]# npm run build:prod
​
构建打包成功之后,会在根目录生成 dist 文件夹,里面就是构建打包好的文件,通常是 xxx.js 、xxx.css、index.html 等静态文件。
​
通常情况下 dist 文件夹的静态文件发布到你的 nginx 或者静态服务器即可,其中的 index.html 是后台服务的入口页面。
[root@java ruoyi-ui]# ls
babel.config.js  dist          package-lock.json  src
bin              node_modules  public             vue.config.js
build            package.json  README.md
[root@java ruoyi-ui]# cd dist/
[root@java dist]# ls
favicon.ico  html  index.html  index.html.gz  robots.txt  static
​
# 将静态资源移动到其他位置,然后进行后端代码打包
[root@java dist]# cd /root/RuoYi-Vue
[root@java RuoYi-Vue]# mv ruoyi-ui/ /opt/

后端代码打包

[root@java ~]# cd RuoYi-Vue/
[root@java RuoYi-Vue]# vim ruoyi-admin/src/main/resources/application.yml
# 修改redis配置信息
  redis:
    # 地址
    host: 10.36.192.253
    # 端口,默认为6379
    port: 6379
    # 数据库索引
    database: 0
    # 密码
    password:
    # 连接超时时间
    timeout: 10s
    lettuce:
    
[root@java RuoYi-Vue]# vim ruoyi-admin/src/main/resources/application-druid.yml
### 修改数据库url,修改数据库密码
# 数据源配置
spring:
    datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        driverClassName: com.mysql.cj.jdbc.Driver
        druid:
            # 主库数据源
            master:
                url: jdbc:mysql://10.36.192.253:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                username: root
                password: QianFeng@123!
                
# 开始进行后端打包
[root@java RuoYi-Vue]# mvn package
…………
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  04:35 min
[INFO] Finished at: 2023-11-03T20:18:20+08:00
[INFO] ------------------------------------------------------------------------
[root@java RuoYi-Vue]# ls ruoyi-admin/target/
classes            maven-archiver  ruoyi-admin.jar 
generated-sources  maven-status    ruoyi-admin.jar.original
​
#ruoyi-admin.jar 放在后端服务器运行

项目上线

前端项目上线

# 拷贝前端资源到前端服务器
[root@java ~]# cd /opt
[root@java opt]# scp -r ruoyi-ui/ 10.36.192.251:/opt/
​
#前端项目上线
[root@nginx ~]# rm -rf /usr/share/nginx/html/*
[root@nginx ~]# cp -r /opt/ruoyi-ui/dist/* /usr/share/nginx/html/
[root@nginx ~]# ls /usr/share/nginx/html/
favicon.ico  html  index.html  index.html.gz  robots.txt  static
​
[root@nginx ~]# vim /etc/nginx/conf.d/default.conf
upstream rs {
    server 10.36.192.252:8080;
}
server {
​
    listen       80;
    server_name  localhost;
​
    access_log  /var/log/nginx/host.access.log  main;
​
    location / {
        root   /usr/share/nginx/html;
        try_files $uri $uri/ /index.html;
        index  index.html index.htm;
    }
​
    location /prod-api/ {
      proxy_pass http://rs/;
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   }
​
}
[root@nginx ~]# systemctl restart nginx
​
#前端上线完成,但是由于后端还未上线,所以有报错,并且验证码无法显示

image-20231103204121355

后端项目上线

# 将jar包传送到后端服务器
[root@java opt]# cp ~/RuoYi-Vue/ruoyi-admin/target/ruoyi-admin.jar /java/
​
#导入初始化数据,首先将初始化数据传到数据库服务器
[root@java ~]# cd /root/RuoYi-Vue/sql
[root@java sql]# ls
quartz.sql  ry_20230706.sql
[root@java sql]# scp * 10.36.192.253:/opt/
​
​
# 导入初始化数据
[root@db redis]# mysql -uroot -p'QianFeng@123!' ruoyi < /opt/quartz.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@db redis]# mysql -uroot -p'QianFeng@123!' ruoyi < /opt/ry_20230706.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
​
#开始测试上线后端服务
[root@java target]# java -jar -server -Xmx1024m -Xms1024m ruoyi-admin.jar
Application Version: 3.8.6
Spring Boot Version: 2.5.15

//                          _ooOoo_                               //
//                         o8888888o                              //
//                         88" . "88                              //
//                         (| ^_^ |)                              //
//                         O\  =  /O                              //
//                      ____/`---'\____                           //
//                    .'  \\|     |//  `.                         //
//                   /  \\|||  :  |||//  \                        //
//                  /  _||||| -:- |||||-  \                       //
//                  |   | \\\  -  /// |   |                       //
//                  | \_|  ''\---/''  |   |                       //
//                  \  .-\__  `-`  ___/-. /                       //
//                ___`. .'  /--.--\  `. . ___                     //
//              ."" '<  `.___\_<|>_/___.'  >'"".                  //
//            | | :  `- \`.;`\ _ /`;.`/ - ` : | |                 //
//            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //
//      ========`-.____`-.___\_____/___.-`____.-'========         //
//                           `=---='                              //
//      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
//             佛祖保佑       永不宕机      永无BUG               //

05:15:09.581 [background-preinit] INFO  o.h.v.i.util.Version - [<clinit>,21] - HV000001: Hibernate Validator 6.2.5.Final
05:15:09.633 [main] INFO  c.r.RuoYiApplication - [logStarting,55] - Starting RuoYiApplication using Java 1.8.0_211 on db with PID 15389 (/opt/RuoYi-Vue/ruoyi-admin/target/ruoyi-admin.jar started by root in /opt/RuoYi-Vue/ruoyi-admin/target)
05:15:09.634 [main] DEBUG c.r.RuoYiApplication - [logStarting,56] - Running with Spring Boot v2.5.15, Spring v5.3.27
05:15:09.634 [main] INFO  c.r.RuoYiApplication - [logStartupProfileInfo,686] - The following 1 profile is active: "druid"
05:15:11.945 [main] INFO  o.a.c.h.Http11NioProtocol - [log,173] - Initializing ProtocolHandler ["http-nio-8080"]
05:15:11.945 [main] INFO  o.a.c.c.StandardService - [log,173] - Starting service [Tomcat]
05:15:11.946 [main] INFO  o.a.c.c.StandardEngine - [log,173] - Starting Servlet engine: [Apache Tomcat/9.0.75]
05:15:12.035 [main] INFO  o.a.c.c.C.[.[.[/] - [log,173] - Initializing Spring embedded WebApplicationContext
05:15:12.514 [main] DEBUG c.r.f.s.f.JwtAuthenticationTokenFilter - [init,242] - Filter 'jwtAuthenticationTokenFilter' configured for use
05:15:13.856 [main] INFO  c.a.d.p.DruidDataSource - [init,996] - {dataSource-1} inited
05:15:13.862 [main] DEBUG c.r.s.m.S.selectDictDataList - [debug,137] - ==>  Preparing: select dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time, remark from sys_dict_data WHERE status = ? order by dict_sort asc
05:15:13.880 [main] DEBUG c.r.s.m.S.selectDictDataList - [debug,137] - ==> Parameters: 0(String)
05:15:13.903 [main] DEBUG c.r.s.m.S.selectDictDataList - [debug,137] - <==      Total: 29
05:15:14.462 [main] DEBUG c.r.s.m.S.selectConfigList - [debug,137] - ==>  Preparing: select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark from sys_config
05:15:14.463 [main] DEBUG c.r.s.m.S.selectConfigList - [debug,137] - ==> Parameters:
05:15:14.465 [main] DEBUG c.r.s.m.S.selectConfigList - [debug,137] - <==      Total: 6
05:15:14.873 [main] INFO  o.q.i.StdSchedulerFactory - [instantiate,1220] - Using default implementation for ThreadExecutor
05:15:14.885 [main] INFO  o.q.c.SchedulerSignalerImpl - [<init>,61] - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
05:15:14.885 [main] INFO  o.q.c.QuartzScheduler - [<init>,229] - Quartz Scheduler v.2.3.2 created.
05:15:14.886 [main] INFO  o.q.s.RAMJobStore - [initialize,155] - RAMJobStore initialized.
05:15:14.887 [main] INFO  o.q.c.QuartzScheduler - [initialize,294] - Scheduler meta-data: Quartz Scheduler (v2.3.2) 'quartzScheduler' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.
​
05:15:14.887 [main] INFO  o.q.i.StdSchedulerFactory - [instantiate,1374] - Quartz scheduler 'quartzScheduler' initialized from an externally provided properties instance.
05:15:14.887 [main] INFO  o.q.i.StdSchedulerFactory - [instantiate,1378] - Quartz scheduler version: 2.3.2
05:15:14.887 [main] INFO  o.q.c.QuartzScheduler - [setJobFactory,2293] - JobFactory set to: org.springframework.scheduling.quartz.SpringBeanJobFactory@649725e3
05:15:14.906 [main] DEBUG c.r.q.m.S.selectJobAll - [debug,137] - ==>  Preparing: select job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark from sys_job
05:15:14.906 [main] DEBUG c.r.q.m.S.selectJobAll - [debug,137] - ==> Parameters:
05:15:14.908 [main] DEBUG c.r.q.m.S.selectJobAll - [debug,137] - <==      Total: 3
05:15:16.124 [main] INFO  o.a.c.h.Http11NioProtocol - [log,173] - Starting ProtocolHandler ["http-nio-8080"]
05:15:16.511 [main] INFO  o.q.c.QuartzScheduler - [start,547] - Scheduler quartzScheduler_$_NON_CLUSTERED started.
05:15:16.521 [main] INFO  c.r.RuoYiApplication - [logStarted,61] - Started RuoYiApplication in 7.487 seconds (JVM running for 7.935)
(♥◠‿◠)ノ゙  若依启动成功   ლ(´ڡ`ლ)゙
 .-------.       ____     __
 |  _ _   \      \   \   /  /
 | ( ' )  |       \  _. /  '
 |(_ o _) /        _( )_ .'
 | (_,_).' __  ___(_ o _)'
 |  |\ \  |  ||   |(_,_)'
 |  | \ `'   /|   `-'  /
 |  |  \    /  \      /
 ''-'   `'-'    `-..-'
​

正式上线

## 开始正式上线
[root@java target]# nohup java -jar -server -Xmx1024m -Xms1024m ruoyi-admin.jar &
## 如果报错链接不上数据库,且数据库配置无问题,将RuoYi-Vue/ruoyi-admin/src/main/resources/application-druid.yml文件中,
master:
                url: jdbc:mysql://10.36.192.253:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
                
将url中useSSL=yes改成useSSL=false,然后重新打包上线
​
在JDBC连接MySQL数据库时,useSSL参数用于指定是否使用SSL(安全套接层)加密连接。SSL是一种用于在计算机网络上提供安全通信的协议,它可以确保在客户端和服务器之间传输的数据在传输过程中是加密的,从而提供了一定程度的安全性。
​
当useSSL参数设置为false时,表示不使用SSL加密连接。这通常在开发和测试环境中比较常见,因为在这些环境下,对数据传输的安全性要求可能较低,而且SSL加密会增加一些额外的性能开销。在这种情况下,如果数据库服务器不要求强制的SSL连接,你可以将useSSL参数设置为false来简化连接配置。
​
但是,在生产环境中,特别是涉及到敏感数据的应用,强烈建议使用SSL加密来保护数据的传输安全性。在生产环境中,通常会将useSSL参数设置为true,以确保数据库连接是安全的。
​
在你的连接字符串中,useSSL=false表示不使用SSL加密连接。如果你的数据库服务器要求SSL连接,那么你需要将useSSL参数设置为true,以便建立加密连接。

猜你喜欢

转载自blog.csdn.net/weixin_69654831/article/details/134318590