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

posted @ 2015-12-30 08:16  Heriam  阅读(4830)  评论(0编辑  收藏  举报