山住多一郎 發表於 2019-10-10 19:16:00

Centos安装OpenVSwitch历程

<p>工作需要,要在公司的虚拟机Centos系统上安装部署openvswitch,前前后后忙了两天才安装成功,下面记录一下安装过程和发现的问题及最后的解决方法。</p>
<p><strong>操作系统:</strong></p>
<div class="cnblogs_code">
<pre># <span style="color: rgba(0, 0, 255, 1)">cat</span> /etc/redhat-<span style="color: rgba(0, 0, 0, 1)">release
CentOS Linux release </span><span style="color: rgba(128, 0, 128, 1)">7.6</span>.<span style="color: rgba(128, 0, 128, 1)">1810</span> (Core) </pre>
</div>
<p><strong>openvswitch版本:</strong></p>
<div class="cnblogs_code">
<pre># ll openvswitch-<span style="color: rgba(128, 0, 128, 1)">2.11</span>.<span style="color: rgba(128, 0, 128, 1)">1</span>.<span style="color: rgba(0, 0, 255, 1)">tar</span><span style="color: rgba(0, 0, 0, 1)">.gz
</span>-rw-r--r--. <span style="color: rgba(128, 0, 128, 1)">1</span> ovswitch ovswitch <span style="color: rgba(128, 0, 128, 1)">7682693</span> Oct <span style="color: rgba(128, 0, 128, 1)">10</span> <span style="color: rgba(128, 0, 128, 1)">06</span>:<span style="color: rgba(128, 0, 128, 1)">58</span> openvswitch-<span style="color: rgba(128, 0, 128, 1)">2.11</span>.<span style="color: rgba(128, 0, 128, 1)">1</span>.<span style="color: rgba(0, 0, 255, 1)">tar</span>.gz</pre>
</div>
<p>&nbsp;</p>
<p>一、 错误的安装方法:</p>
<p>根据以往源码安装方式已经上网搜索的安装方式,</p>
<p>1、 先下载安装包:openvswitch-2.11.1.tar.gz;</p>
<p>2、 解压:tar zxvf&nbsp;openvswitch-2.11.1.tar.gz</p>
<p>3、 执行配置脚本:./configure --<span class="hljs-keyword">with-linux=/lib/modules/`uname -r`<span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-keyword">/build;如果没有配置文件则执行./boot.sh生成;</span></span></span></span></span></p>
<p><span class="hljs-keyword"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-keyword">到这一步报错,发现是因为没有安装内核开发包,于是按照网上方法:</span></span></span></span></span></p>
<p><span class="hljs-keyword"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-keyword">4、 安装内核开发包:yum -y install kernel-devel,安装完成后运行rpm -qa | grep "kernel-devel"发现默认安装的包和系统内核版本不一致;</span></span></span></span></span></p>
<p><span class="hljs-keyword"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-keyword">执行配置文件还是报错,以为是内核安装包版本不一致导致,于是从网上下载了kernel-devel-3.10.0-957.21.3.el7.centos.plus.x86_64.rpm这个包,安装后依然报错:</span></span></span></span></span></p>
<div class="cnblogs_code">
<pre>configure error: linux kernel source in /lib/modules/<span style="color: rgba(128, 0, 128, 1)">3.10</span>.<span style="color: rgba(128, 0, 128, 1)">0</span>-<span style="color: rgba(128, 0, 128, 1)">957.1</span>.<span style="color: rgba(128, 0, 128, 1)">3</span>.el7.x86_64/build is not configured.</pre>
</div>
<p>在这里卡住了很久,不知道解决方法,后来想到去配置文件里面找问题;</p>
<p>5、 进入配置文件:vi configure,<strong>搜索错误信息is not configured</strong></p>
<p>有如下脚本:</p>
<div class="cnblogs_code">
<pre>    <span style="color: rgba(0, 0, 255, 1)">if</span> (test ! -e <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">$KBUILD</span><span style="color: rgba(128, 0, 0, 1)">"</span>/include/linux/version.h &amp;&amp;<span style="color: rgba(0, 0, 0, 1)"> \
      test </span>! -e <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">$KBUILD</span><span style="color: rgba(128, 0, 0, 1)">"</span>/include/generated/uapi/linux/version.h)||<span style="color: rgba(0, 0, 0, 1)"> \
       (test </span>! -e <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">$KBUILD</span><span style="color: rgba(128, 0, 0, 1)">"</span>/include/linux/autoconf.h &amp;&amp;<span style="color: rgba(0, 0, 0, 1)"> \
      test </span>! -e <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">$KBUILD</span><span style="color: rgba(128, 0, 0, 1)">"</span>/include/generated/autoconf.h); <span style="color: rgba(0, 0, 255, 1)">then</span><span style="color: rgba(0, 0, 0, 1)">
      as_fn_error $</span>? <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">Linux kernel source in $KBUILD is not configured</span><span style="color: rgba(128, 0, 0, 1)">"</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">$LINENO</span><span style="color: rgba(128, 0, 0, 1)">"</span> <span style="color: rgba(128, 0, 128, 1)">5</span>
    <span style="color: rgba(0, 0, 255, 1)">fi</span></pre>
</div>
<p>想到可能是由于缺少文件导致,遂去目录找相关文件,并把文件按照相关路径拷贝过去;执行配置脚本,配置成功;</p>
<p>6、 编译程序:make;发现有很多错误,基本上都是定义冲突的错误,上网找不到资料,最后根据错误提示,去源码中注释掉一些冲突的定义,再编译还是无法通过;</p>
<p>7、 这边卡住了一段时间,思考是不是系统版本和OpenVSwitch版本不兼容所致,接着就去官网查了一下版本:</p>
<p><img src="https://img2018.cnblogs.com/blog/731444/201910/731444-20191010190700387-1741396777.png"></p>
<p>&nbsp;</p>
<p>&nbsp;发现版本原来的OpenVSwitch1.3版本对内核3.10不支持,随即换成了最新的版本,再编译依然不通过;接着在官方网站http://docs.openvswitch.org上搜索查找,仍然没找到解决方法;</p>
<p>7、 最后无意中搜索相关的冲突代码,找到一些相关信息:</p>
<p>链接:https://blog.csdn.net/sqzhao/article/details/71077143</p>
<p>大概意思就是Centos系统安装openvswitch会出问题,和其他系统不太一致;</p>
<p>&nbsp;</p>
<p>最后上网搜索了Centos系统安装OpenVSwitch,发现了很多资料,找了一篇教程安装,最后安装成功;</p>
<p>&nbsp;</p>
<p>二、正确的安装方法</p>
<p>1、&nbsp;安装依赖包:yum -y install openssl-devel wget kernel-devel</p>
<p>2、&nbsp;安装开发工具:yum groupinstall "Development Tools"</p>
<p>3、&nbsp;添加用户:adduser ovswitch,切换用户并跳转至用户文件夹:su - ovswitch &nbsp;//此步骤并不是必须,仅仅为为了有一个用户文件夹好用来执行后面的命令,可以是用当前的非root 用户执行下面相关的命令</p>
<p>4、 下载源码:openvswitch-2.11.1.tar.gz</p>
<p>5、&nbsp;解压:tar xfz openvswitch-2.11.1.tar.gz</p>
<p>6、 创建编译目录:mkdir -p ~/rpmbuild/SOURCES</p>
<p>7、&nbsp;从spec文件中删除openvswitch-kmod的依赖包,并创建一个新的spec文件:</p>
<p>sed 's/openvswitch-kmod, //g' openvswitch-2.11.1/rhel/openvswitch.spec &gt; openvswitch-2.11.1/rhel/openvswitch_no_kmod.spec</p>
<p>8、&nbsp;&nbsp;开始编译:rpmbuild -bb --without=check ~/openvswitch-2.11.1/rhel/openvswitch_no_kmod.spec</p>
<p>可能出现以下错误:</p>
<p>error: File /home/ovswitch/rpmbuild/SOURCES/openvswitch-2.11.1.tar.gz: No such file or directory</p>
<p>解决办法:cp openvswitch-2.11.1.tar.gz rpmbuild/SOURCES</p>
<p>(rpmbuild是一个工具,需要自己安装)</p>
<p>9、&nbsp;退出当前用户使用root: exit</p>
<p>10、&nbsp;&nbsp;安装编译生成的rpm文件:</p>
<p>yum localinstall /home/ovswitch/rpmbuild/RPMS/x86_64/openvswitch-2.11.1-1.x86_64.rpm</p>
<p>11、 启动服务:systemctl start openvswitch.service</p>
<p>12、 查看服务状态:systemctl -l status openvswitch.service</p>
<p>&nbsp;</p>
<p>可能出现以下错误:</p>
<p>&nbsp;</p>
<p>openvswitch.service - LSB: Open vSwitch switch<br>&nbsp; &nbsp;Loaded: loaded (/etc/rc.d/init.d/openvswitch)<br>&nbsp; &nbsp;Active: activating (start) since 四 2014-12-04 18:35:32 CST; 1min 30s ago<br>&nbsp; Control: 13694 (openvswitch)<br>&nbsp; &nbsp;CGroup: /system.slice/openvswitch.service<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;├─13694 /bin/sh /etc/rc.d/init.d/openvswitch start<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;├─13696 /bin/sh /usr/share/openvswitch/scripts/ovs-ctl start --system-id=random<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;├─13697 tee -a /var/log/openvswitch/ovs-ctl.log<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;├─13723 ovs-vswitchd unix:/var/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --no-chdir --log-file=/var/log/openvswitch/ovs-vswitchd.log --pidfile=/var/run/openvswitch/ovs-vswitchd.pid --detach --monitor<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;├─13724 ovs-vswitchd unix:/var/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --no-chdir --log-file=/var/log/openvswitch/ovs-vswitchd.log --pidfile=/var/run/openvswitch/ovs-vswitchd.pid --detach --monitor<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;└─13725 ovs-vswitchd unix:/var/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --no-chdir --log-file=/var/log/openvswitch/ovs-vswitchd.log --pidfile=/var/run/openvswitch/ovs-vswitchd.pid --detach --monitor<br><br><br>12月 04 18:35:33 localhost.localdomain openvswitch: /etc/openvswitch/conf.db does not exist ... (warning).<br>12月 04 18:35:33 localhost.localdomain openvswitch: Creating empty database /etc/openvswitch/conf.db ovsdb-tool: I/O error: /etc/openvswitch/conf.db: failed to lock lockfile (Resource temporarily unavailable)<br>12月 04 18:35:33 localhost.localdomain openvswitch: <br>12月 04 18:35:33 localhost.localdomain openvswitch: Inserting openvswitch module [ &nbsp;OK &nbsp;]</p>
<p>&nbsp;</p>
<p>解决办法:</p>
<p>yum install&nbsp;policycoreutils-python.x86_64 0:2.2.5-11.el7</p>
<p>mkdir /etc/openvswitch<br>semanage fcontext -a -t openvswitch_rw_t "/etc/openvswitch(/.*)?"<br>restorecon -Rv /etc/openvswitch</p>
<p>&nbsp;</p>
<p>再次使用:</p>
<p>systemctl stop openvswitch.service</p>
<p>systemctl start openvswitch.service</p>
<p>&nbsp;</p>
<p>再次查看服务状态:systemctl -l status openvswitch.service</p>
<p>&nbsp;</p>
<p>openvswitch.service - LSB: Open vSwitch switch<br>&nbsp; &nbsp;Loaded: loaded (/etc/rc.d/init.d/openvswitch)<br>&nbsp; &nbsp;Active: active (running) since 四 2014-12-04 18:38:52 CST; 6s ago<br>&nbsp; Process: 13741 ExecStart=/etc/rc.d/init.d/openvswitch start (code=exited, status=0/SUCCESS)<br>&nbsp; &nbsp;CGroup: /system.slice/openvswitch.service<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;├─13724 ovs-vswitchd: monitoring pid 13725 (healthy) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;├─13725 ovs-vswitchd unix:/var/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --no-chdir --log-file=/var/log/openvswitch/ovs-vswitchd.log --pidfile=/var/run/openvswitch/ovs-vswitchd.pid --detach --monitor<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;├─13764 ovsdb-server: monitoring pid 13765 (healthy) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;└─13765 ovsdb-server /etc/openvswitch/conf.db -vconsole:emer -vsyslog:err -vfile:info --remote=punix:/var/run/openvswitch/db.sock --private-key=db:Open_vSwitch,SSL,private_key --certificate=db:Open_vSwitch,SSL,certificate --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert --no-chdir --log-file=/var/log/openvswitch/ovsdb-server.log --pidfile=/var/run/openvswitch/ovsdb-server.pid --detach --monitor<br><br><br>12月 04 18:38:51 localhost.localdomain systemd: Starting LSB: Open vSwitch switch...<br>12月 04 18:38:51 localhost.localdomain openvswitch: /etc/openvswitch/conf.db does not exist ... (warning).<br>12月 04 18:38:51 localhost.localdomain openvswitch: Creating empty database /etc/openvswitch/conf.db [ &nbsp;OK &nbsp;]<br>12月 04 18:38:52 localhost.localdomain openvswitch: Starting ovsdb-server [ &nbsp;OK &nbsp;]<br>12月 04 18:38:52 localhost.localdomain openvswitch: Configuring Open vSwitch system IDs [ &nbsp;OK &nbsp;]<br>12月 04 18:38:52 localhost.localdomain openvswitch: ovs-vswitchd is already running.<br>12月 04 18:38:52 localhost.localdomain openvswitch: Enabling remote OVSDB managers [ &nbsp;OK &nbsp;]<br>12月 04 18:38:52 localhost.localdomain systemd: Started LSB: Open vSwitch switch.<br>12月 04 18:38:52 localhost.localdomain openvswitch: Starting ovs-vswitchd [ &nbsp;OK &nbsp;]<br>12月 04 18:38:52 localhost.localdomain openvswitch: Enabling remote OVSDB managers [ &nbsp;OK &nbsp;]</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>正确方法参考:https://www.cnblogs.com/bethal/p/6043899.html</p><br><br>
来源:https://www.cnblogs.com/slz-coder150315/p/11650019.html
頁: [1]
查看完整版本: Centos安装OpenVSwitch历程