安装Sysrepo步骤
安装环境:ubuntu-18.04.5
一、更换apt源
1.复制源文件备份,以防万一
我们要修改的文件是sources.list,它在目录/etc/apt/下,sources.list是包管理工具apt所用的记录软件包仓库位置的配置文件,同样类型的还有位于 同目录下sources.list.d文件下的各种.list后缀的各文件。
命令如下:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
2.编辑源列表文件
命令如下:
sudo vim /etc/apt/sources.list
将原来的内容删除,粘贴以下内容:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
3.更新软件列表
运行如下命令:
sudo apt-get update
4.更新软件包
运行如下命令:
sudo apt-get upgrade
二、安装依赖包
apt-get install cmake libpcre3-dev libavl-dev libev-dev
apt-get install protobuf-compiler libprotobuf-dev libprotoc-dev
三、安装protobuf-c
1、在github上下载protobuf-c源码
(1)cd
(2)git clone https://github.com/protobuf-c/protobuf-c.git
(3)cd protobuf-c
(4)./autogen.sh
注:执行这一步可能会报出如下错误:
解决方法如下
1. sudo apt-get install autoconf
2. sudo apt-get install automake
3.sudo apt-get install libtool
这时候再次执行./autogen.sh就不出错了
再次执行结果如下:
(5)./configure
注:执行这一步可能会报出如下错误:
应该是系统没有安装g++,安装g++
apt-get install g++
在此执行./configure指令,可能会报如下错误:
The pkg-config script could not be found or is too old.
解决方法是apt-get install pkg-config
执行完成之后再次执行./configure,运行成功:
(6)make
(7)make install
四、安装libyang
1、首先安装依赖:
(1)cmocka简介:
官网:https://cmocka.org/
cmocka是google开源的单元测试框架。
(2)编译安装
a.下载源码
https://cmocka.org/files/
如:cmocka-1.1.2.tar.xz
b.解压
xz -d cmocka-1.1.2.tar.xz
tar -xvf cmocka-1.1.2.tar
c.编译安装
cd cmocka-1.1.2
mkdir build
cd build
cmake .. (两个点表示自己的上一级目录,一个点表示当前目录)
make
make install
d.默认库所在位置
e.在/usr/lib中创建cmocka库的链接
ln -s /usr/local/lib/libcmocka.so* /usr/lib/
f.运行一下ldconfig
ldconfig
2、下载源码
git clone https://github.com/CESNET/libyang.git
3、cd libyang/
4、mkdir build
5、cd build
6、mkdir build
7、cd build
8、cmake ..
9、make
10、make install
五、安装Sysrepo
1、下载源码
git clone https://github.com/sysrepo/sysrepo.git
2、cd sysrepo/
3、mkdir build
4、cd build
5、cmake ..
6、make
7、make install
六、验证sysrepo是否安装成功:
执行sysrepoctl
报出如下错误:sysrepoctl: error while loading shared libraries: libyang.so.1: cannot open shared object file: No such file or directory
解决方案是
cd
cd sysrepo/build/
cp libsysrepo.so.5 /usr/lib/
因为:系统默认只会去/usr/lib,/usr/local/lib下去寻找加载库,我们在执行configure的时候没有加--prefix参数,指定安装目录,只能手动添加进去了
再次执行sysrepoctl
报出如下错误:sysrepoctl: error while loading shared libraries: libyang.so.1: cannot open shared object file: No such file or directory
解决方法与上面一致:
cd
cd libyang/build/
cp libyang.so.1 /usr/lib/
问题完美解决
再次执行sysrepoctl,成功
至此,完成了sysrepo的安装工作