NSD ENGINEER DAY04
- 案例1:配置IPv6地址
- 案例2:配置聚合连接
1 案例1:配置IPv6地址
1.1 问题
本例要求为两个虚拟机 server0、desktop0的接口 eth0 配置下列 IPv6 地址:
- server0 上的地址应该是 2003:ac18::305/64
- desktop0 上的地址应该是 2003:ac18::306/64
- 两个系统必须能与网络 2003:ac18/64 内的系统通信
- 地址必须在重启后依旧生效
- 两个系统必须保持当前的IPv4地址并能通信
1.2 方案
如何表示一个IP地址:
- IPv4地址(32位) —— 点 分隔 十进制,比如172.25.0.11
- IPv6地址(128位)—— 冒号 分隔 十六进制,比如fe80::5054:ff:fe00:b 。前置0可以省略,多个连续的冒号分隔可简写成两个(::)。
针对IPv6目标地址的连通性测试应使用ping6命令工具。
1.3 步骤
实现此案例需要按照如下步骤进行。
步骤一:修改主机server0的网卡eth0的配置
1)确认网卡eth0所属的网络连接名(NAME)
- [[email protected] ~]# nmcli connection show
- NAME UUID TYPE DEVICE
- System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
2)修改此连接的IPv6地址配置
使用方法一(命令行):
- [[email protected] ~]# nmcli connection modify "System eth0" ipv6.method manual ipv6.addresses "2003:ac18::305/64"
或者,使用方法二(图形工具),运行nm-connection-editor,在打开的图形程序界面中双击连接名称System eth0,选择“IPv6 Settings”选项卡(如图-1所示)。
图-1
然后在“Method”处下拉选择“Manual”,再单击中间栏右侧的“Add”按钮添加指定的IPv6地址2003:ac18::305、掩码长度64,勾选底部的“Require IPv6 addressing for this connection to complete”(如图-2所示),最后单击右下角的“Save”保存,并关闭配置窗口。
图-2
3)激活新配置
- [[email protected] ~]# nmcli connection up "System eth0"
- Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)
4)确认地址已成功设置
执行ifconfig命令可以看到新增加的IPv6地址:
- [[email protected] ~]# ifconfig eth0 | grep inet6
- eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 172.25.0.11 netmask 255.255.255.0 broadcast 172.25.0.255
- inet6 2003:ac18::305 prefixlen 64 scopeid 0x0<global> //确认地址
- inet6 fe80::5054:ff:fe00:b prefixlen 64 scopeid 0x20<link>
- ether 52:54:00:00:00:0b txqueuelen 1000 (Ethernet)
- RX packets 8697 bytes 5617496 (5.3 MiB)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 6681 bytes 5803117 (5.5 MiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
步骤二:修改主机desktop0的网卡eth0的配置
除了IPv6地址应使用2003:ac18::306以外,其他操作与步骤一相同。
步骤三:测试主机server0、desktop0之间的IPv6地址互连
在server0上,使用ping6命令测试desktop0的IPv6地址,可以正常连通:
- [[email protected] ~]# ping6 2003:ac18::306
- PING 2003:ac18::306(2003:ac18::306) 56 data bytes
- 64 bytes from 2003:ac18::306: icmp_seq=1 ttl=64 time=0.656 ms
- 64 bytes from 2003:ac18::306: icmp_seq=2 ttl=64 time=1.33 ms
- 64 bytes from 2003:ac18::306: icmp_seq=3 ttl=64 time=1.29 ms
- 64 bytes from 2003:ac18::306: icmp_seq=4 ttl=64 time=1.48 ms
- .. ..
步骤四:确保配置有正确的静态主机名
避免重启后无法确定本机的主机名,容易引起混淆。
对于主机server0:
- [[email protected] ~]# hostnamectl set-hostname server0.example.com
- [[email protected] ~]# hostnamectl
- Static hostname: server0.example.com
- Icon name: computer
- .. ..
对于主机desktop0:
- [[email protected] ~]# hostnamectl set-hostname desktop0.example.com
- [[email protected] ~]# hostnamectl
- Static hostname: desktop0.example.com
- Icon name: computer
- .. ..
2 案例2:配置聚合连接
2.1 问题
本例要求在两个虚拟机 server0、desktop0之间配置一个链路,要求如下:
- 此链路使用接口 eth1 和 eth2
- 此链路在其中一个接口失效时仍然能工作
- 此链路在 server0 上使用下面的地址 172.16.3.20/255.255.255.0
- 此链路在 desktop0 上使用下面的地址 172.16.3.25/255.255.255.0
- 此链路在系统重启之后依然保持正常状态
2.2 方案
聚合连接(team):指的是网络连接的捆绑/组队,通过将多个实际网卡(team-slave)整个为逻辑上的单个连接,实现负载均衡、热备份等单块网卡难以完成的特殊功能。
聚合连接的类型:热备份activebackup、轮询负载均衡roundrobin。
定义聚合连接的类型配置时,采用JSON语法标记,主要特点如下:
- 标记一个对象 —— { 对象 }
- 每一个对象 —— 名称:值
- 每一个字符串 —— "字符串"
热备份-聚合连接(activebackup):
- { "runner":{ "name":"activebackup" } }
负载均衡-聚合连接(roundrobin):
- { "runner":{ "name":"roundrobin" } }
2.3 步骤
除了所配置的IP地址不一样以外,在server0、desktop0主机上的其他操作相同。此处仅列出在server0上的配置过程。
实现此案例需要按照如下步骤进行。
步骤一:准备练习用网卡环境
新建的聚合连接将组合新增加的两块网卡eth1、eth2。
- [[email protected] ~]# ifconfig
- eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 172.25.0.11 netmask 255.255.255.0 broadcast 172.25.0.255
- inet6 2003:ac18::305 prefixlen 64 scopeid 0x0<global>
- inet6 fe80::5054:ff:fe00:b prefixlen 64 scopeid 0x20<link>
- ether 52:54:00:00:00:0b txqueuelen 1000 (Ethernet)
- RX packets 172995 bytes 23870389 (22.7 MiB)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 54053 bytes 34274222 (32.6 MiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- ether 52:54:00:f8:86:c1 txqueuelen 1000 (Ethernet)
- RX packets 104217 bytes 5437855 (5.1 MiB)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 171 bytes 17171 (16.7 KiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- ether 52:54:00:38:79:d9 txqueuelen 1000 (Ethernet)
- RX packets 104118 bytes 5428927 (5.1 MiB)
- RX errors 0 dropped 2060 overruns 0 frame 0
- TX packets 0 bytes 0 (0.0 B)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- .. ..
步骤二:创建聚合连接配置
1)新建聚合连接
- [[email protected] ~]# nmcli con add con-name team0 type team ifname team0 config ‘{ "runner":{ "name":"activebackup" } }‘
- Connection ‘team0‘ (8e61d730-50ff-4a7b-8ca0-fcf5955f6ea7) successfully added.
2)配置IPv4地址
- [[email protected] ~]# nmcli con modify team0 ipv4.method manual ipv4.addresses ‘172.16.3.20/24‘ connection.autoconnect yes
3)新建聚合成员连接
- [[email protected] ~]# nmcli con add con-name team0-p1 type team-slave ifname eth1 master team0
- Connection ‘team0-p1‘ (a62d23a2-9a2a-4855-8fbc-60ce1fd43f0b) successfully added.
- [[email protected] ~]# nmcli con add con-name team0-p2 type team-slave ifname eth2 master team0
- Connection ‘team0-p2‘ (f4d4980e-8123-4840-89ac-1af148cc2eea) successfully added.
步骤三:激活聚合连接
1)激活聚合连接
- [[email protected] ~]# nmcli connection up team0
- Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
2)激活聚合成员连接
- [[email protected] ~]# nmcli connection up team0-p1
- Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
- [[email protected] ~]# nmcli connection up team0-p2
- Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)
步骤四:确认聚合连接状态
1)查看聚合连接地址
- [[email protected] ~]# ifconfig team0
- team0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 172.16.3.20 netmask 255.255.255.0 broadcast 172.16.3.255
- inet6 fe80::c80d:efff:fe08:ca57 prefixlen 64 scopeid 0x20<link>
- ether ca:0d:ef:08:ca:57 txqueuelen 0 (Ethernet)
- RX packets 0 bytes 0 (0.0 B)
- RX errors 0 dropped 36 overruns 0 frame 0
- TX packets 68 bytes 8695 (8.4 KiB)
- TX errors 0 dropped 1 overruns 0 carrier 0 collisions 0
2)查看聚合连接运行状态
- [[email protected] ~]# teamdctl team0 state
- setup:
- runner: activebackup //运行模式/类型
- ports:
- eth1 //成员网卡1
- link watches:
- link summary: up
- instance[link_watch_0]:
- name: ethtool
- link: up
- eth2 //成员网卡2
- link watches:
- link summary: up
- instance[link_watch_0]:
- name: ethtool
- link: up
- runner:
- active port: eth1 //当前活动的成员网卡