天天看点

NETCONF协议之netopeer软件安装

NETCONF协议之netopeer软件安装与环境搭建

0、  系统环境

RedHat Enterprise Linux server-7.3  64位

对于redhat系统在以下的处理中,将选择Fedora的操作进行执行。

1、  简介:

NETCONF的自动化配置系统采用Client/Server架构,而netopeer即实现了netconf的C/S框架的开源项目。

Netopeer是基于开源项目libnetconf库完成的,已实现client和server端的代码。主要涉及的组件为netopeer-cli和netopeer-server;其中netopeer-cli为一个CLI程序,允许通过该程序连接到netconfserver,和操纵它的配置数据;netopeer-server为一个netconf服务器端的守护进程,允许与netconf client建立连接,接收配置数据等操作。除了这两个重要的模块,netopeer项目还包含了libnetconf transAPI模块举例,位于项目源码transAPI/路径下,例如cfgsystem模块,实现的是一个ietf-system数据模型。        

2、  安装必要的依赖包

a) 针对采用apt-get对软件包(deb包)进行管理的linux操作系统,如Ubuntu15.04:

$ sudo apt-getinstall libtool

$ sudo apt-getinstall libtool-bin

$ sudo apt-getinstall libxml2-dev

$ sudo apt-getinstall libxslt1-dev

$ sudo apt-getinstall libcurl4-openssl-dev

$ sudo apt-getinstall xsltproc         

$ sudo apt-getinstall python-setuptools 

$ sudo apt-getinstall cmake 

$ sudo apt-getinstall zlib1g-dev

$ sudo apt-get installlibssl-dev

$ sudo apt-getinstall pkg-config

$ sudo apt-getinstall lib-readline-dev

$ sudo apt-getinstall python-libxml2

 b) 针对采用yum 对软件包(rpm包)进行管理的linux操作系统,如Fedora和RedHat:

 $ sudo yuminstall libtool

$ sudo yuminstall libxml2-devel

$ sudo yuminstall libxslt-devel

$ sudo yuminstall libcurl-devel

$ sudo yuminstall python-setuptools

$ sudo yuminstall pkg-config

$ sudo yuminstall readline-devel

$ sudo yuminstall libxml2-python

3、  手动编译安装部份依赖包

         首先可在文件系统中创建一个目录用于存放接下来要处理的文件

         sudomkdir /home/work

         cd  /home/work

A)    pyang依赖包安装

对于Ubuntu 15.04 或 Fedora 20:

$ git clone https://github.com/mbj4668/pyang.git

$ cd pyang

$ sudo pythonsetup.py install

$ cd ..

B) libssh 依赖包安装

         对于Ubuntu15.04 需要确保libssh 的版本在0.6.4版本及以上,如果系统前期安装过libssh但是版本比0.6.4低,需要先remove掉早期的版本后安装新的版本

下载libssh源码包(https://git.libssh.org/projects/libssh.git),可以自行下载最新的压缩包文件后,解压至当前的目录下,也可以使用git clone https://git.libssh.org/projects/libssh.git libssh 获取

$ cd libssh

$ mkdir build

$ cd build

$ cmake .. (注:此处cmake后面必须有两个点,用于将build的结果输出至上一级目录,也就是libssh目录中)

$ make

$ sudo makeinstall

$ cd ..

对于Fedora 20,我们可以安装与ubuntu相同的方式来安装依赖包,也可以使用下面更为简单的操作

$ sudo yuminstall libssh-devel

C)  libnetconf依赖包安装

# gitclone https://github.com/CESNET/libnetconf.git

# cd libnetconf

# ./configure

# make

# make install

4、  编译netopeer

a) 下载netopeer源码

# git clone https://github.com/CESNET/netopeer.git

b) 编译安装netopeer-server

# cdnetopeer/server

# ./configure

# make

# make install

c) 编译安装netopeer-cli

# cdnetopeer/cli

# ./configure

# make

# make install

5、  启动netopeer server:

对于Ubuntu 15.04 我们必须安装 openssh-server 服务以区别 Netopeer 可以启动. 

$ sudo apt-getinstall openssh-server 

接着启动netopeer 的服务端

$ sudo/usr/local/bin/netopeer-server -d

对于Fedora 20,以root用户登录,我们需要将/usr/local/lib 加入到动态搜索路径库中去

# exportLD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

 接着我们需要关闭系统防火墙并将其设置为默认关闭状态

# systemctl stopfirewalld

# systemctldisable firewalld

最后我们就可以启动netopeer server 服务了

       #/usr/local/bin/netopeer-server  -d

默认监听端口x.x.x.x:830,连接的用户名密码为系统用户

注:在启动服务的时候,我们增加了-d 参数,以确保启动的server处于内存常驻模式。也可以通过增加–v 参数(-v参数后跟值 0~3 ,分别对应着errors, warnings, verbose, debug级别的日志类型)来设置日志记录级别。

6、  验证netopeer-cli与netopeer-server连接

运行netopeer-cli,连接netopeerserver

# netopeer-cli

netconf>connect localhost

netconf>get-config startup

其它操作

a)      配置netopeer server模块

# netopeer-configurator

b)      检查默认启动的模块

# netopeer-manager list

【异常处理】:

1、编译libnetconf异常

如果在对libnetconf执行./configure进行配置时,如果提示不能找到libssh 的错误时,设置下述的编译标志后再次执行./configure配置

export  CPPFLAGS='-I/usr/local/include'

export  LDFLAGS='-L/usr/local/lib'

或者可以尝试将libssh安装到/usr 目录去,而不是/usr/local 目录。这样做的第一步是先删除掉libssh 编译目录(即执行的时候新建的’build’目录)下的所有内容

