Counting the number of processes running in Linux

Option 1: Number of processes run by a lsdyna_smp_s_r1

Sometimes we need to get the number of processes run by a lsdyna_smp_s_r1. For example if you are running a software named lsdyna_smp_s_r1 and you want to know how many processes were spawn, you can use the command

# ps -C lsdyna_smp_s_r1 | wc -l
183

OR if you are checking for the number of processes for SSH

# pgrep lsdyna_smp_s_r1 | wc -l
183

Option 2: Number of processes run by a User

# ps -U user1 | wc -l
333

 

Massive DNS Requests caused by IPv6

When I do a tcpdump, I notice the issues…..

11:25:27.106997 IP hpc-mn1.52900 > xxx.domain: 28690+ AAAA? bmc72. (23)
11:25:27.107385 IP xxx.domain > hpc-mn1.52900: 28690 NXDomain 0/1/0 (98)
11:25:27.108387 IP hpc-mn1.47867 > xxx.domain: 19474+ AAAA? bmc72. (23)
11:25:27.108933 IP xxx.domain > hpc-mn1.47867: 19474 NXDomain 0/1/0 (98)

AAAA? are IPv6 DNS Request.

There is a great article that address this. You may want to take a look at https://jongsma.wordpress.com/tag/tcpdump/

 

Using TCPDump on CENTOS 7

tcpdump is a swiss-army tool to help you troubleshoot network and security tools

Capture information based on IP Address

# tcpdump -i eth0 host 192.168.1.1

If you are capturing source

# tcpdump -i eth0 src 192.168.1.5

OR If you are capturing destination

# tcpdump -i eth0 dst 192.168.1.10

Capture and write to a standard pcap file

# tcpdump -i eth0 -s0 -w temp.pcap

where s0 – set the size of captured to unlimited. In other words, capture all packets

Line Buffered Mode

If you are using grep to capture selected parameter, you will need to force the line buffered (-l). The output is sent immediately to the piped command

# tcpdump -i eth0 -s0 -l | grep 'bmc'

Capture on Protocol

# tcpdump -i eth0 udp

OR

# tcpdump -i eth0 -n icmp

References:

  1. Tcpdump Examples
  2. Tcpdump Examples: 50 Practical Recipes for Everyday Tasks

Using dmidecode to find hardware information

Taken from the Manual Page

dmidecode is a tool for dumping a computer’s DMI (some say SMBIOS) table contents in a human-readable format. This table contains a description of the system’s hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision.

 

Option 1: Getting DMI Type

[root@my-node1 ~]# dmidecode -t
dmidecode: option requires an argument -- 't'
Type number or keyword expected
Valid type keywords are:
bios
system
baseboard
chassis
processor
memory
cache
connector
slot

 

Option 2: DMI TYPES (From MAN Page)

DMI TYPES
The SMBIOS specification defines the following DMI types:

Type Information
────────────────────────────────────────────
0 BIOS
1 System
2 Baseboard
3 Chassis
4 Processor
5 Memory Controller
6 Memory Module
7 Cache
8 Port Connector
9 System Slots
10 On Board Devices
11 OEM Strings
12 System Configuration Options
13 BIOS Language
14 Group Associations
15 System Event Log
16 Physical Memory Array
17 Memory Device
18 32-bit Memory Error
19 Memory Array Mapped Address
20 Memory Device Mapped Address
21 Built-in Pointing Device
22 Portable Battery
23 System Reset
24 Hardware Security
25 System Power Controls
26 Voltage Probe
27 Cooling Device
28 Temperature Probe
29 Electrical Current Probe
30 Out-of-band Remote Access
31 Boot Integrity Services
32 System Boot
33 64-bit Memory Error
34 Management Device
35 Management Device Component
36 Management Device Threshold Data
37 Memory Channel
38 IPMI Device
39 Power Supply
40 Additional Information
41 Onboard Devices Extended Information
42 Management Controller Host Interface

 

Option 3 – Using Keyword types

Keywords can be used instead of type numbers with --type. Each keyword is equivalent to a list of type numbers:

Keyword Types
──────────────────────────────
bios 0, 13
system 1, 12, 15, 23, 32
baseboard 2, 10, 41
chassis 3
processor 4
memory 5, 6, 16, 17
cache 7
connector 8
slot 9

Keywords are matched case-insensitively. The following command lines are equivalent:

· dmidecode --type 0 --type 13
· dmidecode --type 0,13
· dmidecode --type bios
· dmidecode --type BIOS

 

Checking and Modifying Timestamp of whole Directory recursively

