Ubuntu系統下OpenDaylight源碼編譯安裝


操作系統:Linux x64 / Ubuntu 14.04

研究領域:軟件定義網絡SDN (Software-defined Networking)

開發組件:OpenDaylight

本文原文鏈接:https://jiang-hao.com/articles/2018/backend-BuildandInstallOpenDaylightonUbuntu.html

 

 

一、環境搭建

1. Java+Apache Maven基本開發環境搭建。詳見相應的前面兩篇文檔:

《Linux Ubuntu系統下Java開發環境搭建》

《Linux Ubuntu系統下Apache Maven的安裝和配置》

 

 

2. 安裝用來獲取OpenDaylight源碼的Git工具。

 

sudo apt-get install git-core

 

 

 

 

 

3. 針對Opendaylight,安裝好Maven后,需要編輯一個非常重要的文件 settings.xml。直接修改該文件,就能在機器上全局地定制 Maven的行為。~/.m2是默認的maven本地倉庫。剛裝好maven的后~/.m2下是沒有settings.xml的文件的。在/etc/maven下有settings.xml的原型,一般情況下,我們更偏向於復制該文件至home目錄下的.m2/目錄下(這里~表示用戶目錄),然后修改該文件,在用戶范圍定制 Maven的行為。前者又被叫做全局配置,后者被稱為用戶配置。如果兩者都存在,它們的內容將被合並,並且用戶范圍的settings.xml優先。在這里要在~/目錄下創建.m2文件夾,然后執行修改命令(詳見官網:https://wiki.opendaylight.org/view/GettingStarted:Development_Environment_Setup):

 

sudo mkdir .m2
sudo cp -n ~/.m2/settings.xml{,.orig} ; \wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml

 

 

 

 

 

完成后輸入“sudo gedit /.m2/settings.xml”查看settings.xml內容,應該顯示如下:

 

# Shortcut command for grabbing settings.xml
cp -n ~/.m2/settings.xml{,.orig} ; \
wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 
  <profiles>
    <profile>
      <id>opendaylight-release</id>
      <repositories>
        <repository>
          <id>opendaylight-mirror</id>
          <name>opendaylight-mirror</name>
          <url>http://nexus.opendaylight.org/content/repositories/public/</url>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>opendaylight-mirror</id>
          <name>opendaylight-mirror</name>
          <url>http://nexus.opendaylight.org/content/repositories/public/</url>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>

    <profile>
      <id>opendaylight-snapshots</id>
      <repositories>
        <repository>
          <id>opendaylight-snapshot</id>
          <name>opendaylight-snapshot</name>
          <url>http://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>opendaylight-snapshot</id>
          <name>opendaylight-snapshot</name>
          <url>http://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>opendaylight-release</activeProfile>
    <activeProfile>opendaylight-snapshots</activeProfile>
  </activeProfiles>
</settings>

 

 

 

二、OpenDaylight源碼獲取、編譯和安裝

 

1. 新建項目文件夾,獲取OpenDaylight源碼:

 

sudo mkdir openDayLight
cd openDayLight
sudo git clone https://git.opendaylight.org/gerrit/p/controller.git

 

 

2. 指定編譯ODL的版本(以Lithium鋰版本為例)並查看確認:

 

cd controller
sudo git checkout stable/lithium
git branch

 

 

 

3. 聯網編譯Controller(確認之前的settings.xml文件已經修改好):

 

mvn clean install


* 如果編譯過程中出現Test編譯錯誤,可以加上 -DskipTests 跳過測試加快編譯速度,其他編譯錯誤和嘗試解決方案:

 

目前遇到兩種:
a. 指定目錄不能創建或訪問:更改文件夾讀寫權限,進入sudo模式重新編譯
b. pom.xml相關錯誤:將~/.m2下的settings.xml復制到/root/.m2目錄下:sudo cp ~/.m2/settings.xml /root/.m2,重新編譯
編譯成功!

 

 

 

4. 控制器驗證運行。

舊版本的目錄結構是“controller/opendaylight/distribution”,在新版本的目錄結構中不再存在“distribution”這個子文件夾,這就是很多朋友參照以前的指南卻找不到distribution子文件夾來啟動控制器的原因。在這里應該cd進入“controller/karaf/opendaylight-karaf”文件夾,輸入:

 

./target/assembly/bin/karaf

 

 

這時將啟動控制器進入opendaylight-user@root>模式。這個時候,Opendaylight的controller項目初步安裝就完成了!

 

 

 

*三、TEST:Integration項目源碼的編譯安裝

*之前編譯好的Controller項目是沒有WebGUI(DLUX)等豐富Feature的核心控制器。Integration是一個框架性的工程,所有自己開發和修改的部分(包括controller、openflowPlugin&Java三個工程)編譯為包后,都可以放在該工程的目錄下一起執行。注意,如果是自己開發的包,則可以直接放到該目錄下。但是如果是修改的原本工程,然后編譯的包要替換掉上面目錄中原來的包,這里有個問題是 integration 的 plugin目錄下的包名和 controller, openflowplugin, openflowjava 中編譯出來的包命名方式有點小差別,復制過去之前先重命名下,使之和目錄下的原來包文件名一致,再復制替換。(參考自@jason-zhou童鞋的《OpenDaylight開發學習筆記基礎之Controller篇》)。將各個工程的jar包copy到integration里后,運用mvn clean install 編譯integration。工程所在目錄:

 

username@ubuntu:~/developApps/openDayLight/integration/distributions/karaf/target/assembly/system/org/opendaylight$ ls
aaa               integration      neutron         sdninterfaceapp  usc
bgpcep            iotdm            nic             sfc              vpnservice
capwap            l2switch         odlparent       snmp             vtn
<strong><span style="color:#ff0000;">controller</span></strong>        lacp             <strong><span style="color:#ff0000;">openflowjava</span></strong>    sxp              yangtools
coretutorials     lispflowmapping  <span style="color:#ff0000;"><strong>openflowplugin</strong></span>  tcpmd5
didm              mdsal            ovsdb           topoprocessing
dlux              nemo             packetcable     tsdr
groupbasedpolicy  netconf          reservation     ttp


*這里僅給出基本的Integration項目的編譯安裝步驟,Openflowplugin和Openflowjava工程將另文詳述。

 

 

 

 

1. 下載並編譯Integration。

回到openDaylight根目錄,輸入如下命令獲取Integration源碼:

 

git clone https://git.opendaylight.org/gerrit/p/integration.git


操作完成后可以看到目錄下多出了integration目錄,進入integration目錄,指定版本(checkout)為stable/lithium,進行編譯:

 

 

cd integration
git checkout stable/lithium
mvn clean install -DskipTests        (或者 cd進入子目錄/distributions/karaf下執行此命令)

 

 

 

 

 

2.編譯完成后,進入integration/distributions/karaf/target/assembly目錄,運行如下命令啟動ODL:

 

bin/karaf

 

 

此時進入ODL命令行界面,通過“feature:list -i”命令可以查看已經安裝的功能模塊,通過“feature:install <feature>”命令可以安裝想要的feature。

 

* Karaf module會把控制器的Plugin制作成Karaf Feature,然后打包成可以導入到Apache karaf的kar文件。Karaf基於OSGI的運行環境,做為OSGI應用的管理容器提供各種管理utility。

 

到這里,一個可供開發和安裝豐富Feature功能模塊的OpenDaylight控制器已經基本搭建完成。

 

本文永久更新地址:https://jiang-hao.com/articles/2018/backend-BuildandInstallOpenDaylightonUbuntu.html

博客地址:https:/jiang-hao.com


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM