别再折腾Docker镜像了!Ubuntu 18.04 + Docker 19.03.6 一键部署OAI 5G核心网(v1.4.0)保姆级避坑指南
·
Ubuntu 18.04环境下OAI 5G核心网高效部署实战指南
1. 环境准备与痛点分析
每次尝试部署OAI 5G核心网时,最令人头疼的莫过于漫长的Docker镜像下载等待和版本兼容性问题。本文将分享一套经过实战验证的部署方案,基于Ubuntu 18.04和Docker 19.03.6的黄金组合,配合国内镜像源加速,让你摆脱反复试错的困扰。
关键组件版本锁定:
- 操作系统:Ubuntu 18.04.6 LTS
- Docker引擎:19.03.6
- Docker-Compose:1.29.2
- OAI核心网版本:v1.4.0
注意:版本严格匹配是避免兼容性问题的首要条件,后续所有操作都基于此版本组合
2. 系统环境快速配置
2.1 基础环境调优
在开始安装前,建议执行以下系统优化操作:
# 更新软件源并升级现有包
sudo apt update && sudo apt upgrade -y
# 安装基础工具集
sudo apt install -y git curl wget vim net-tools python3-pip
国内用户必做:替换APT软件源为阿里云镜像
sudo sed -i 's|http://.*archive.ubuntu.com|http://mirrors.aliyun.com|g' /etc/apt/sources.list
sudo sed -i 's|http://.*security.ubuntu.com|http://mirrors.aliyun.com|g' /etc/apt/sources.list
2.2 Docker精准安装
避免使用最新版Docker,19.03.6版本经测试与OAI v1.4.0兼容性最佳:
# 卸载旧版本(如有)
sudo apt remove docker docker-engine docker.io containerd runc
# 安装依赖工具
sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
# 添加Docker官方GPG密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# 添加稳定版仓库
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# 安装指定版本
sudo apt update
sudo apt install -y docker-ce=5:19.03.6~3-0~ubuntu-bionic docker-ce-cli=5:19.03.6~3-0~ubuntu-bionic containerd.io
# 验证安装
sudo docker version | grep -A2 "Server:"
预期输出应显示:
Server: Docker Engine - Community
Engine:
Version: 19.03.6
3. 镜像加速与核心网组件部署
3.1 配置Docker镜像加速
创建或修改/etc/docker/daemon.json文件:
{
"registry-mirrors": ["https://<你的ID>.mirror.aliyuncs.com"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
}
}
重启Docker服务使配置生效:
sudo systemctl daemon-reload
sudo systemctl restart docker
3.2 核心网镜像批量下载
使用预编写的脚本一次性下载所有必需镜像:
#!/bin/bash
IMAGES=(
"oaisoftwarealliance/oai-amf:v1.4.0"
"oaisoftwarealliance/oai-nrf:v1.4.0"
"oaisoftwarealliance/oai-smf:v1.4.0"
"oaisoftwarealliance/oai-spgwu-tiny:v1.4.0"
"oaisoftwarealliance/oai-udr:v1.4.0"
"oaisoftwarealliance/oai-udm:v1.4.0"
"oaisoftwarealliance/oai-ausf:v1.4.0"
"oaisoftwarealliance/oai-upf-vpp:v1.4.0"
"oaisoftwarealliance/oai-nssf:v1.4.0"
"oaisoftwarealliance/trf-gen-cn5g:latest"
)
for image in "${IMAGES[@]}"; do
echo "Pulling $image..."
docker pull $image
done
镜像重命名操作:
docker image tag oaisoftwarealliance/oai-amf:v1.4.0 oai-amf:v1.4.0
docker image tag oaisoftwarealliance/oai-nrf:v1.4.0 oai-nrf:v1.4.0
# 其他镜像类似操作...
4. 网络配置与核心网启动
4.1 创建专用网络
docker network create \
--driver=bridge \
--subnet=192.168.70.128/26 \
-o "com.docker.network.bridge.name"="demo-oai" \
demo-oai-public-net
验证网络创建:
docker network inspect demo-oai-public-net | grep -E "Subnet|Gateway"
4.2 核心网代码获取
git clone https://gitlab.eurecom.fr/oai/cn5g/oai-cn5g-fed.git
cd oai-cn5g-fed
git checkout -f v1.4.0
./scripts/syncComponents.sh
4.3 一键启动脚本
创建start_oai.sh启动脚本:
#!/bin/bash
# 启用IP转发
sudo sysctl net.ipv4.conf.all.forwarding=1
sudo iptables -P FORWARD ACCEPT
# 启动基础核心网
python3 core-network.py --type start-basic
# 查看运行状态
echo "Checking container status..."
docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}"
5. 常见问题排查指南
5.1 容器启动失败排查
查看特定组件日志:
docker logs oai-amf --tail 100
关键错误代码解析:
| 错误代码 | 可能原因 | 解决方案 |
|---|---|---|
| E1001 | 端口冲突 | 检查8080、8000等端口占用 |
| E2002 | 网络配置错误 | 验证demo-oai网络配置 |
| E3003 | 镜像版本不匹配 | 确认所有镜像均为v1.4.0 |
5.2 性能优化参数
编辑docker-compose-mini-nonrf.yaml添加资源限制:
services:
oai-amf:
deploy:
resources:
limits:
cpus: '1'
memory: 1G
ulimits:
nofile:
soft: 65536
hard: 65536
6. 高级部署技巧
6.1 持久化数据配置
创建数据卷避免重启丢失配置:
docker volume create oai-amf-data
然后在compose文件中挂载:
volumes:
- oai-amf-data:/opt/oai-amf/config
6.2 健康检查配置
为每个服务添加健康检查:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:80/health"]
interval: 30s
timeout: 10s
retries: 3
7. 实战经验分享
在实际部署过程中,发现几个关键点需要特别注意:
- 时间同步问题:容器内时间与主机不同步会导致认证失败,建议在宿主机安装NTP服务:
sudo apt install chrony -y
sudo timedatectl set-ntp true
- 内存不足处理:当物理内存不足时,可以调整swappiness值:
echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
- 批量操作技巧:使用docker-compose命令同时管理所有服务:
# 查看所有容器状态
docker-compose -f docker-compose-mini-nonrf.yaml ps
# 停止所有服务
docker-compose -f docker-compose-mini-nonrf.yaml down
更多推荐
所有评论(0)