添加 readme.md
parent
7a4232c076
commit
5b0371034b
|
@ -0,0 +1,401 @@
|
|||
# UP-Portal 系统部署指南
|
||||
|
||||
## 目录
|
||||
- [项目结构](#项目结构)
|
||||
- [部署步骤](#部署步骤)
|
||||
- [Nginx 部署](#一nginx-部署)
|
||||
- [前端部署](#二前端部署)
|
||||
- [服务器环境](#三服务器环境部署)
|
||||
- [Nacos 部署](#四nacos-部署)
|
||||
- [Minio 部署](#五minio-部署)
|
||||
- [服务端部署](#六服务端部署)
|
||||
- [注意事项](#注意事项)
|
||||
|
||||
---
|
||||
|
||||
## 项目结构
|
||||
```
|
||||
portal_client/ # 网站前端
|
||||
portal_admin/ # 网站管理端
|
||||
portal_server/ # 后端服务
|
||||
nacos_config/ # Nacos 配置文件
|
||||
sql/ # 数据库脚本
|
||||
up-portal/ # 图片资源
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 部署步骤
|
||||
|
||||
### 一、Nginx 部署
|
||||
|
||||
#### 1. 安装依赖
|
||||
```bash
|
||||
apt install -y gcc make libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev
|
||||
```
|
||||
|
||||
#### 2. 编译安装
|
||||
```bash
|
||||
tar -xzvf nginx-x.x.x.tar.gz
|
||||
cd nginx-x.x.x
|
||||
./configure
|
||||
make
|
||||
make install
|
||||
```
|
||||
|
||||
#### 3. 配置系统服务
|
||||
创建文件 `/lib/systemd/system/nginx.service`:
|
||||
```ini
|
||||
[Unit]
|
||||
Description=nginx
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
ExecStart=/usr/local/nginx/sbin/nginx
|
||||
ExecReload=/usr/local/nginx/sbin/nginx -s reload
|
||||
ExecStop=/usr/local/nginx/sbin/nginx -s stop
|
||||
PrivateTmp=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
#### 4. 启动服务
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
systemctl enable nginx
|
||||
systemctl start nginx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 二、前端部署
|
||||
|
||||
#### 1. 打包前端
|
||||
```bash
|
||||
npm run build:prod
|
||||
```
|
||||
|
||||
#### 2. Nginx 配置
|
||||
编辑 `/usr/local/nginx/conf/nginx.conf`:
|
||||
```nginx
|
||||
# 客户端(80端口)
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
location / {
|
||||
root /path/to/up-portal-1.0.1;
|
||||
index index.html;
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /portal/ {
|
||||
proxy_pass http://localhost:9080;
|
||||
}
|
||||
|
||||
location /files {
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_pass http://localhost:9000/up-portal;
|
||||
}
|
||||
}
|
||||
|
||||
# 管理端(8080端口)
|
||||
server {
|
||||
listen 8080;
|
||||
server_name localhost;
|
||||
|
||||
location / {
|
||||
root /path/to/up-portal-admin-1.0.1;
|
||||
index index.html;
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /files {
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_pass http://localhost:9000/up-portal;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 三、服务器环境部署
|
||||
|
||||
#### 1. 安装 JDK
|
||||
```bash
|
||||
tar -xzvf jdk-x.x.x_linux-x64_bin.tar.gz -C /opt
|
||||
# 配置环境变量,并使其生效。
|
||||
vim /etc/profile
|
||||
...
|
||||
echo 'export JAVA_HOME=/opt/jdk-x.x.x
|
||||
export PATH=$PATH:$JAVA_HOME/bin' >> /etc/profile
|
||||
source /etc/profile
|
||||
```
|
||||
|
||||
#### 2. 安装 MySQL
|
||||
```bash
|
||||
apt install -y mysql-server
|
||||
|
||||
# 查看mysql内置用户和密码
|
||||
|
||||
cat /etc/mysql/debian.cnf
|
||||
...
|
||||
user = debian-sys-maint
|
||||
password = HzIAVrYXdjwUndPe
|
||||
...
|
||||
|
||||
# 设置root用户的密码 配置远程访问
|
||||
mysql -udebian-sys-maint -p
|
||||
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456';
|
||||
mysql> use mysql; # 使用模式mysql
|
||||
mysql> update user set host = '%' where user = 'root';
|
||||
mysql> exit;
|
||||
|
||||
|
||||
# 修改配置文件
|
||||
vim /etc/mysql/mysql.conf.d/mysqld.cnf
|
||||
...
|
||||
# bind-address = 127.0.0.1 # 或将 127.0.0.1 改为 0.0.0.0
|
||||
...
|
||||
# 重新启动服务
|
||||
service mysql restart
|
||||
|
||||
|
||||
#### 3. 安装 Redis
|
||||
```bash
|
||||
#安装Redis
|
||||
apt install -y redis-server
|
||||
|
||||
# 修改配置
|
||||
vim /etc/redis/redis.conf
|
||||
...
|
||||
# bind 127.0.0.1
|
||||
# protected-mode yes
|
||||
requirepass foobared
|
||||
...
|
||||
|
||||
#重新启动redis
|
||||
redis-cli shutdown
|
||||
redis-server /etc/redis/redis.conf
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
#### 4. 安装 RabbitMQ
|
||||
```bash
|
||||
# 使用apt命令安装RabbitMQ,但需要Erlang语言的支持
|
||||
apt install -y erlang-nox
|
||||
apt install -y rabbitmq-server
|
||||
# 默认guest用户不能进行远程登录,添加admin用户,并赋予administrator权限。
|
||||
rabbitmqctl add_user admin admin
|
||||
rabbitmqctl set_user_tags admin administrator
|
||||
rabbitmqctl set_permissions -p / admin '.*' '.*' '.*'
|
||||
# 启动RabbitMQ Web管理工具。
|
||||
cd /etc/rabbitmq
|
||||
rabbitmq-plugins enable rabbitmq_management
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 四、Nacos 部署
|
||||
|
||||
#### 1. 安装配置
|
||||
```bash
|
||||
tar -xzvf nacos-server-x.x.x.tar.gz -C /opt
|
||||
|
||||
#修改配置文件
|
||||
cd /opt/nacos
|
||||
vim bin/startup.sh
|
||||
...
|
||||
# [ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
|
||||
# [ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
|
||||
# [ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/opt/taobao/java
|
||||
# [ ! -e "$JAVA_HOME/bin/java" ] && unset JAVA_HOME
|
||||
JAVA_HOME=/opt/jdk-x.x.x
|
||||
...
|
||||
|
||||
# 配置数据库
|
||||
vim /opt/nacos/conf/application.properties
|
||||
|
||||
```
|
||||
```properties
|
||||
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?
|
||||
characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
|
||||
&useUnicode=true&useSSL=false&serverTimezone=UTC
|
||||
db.user.0=nacos
|
||||
db.password.0=nacos
|
||||
|
||||
```
|
||||
|
||||
#### 2. 将nacos配置为系统服务,并且设置开机自启动
|
||||
创建 `/lib/systemd/system/nacos.service`:
|
||||
```ini
|
||||
[Unit]
|
||||
Description=nacos
|
||||
After=network.target
|
||||
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
ExecStart=/opt/nacos/bin/startup.sh -m standalone
|
||||
ExecReload=/opt/nacos/bin/shutdown.sh
|
||||
ExecStop=/opt/nacos/bin/shutdown.sh
|
||||
PrivateTmp=true
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
```
|
||||
#### 3.重新加载系统服务,启用nacos服务并开启。
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
systemctl enable nacos.service
|
||||
systemctl start nacos.service
|
||||
|
||||
```
|
||||
---
|
||||
|
||||
### 五、Minio 部署
|
||||
|
||||
#### 1. 安装与启动
|
||||
```bash
|
||||
#在/opt目录(可自定义)下创建目录minio,及其子目录bin、conf、data、logs、target,下载minio至target目录中,并为其添加可执行权限。
|
||||
cd /opt
|
||||
mkdir minio
|
||||
cd ./minio
|
||||
mkdir bin conf data logs target
|
||||
cd target
|
||||
wget https://dl.min.io/server/minio/release/linux-amd64/minio
|
||||
chmod +x minio
|
||||
|
||||
|
||||
# 启动脚本
|
||||
$ vim bin/startup.sh
|
||||
#!/bin/bash
|
||||
export BASE_DIR=`cd $(dirname $0)/..; pwd`
|
||||
export MINIO_ROOT_USER=minioadmin
|
||||
export MINIO_ROOT_PASSWORD=minioadmin
|
||||
if [ ! -d "${BASE_DIR}/conf" ]; then
|
||||
mkdir ${BASE_DIR}/conf
|
||||
fi
|
||||
if [ ! -d "${BASE_DIR}/data" ]; then
|
||||
mkdir ${BASE_DIR}/data
|
||||
fi
|
||||
if [ ! -d "${BASE_DIR}/logs" ]; then
|
||||
mkdir ${BASE_DIR}/logs
|
||||
fi
|
||||
nohup /opt/minio/target/minio server --address :9000 --console-address :19678 /home/cb/miniodata > /opt/minio/logs/miniostart.log &
|
||||
echo "minio is starting, you can check the ${BASE_DIR}/logs/start.out"
|
||||
$ chmod u+x bin/startup.sh
|
||||
|
||||
# 停止脚本
|
||||
$ vim bin/shutdown.sh
|
||||
!/bin/bash
|
||||
target_dir=`cd $(dirname $0)/../target; pwd`
|
||||
pid=`ps ax | grep ${target_dir} | grep -v grep | awk '{print $1}'`
|
||||
if [ -z "$pid" ] ; then
|
||||
echo "No minio server is running."
|
||||
exit -1;
|
||||
fi
|
||||
kill ${pid}
|
||||
echo "Send shutdown request to minio server OK."
|
||||
$ chmod u+x bin/shutdown.sh
|
||||
|
||||
# 将minio配置为系统服务,并且设置开机自启动
|
||||
$ cd /lib/systemd/system
|
||||
$ vim minio.service
|
||||
[Unit]
|
||||
Description=minio
|
||||
After=network.target
|
||||
[Service]
|
||||
Type=forking
|
||||
ExecStart=/opt/minio/bin/startup.sh
|
||||
ExecReload=/opt/minio/bin/shutdown.sh
|
||||
ExecStop=/opt/minio/bin/shutdown.sh
|
||||
PrivateTmp=true
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
# 重新加载系统服务,启用minio服务并开启。
|
||||
$ systemctl daemon-reload
|
||||
$ systemctl enable minio.service
|
||||
$ systemctl start minio.service
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 六、服务端部署
|
||||
|
||||
#### 1. 目录准备
|
||||
```bash
|
||||
mkdir -p /opt/dkha/{bin,conf,data,logs,target}
|
||||
```
|
||||
#### 2. 代码打包上传
|
||||
```bash
|
||||
#执行maven的打包命令,将生成的jar包上传至target目录,包括school-dkha-admin-server.jar、school-dkha-auth.jar、school-dkha-gateway.jar、school-dkha-portal-server.jar,为上述jar包添加可执行权限。
|
||||
$ mvn package
|
||||
$ chmod u+x target/*
|
||||
|
||||
|
||||
```
|
||||
|
||||
#### 3. 启动脚本
|
||||
创建 `/opt/dkha/bin/startup.sh`:
|
||||
```bash
|
||||
#!/bin/bash
|
||||
error_exit ()
|
||||
{
|
||||
echo "ERROR: $1 !!"
|
||||
exit 1
|
||||
}
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
error_exit "Please set the JAVA_HOME variable in your environment, we need java(x64)! jdk8 or later is better!"
|
||||
fi
|
||||
export BASE_DIR=`cd $(dirname $0)/..; pwd`
|
||||
if [ ! -d "${BASE_DIR}/logs" ]; then
|
||||
mkdir ${BASE_DIR}/logs
|
||||
fi
|
||||
for SERVICE in `cd $BASE_DIR/target; ls`; do
|
||||
SERVICE_NAME=${SERVICE%\.*}
|
||||
echo "Service ${SERVICE_NAME} is starting..."
|
||||
nohup java -Dspring.profiles.active=prod -jar ${BASE_DIR}/target/${SERVICE} > ${BASE_DIR}/logs/${SERVICE_NAME}.out 2>&1 &
|
||||
done
|
||||
echo "UP-portal server startup successfully!"
|
||||
$ chmod u+x bin/startup.sh
|
||||
|
||||
#注释:若运行脚本无效,则可在目录下单独运行所有jar包
|
||||
nohup java -jar school-dkha-portal-server.jar --spring.profiles.active=prod &
|
||||
|
||||
```
|
||||
#### 4. 停止脚本
|
||||
```bash
|
||||
$ vim bin/shutdown.sh
|
||||
#!/bin/bash
|
||||
target_dir=`cd $(dirname $0)/../target; pwd`
|
||||
pid=`ps ax | grep ${target_dir} | grep java | grep -v grep | awk '{print $1}'`
|
||||
if [ -z "$pid" ] ; then
|
||||
echo "No UP-portal server is running."
|
||||
exit -1;
|
||||
fi
|
||||
kill ${pid}
|
||||
echo "Send shutdown request to UP-portal server OK."
|
||||
$ chmod u+x bin/shutdown.sh
|
||||
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 注意事项
|
||||
1. **路径调整**:所有 `/opt/` 下的路径需根据实际部署位置修改
|
||||
2. **安全配置**:
|
||||
- MySQL 密码 `123456`、Redis 密码 `your_password` 等需替换为强密码
|
||||
- Minio 的 `MINIO_ROOT_USER` 和 `MINIO_ROOT_PASSWORD` 需修改
|
||||
3. **端口冲突**:检查 `9000`(Minio)、`9080`(服务端)等端口是否被占用
|
||||
4. **日志监控**:定期查看 `/opt/dkha/logs/` 和 `/opt/minio/logs/` 下的日志文件
|
Loading…
Reference in New Issue