部署方式:集成部署、前后端分离部署、docker部署
方式一、集成部署
1、环境:
环境 版本 下载地址
NodeJs 16 https://nodejs.org/download/release/latest-v16.x/
Jdk 1.8 https://www.oracle.com/java/technologies/downloads/
Mysql 8.0/5.7 https://dev.mysql.com/downloads/
全都安装在同一台主机上。
学生端访问地址为:http://ip:8000/student 管理员端访问地址为:http://ip:8000/admin 学生端默认账号:student / 123456 管理端默认账号:admin / 123456
2、准备工作:
检查是否有本地源或者阿里云源
cd /etc/yum.repos.d
rm -rf *
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo && curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo——安装阿里云源
本地域名解析
hostnamectl set-hostname java-server
在192.168.52.153中:vim /etc/hosts
192.168.52.154 java-server
yum install -y wget git nptdate---安装工具软件包。
3、安装打包工具
安装jdk
java开发工具包(包含java运行环境和java编译器)
上传jdk-8u211-linux-x64.tar.gz包。
[root@web-nginx ~]# tar xzvf jdk-8u211-linux-x64.tar.gz -C /usr/local/
[root@web-nginx ~]# mv /usr/local/jdk1.8.0_211/ /usr/local/java
[root@web-nginx ~]# vim /etc/profile.d/java.sh
JAVA_HOME=/usr/local/java
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME PATH
[root@web-nginx ~]# source /etc/profile.d/java.sh
[root@web-nginx ~]# java -version
安装maven
一种用于管理和构建Java项目的工具
[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.d/mvn.sh
MAVEN_HOME=/usr/local/maven
PATH=$PATH:$MAVEN_HOME/bin
export MAVEN_HOME PATH
[root@web-nginx ~]# source /etc/profile.d/mvn.sh
[root@web-nginx ~]# mvn -version
安装nodejs
Node.js是一个开源的JavaScript运行时环境,允许开发者使用JavaScript编写 “服务器端” 代码。
[root@web-nginx ~]# wget https://nodejs.org/download/release/latest-v16.x/node-v16.20.2-linux-x64.tar.xz
[root@web-nginx ~]# wget https://nodejs.org/download/release/latest-v16.x/node-v16.20.2-linux-x64.tar.xz
[root@web-nginx ~]# cd /usr/local/
[root@web-nginx local]# mv node-v16.20.2-linux-x64/ node
[root@web-nginx ~]# vim /etc/profile.d/node.sh
NODE_HOME=/usr/local/node
PATH=$NODE_HOME/bin:$PATH
export NODE_HOME PATH
[root@web-nginx ~]# source /etc/profile.d/node.sh
[root@web-nginx ~]# node --version
4、获取考试系统的整个源代码
[root@web-nginx ~]# yum install -y git
[root@web-nginx ~]# git clone https://gitee.com/hyunze/xzs-mysql.git 使用vue版本。
5、安装mysql5.7
查看源代码文档说明,看要求的是什么版本。
[root@web-nginx ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm 下载指定的rpm存储库文件包
[root@web-nginx ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm 作用同上,安装或更新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
[root@web-nginx ~]# systemctl start mysqld
[root@web-nginx ~]# grep pass /var/log/mysqld.log
[root@web-nginx ~]# mysqladmin -uroot -p'旧密码' password '新密码'
[root@web-nginx ~]# mysql -uroot -p'新密码'
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(数据库主机ip):3306/xzs?(源代码要求的数据库名)useSSL=false&useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&allowMultiQueries=true
username: root
password: 数据库密码
driver-class-name: com.mysql.cj.jdbc.Driver
导入初始化sql
[root@web-nginx ~]# mysql -uroot -p'QianFeng@123!' xzs < xzs-mysql/sql/xzs-mysql.sql
6、打包
前端打包
学生端界面打包
[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/ 设置 SASS 二进制文件的下载站点。
[root@web-nginx xzs-student]# npm install --registry https://registry.npm.taobao.org
在安装 Node.js 项目依赖时,指定使用淘宝提供的 npm 镜像注册表
[root@web-nginx xzs-student]# npm run build 构建和部署 Node.js 应用程序
[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程序打包
[root@web-nginx ~]# cd xzs-mysql/source/xzs
[root@web-nginx xzs]# mvn package 构建和打包Java项目
7、服务上线
[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 &
最后一条指令含义:在后台运行一个Java程序,这个程序的JAR文件名为xzs-3.9.0.jar,它使用生产环境的配置,并且将其输出重定向到start1.log文件中。无论当前用户是否登录,这个Java程序都会继续运行。