Linux Server Review

Linux Server Review

Usage

# load:
uptime

# what it does
netstat -tlpn # package net-tools
ps auxf

# memory:
# vmstat
# r: runnable (running or waiting to run in queue)
# b: uninterruptible sleep (D in ps)
vmstat # summary
vmstat 1 5 -w # every 1 sec, print 5 . wide .(first line is summary since reboot)
vmstat -s # summary memory stats

free -m
grep -i oom /var/log/messages ( /var/log/syslog )

# CPU:
top

# package sysstat:
mpstat -P ALL # cpu balance

lscpu
pidstat

# disk:
vmstat -d
df -h
df -i
iostat -xz 1

# biggest files in / :
du -mxS / |sort -n|tail -10

# network:
# package sysstat
sar -n DEV 1 # network throughput
sar -n TCP,ETCP 1 # TCP stats (also: ss -s)

Linux Distribution and Kernel

# distro:
cat /etc/debian_version
lsb_release -a # apt-get install lsb-release

# kernel
uname -a
sysctl -a

Logging

journalctl
journalctl -n 20 --no-pager -u nginx # last lines for a specific unit
journalctl --since yesterday --until "1 hour ago" # takes 2022-12-24, 08:00 ...
journalctl -k # kernel messages, dmesg
journalctl -p err # 0, 1, 2, 3 ...
dmesg | tail
tail /var/log/messages  ( /var/log/syslog /var/log/kern.log )
last -a

systemd

systemctl # same as systemctl list-units
systemctl cat <service> # shows location and contents of config file for <service>
systemctl list-unit-files # lists if they are masked (won't start, use unmask option)
systemctl reload unit # reload options after changes, install

systemctl --failed 
systemd-analyze # startup time, append 'blame' for breakdown

Filesystems and Volumes

fdisk -l
df -lT # -l local, -T type
lsblk -f # filesystem
file -s /dev/hda1
blkid /dev/hda1

mount
cat /etc/fstab

Networking

ss -s
netstat -s
netstat -i
ip -s link
ifconfig
lsof -i
sar -n DEV

ip route
netstat -r

iptables -L
iptables -t nat -L # does not show with -L