Friday, February 17, 2017

get list of memory consuming processes

the below two commands will provide you the processes which are consuming maximum memory on Linux machine.

#ps -A --sort -rss -o comm,pmem | head -10
#ps axu | awk '{print $2, $3, $4, $11}' | head -1 && ps axu | awk '{print $2, $3, $4, $11}' | sort -k3 -nr |head -10

Monday, January 16, 2017

logrotate config for syslogs

here is an example of logrotate script/config file I use for syslogs.

[root@oxygen ~]# cat /etc/logrotate.d/syslog
/var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron 
{
    rotate 5
    compress
    size 50M
    create 0600 root root
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
        /bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}

Monday, March 28, 2016

how to find wwn information of hba cards under linux

On Red Hat Enterprise Linux & openSUSE, you can run below command to get World Wide Name of a HBA card.

# systool -c fc_host -v | grep "port_name"

Note : systool command is provided by sysfsutils package.

alternative command for the same thing that should work in any standard Linux kernel.

# cat /sys/class/scsi_host/host*/device/fc_host/host*/node_name



Tuesday, December 22, 2015

nic bonding / teaming in centos 7

list all available NICs

# nmcli -p dev status
================================================
               Status of devices
================================================
DEVICE  TYPE      STATE      CONNECTION
------------------------------------------------
ens192  ethernet  connected  ens192
ens224  ethernet  connected  ens224
lo      loopback  unmanaged  --
[root@centos7 ~]#

add interface with ipv4 only address, two slaves and active-backup

#nmcli connection add type bond ifname bond0 con-name bond0 mode balance-rr primary ens192 miimon 200 ip4 192.168.0.2 gw4 192.168.0.1
#nmcli connection mod bond0 ipv4.dns “192.168.0.1” ipv6.method “ignore”
#nmcli connection add type bond-slave ifname ens192 master bond0
#nmcli connection add type bond-slave ifname ens224 master bond0

activate the newly created bond /team connection

#nmcli c u bond0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)

Verify the connectivity.

#nmcli network connectivity
full

[root@centos7 ~]# nmcli -p connection show bond0
===============================================================================
                      Connection profile details (bond0)
===============================================================================
connection.id:                          bond0
connection.uuid:                        XXXXXXX-XXXXX-XXXX-XXXXX-XXXXXXXX
connection.interface-name:              bond0
connection.type:                        bond
connection.autoconnect:                 yes
connection.autoconnect-priority:        0
<--------------------->


Tuesday, December 1, 2015

disable ipv6 on rhel/centos version 5 / 6 / 7

on RHEL5

# cat /proc/sys/net/ipv6/conf/all/disable_ipv6
0
# echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
# cat /proc/sys/net/ipv6/conf/all/disable_ipv6
1


on RHEL6 and RHEL7

# cat /proc/sys/net/ipv6/conf/all/disable_ipv6
0
# cat /proc/sys/net/ipv6/conf/default/disable_ipv6
0
# echo 1 > /proc/sys/net/ipv6/conf/default/disable_ipv6
# echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
# cat /proc/sys/net/ipv6/conf/all/disable_ipv6
1
# cat /proc/sys/net/ipv6/conf/default/disable_ipv6
1

Monday, November 23, 2015

monitoring linux host with sar utility

you can use sar to monitor your Linux system effectively.

use the below command to redirect output to a file. i.e. to save data for that email to customer :)

[root@localhost ~]# sar 2 4 -o /tmp/sardata > /dev/null 2>&1

now you can use the below one to read that file too.

[root@localhost ~]# sar -f /tmp/sardata

memory stats using sar

[root@localhost ~]# sar -r 2 4

disk stats

[root@localhost ~]# sar -d -p 2 4

view historical data of sar

[root@localhost ~]# sar -r -f /var/log/sa/sa20

Friday, June 5, 2015

rescan new lun/ vdisk in linux

Use below for loop to detect new LUN assignments on existing HBA

#for host in `ls /sys/class/scsi_host/`;
do echo "- - -" >/sys/class/scsi_host/${host}/scan
done

echo "c t l" >  /sys/class/scsi_host/hostH/scan

The three values stand for channel, SCSI target ID, and LUN. The dashes act as wildcards meaning "rescan everything"

Use below commands when you are expanding existing disk in VM.

[root@rhel7test1 ~]# ls /sys/class/scsi_device/
2:0:0:0  2:0:1:0  2:0:2:0  2:0:3:0  3:0:0:0

 Now rescan each of these devices.
[root@rhel7test1 ~]# echo 1> /sys/class/scsi_device/2\:0\:0\:0/device/rescan
[root@rhel7test1 ~]# echo 1> /sys/class/scsi_device/2\:0\:1\:0/device/rescan
[root@rhel7test1 ~]# echo 1> /sys/class/scsi_device/2\:0\:2\:0/device/rescan
[root@rhel7test1 ~]# echo 1> /sys/class/scsi_device/2\:0\:3\:0/device/rescan
[root@rhel7test1 ~]# echo 1> /sys/class/scsi_device/3\:0\:0\:0/device/rescan

You can also use rescan-scsi-bus.sh utility. Install the sg3_utils package

[root@rhel7test1 ~]# rescan-scsi-bus.sh
which: no multipath in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
Scanning SCSI subsystem for new devices
Scanning host 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 1 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 2 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
 Scanning for device 2 0 0 0 ...
OLD: Host: scsi2 Channel: 00 Id: 00 Lun: 00
      Vendor: VMware   Model: Virtual disk     Rev: 1.0
      Type:   Direct-Access                    ANSI SCSI revision: 02
 Scanning for device 2 0 1 0 ...
OLD: Host: scsi2 Channel: 00 Id: 01 Lun: 00
      Vendor: VMware   Model: Virtual disk     Rev: 1.0
      Type:   Direct-Access                    ANSI SCSI revision: 02
 Scanning for device 2 0 2 0 ...
OLD: Host: scsi2 Channel: 00 Id: 02 Lun: 00
      Vendor: VMware   Model: Virtual disk     Rev: 1.0
      Type:   Direct-Access                    ANSI SCSI revision: 02
 Scanning for device 2 0 3 0 ...
OLD: Host: scsi2 Channel: 00 Id: 03 Lun: 00
      Vendor: VMware   Model: Virtual disk     Rev: 1.0
      Type:   Direct-Access                    ANSI SCSI revision: 02
Scanning host 3 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
 Scanning for device 3 0 0 0 ...
OLD: Host: scsi3 Channel: 00 Id: 00 Lun: 00
      Vendor: NECVMWar Model: VMware SATA CD00 Rev: 1.00
      Type:   CD-ROM                           ANSI SCSI revision: 05
Scanning host 4 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 5 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 6 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 7 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 8 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 9 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 10 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 11 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 12 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 13 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 14 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 15 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 16 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 17 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 18 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 19 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 20 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 21 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 22 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 23 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 24 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 25 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 26 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 27 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 28 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 29 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 30 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 31 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning host 32 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
0 new or changed device(s) found.
0 remapped or resized device(s) found.
0 device(s) removed.