Step 1: Show the complete date, time and year for a specific file

$ ls -l --full-time
-rwxrwxr-x  1 root root  1109 2018-07-20 12:52:52.587945000 +0800 Allwmake
drwxrwxr-x  5 root root  4096 2018-07-20 12:52:52.602945000 +0800 applications
drwxrwxr-x  3 root root  8192 2018-07-20 12:53:19.536973000 +0800 bin
-rw-rw-r--  1 root root 35646 2018-07-20 12:52:52.592945000 +0800 COPYING
drwxrwxr-x  5 root root  4096 2018-07-20 12:53:19.936974000 +0800 doc
drwxrwxr-x  8 root root  4096 2018-07-20 12:53:20.039974000 +0800 etc
drwxr-xr-x  4 root root  4096 2018-07-20 12:55:17.230101000 +0800 platforms
-rw-rw-r--  1 root root  1620 2018-07-20 12:52:52.597945000 +0800 README.org
drwxrwxr-x 38 root root  4096 2018-07-20 12:53:22.032976000 +0800 src
drwxrwxr-x 17 root root  4096 2018-07-20 12:54:45.114064000 +0800 tutorials
drwxrwxr-x  7 root root  4096 2018-07-20 12:55:15.939099000 +0800 wmake

Step 2: If you wish to modify the time-stamp for the entire directory, you can use the command,

% for file in `find .`; do touch $file; done

References:

  1. touch – change file timestamps(Unix Tutorial)

Disable SElinux in CentOS 7

1. Check the SELinux Status on CentOS 7

# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 28

2. Disable SElinux Temporarily

# setenforce 0

2a. Check Status

# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: permissive
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 28

3. Disable SElinux Permanently

# vim /etc/sysconfig/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

3a. Check Status

# sestatus
SELinux status: disabled

Setting up NTP in CentOS 7

Prerequisites Step 1: Endure you are in the correct time zone

# timedatectl
      Local time: Wed 2018-09-12 13:48:31 +08
  Universal time: Wed 2018-09-12 05:48:31 UTC
        RTC time: Wed 2018-09-12 05:48:31
       Time zone: Asia/Singapore (+08, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

Prerequisites Step 2: List Time Zone

# timedatectl list-timezones
.....
Asia/Singapore
.....

Prerequisites Step 3: Set Time Zone

# timedatectl set-timezone Asia/Singapore

 

Step 1: Yum Install

NTP can be installed from the CentOS repositories with yum

# yum install ntp

Step 2: Edit the Public Time Servers

Once you have installed ntp package, go to official NTP Public Pool Time Servers . For Singapore, you can use this specific pool zone, add the following to your ntp.conf file:

server 0.sg.pool.ntp.org iburst
server 1.sg.pool.ntp.org iburst
server 2.sg.pool.ntp.org iburst
server 3.sg.pool.ntp.org iburst

Step 3: Allow the clients from the network to sync with this server

Restrict which clients from which network is allowed to query and sync time

restrict 192.168.5.0 netmask 255.255.224.0 nomodify notrap

Step 4: Record all NTP server issues into one dedicated log file. Edit /etc/ntp.conf

logfile /var/log/ntp.log

Step 5: Add Firewall Rule and Start Services

# firewall-cmd --add-service=ntp --permanent
# firewall-cmd --reload
# systemctl start ntpd
# systemctl enable ntpd
# systemctl status ntpd

Step 6: Verify Time Sync

# ntpq -p
# date -R

Or query or synchronize against a selected pool of time servers

# ntpdate -q 0.sg.pool.ntp.org

References:

  1. Setting Up “NTP (Network Time Protocol) Server” in RHEL/CentOS 7 (by Tecmint.com)

Fixing out of memory Issues in Rsync

If you are doing rsync and you encountered this error like rsync out of memory, you may want to take a look.a this article (Rsync out of memory? Try this…). Need to add an additional parameter (–no-inc-recursive) to the rsync commands.

According to the article, the the out of memory failure occured when  rsync attempts to load all the filenames and info in to RAM at startup.

# rsync -lH -rva --no-inc-recursive --progress gromacs remote_server:/usr/local

Making ISO using mkisofs

mkisofs is a wonderful utility to generate ISO images. To generate a compatible ISO images on a disc which are readable everywhere, consider the following commands

# mkisofs -rdlJ -o disc_directory_image.iso directory/

-r : “Rock Ridge” format is enabled to allow long filenames on UNIX systems
-J : allow long filenames on Windows Systems
-l : Allow full 31-character filenames.
-d : Do not append a period to files that do not have one which violate ISO9660