1.復制主機文件到容器
為了方便后續安裝,將本地已有的安裝包直接復制到容器內。
docker cp <主機目錄> <容器id>:<容器內目錄>
例如將本地/home/ubuntu/Downloads/內的文件復制到容器99e69f9c2311的/home/apps中
$ docker cp /home/ubuntu/Downloads/ 99e69f9c2311:/home/apps
2.容器內Java安裝
將jdk安裝文件jdk-8u231-linux-x64.tar.gz拷貝到容器的/usr/local/java目錄下(也可選擇其他目錄),解壓
配置環境變量
$ nano ~/.bashrc
在末尾追加以下內容,crtl o保存,ctrl x退出
export JAVA_HOME=/usr/local/java/**jdk1.8.0_231**
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
使配置生效
$ source ~/.bashrc
3.容器內安裝OpenDayLight 0.4.4-Beryllium-SR4 和 0.6.4-Carbon
- 安裝時遇到的坑:jdk 11不支持Beryllium(Carbon沒試過),解壓后karaf無法啟動,要用jdk 8
之后安裝和正常環境下一致。 - 為了方便查看ip,需要使用ifconfig命令,如果在/sbin/下找不到,就要安裝
$ apt-get install net-tools
- 打包更新鏡像
$ docker commit -m "install odl Be and C" -a "wdf000" 99e69f9c2311 wdf000/opendaylight:20200108
- 在新的鏡像上運行新的容器,取名為odl,還要將6633/6653兩個控制器和交換機的通訊端口,以及8181控制器的web端口映射到外層系統主機,便於外層系統直接訪問
$ docker run -itd -p 8181:8181 -p 6653:6653 -p 6633:6633 --name odl wdf000/opendaylight:20200108
運行容器ODL,並啟動控制器,在外層系統主機直接訪問。
4.安裝SDN 仿真工具Mininet
直接裝在容器內
- 安裝時遇到的坑:執行安裝腳本~/mininet/util/install.sh時報錯./install.sh: line 46: sudo: command not found
方法如下:
$ apt-get update
$ apt-get install sudo
- 安裝時遇到的坑:執行安裝腳本時報錯E: Failed to fetch http://mirrors.aliyun.com/ubuntu/pool/main/g/gtk+3.0/libgtk-3-0_3.18.9-1ubuntu3.3_amd64.deb Hash Sum mismatch
方法如下:
$ #修改DNS,添加阿里的DNS(保留原有的DNS)
$ sudo nano /etc/resolv.conf
nameserver 223.5.5.5
nameserver 223.6.6.6
附上阿里Ubuntu鏡像的源:
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe
-
安裝時遇到的坑:下載openflow時網速很慢,下載進度卡住不動了
方法如下:
修改install.sh腳本,將git clone git://github.com/mininet/openflow 修改為 git clone https://github.com/mininet/openflow.git -
安裝時遇到的坑:下載optest時報錯:fatal: read error: Connection reset by peer
方法如下:
修改install.sh安裝腳本,將git clone git://github.com/floodlight/oftest 修改為 git clone https://github.com/floodlight/oftest.git -
終於裝好了
-
運行時遇到的坑:Error setting resource limits. Mininet's performance may be affected.
暫時沒有解決。
安裝在ubuntu上
$ git clone https://github.com/mininet/mininet.git
$ sudo ./mininet/util/install.sh -a
安裝過程如果遇到網絡問題,按照前面說的方法,修改安裝腳本里面git clone的地址即可解決。
運行正常。(容器內安裝很可能因為資源不足的原因,才會出現運行錯誤,容器內使用的ubuntu是從hub docker上pull下來的,只有百兆,和實際的ubuntu功能會差很多。)
5.Mininet連接運行在容器內的OpenDaylight
$ 獲取容器ip地址
$ docker inspect --format '{{.NetworkSettings.IPAddress }}' <容器id>
Carbon
$ sudo mn --controller=remote,ip=172.17.0.2,port=6633 --switch=ovsk,protocols=OpenFlow13
Beryllium
剛開始控制器沒連上,嘗試將6633端口改為6653,成功。
$ sudo mn --controller=remote,ip=172.17.0.2,port=6653 --switch=ovsk,protocols=OpenFlow13