# ems_backend

后端

## 文件资源

| 路径                   | 说明                       |
| ---------------------- | -------------------------- |
| /usr/local/omc/static  | 网管静态资源文件路径       |
| /usr/local/omc/upload  | 网管上传文件资源路径       |
| /usr/local/omc/backup  | 网管备份网元的数据路径     |
| /usr/local/omc/trace   | 网管跟踪相关的数据路径     |
| /usr/local/omc/tcpdump | 网管 tcpdump 抓包件路径    |
| /usr/local/omc/packet  | 网管信令抓包的数据路径     |
| /usr/local/etc/omc     | 网管与网元之间相关文件     |
| /tmp/omc               | 存放从网元拉取到本地的文件 |

## 端口

| 端口        | 说明                 |
| ----------- | -------------------- |
| 33030/33443 | 网管 Api             |
| 80/443      | 网管 Web             |
| 33033/33034 | 信令跟踪上报 UDP/TCP |
| 33060       | 性能分析 pprof       |
| 33040       | 网管测试 Api         |
| 21/22/25    | SSH/FTP              |
| 33066       | 网管连接 mysql       |
| 6379        | 网管连接 redis       |

## redis 配置文件相关

```conf
# IP绑定与端口
bind 0.0.0.0
port 6379
# 安全设置
protected-mode yes
requirepass "helloearth"
# 查看主备
info replication
# 从节点只能读取数据，不能直接写入数据
# replicaof是新版本的命令，旧版本是slaveof命令
slaveof 192.168.114.114 6379
replicaof 192.168.114.114 6379
masterauth "helloearth"
# 允许从节点进行读写操作
replica-read-only no
```

## 编译发布

```bash
# 版本发布空间
\\192.168.1.205\share_205\release\omc

# 研发git
192.168.1.120
altouser/a1t0U53r

# 默认IOS镜像用户和密码
agtuser/admin123
manager/admin123
omcuser/a9tU53r

# 软件包编译环境 密码：Admin123@pl
ssh -P 18522 root@192.168.9.58 # arm64 anolis:8
ssh -P 18422 root@192.168.9.58 # amd64 ubuntu:22.04
ssh -P 18322 root@192.168.9.58 # amd64 ubuntu:18.04
ssh -P 18222 root@192.168.9.58 # amd64 openEuler:20.03
ssh -P 18122 root@192.168.9.58 # arm64 ubuntu:18.04

```

# 系统工具依赖包

- [ubuntu-iperf3](https://launchpad.net/ubuntu/+source/iperf3)
- [ubuntu-libsctp1](https://launchpad.net/ubuntu/jammy/amd64/libsctp1/1.0.19+dfsg-1build1)
- [ky10-aarch64](https://update.cs2c.com.cn/NS/V10/V10SP3/os/adv/lic/base/aarch64/Packages/)

## 调试开发

```sh
# 安装 Go版本 1.21.6 后进入项目根目录
cd /ems_backend
# 下载依赖
go mod download

# 信令跟踪需要安装 libpcap-dev > 1.10.1-4build1
apt install -y libpcap-dev
go env -w CGO_ENABLED='1'

# 调试启动
go run main.go --env local -c ./local/omc.yaml

# 调试分析
# http://127.0.0.1:33060/debug/pprof/
go tool pprof -http=:9090 http://127.0.0.1:33060/debug/pprof/heap

# 生成 swagger 文档
swag init -d ./ -g main.go -o ./swagger_docs
swag fmt -d ./ -g main.go

# 打包命名 omc
go build -ldflags="-s -w" -o omc
```

## 二进制打包

```sh
go env -w GOOS=linux

go env -w GOOS=windows

go build -o omc -v -ldflags="-s -w -X 'be.ems/src/framework/config.Version=2.2503.14' -X 'be.ems/src/framework/config.BuildTime=$(date)' -X 'be.ems/src/framework/config.GoVer=$(go version)'"

```

## 软件包安装

```sh
# 脚本升级
sudo bash /usr/local/etc/omc/script/setup.sh -u

# Deb
sudo dpkg -l omc
sudo dpkg -r omc
sudo M_PARAM=std C_PARAM=agt dpkg -i omc-r2.2503.2-20250320-ubuntu-amd64.deb
sudo M_PARAM=lite C_PARAM=agt dpkg -i omc-r2.2503.2-20250320-ubuntu-amd64.deb

# Rpm
sudo rpm -qi omc
sudo rpm -e omc
sudo M_PARAM=lite C_PARAM=agt rpm -i omc-r2.2503.2-20250320-anolis-arm64.rpm
sudo rpm -Uvh --reinstall --nosignature --force omc-r2.2503.2-20250320-anolis-arm64.rpm

```

## 数据库相关

```sh
# 数据库导入
mysql -uroot -p1000omc@kp! -P 33066 --protocol tcp -D omc_db < u_user_info.sql

# 数据库数据临时备份
SELECT COUNT(1) FROM cdr_event_smsc WHERE TIMESTAMP >= 173972159
CREATE TABLE cdr_event_smsc_bak LIKE cdr_event_smsc
INSERT INTO cdr_event_smsc_bak SELECT * FROM cdr_event_smsc WHERE TIMESTAMP <= 1739540000
DELETE FROM cdr_event_smsc WHERE TIMESTAMP <= 1739540000

# 执行数据库脚本
./omc.exe -c ./local/omc.yaml --sqlPath ./build/database/std/common --sqlSource std
./omc.exe -c ./local/omc.yaml --sqlPath ./build/database/std/install --sqlSource std
./omc.exe -c ./local/omc.yaml --sqlPath ./build/database/std/upgrade/upg_sys_dict_data.sql --sqlSource std

./omc.exe -c ./local/omc.yaml --sqlPath ./build/database/lite/common --sqlSource lite
./omc.exe -c ./local/omc.yaml --sqlPath ./build/database/lite/install --sqlSource lite
./omc.exe -c ./local/omc.yaml --sqlPath ./build/vendor/omc/database/lite/customized.sql --sqlSource lite

sudo /usr/local/bin/omc -c /usr/local/etc/omc/omc.yaml --sqlPath /usr/local/etc/omc/database/lite/install --sqlSource lite
sudo /usr/local/bin/omc -c /usr/local/etc/omc/omc.yaml --sqlPath /usr/local/etc/omc/database/lite/upgrade/upg_sys_dict_data.sql --sqlSource lite
```
