1 前期准备

1.1 安装Ubuntu

建议使用 Ubuntu 18.04.5+(包括 Ubuntu 20.04)作为主机系统。

可以参考此教程安装Ubuntu 18.04+。

安装完成后执行软件更新:

sudo apt-get update
sudo apt-get upgrade

1.2 安装NVIDIA GPU驱动

对于 Ubuntu 18.04+,只需运行:

sudo apt-get update
sudo apt-add-repository multiverse
sudo apt-get update
sudo apt-get install nvidia-driver-455

重新启动主机以使更改生效。

输入nvidia-smi来检查 NVIDIA GPU 在主机上是否正常工作。

如果安装成功,将显示以下信息:

Tue Jun 15 18:18:17 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.80       Driver Version: 460.80       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GT 1030     Off  | 00000000:01:00.0  On |                  N/A |
| 20%   39C    P0    N/A /  30W |    494MiB /  1999MiB |      4%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1859      G   /usr/lib/xorg/Xorg                 18MiB |
|    0   N/A  N/A      1899      G   /usr/bin/gnome-shell               67MiB |
|    0   N/A  N/A      2662      G   /usr/lib/xorg/Xorg                202MiB |
|    0   N/A  N/A      2789      G   /usr/bin/gnome-shell               28MiB |
|    0   N/A  N/A      3313      G   ...AAAAAAAAA= --shared-files       30MiB |
|    0   N/A  N/A      3760      G   /usr/lib/firefox/firefox          140MiB |
|    0   N/A  N/A      5725      G   /usr/lib/firefox/firefox            0MiB |
+-----------------------------------------------------------------------------+

1.3 安装Docker Engine

Apollo 6.0+ 需要 Docker 19.03+ 才能正常工作。按照此文档在Ubuntu上安装Docker Engine。

Ubuntu 上的 Docker-CE 也可以使用 Docker 的官方便利脚本进行设置:

curl https://get.docker.com | sh
sudo systemctl start docker && sudo systemctl enable docker

继续按照此文档进行一些操作,Manage Docker as a non-root userConfigure Docker to start on boot是必须要做的。

1.4 安装NVIDIA Container Toolkit

运行以下命令来安装NVIDIA Container Toolkit:

distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get -y update
sudo apt-get install -y nvidia-docker2

可能会报以下错误:

gpg: could not find a valid OpenPGP

W: Failed to fetch https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/x86_64/InRelease  Could not connect to nvidia.github.io:443 (::1). - connect (111: Connection refused) Could not connect to nvidia.github.io:443 (127.0.0.1). - connect (111: Connection refused)
W: Failed to fetch https://nvidia.github.io/nvidia-container-runtime/stable/ubuntu18.04/x86_64/InRelease  Unable to connect to nvidia.github.io:https:
W: Failed to fetch https://nvidia.github.io/nvidia-docker/ubuntu18.04/x86_64/InRelease  Unable to connect to nvidia.github.io:https:

E: Unable to locate package nvidia-docker2

这里,科学上网并不能解决问题。

打开文件/etc/apt/sources.list.d/nvidia-docker.list,然后添加以下内容,最后保存并退出。

deb https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/$(ARCH) /
#deb https://nvidia.github.io/libnvidia-container/experimental/ubuntu18.04/$(ARCH) /
deb https://nvidia.github.io/nvidia-container-runtime/stable/ubuntu18.04/$(ARCH) /
#deb https://nvidia.github.io/nvidia-container-runtime/experimental/ubuntu18.04/$(ARCH) /
deb https://nvidia.github.io/nvidia-docker/ubuntu18.04/$(ARCH) /

打开/etc/hosts,然后添加以下内容,最后保存并退出。

# nvidia.github.io
185.199.108.153 nvidia.github.io
185.199.109.153 nvidia.github.io
185.199.110.153 nvidia.github.io
185.199.111.153 nvidia.github.io

不要忘记重新启动 Docker 守护进程以使上述更改生效。

sudo systemctl restart docker

参考:

  • https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#installing-on-ubuntu-and-debian
  • https://blog.csdn.net/weixin_43002433/article/details/108888927

2 下载Apollo源文件

从Gitee克隆Apollo仓库:

# 使用 HTTPS 的方式
git clone https://gitee.com/ApolloAuto/apollo.git

终端输出:

Cloning into 'apollo'...
remote: Enumerating objects: 329426, done.
remote: Counting objects: 100% (337/337), done.
remote: Compressing objects: 100% (336/336), done.
fatal: The remote end hung up unexpectedly.22 GiB | 6.13 MiB/s      
fatal: early EOF
fatal: index-pack failed

可以看出,虽然没有在Github克隆,而是Gitee,但还是克隆失败。应该不是网络的问题,而是Apollo仓库太大了。

解决办法:只克隆master分支最近一次的commit,减小文件大小,加快克隆速度。

git clone --depth 1 --branch master https://gitee.com/ApolloAuto/apollo.git

终端输出:

Cloning into 'apollo'...
remote: Enumerating objects: 10613, done.
remote: Counting objects: 100% (10613/10613), done.
remote: Compressing objects: 100% (9170/9170), done.
remote: Total 10613 (delta 3379), reused 4544 (delta 1157), pack-reused 0
Receiving objects: 100% (10613/10613), 1.12 GiB | 4.53 MiB/s, done.
Resolving deltas: 100% (3379/3379), done.
Checking out files: 100% (9640/9640), done.

可以看出,克隆成功。

(可选)为方便起见,可以在Apollo的根目录运行以下命令来设置指向该目录的环境变量APOLLO_ROOT_DIR

cd apollo
echo "export APOLLO_ROOT_DIR=$(pwd)" >> ~/.bashrc  && source ~/.bashrc

3 启动Docker容器

${APOLLO_ROOT_DIR}目录, 输入以下命令启动Apollo的Docker容器。

bash docker/scripts/dev_start.sh

如果终端最后输出以下信息,就表明此脚本运行成功。

[ OK ] Congratulations! You have successfully finished setting up Apollo Dev Environment.
[ OK ] To login into the newly created apollo_dev_tortoise container, please run the following command:
[ OK ]   bash docker/scripts/dev_into.sh
[ OK ] Enjoy!

此脚本会拉取Apollo需要的镜像,可以使用以下命令查询Docker镜像。

docker images

输出:

REPOSITORY                                                                 TAG                                                              IMAGE ID       CREATED         SIZE
apolloauto/apollo                                                          dev-x86_64-18.04-20210517_1712                                   d18097fa01e1   4 weeks ago     13.7GB
apolloauto/apollo                                                          smoke_volume-yolo_obstacle_detection_model-x86_64-latest         819a274335fb   5 months ago    80.1MB
apolloauto/apollo                                                          map_volume-sunnyvale_big_loop-latest                             e7b1a71d5b9d   6 months ago    440MB
apolloauto/apollo                                                          yolov4_volume-emergency_detection_model-x86_64-latest            e3e249ea7a8a   8 months ago    264MB
apolloauto/apollo                                                          faster_rcnn_volume-traffic_light_detection_model-x86_64-latest   58537bb25841   9 months ago    170MB
apolloauto/apollo                                                          data_volume-audio_model-x86_64-latest                            17cb2a72a392   9 months ago    194MB
apolloauto/apollo                                                          map_volume-sunnyvale_with_two_offices-latest                     93a347cea6a0   15 months ago   509MB
apolloauto/apollo                                                          map_volume-san_mateo-latest                                      48cd73de58ba   20 months ago   202MB
apolloauto/apollo                                                          map_volume-sunnyvale_loop-latest                                 36dc0d1c2551   3 years ago     906MB

4 进入Apollo的Docker容器

bash docker/scripts/dev_into.sh

5 在容器内构建Apollo

在Docker容器的/apollo目录下, 输入:

./apollo.sh build

以构建整个Apollo工程。或者输入:

./apollo.sh build_opt

来进行优化模式的构建。

可以参考Apollo构建和测试说明来全面了解Apollo的构建和测试。

构建成功的终端截图:
在这里插入图片描述

6 运行Apollo

6.1 启动Apollo

# Startup modules monitor and dreamview, the default option is start.
./scripts/bootstrap.sh [start | stop | restart]

在这里插入图片描述

6.2 访问Dreamview Web UI

在浏览器中打开http://localhost:8888,界面如下:
在这里插入图片描述

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