简介:

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

集成部署

环境版本下载地址NodeJs16https://nodejs.org/download/release/latest-v16.x/Jdk1.8https://www.oracle.com/java/technologies/downloads/Mysql8.0/5.7https://dev.mysql.com/downloads/

数据库脚本下载地址:https://www.mindskip.net:999,创建表初始化数据,数据库名称为xzs 代码下载 mysql版本,配合相应的数据库使用 安装mysql ,导入xzs-mysql.sql脚本 学生端默认账号:student / 123456 管理端默认账号:admin / 123456

实操

所有操作都在一台服务器实施,前后端不分离

安装打包工具

安装jdk

[root@web-nginx ~]# tar xzvf jdk-8u221-linux-x64.tar.gz -C /usr/local/

[root@web-nginx ~]# mv /usr/local/jdk1.8.0_221/ /usr/local/java

配置环境变量

[root@web-nginx ~]# vim /etc/profile

JAVA_HOME=/usr/local/java

PATH=$JAVA_HOME/bin:$PATH

export JAVA_HOME PATH

重载环境变量

[root@web-nginx ~]# source /etc/profile

查看java是否安装成功

[root@web-nginx ~]# 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)

安装maven

[root@web-nginx ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz

解压并改名

[root@web-nginx ~]# tar xzvf apache-maven-3.8.8-bin.tar.gz -C /usr/local/

[root@web-nginx ~]# mv /usr/local/apache-maven-3.8.8/ /usr/local/maven

设置环境变量

[root@web-nginx ~]# vim /etc/profile

MAVEN_HOME=/usr/local/maven

PATH=$PATH:$MAVEN_HOME/bin

export MAVEN_HOME PATH

重载环境变量

[root@web-nginx ~]# source /etc/profile

检测maven是否安装成功

[root@web-nginx ~]# mvn -version

Apache Maven 3.8.8 (4c87b05d9aedce574290d1acc98575ed5eb6cd39)

Maven home: /usr/local/maven

Java version: 1.8.0_211, vendor: Oracle Corporation, runtime: /usr/local/java/jre

Default locale: en_US, platform encoding: UTF-8

OS name: "linux", version: "3.10.0-1160.el7.x86_64", arch: "amd64", family: "unix"

安装node.js前端打包工具命令npm

[root@web-nginx ~]# wget https://nodejs.org/download/release/latest-v16.x/node-v16.20.2-linux-x64.tar.xz

[root@web-nginx ~]# tar xf node-v16.20.2-linux-x64.tar.xz -C /usr/local/

[root@web-nginx ~]# cd /usr/local/

[root@web-nginx local]# mv node-v16.20.2-linux-x64/ node

配置环境变量

[root@web-nginx ~]# vim /etc/profile

NODE_HOME=/usr/local/node

PATH=$NODE_HOME/bin:$PATH

export NODE_HOME PATH

重载环境变量

[root@web-nginx ~]# source /etc/profile

查看是否安装成功,查看版本

[root@web-nginx ~]# node --version

v16.20.2

获取源代码

安装Git命令获取源代码

[root@web-nginx ~]# yum install -y git

获取clone代码

[root@web-nginx ~]# git clone https://gitee.com/hyunze/xzs-mysql.git

安装mysql5.7

[root@web-nginx ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

[root@web-nginx ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm

[root@web-nginx ~]# vim /etc/yum.repos.d/mysql-community.repo

将mysql8.0关闭将mysql5.7开启

enabled=1

gpgcheck=0

[root@web-nginx ~]# yum install -y mysql-community-server

启动mysql

[root@web-nginx ~]# systemctl start mysqld

过滤第一次登录所需的密码

[root@web-nginx ~]# grep pass /var/log/mysqld.log

改密码

[root@web-nginx ~]# mysqladmin -uroot -p'HdV>.f>Ir8;h' password 'QianFeng@123!'

[root@web-nginx ~]# 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.31 MySQL Community Server (GPL)

...

创建数据库xzs

mysql> create database xzs character set utf8 collate utf8_general_ci;

Query OK, 1 row affected (0.00 sec)

设置root允许远程登录

mysql> update mysql.user set host = '%' where user = 'root';

Query OK, 1 row affected (0.10 sec)

Rows matched: 1 Changed: 1 Warnings: 0

刷新权限

mysql> flush privileges;

mysql> \q

Bye

配置mysql环境

修改mysql

[root@web-nginx ~]# vim xzs-mysql/source/xzs/src/main/resources/application-prod.yml

logging:

path: /usr/log/xzs/

spring:

datasource:

url: jdbc:mysql://192.168.1.101:3306/xzs?useSSL=false&useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&allowMultiQueries=true

username: root

password: QianFeng@123!

driver-class-name: com.mysql.cj.jdbc.Driver

#####url那一行 ip改为自己做实验服务器的ip,/ ?的名字改为自己之前创建数据库的名字。password改为远程登录MySQL数据库的密码

导入初始化mysql

[root@web-nginx ~]# mysql -uroot -p'QianFeng@123!' xzs < xzs-mysql/sql/xzs-mysql.sql

前端打包

学生端

[root@web-nginx ~]# cd xzs-mysql/source/vue/xzs-student/

打包

[root@web-nginx xzs-student]# npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/

[root@web-nginx xzs-student]# npm install --registry https://registry.npm.taobao.org

[root@web-nginx xzs-student]# npm run build

[root@web-nginx xzs-student]# cp -r student xzs-mysql/source/xzs/src/main/resources/static

管理端

[root@web-nginx ~]# cd xzs-mysql/source/vue/xzs-admin/

打包

[root@web-nginx xzs-admin]# npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/

[root@web-nginx xzs-admin]# npm install --registry https://registry.npm.taobao.org

[root@web-nginx xzs-admin]# npm run build

[root@web-nginx xzs-admin]# cp -r admin xzs-mysql/source/xzs/src/main/resources/static

将java程序打包成jar包

这时候进行打包,所使用的镜像源是国外的源,因此会导致打包时间巨长,打包超时,打包失败,为了杜绝这种现象,我们可以采用阿里云的镜像源

打开   maven镜像_maven下载地址_maven安装教程-阿里巴巴开源镜像站 (aliyun.com)https://developer.aliyun.com/mirror/maven?spm=a2c6h.13651102.0.0.3e221b11gh5cgw

配置maven的配置文件,替换镜像源

vim /usr/local/maven/conf/settings.xml

将源文件里的内容替换为

这时开始打包  速度就会很快

[root@web-nginx ~]# cd xzs-mysql/source/xzs

[root@web-nginx xzs]# mvn package

服务上线

[root@web-nginx ~]# mkdir -p /application/java-server

[root@web-nginx ~]# cp xzs-mysql/source/xzs/target/xzs-3.9.0.jar /application/java-server

[root@web-nginx ~]# cd /application/java-server

让服务在后台运行

[root@web-nginx java-server]# nohup java -Duser.timezone=Asia/Shanghai -jar -Dspring.profiles.active=prod xzs-3.9.0.jar > start1.log 2>&1 &

成功运行的日志显示

访问

学生端访问地址为:http://ip:8000/student

管理员端访问地址为:http://ip:8000/admin​​​​​​

学生端默认账号:student / 123456

管理端默认账号:admin / 123456

实验中遇到问题

1.mysql设置root允许远程登录,语法出现错误

2.学生端及管理端进行打包时,注意路径的使用

3.在后端打包时,如果使用国外的源,可以替换为阿里云的镜像源,提升打包成功率。

4.养成观察日志的习惯,遇到错误在日志中寻找错误原因

参考文章

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: