CentOS 7

CentOS7下的各种应用


CentOS7双网卡绑定

<h2>(一)简述</h2> <h3>1.teaming技术</h3> <p>双网卡绑定技术在centos7中使用了teaming技术,而在rhel6/centos7中使用的是bonding技术, 在centos7中双网卡绑定既能使用teaming也可以使用bonding,这里推荐使用teaming技术,方便与查看和监控。</p> <h3>2.原理</h3> <pre><code>这里介绍两种最常见的双网卡绑定模式: (1) roundrobin - 轮询模式 所有链路处于负载均衡状态,这种模式的特点增加了带宽,同时支持容错能力。 (2) activebackup - 主备模式 一个网卡处于活动状态,另一个处于备份状态,所有流量都在主链路上处理,当活动网卡down掉时,启用备份网卡。</code></pre> <h3>3.查看服务器的相关信息</h3> <p>安装前state为connected</p> <pre><code class="language-bash">[root@localhost ~]# nmcli dev DEVICE TYPE STATE CONNECTION em1 ethernet connected -- em2 ethernet connected -- em3 ethernet unavailable -- em4 ethernet unavailable -- lo loopback unmanaged -- </code></pre> <pre><code class="language-bash">[root@localhost ~]# ip a 1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: em1: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc mq master team0 state UP qlen 1000 link/ether 36:3c:c4:19:d0:ef brd ff:ff:ff:ff:ff:ff 3: em2: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc mq master team0 state UP qlen 1000 link/ether 36:3c:c4:19:d0:ef brd ff:ff:ff:ff:ff:ff 4: em3: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 24:6e:96:a2:dd:ae brd ff:ff:ff:ff:ff:ff 5: em4: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 24:6e:96:a2:dd:af brd ff:ff:ff:ff:ff:ff 18: team0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue state UP qlen 1000 link/ether 36:3c:c4:19:d0:ef brd ff:ff:ff:ff:ff:ff inet 10.128.105.156/24 brd 10.128.105.255 scope global team0 valid_lft forever preferred_lft forever inet6 fe80::718:e575:f031:47d4/64 scope link valid_lft forever preferred_lft forever</code></pre> <p>其中state UP 为网卡有网线或启用的网口,有上边的参数可知,em1和em2有网线接口,其他的网口没有。lo为本地回环网卡</p> <h2>(二)Roundrobin(轮询)安装步骤</h2> <h3>1.查看网卡的连接信息:nmcli con sh</h3> <pre><code class="language-bash">[root@localhost ~]# nmcli con sh NAME UUID TYPE DEVICE em1 4c8a8aee-327b-4f29-9ec4-ea2b2551420b 802-3-ethernet -- em2 62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42 802-3-ethernet -- em3 56ef9d05-3a5d-4cd6-af5b-3d39adce619f 802-3-ethernet -- em4 761f7809-d10c-4e3b-bc06-c0906ca55d1c 802-3-ethernet -- </code></pre> <h3>2.删除无用的网卡:nmcli con del em3</h3> <p>此步,我未操作。</p> <pre><code class="language-bash">[root@localhost ~]# nmcli con del em3 Connection 'em3' (56ef9d05-3a5d-4cd6-af5b-3d39adce619f) successfully deleted. [root@localhost ~]# nmcli con sh NAME UUID TYPE DEVICE em1 4c8a8aee-327b-4f29-9ec4-ea2b2551420b 802-3-ethernet -- em2 62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42 802-3-ethernet -- em4 761f7809-d10c-4e3b-bc06-c0906ca55d1c 802-3-ethernet -- </code></pre> <h3>3.使用nmcli命令操作,创建team接口team0,同时设置teaming模式为roundrobin</h3> <pre><code class="language-bash">[root@localhost ~]# nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name": "roundrobin"}}'</code></pre> <pre><code class="language-bash">[root@localhost ~]# nmcli con sh NAME UUID TYPE DEVICE team0 5a1976d7-2c91-456e-8dda-0b12c6ef0c04 team team0 em1 4c8a8aee-327b-4f29-9ec4-ea2b2551420b 802-3-ethernet -- em2 62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42 802-3-ethernet -- em4 761f7809-d10c-4e3b-bc06-c0906ca55d1c 802-3-ethernet -- </code></pre> <h3>4.给接口team0设置ip地址和网关,</h3> <pre><code class="language-bash">[root@localhost ~]# nmcli con modify team0 ipv4.address '10.128.105.157/24' ipv4.gateway '10.128.105.254' </code></pre> <h3>设置为手动模式,并取消手动模式</h3> <pre><code class="language-bash">[root@localhost ~]# nmcli con modify team0 ipv4.method manual</code></pre> <h3>5.将两张物理网卡添加到team</h3> <pre><code class="language-bash">[root@localhost ~]# nmcli con add type team-slave con-name team0-port2 ifname em1 master team0 Connection 'team0-port2' (e01c37f5-b3a1-4e6d-96ab-a6e676ad3c32) successfully added. [root@localhost ~]# nmcli con add type team-slave con-name team0-port2 ifname em2 master team0 Connection 'team0-port2' (8b13a9de-d64c-44fc-a86d-ea45d2f511cf) successfully added.</code></pre> <pre><code class="language-bash"> [root@localhost ~]# nmcli con sh NAME UUID TYPE DEVICE team0 64b123d5-189d-43b0-a850-77d47c0da86c team team0 team0-port1 24181898-bffe-4ae1-90e8-f47da64b5512 802-3-ethernet em1 team0-port2 8b13a9de-d64c-44fc-a86d-ea45d2f511cf 802-3-ethernet em2 em1 4c8a8aee-327b-4f29-9ec4-ea2b2551420b 802-3-ethernet -- em2 62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42 802-3-ethernet -- em4 761f7809-d10c-4e3b-bc06-c0906ca55d1c 802-3-ethernet -- </code></pre> <h3>6.使用ifup team0 启用team0网卡,然后重启网络服务。</h3> <p>ifup team0 如果启不来,可以reboot。 systemctl restart network 会报错,原因未查明。</p> <pre><code class="language-bash">[root@localhost ~]# ifup team0 [root@localhost ~]# /etc/init.d/network restart Restarting network (via systemctl): [ OK ] [root@localhost ~]# ip a |grep team0 2: em1: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc mq master team0 state UP qlen 1000 10: team0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue state UP qlen 1000 inet 10.128.105.157/24 brd 10.128.105.255 scope global team0</code></pre> <h3>7.现在查看team0的状态模式是否是roundrobin。teamdctl team0 st</h3> <pre><code class="language-bash">[root@localhost ~]# teamdctl team0 st setup: runner: roundrobin ports: em1 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0 em2 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up</code></pre> <p>这样,team模式的roundrobin搭建成功。</p> <h3>8.测试是否正常工作</h3> <h4>8.1.首先把em1网卡禁用,用其他的服务器ping看是否断。</h4> <pre><code class="language-bash">[root@localhost etc]# ifdown em1 Device 'em1' successfully disconnected. [root@localhost etc]# nmcli con sh NAME UUID TYPE DEVICE team0 64b123d5-189d-43b0-a850-77d47c0da86c team team0 team0-port2 8b13a9de-d64c-44fc-a86d-ea45d2f511cf 802-3-ethernet em2 em1 4c8a8aee-327b-4f29-9ec4-ea2b2551420b 802-3-ethernet -- em2 62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42 802-3-ethernet -- em4 761f7809-d10c-4e3b-bc06-c0906ca55d1c 802-3-ethernet -- team0-port1 24181898-bffe-4ae1-90e8-f47da64b5512 802-3-ethernet -- [root@localhost ~]# teamdctl team0 st setup: runner: roundrobin ports: em2 link watches: link summary: up instance[link_watch_0]: name: ethtool link: up down count: 0</code></pre> <p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/43a0e1f300f6ff214d1dc7e5bad1a0c3?showdoc=.jpg" alt="" /></p> <p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/de5b190f46e46258ae717db6cbf4c310?showdoc=.jpg" alt="" /> 从上图看出实在正常的。</p> <h4>8.2.把网卡em1启用,em2禁用查看下下</h4> <pre><code class="language-bash">[root@localhost etc]# ifup em1 [root@localhost etc]# nmcli con sh NAME UUID TYPE DEVICE team0 64b123d5-189d-43b0-a850-77d47c0da86c team team0 team0-port1 24181898-bffe-4ae1-90e8-f47da64b5512 802-3-ethernet em1 team0-port2 8b13a9de-d64c-44fc-a86d-ea45d2f511cf 802-3-ethernet em2 em1 4c8a8aee-327b-4f29-9ec4-ea2b2551420b 802-3-ethernet -- em2 62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42 802-3-ethernet -- em4 761f7809-d10c-4e3b-bc06-c0906ca55d1c 802-3-ethernet -- [root@localhost etc]# ifdown em2 Device 'em2' successfully disconnected. [root@localhost etc]# nmcli con sh NAME UUID TYPE DEVICE team0 64b123d5-189d-43b0-a850-77d47c0da86c team team0 team0-port1 24181898-bffe-4ae1-90e8-f47da64b5512 802-3-ethernet em1 em1 4c8a8aee-327b-4f29-9ec4-ea2b2551420b 802-3-ethernet -- em2 62bde3ef-9f40-42aa-9b3a-4fe8b1aabf42 802-3-ethernet -- em4 761f7809-d10c-4e3b-bc06-c0906ca55d1c 802-3-ethernet -- team0-port2 8b13a9de-d64c-44fc-a86d-ea45d2f511cf 802-3-ethernet -- </code></pre> <p>网卡流量em2没变,而em1变化了。 <img src="https://www.showdoc.cc/server/api/common/visitfile/sign/e9004857a9bb2ab1d5bcfc3bb12bcc7e?showdoc=.jpg" alt="" /></p> <h2>(三)双网卡绑定activebackup的实现</h2> <p>待续</p> <p>来源:<a href="https://blog.51cto.com/liqingbiao/2089733">https://blog.51cto.com/liqingbiao/2089733</a></p>

页面列表

ITEM_HTML