Mac 本地开发部署环境记录
本文档记录在 Mac 本机运行 wvp-GB28181-pro 的环境配置。当前目标是:
- MySQL 使用 Mac 本机已有服务。
- Redis 使用 Docker 容器。
- ZLMediaKit 使用 Mac 本地编译运行的
MediaServer。 - WVP 后端使用 IDEA 启动。
- 前端使用本机 Node/NPM 启动。
1. 项目信息
| 项目 | 值 |
|---|---|
| 项目目录 | /Users/lizhenglee/Documents/swzj/sp/wvp-GB28181-pro |
| 后端版本 | 2.7.4 |
| 后端 Java 版本 | 21 |
| 后端 Profile | dev |
| 后端端口 | 18080 |
| 前端目录 | /Users/lizhenglee/Documents/swzj/sp/wvp-GB28181-pro/web |
| 前端端口 | 9528 |
2. Java 和 IDEA
后端需要 JDK 21。
IDEA 项目 JDK 使用:
text
ms-21
当前项目 pom.xml 中要求:
xml
<java.version>21</java.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
IDEA 后端启动配置:
text
Run/Debug Configurations
Type: Application
Main class: com.genersoft.iot.vmp.VManageBootstrap
JDK: 21
Working directory: /Users/lizhenglee/Documents/swzj/sp/wvp-GB28181-pro
Active profiles: dev
如果没有 Active profiles 输入框,可以在 VM options 中配置:
text
-Dspring.profiles.active=dev
当前 src/main/resources/application.yml 已配置:
yaml
spring:
profiles:
active: dev
3. MySQL 本地配置
本机 MySQL 使用已有服务。
当前后端配置:
yaml
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/wvp2?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true&serverTimezone=PRC&useSSL=false&allowMultiQueries=true&allowPublicKeyRetrieval=true
username: root
password: 12345678
数据库名:
text
wvp2
全新初始化数据库:
bash
cd /Users/lizhenglee/Documents/swzj/sp/wvp-GB28181-pro
mysql -uroot -p -e "DROP DATABASE IF EXISTS wvp2;"
mysql -uroot -p -e "CREATE DATABASE wvp2 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
mysql -uroot -p wvp2 < 数据库/2.7.4/初始化-mysql-2.7.4.sql
注意:
- 全新库只执行
数据库/2.7.4/初始化-mysql-2.7.4.sql。 - 不要对全新库执行
数据库/2.7.4/更新-mysql-2.7.4.sql。 wvp_device_mobile_position在 2.7.4 中已经改为wvp_mobile_position。
检查默认用户:
bash
mysql -uroot -p wvp2 -e "select id, username, password from wvp_user;"
默认 WVP 登录账号:
text
账号:admin
密码:admin
4. Redis Docker 配置
Redis 使用 Docker 容器,容器名:
text
local-redis
首次创建:
bash
docker run -d \
--name local-redis \
-p 6379:6379 \
redis:7 \
redis-server --requirepass root
以后启动:
bash
docker start local-redis
查看状态:
bash
docker ps -a --filter name=local-redis
验证 Redis:
bash
docker exec -it local-redis redis-cli -a root ping
正常返回:
text
PONG
当前后端 Redis 配置:
yaml
spring:
data:
redis:
host: 127.0.0.1
port: 6379
database: 6
password: root
timeout: 10000
5. ZLMediaKit 本地配置
ZLMediaKit 使用 Mac 本地编译的 MediaServer。
启动路径示例:
text
/Users/lizhenglee/CLionProjects/ZLMediaKit/release/darwin/Debug/MediaServer
启动后需要确认监听端口:
text
HTTP: 80
RTSP: 554
RTMP: 1935
RTP: 10000
WVP 当前媒体配置:
yaml
media:
id: your_server_id
ip: 127.0.0.1
http-port: 80
secret: qCJU77A6LJOeldE56QU5rUwbgreGLH0y
sdp-ip: 192.168.0.12
stream-ip: 192.168.0.12
rtp:
enable: true
port-range: 40000,45000
send-port-range: 50000,55000
说明:
media.ip=127.0.0.1表示 WVP 本机访问 ZLM HTTP API。media.http-port=80必须和 ZLM 实际 HTTP 端口一致。media.id必须和 ZLM 的general.mediaServerId一致。当前 ZLM hook 上报的是your_server_id。media.secret必须和 ZLM 配置中的api.secret/hook.admin_params对应。sdp-ip和stream-ip必须填写摄像机能访问到的 Mac 局域网 IP,当前是192.168.0.12。
如果 WVP 日志出现:
text
[ZLM HOOK] 此zlm未接入 your_server_id
说明 WVP 的 media.id 和 ZLM 的 general.mediaServerId 不一致。
如果 WVP 日志出现:
text
Failed to connect to /127.0.0.1:80
说明 WVP 连接不到本地 ZLM,先确认 ZLM 已启动并监听 80:
bash
lsof -nP -iTCP:80 -sTCP:LISTEN
6. WVP SIP 配置
当前 SIP 配置:
yaml
sip:
port: 8116
domain: 4101050000
id: 41010500002000000001
password: 12345678
alarm: false
设备接入 WVP 时常用参数:
text
SIP服务器IP:192.168.0.12
SIP服务器端口:8116
SIP服务器ID:41010500002000000001
SIP服务器域:4101050000
认证密码:12345678
传输协议:UDP
测试设备国标编号示例:
text
44010200491320000001
如果设备已经在数据库 wvp_device 中存在,并且该设备记录有单独密码,则设备密码会优先于 sip.password。
检查设备密码:
bash
mysql -uroot -p wvp2 -e "select id, device_id, password from wvp_device where device_id='44010200491320000001';"
7. WVP 后端启动顺序
推荐启动顺序:
text
1. 启动 MySQL
2. 启动 Redis Docker 容器
3. 启动 ZLMediaKit MediaServer
4. 在 IDEA 中启动 WVP 后端
5. 启动前端
Redis:
bash
docker start local-redis
docker exec -it local-redis redis-cli -a root ping
ZLMediaKit:
bash
/Users/lizhenglee/CLionProjects/ZLMediaKit/release/darwin/Debug/MediaServer
IDEA 启动:
text
Main class: com.genersoft.iot.vmp.VManageBootstrap
Active profile: dev
启动成功后后端地址:
text
http://localhost:18080
如果 SIP 端口被占用:
bash
lsof -nP -iTCP:8116 -sTCP:LISTEN
lsof -nP -iUDP:8116
结束占用进程:
bash
kill <PID>
必要时:
bash
kill -9 <PID>
8. 前端 Node 环境
前端是 Vue 2 + Vue CLI 4:
json
"vue": "2.6.10",
"@vue/cli-service": "4.4.4"
推荐 Node:
text
Node.js 16.20.2
npm 8.19.4
使用 nvm:
bash
nvm use 16.20.2
node -v
npm -v
如果 Apple Silicon 下安装依赖遇到 deasync / node-gyp 编译错误,可以使用 Rosetta x64 shell:
bash
softwareupdate --install-rosetta --agree-to-license
arch -x86_64 zsh
export NVM_ARCH=x64
nvm install 16.20.2
nvm use 16.20.2
node -p "process.arch"
期望输出:
text
x64
安装依赖:
bash
cd /Users/lizhenglee/Documents/swzj/sp/wvp-GB28181-pro/web
rm -rf node_modules package-lock.json
npm install --legacy-peer-deps
本地启动前端:
bash
cd /Users/lizhenglee/Documents/swzj/sp/wvp-GB28181-pro/web
nvm use 16.20.2
npm run dev
访问:
text
http://localhost:9528
生产打包:
bash
npm run build:prod
构建产物:
text
web/dist
9. 点播问题排查
如果设备注册成功,但点播失败,重点看 WVP 日志中的收流地址。
错误示例:
text
收流地址:127.0.0.1:xxxxx
rtpServer收流超时
原因:
text
127.0.0.1 对摄像机来说是摄像机自己,不是 Mac。
正确情况:
text
收流地址:192.168.0.12:xxxxx
需要确认:
media.sdp-ip是 Mac 局域网 IP。media.stream-ip是 Mac 局域网 IP。- 摄像机能访问 Mac。
- Mac 防火墙没有拦截 ZLM/WVP。
- ZLM 的 RTP 端口范围可用。
当前配置:
yaml
media:
sdp-ip: 192.168.0.12
stream-ip: 192.168.0.12
查看 Mac 局域网 IP:
bash
ifconfig | grep "inet 192.168"
如果 Mac IP 变化,需要同步修改 application-dev.yml 中的:
yaml
media:
sdp-ip: 新的Mac局域网IP
stream-ip: 新的Mac局域网IP
10. 常用检查命令
检查 Redis:
bash
docker ps -a --filter name=local-redis
docker exec -it local-redis redis-cli -a root ping
检查 MySQL:
bash
mysql -uroot -p -e "show databases;"
mysql -uroot -p wvp2 -e "show tables;"
检查后端端口:
bash
lsof -nP -iTCP:18080 -sTCP:LISTEN
检查 SIP 端口:
bash
lsof -nP -iTCP:8116 -sTCP:LISTEN
lsof -nP -iUDP:8116
检查 ZLM HTTP 端口:
bash
lsof -nP -iTCP:80 -sTCP:LISTEN
检查 Mac 局域网 IP:
bash
ifconfig | grep "inet 192.168"
11. 当前关键账号和密码
| 类型 | 值 |
|---|---|
| WVP 登录账号 | admin |
| WVP 登录密码 | admin |
| MySQL 数据库 | wvp2 |
| MySQL 用户 | root |
| MySQL 密码 | 12345678 |
| Redis 密码 | root |
| SIP 认证密码 | 12345678 |
| ZLM secret | qCJU77A6LJOeldE56QU5rUwbgreGLH0y |
12. 当前本地启动清单
每次本地开发前按顺序确认:
bash
# 1. Redis
docker start local-redis
docker exec -it local-redis redis-cli -a root ping
# 2. ZLM
/Users/lizhenglee/CLionProjects/ZLMediaKit/release/darwin/Debug/MediaServer
# 3. IDEA 启动 WVP
# Main class: com.genersoft.iot.vmp.VManageBootstrap
# Profile: dev
# 4. 前端
cd /Users/lizhenglee/Documents/swzj/sp/wvp-GB28181-pro/web
nvm use 16.20.2
npm run dev