一、准备环境
linux (centos 6.7 )
maven-3.3
java1.7+
二、源代码下载
以上代码可以放到任何一个目录中,我下载目录如下(/var/opendaylight/odl_helium_sr4):
(PS: l2switch-stable-helium 下面会讲到 而且是重点讲解)
三、编译源代码
众所周知,opendaylight采用maven管理整个项目,因此编译opendaylight各个模块均需要使用maven相关知识。 本人在编译opendaylight的时候,遇到了各种问题这里我会详细的,一步一步,介绍如何编译opendaylight并使之运行起来。 (PS:为了编译方便,请将用户权限切换置root权限)
-
controller 控制器
编译完整版本(在controller根目录下进行编译)
1) 切入controller 根目录
[root@centos6 controller]# ls
features LICENSE opendaylight README.OPENDAYLIGH Titests NOTICE pom.xml third-party
[root@centos6 controller]# pwd
/var/opendaylight/odl_helium_sr4/controller
[root@centos6 controller]#
2) 执行mvn clean install -Dmaven.test.skip=true
clean ---- 清空临时文件(初次可以不用写)
install ---- 编译并安装
-Dmaven.test.skip=true ---- 跳过单元测试(为了节省时间以及避免出错)
此步骤需要很长一段时间,因为需要从网上下载大量的依赖文件。
3) 编译完成
[INFO] features-restconf ............................................ SUCCESS [ 2.743 s]
2) 找不到 org/apache/commons/lang/StringUtils (可能有的人遇不到)
[INFO] distribution.opendaylight-karaf .................... SUCCESS [ 9.101 s]
[INFO] controller-features .......................................... SUCCESS [ 0.857 s]
[INFO] extras-features ................................................ SUCCESS [ 3.231 s]
[INFO] features-adsal-compatibility .......................... SUCCESS [ 1.659 s]
[INFO] features-netconf-connector ........................... SUCCESS [ 0.444 s]
[INFO] features-controller .......................................... SUCCESS [ 0.048 s]
[INFO] odl-model-project ........................................... SUCCESS [ 2.069 s]
[INFO] opendaylight-configfile-archetype ............... SUCCESS [ 0.109 s]
[INFO] archetypes-parent ........................................... SUCCESS [ 0.157 s]
[INFO] distribution-karaf-archetype ........................... SUCCESS [ 3.836 s]
[INFO] opendaylight-karaf-features-archetype ........ SUCCESS [ 0.125 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22:19 min
[INFO] Finished at: 2015-10-23T20:43:04+08:00
[INFO] Final Memory: 452M/933M
[INFO] ------------------------------------------------------------------------
PS:下面是重点内容 <编译过程遇到问题与解决方案>
1) PermGen space 永久内存保存区域越界
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18:30 min
[INFO] Finished at: 2015-10-18T19:17:33+08:00
[INFO] Final Memory: 400M/597M
[INFO] ------------------------------------------------------------------------
[ERROR] PermGen space -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/OutOfMemoryError
原因:jvm默认PermGen内存大小为64M,对于编译Opendaylight来说确实有点小。
解决方案: 增大内存大小。
大体思想: 设置环境变量 修改/etc/profile(针对所有用户)或者/root/.bashrc(针对当前用户)
MAVEN_OPTS="$MAVEN_OPTS -Xms512m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m"
export MAVEN_OPTS
以是本人当前配置文件,写在了/etc/profile
#
#Set Java env
#
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk.x86_64
CLASSPATH=.:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
JVM_OPTS="-Xms256m -XX:PermSize=256m -XX:MaxPermSize=512m"
MAVEN_OPTS="$MAVEN_OPTS -Xms512m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m"
export MAVEN_OPTS JAVA_HOME CLASSPATH JVM_OPTS PATH
#
#Set Maven env
#
M2_HOME=/usr/local/bin/apache-maven-3.3.3/
M2=$M2_HOME/bin
PATH=$M2:$PATH
[INFO] odl-model-project .................................. FAILURE [ 2.176 s]
[INFO] opendaylight-configfile-archetype .................. SKIPPED
[INFO] archetypes-parent .................................. SKIPPED
[INFO] distribution-karaf-archetype ....................... SKIPPED
[INFO] opendaylight-karaf-features-archetype .............. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22:42 min
[INFO] Finished at: 2015-10-19T18:53:03+08:00
[INFO] Final Memory: 501M/913M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:jar (default-jar) on project odl-model-project: Execution default-jar of goal org.apache.maven.plugins:maven-archetype-plugin:2.2:jar failed: A required class was missing while executing org.apache.maven.plugins:maven-archetype-plugin:2.2:jar: org/apache/commons/lang/StringUtils
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.apache.maven.plugins:maven-archetype-plugin:2.2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/root/.m2/repository/org/apache/maven/plugins/maven-archetype-plugin/2.2/maven- archetype-plugin-2.2.jar
[ERROR] urls[1] = file:/root/.m2/repository/org/apache/maven/archetype/archetype-catalog/2.2/archetype-catalog-2.2.jar
........
[ERROR] urls[26] = file:/root/.m2/repository/asm/asm-tree/3.2/asm-tree-3.2.jar
[ERROR] urls[27] = file:/root/.m2/repository/org/beanshell/bsh/2.0b4/bsh-2.0b4.jar
[ERROR] urls[28] = file:/root/.m2/repository/org/apache/maven/shared/maven-script-interpreter/1.0/maven-script- interpreter-1.0.jar
[ERROR] urls[29] = file:/root/.m2/repository/org/apache/ant/ant/1.8.1/ant-1.8.1.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[project>org.opendaylight.controller.archetypes:odl-model-project:1.1.5-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]
[ERROR]
[ERROR] -----------------------------------------------------:org.apache.commons.lang.StringUtils
[ERROR] urls[0] = file:/root/.m2/repository/org/apache/maven/plugins/maven-archetype-plugin/2.2/maven-archetype-plugin-2.2.jar
[ERROR] urls[1] = file:/root/.m2/repository/org/apache/maven/archetype/archetype-catalog/2.2/archetype-catalog-2.2.jar
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :odl-model-project
[root@centos6 controller]#
问题现象: 编译odl-model-projec工程,依赖这个此插件maven-archetype-plugin:2.2:jar 此插件又需要此类org.apache.commons.lang.StringUtils,但是没有找到。
原因:(不清楚!!是的我不清楚)在编译archetype项目的时候,未找到它所依赖org.apache.commons.lang.StringUtils类,但是通过查看本地仓库查找的确存在这个类了(ls .m2/repository/commons-lang/commons-lang/ 有很多版本2.1 ~2.6),但是为什么还是没有找到呢? 非常奇怪的问题,而且在公司里环境是可以的。
解决方案:手动修改pom.xml文件,强制工程自己去寻找依赖文件。修改此工程的pom文件 /var/opendaylight/odl_helium_sr4/controller/opendaylight/archetypes/pom.xml 红色部分是我自己添加的。
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.2</version>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
添加完就能顺利编译通过了,但是在archetypes目录中其他工程也会报这个错误,同样道理去修改对应的pom文件,即可。
运行karaf
1) 进入此目录/var/opendaylight/odl_helium_sr4/controller/opendaylight/distribution/opendaylight-karaf/target/assembly/bin (Opendaylight采用OSGi框架,而karaf是OSGi的实现一个容器)
执行./karaf 会有如下显示,表示启动成功
PS:下面是重点内容 <运行karaf问题与解决方案>
Caused by: java.rmi.UnknownHostException: Unknown host: 0.0.0.0; nested exception is:
1) Caused by: java.net.UnknownHostException: centos6.7: 未知的名称或服务
java.net.UnknownHostException: centos6.7: centos6.7: 未知的名称或服务
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:616)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:341)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at com.sun.jndi.rmi.registry.RegistryContext.bind(RegistryContext.java:137)
... 5 more
Caused by: java.net.UnknownHostException: centos6.7: centos6.7: 未知的名称或服务
at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:147)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
原因:(不清除启动流程)。找到不到centos6.7这个服务,我当时比较奇怪,这个centos6.7就是我linux系统版本,非常特殊。
解决方案:经过百度查询(百度就是一个2B,查很长时间),需要修改/etc/hosts文件,因此没有找到ip。以下红色内容是我修改的: 增加centos6.7
127.0.0.1 centos6.7 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
启动web界面
大家都知道Opendaylight是有web界面,因此我在安装Opendaylight的时候是以显示web界面为最终目标。
参考此网站的说明 http://www.sdnlab.com/1931.html,我需要安装如下feature才可以。
odl-restconf odl-l2switch-switch odl-openflowplugin-all odl-mdsal-apidocs odl-dlux-all odl-adsal-northbound
因此我就按照上面顺序安装
opendaylight-user@root>
opendaylight-user@root>feature:installodl-restconf (时间较长 耐心等待)
Refreshing bundles org.apache.xbean.finder-shaded (65)
opendaylight-user@root>feature:install odl-l2switch-switch (有无错啦)
Error executing command: No feature named 'odl-l2switch-switch with version '0.0.0' available
当我安装第二个feature出现了这个错误, 大致意思找不到这个feature。
这里只能再次吐槽,百度这个2!!!2!!! 搜索了2两天就是没有结果。 没办法只能靠vpn大家都懂的!! 这种问题还是要靠谷歌。 谷歌一下就搜出来了(具体地址找不到了),大概意思,controller只是一个部分代码,需要单独下载l2-switch项目。 所以在文章最开始,目录显示有4个目录。那么我们就来编译l2-switch(代码下载地址),非常简单并且没有出现任何问题,mvn install!!!
那么问题就来了,我们把feature下载并编译完成,如何才能将这个feature和controller关联起来呢??? 这个问题,请教了公司同事。
每个项目pom文件中都有自己的依赖feature,我们可以把l2-switch加入到这个pom文件中(甚至以后自己写的feature也可以加到pom中),在同事指导果然后找到了依赖。下面红色地方是我增加的:
/var/opendaylight/odl_helium_sr4/controller/opendaylight/distribution/opendaylight-karaf
这个目录下面的pom文件---即karaf工程的pom文件。
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>features-restconf</artifactId>
<version>1.1.5-SNAPSHOT</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.opendaylight.l2switch</groupId>
<artifactId>features-l2switch</artifactId>
<version>0.1.5-SNAPSHOT</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
</dependencies>
重新编译,karaf工程即可。必须要重新编译,否则仍然找不到这个feature啊!!!当我编译完,再按照上面步骤,非常的顺利并且成功启动了web界面。
-
openflowjava
openflowplugin依赖openflowjava,因此我们在这里先编译openflowjava,编译命令和上面一样: mvn install -Dmaven.test.skip=true
由于在编译controller的时候下载了很多插件,因此这个项目编译比较快,而且没有遇到问题。
-
openflowplugin
openflowplugin编译过程,也非常顺利。由于篇幅比较大了,这里就不粘贴编译结果了
简单总结一下:
经过一周研究,opendaylight环境终于搭建完成了,在这过程中有同学、同事还有很多不认识的网友悉心指导,因此我写这篇博客,把我的经历一步一步写下来。一来是为了保存,二来是为了后续其他人学习opendaylight时候,能够找到一篇比较完整的安装流程的博客,三来吐槽百度!!!
感谢那些曾经帮助我过的,IT同僚们!!!
非常希望大家能够转发,但请保留原地址!!!!