部署
部署
Linux线上环境搭建,新服务器推荐使用oneinstack
# 一键配置服务器环境
wget -c http://mirrors.oneinstack.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz && ./oneinstack/install.sh --nginx_option 1 --jdk_option 3 --db_option 1 --dbinstallmethod 1 --dbrootpwd ycbwi5xd --redis --reboot
服务部署
将admin和client编译后生产的文件上传到服务器。服务目录结构:
financial
├── admin
│ └── server
│ └── prod.yml
│ └── financial3a.conf
│ └── financial3a.jar
│ └── front
├── client
│ └── server
│ └── prod.yml
│ └── financial3.conf
│ └── financial3.jar
│ └── front
配置
prod.yml配置内容参考,根据实际情况修改为服务器配置对应值
⚠️ admin和client配置中server.port配的端口不能一样
# 生产环境数据库连接信息
spring:
profiles:
active: prod
datasource:
url: jdbc:mysql://localhost:3306/financial3?characterEncoding=UTF-8&useUnicode=true&useSSL=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true
password:
username:
data:
redis:
url: "redis://127.0.0.1:6379" # 需要密码访问redis时配置:"redis://:password@127.0.0.1:6379"
# 服务运行日志存储路径
logging:
file:
path: /data/logs/financial3
# 服务端口和tomcat虚拟根目录
server:
port: 9097
tomcat:
basedir: /data/worker/financial3/
# 系统服务配置,
app:
aliyun: # 访问阿里云接口的access
accessKeyId:
accessKeySecret:
sms:
signature: 纷析云 # 阿里云短信签名
template-code:
verification: SMS_175580136 # 阿里云验证码短信模板ID
register: SMS_217436843 # 注册账号发送默认密码,需要自己申请模板,申请模板内容:您的手机已经成功注册纷析云财务软件,密码是${password},您可以登录使用啦!
backup-path: /data/backup # 账套备份文件存储路径
upload-root: /data/upload # 文件上传存储路径
font-path: /data/server/financial3/simsun.ttc #pdf字体
.conf文件配置参考
⚠️ *.conf文件的名称必须和jar文件名称一致
JAVA_HOME=/usr/lib/jdk-17.0.6/
JAVA_OPTS="-server -Xms512m -Xmx512m -Dspring.config.import=file:/data/server/financial3/prod.yml -Djava.io.tmpdir=/data/temp/financial3/ -Djava.security.egd=file:/dev/./urandom"
- JAVA_HOME:指定java所在路径
- JAVA_OPTS:服务启动参数设置
- -Dspring.config.import=file:/data/server/financial3/prod.yml指定对应服务的prod.yml配置路径
- -Djava.io.tmpdir 服务临时目录位置
运行
# jar 方式启动
java -jar financial3a.jar
# 以Linux程序启动
./financial3a.jar
上述方式,可作为测试使用,实际生产环境还是不够方便,我们可添加centos系统服务,方便程序启动和停止,操作方式如下:
Centos服务注册
在系统的 /etc/systemd/system 目录创建两个服务文件:
financial3.service
⚠️ 注意各配置路径
```editorconfig
[Unit]
Description=financial3
After=network.target
[Service]
User=www
Group=www
WorkingDirectory=/data/worker/financial3
ExecStart=/financial/client/server/financial3.jar
ExecStop=kill
SuccessExitStatus=143
Restart=always
[Install]
WantedBy=multi-user.target
**financial3a.service**
> ⚠️ 注意各配置路径
```editorconfig
[Unit]
Description=financial3a
After=network.target
[Service]
User=www
Group=www
WorkingDirectory=/data/worker/financial3a
ExecStart=/financial/admin/server/financial3a.jar
ExecStop=kill
SuccessExitStatus=143
Restart=always
[Install]
WantedBy=multi-user.target
启动服务
systemctl start financial3
systemctl start financial3a
# 设置为自动启动
systemctl enable financial3
systemctl enable financial3a
前端部署
nginx域名配置
```nginx configuration
两个配置,一个root指定到admin的front,一个指定到client的font下面,
api中proxy_pass指定到对应服务配置的端口,进行服务转发
如果没有域名,servername设置为 ““,对应的listen设置为不一样的两个端口。
server {
listen 80;
server_name admin.financial.com;
access_log /dnmp/logs/nginx/f2_nginx.log combined;
index index.html index.htm index.php;
root /financial/admin/front;
location ^~ /api/ {
index index.html index.htm;
if ( !-e $request_filename ) {
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:9091;
}
include proxy.conf;
}
location / {
try_files $uri $uri/ /index.html;
}
}
server {
listen 80;
server_name financial.com;
access_log /dnmp/logs/nginx/f2_nginx.log combined;
index index.html index.htm index.php;
root /financial/client/front;
location ^~ /api/ {
index index.html index.htm;
if ( !-e $request_filename ) {
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:9092;
}
include proxy.conf;
}
location / {
try_files $uri $uri/ /index.html;
}
}
### proxy.conf配置
```nginx configuration
proxy_connect_timeout 300s;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 32k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_redirect off;
proxy_hide_header Vary;
proxy_set_header Accept-Encoding '';
proxy_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;