# Systemd 服务配置 本目录包含灵越智报各服务的 systemd 配置文件。 ## 服务列表 | 服务文件 | 服务名 | 端口 | 说明 | |---------|--------|------|------| | `lingyue-starter.service` | lingyue-starter | 5232 | Java 主应用(单体启动器) | | `lingyue-extract.service` | lingyue-extract | 8086 | 模板系统服务 | | `lingyue-ner.service` | lingyue-ner | 8001 | NER Python 服务 | ## 安装步骤 ### 1. 复制服务文件到 systemd 目录 ```bash sudo cp scripts/systemd/*.service /etc/systemd/system/ ``` ### 2. 重新加载 systemd 配置 ```bash sudo systemctl daemon-reload ``` ### 3. 启用服务(开机自启) ```bash # 启用主应用 sudo systemctl enable lingyue-starter # 启用模板服务(可选,如果单独运行) sudo systemctl enable lingyue-extract # 启用 NER 服务 sudo systemctl enable lingyue-ner ``` ### 4. 启动服务 ```bash # 启动主应用 sudo systemctl start lingyue-starter # 启动 NER 服务 sudo systemctl start lingyue-ner ``` ## 常用命令 ```bash # 查看服务状态 sudo systemctl status lingyue-starter sudo systemctl status lingyue-extract sudo systemctl status lingyue-ner # 启动服务 sudo systemctl start lingyue-starter # 停止服务 sudo systemctl stop lingyue-starter # 重启服务 sudo systemctl restart lingyue-starter # 查看实时日志 sudo journalctl -u lingyue-starter -f # 查看最近 100 行日志 sudo journalctl -u lingyue-starter -n 100 ``` ## 日志位置 日志文件存储在 `/var/log/lingyue/` 目录: ``` /var/log/lingyue/ ├── lingyue-starter.log # 主应用日志 ├── lingyue-starter-error.log # 主应用错误日志 ├── extract-service.log # 模板服务日志 ├── extract-service-error.log # 模板服务错误日志 ├── ner-service.log # NER 服务日志 └── ner-service-error.log # NER 服务错误日志 ``` 创建日志目录: ```bash sudo mkdir -p /var/log/lingyue sudo chmod 755 /var/log/lingyue ``` ## 修改配置 如需修改配置(如端口、数据库连接等),编辑对应的 `.service` 文件中的 `Environment` 部分: ```ini # 数据库配置 Environment=DB_HOST=localhost Environment=DB_PORT=5432 Environment=DB_NAME=lingyue_zhibao Environment=DB_USERNAME=lingyue Environment=DB_PASSWORD=123123 ``` 修改后重新加载并重启: ```bash sudo systemctl daemon-reload sudo systemctl restart lingyue-starter ``` ## 健康检查 ```bash # 主应用健康检查 curl http://localhost:5232/actuator/health # 模板服务健康检查 curl http://localhost:8086/api/v1/extract/health # NER 服务健康检查 curl http://localhost:8001/health ``` ## 一键脚本 也可以使用项目根目录的 `server-deploy.sh` 进行管理: ```bash # 查看状态 ./server-deploy.sh status # 启动所有服务 ./server-deploy.sh start # 停止所有服务 ./server-deploy.sh stop # 重启 ./server-deploy.sh restart ```