Monday, June 24, 2019

How to configure network bonding in linux

How to configure network bonding in linux

 We will configure active-backup bonding
 Then will do testing, just to disable one interface and check. we should be able to access our  machine using the bond ip.


[root@server ~]# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.159.164
NETMASK=255.255.255.0
GATEWAY=192.168.5.1
USERCTL=no
BOOTPROTO=static
ONBOOT=yes
BONDING_OPTS="mode=1 miimon=100"

[root@server ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
[root@server ~]#
[root@server ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

[root@server ~]# vi /etc/modprobe.conf
alias bond0 bonding
[root@server ~]#

[root@server ~]# modprobe bonding


[root@server ~]# /etc/init.d/network restart
Shutting down interface bond0:                             [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface bond0:                               [  OK  ]
[root@server ~]#


[root@server ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up            <============== Showing status up eth0
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 00:0c:29:16:ad:b4
Slave queue ID: 0

Slave Interface: eth1
MII Status: up        <============== Show status up for eth1
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 00:0c:29:16:ad:be
Slave queue ID: 0
[root@server ~]#



[root@server ~]# ethtool eth0
Settings for eth0:
        Current message level: 0x00000007 (7)
        Link detected: yes
[root@server ~]# ethtool eth1
Settings for eth1:
        Current message level: 0x00000007 (7)
        Link detected: yes
[root@server ~]#


===============================================================================
Now we do some testing by disabling link for eth 1 and then check bond0 status
===============================================================================

[root@server ~]# grep link /var/log/messages
Jun 22 18:29:59 server kernel: eth1: link down
Jun 22 18:29:59 server kernel: bonding: bond0: link status definitely down for interface eth1, disabling it

[root@server ~]#
[root@server ~]#


[root@server ~]# ethtool eth1
Settings for eth1:
        Current message level: 0x00000007 (7)
        Link detected: no
[root@server ~]#


[root@server ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0 <======== show link status up for eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 00:0c:29:16:ad:b4
Slave queue ID: 0

Slave Interface: eth1
MII Status: down    <======== show link status down for eth1, and we still connected to our machine
Speed: Unknown                  hence we confirm bonding is working well
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: 00:0c:29:16:ad:be
Slave queue ID: 0

[root@server ~]#
[root@server ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UNKNOWN qlen 1000
    link/ether 00:0c:29:16:ad:b4 brd ff:ff:ff:ff:ff:ff
3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,SLAVE,UP> mtu 1500 qdisc pfifo_fast master bond0 state DOWN qlen 1000 
    link/ether 00:0c:29:16:ad:b4 brd ff:ff:ff:ff:ff:ff
4: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN
    link/ether e6:79:4f:de:c4:c1 brd ff:ff:ff:ff:ff:ff
5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
    link/ether 00:0c:29:16:ad:b4 brd ff:ff:ff:ff:ff:ff
    inet 192.168.159.164/24 brd 192.168.159.255 scope global bond0
    inet6 fe80::20c:29ff:fe16:adb4/64 scope link
       valid_lft forever preferred_lft forever

=====================================================================================================================      
Note: output of eth1 output there is LOWER_UP, flag is missing which we will match again once eth1 network recoverd
=====================================================================================================================


=========================================================
check bond0 status after connection recoverd for eth1
=========================================================

[root@server ~]# grep link /var/log/messages
Jun 22 18:32:15 server kernel: eth1: link up
Jun 22 18:32:15 server kernel: bond0: link status definitely up for interface eth1, 4294967295 Mbps full duplex.

[root@server ~]# cat /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 00:0c:29:16:ad:b4
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: 00:0c:29:16:ad:be
Slave queue ID: 0
[root@server ~]# ethtool eth1
Settings for eth1:
        Current message level: 0x00000007 (7)
        Link detected: yes
[root@server ~]#

=====================================================================================================================
Note: output of eth1 output there is LOWER_UP, flag is back which we will match again once eth1 network recoverd
=====================================================================================================================
[root@server ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UNKNOWN qlen 1000
    link/ether 00:0c:29:16:ad:b4 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
    link/ether 00:0c:29:16:ad:b4 brd ff:ff:ff:ff:ff:ff
4: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN
    link/ether e6:79:4f:de:c4:c1 brd ff:ff:ff:ff:ff:ff
5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
    link/ether 00:0c:29:16:ad:b4 brd ff:ff:ff:ff:ff:ff
    inet 192.168.159.164/24 brd 192.168.159.255 scope global bond0
    inet6 fe80::20c:29ff:fe16:adb4/64 scope link
       valid_lft forever preferred_lft forever
[root@server ~]#







=========================================================
Different Modes that can be used in /etc/modprobe.conf
=========================================================
    balance-rr or 0 — round-robin mode for fault tolerance and load balancing.
    active-backup or 1 — Sets active-backup mode for fault tolerance.
    balance-xor or 2 — Sets an XOR (exclusive-or) mode for fault tolerance and load balancing.
    broadcast or 3 — Sets a broadcast mode for fault tolerance. All transmissions are sent on all slave interfaces.
    802.3ad or 4 — Sets an IEEE 802.3ad dynamic link aggregation mode. Creates aggregation groups that share the same speed & duplex settings.
    balance-tlb or 5 — Sets a Transmit Load Balancing (TLB) mode for fault tolerance & load balancing.
    balance-alb or 6 — Sets an Active Load Balancing (ALB) mode for fault tolerance & load balancing.

=====================================================
    #Now following is explanation about LOWER_UP:
=====================================================   
LOWER_UP is a physical layer link flag (the layer below the network layer, where IP is generally located).
LOWER_UP indicates that an Ethernet cable is plugged in device is connected to the network.

LOWER_UP differs from UP, which additionally requires the network interface to be enabled.

Saturday, June 22, 2019

Configure Multipath in linux

[root@server scsi_host]# iscsiadm -m discovery -t st -p  192.168.150.1
Starting iscsid:                                           [  OK  ]
192.168.150.1:3260,-1 iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool
[root@server scsi_host]# iscsiadm -m discovery -t st -p  192.168.150.1,3260
192.168.150.1:3260,-1 iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool
[root@server scsi_host]# iscsiadm -m node -L all
Logging in to [iface: default, target: iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool, portal: 192.168.150.1,3260] (multiple)
Login to [iface: default, target: iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool, portal: 192.168.150.1,3260] successful.

[root@server scsi_host]# multipath -ll
mpatha (2628fb3127e8f77f6) dm-3 ROCKET,IMAGEFILE
size=5.0G features='0' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=active
  `- 3:0:0:0 sde 8:64 active ready running

 
 =================================================================
  Now configure 2nd network path for storage disks.
 =================================================================
[root@server scsi_host]#  iscsiadm -m discovery -t st -p  192.168.159.1
192.168.159.1:3260,-1 iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool
192.168.159.1:3260,-1 iqn.2008-08.com.starwindsoftware:192.168.159.1-linuxstoragepool
[root@server scsi_host]#  iscsiadm -m discovery -t st -p  192.168.159.1,3260
192.168.159.1:3260,-1 iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool
192.168.159.1:3260,-1 iqn.2008-08.com.starwindsoftware:192.168.159.1-linuxstoragepool


[root@server multipath]#  iscsiadm -m node -L all
Logging in to [iface: default, target: iqn.2008-08.com.starwindsoftware:192.168.159.1-linuxstoragepool, portal: 192.168.159.1,3260] (multiple)
Logging in to [iface: default, target: iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool, portal: 192.168.159.1,3260] (multiple)
Login to [iface: default, target: iqn.2008-08.com.starwindsoftware:192.168.159.1-linuxstoragepool, portal: 192.168.159.1,3260] successful.
Login to [iface: default, target: iqn.2008-08.com.starwindsoftware:192.168.150.1-linuxstoragepool, portal: 192.168.159.1,3260] successful.

==============================================================
Now in following output you can see boths disks are showing 2 paths for eachs disk
==============================================================
[root@server multipath]# multipath -ll
mpathb (26eb538fc86227b31) dm-4 ROCKET,IMAGEFILE
size=50G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=enabled
| `- 3:0:0:1 sdf 8:80  active ready running
`-+- policy='round-robin 0' prio=1 status=active
  `- 5:0:0:1 sdh 8:112 active ready running
mpatha (2628fb3127e8f77f6) dm-3 ROCKET,IMAGEFILE
size=5.0G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=enabled
| `- 3:0:0:0 sde 8:64  active ready running
`-+- policy='round-robin 0' prio=1 status=active
  `- 5:0:0:0 sdg 8:96  active ready running
[root@server multipath]#
[root@server multipath]#
[root@server multipath]#

====================================================================
Now lets try to disable one path and we should see active faulty running in multipath -ll output
====================================================================
 [root@server ~]# multipath -ll

mpathb (26eb538fc86227b31) dm-4 ROCKET,IMAGEFILE
size=50G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=0 status=enabled
| `- 3:0:0:1 sdf 8:80  active faulty running      <============ See we have one path faulty for  mpathb disk
`-+- policy='round-robin 0' prio=1 status=active
  `- 5:0:0:1 sdh 8:112 active ready running
mpatha (2628fb3127e8f77f6) dm-3 ROCKET,IMAGEFILE
size=5.0G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=0 status=enabled
| `- 3:0:0:0 sde 8:64  active faulty running
`-+- policy='round-robin 0' prio=1 status=active
  `- 5:0:0:0 sdg 8:96  active ready running

 ============================ ===========================
Now enable vmnet virtaul adapter and path should be recover by its own
=========================== ============================  
  [root@server ~]# multipath -ll
mpathb (26eb538fc86227b31) dm-4 ROCKET,IMAGEFILE
size=50G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=enabled
| `- 3:0:0:1 sdf 8:80  active ready running
`-+- policy='round-robin 0' prio=1 status=active
  `- 5:0:0:1 sdh 8:112 active ready running
mpatha (2628fb3127e8f77f6) dm-3 ROCKET,IMAGEFILE
size=5.0G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=enabled
| `- 3:0:0:0 sde 8:64  active ready running
`-+- policy='round-robin 0' prio=1 status=active
  `- 5:0:0:0 sdg 8:96  active ready running

kubernetes Pod Scheduling

 ===================   Deployment ================= 1.) Deployment without any nodeName or nodeSelector, pod will spread among all of the av...