cd build

rm -rf *

然后再执行

cmake -DCMAKE_INSTALL_PREFIX=/usr ..

make

sudo make install 

2、编译netopeer异常

a) 执行./ configure,出现如下错误:

checking for pkg-config.../usr/bin/pkg-config

checking for roff2html... no

checking for distro... redhat

checking pkg-config is at least version0.9.0... yes

checking for LIBNETCONF... no

configure: error: Package requirements(libnetconf) were not met:

No package 'libnetconf' found

Consider adjusting the PKG_CONFIG_PATHenvironment variable if you installed software in a non-standard prefix.

Alternatively, you may set the environmentvariables LIBNETCONF_CFLAGS and LIBNETCONF_LIBS to avoid the need to callpkg-config.

See the pkg-config man page for moredetails.

原因:

在一些相同中,比如Fedora x64,计时我们将netconf安装到了默认的路况/usr/local,但是环境变量中可能仍然缺少PKG_CONFIG_PATH环境变量,进而使得我们在编译netopeer的服务端时出现上述错误。

解决办法:

         采用以下方式增加必要的环境变量

exportPKG_CONFIG_PATH=/usr/local/lib/pkgconfig

         然后重新执行./ configure

b) 解决完上述环境变量的问题后,执行./ configure,出现如下新的错误:

configure: error: cannot run C compiledprograms.

If you meant to cross compile, use`--host'.

See `config.log' for more details

原因:

         C编译器环境异常/交叉编译异常

解决办法:

1)首先确保当前linux系统已经安装了完整的C编译环境

对于Fedora而言,需要确保安装了以下依赖包

yum install libssh2-devel

yum install xslt-devel

yum install libcurl-devel

yum install xsltproc

对于ubuntu而言,需要确保安装了以下依赖包

sudo apt-get install libssh2-1-dev

sudo apt-get install libxslt1-dev

sudo apt-get install libcurl4-openssl-dev

2)在已经确定C编译环境都是正常的前提下,仍出现上述错误,则可能是编译适配主机的类型不匹配

在执行./configure时增加--host=x86_64来指定主机类型(注:这一处理可见【参考】一节介绍)

./configure --host=x86_64

【参考】

一、./configure -build,-host,-target设置

build:执行代码编译的主机,正常的话就是你的主机系统。这个参数一般由config.guess来猜就可以。当然自己指定也可以。

host:编译出来的二进制程序所执行的主机,因为绝大多数是如果本机编译,本机执行。所以这个值就等于build。只有交叉编译的时候(也就是本机编译,其他系统机器执行)才会build和host不同。用host指定运行主机。

target:这个选项只有在建立交叉编译环境的时候用到,正常编译和交叉编译都不会用到。他用build主机上的编译器,编译一个新的编译器(binutils, gcc,gdb等),这个新的编译器将来编译出来的其他程序将运行在target指定的系统上。

让我们以编译binutils为例:

1. `./configure --build=mipsel-linux--host=mipsel-linux --target=mipsel-linux' 

说明我们利用mipsel-linux的编译器对binutils进行编译,编译出来的binutils运行在mipsel-linux,这个binutils用来编译能够在mipsel-linux运行的代码。“当然没有人会用这个选项来编译binutils”

2. `./configure --build=i386-linux--host=mipsel-linux

--target=mipsel-linux' will cross-buildnative mipsel-linux binutils oni386-linux.

说明我们利用i386-linux的编译器对binutils进行编译,编译出来的binutils运行在mipsel-linux,这个binutils用来编译能够在mipsel-linux运行的代码。“这个选项可以用来为其他的机器编译它的编译器”。

3. `./configure --build=i386-linux--host=i386-linux

--target=mipsel-linux' will buildmipsel-linux cross-binutils on i386-linux.

说明我们利用i386-linux的编译器对binutils进行编译,编译出来的binutils运行在i386-linux,这个binutils用来编译能够在mipsel-linux运行的代码。“这个选项用来在i386主机上建立一个mipsel-linux的交叉编译环境”。

4. `./configure --build=mipsel-linux --host=i386-linux

--target=mipsel-linux' will cross-buildmipsel-linux cross-binutils for

i386-linux on mipsel-linux.

说明我们利用mipsel-linux的编译器对binutils进行编译,编译出来的binutils运行在i386-linux,这个binutils用来编译能够在mipsel-linux运行的代码。“这个选项可以用来在i386主机上建立一个mipsel-linux的交叉编译环境,但是交叉编译环境在mipsel-linux 编译出来,安装到i386-linux主机上,估计没有多少人会这么用吧”

总的来说,只有host !=build的时候编译才是交叉编译。否则就是正常编译。

二、Set up Netopeer Server to use with NETCONFc

http://www.seguesoft.com/how-to-set-up-netopeer-server-to-use-with-netconfc#nopackage

三、相应网页资源

网易网易开源镜像站(如linux系统环境未能成功连接网络使用yum方式进行资源包下载安装,可以基于windows系统在镜像站中进行相应安装包下载后传至linux中进行安装): http://mirrors.163.com/

    Libnetconf文档网站:https://rawgit.com/CESNET/libnetconf/master/doc/doxygen/html/index.html

    Netopeer项目 :https://github.com/CESNET/Netopeer

    Libnetconf项目:https://github.com/CESNET/libnetconf

    Pyang项目:https://github.com/mbj4668/pyang

    Libssh项目:https://git.libssh.org/projects/libssh.git

         NETCONF相关:http://www.seguesoft.com/index.php

继续阅读