Skip to content

Latest commit

 

History

History
337 lines (230 loc) · 6.74 KB

linux.md

File metadata and controls

337 lines (230 loc) · 6.74 KB

Linux

Shell

Shell - the command line program with some scripting constructs that calls the binary programs in /bin, /usr/bin and similar directories.

Start with Bash which is the standard open source Linux shell.

Distro Lineage

Distro & Version

The generic way:

cat /etc/*-release

These files have different contents:

Distro File
Alpine /etc/os-release
/etc/alpine-release
Amazon Linux /etc/os-release
/etc/system-release
/etc/amazon-release
CentOS /etc/os-release
/etc/system-release
/etc/redhat-release
/etc/centos-release
Debian /etc/os-release
Gentoo /etc/os-release
/etc/gentoo-release
Redhat /etc/os-release
/etc/system-release
/etc/redhat-release
RockyLinux /etc/os-release
/etc/system-release
/etc/redhat-release
/etc/rocky-release
Ubuntu /etc/os-release
/etc/lsb-release

Cron

In RHEL 6

/etc/cron.allow

/etc/cron.deny

/var/spool/cron root:root 700

User Crons

Stored in /var/spool/cron/$USER.

crontab command is suid to allow user to manage it.

Opens the crontab in $EDITOR (default vi if $EDITOR environment variable is not set):

crontab -e

Timezone

This affects the cron scheduling above and recorded dates of jobs eg. data loading and recording.

For modern Linux systems with systemd:

timedatectl list-timezones

Servers should usually be set to UTC for consistent easy comparison across international systems unless this affects data loading dates from cron above.

timedatectl set-timezone UTC

Networking

See Networking doc.

IPtables

Top for iptables, awesome!

iptstate

List rules with line numbers:

iptables -nL -line-numbers

DHCP

Install ISC DHCPd:

yum install -y dhcp

Edit config:

vim /etc/dhcp/dhcpd.conf

Enable it at boot:

systemctl enable dhcpd.service

Start the service:

systemctl start dhcpd.service

Test DHCP

Install dhcping tool:

yum install -y dhcping

Test DHCP response:

dhcping -s localhost

CGroups

Limit resource usage.

This is used by modern containerization like containerd and Docker.

Can limit:

  • CPU Time
  • CPU core assignments
  • Memory
  • Devices
  • Disk / Block I/O
  • Network bandwidth
yum install -y libcgroup
service cgconfig start
ls /cgroup
lscgroup

Create cgroup - /etc/cgconfig.conf:

group blah {
  cpu {
    cpu.shares = 400;
  }
}
service cgconfig restart

then add processes (tasks) into cgroups according to parameters in the file:

/etc/cgrules.conf:

<user> <subsystems> <control_group>
@<group> <subsystems> <control_group>
<user>:<command> <subsystems> <control_group>
eg.
*:firefox cpu,memory browsers/
service cgred start

Sysconfig services can instead add this to their /etc/sysconfig/<servicename> file

CGROUP_DAEMON="<subsystem>:<control_group>"

Disk Management

List disk space of mounted partitions:

df -h

List partitions:

cat /proc/partitions

Format a spare partition:

mkfs.ext4 /dev/sda2

Check and recover filesystem, replay journal, prompts for fixes:

fsck /dev/sda2

Mount a filesystem to the directory /data:

mount /dev/sda2 /data

/etc/fstab

Ensure the partition is:

  1. mounted by UUID as device numbers can change
  2. has nofail option set to make sure that a machine will attempt to come up to be able to SSH manage it otherwise you may end up in an AWS EC2 Disk Mount Recovery situation.

First inspect your /etc/fstab:

cat /etc/fstab

Back up /etc/fstab before editing it:

sudo cp -av /etc/fstab /etc/fstab.bak."$(date +%F_%H%S)"

Add the nofail option on any lines on which it does not exist:

sudo sed -i '/nofail/ ! s/defaults/defaults,nofail/' /etc/fstab

Inspect the changes:

cat /etc/fstab

Each line in the /etc/fstab should then look like:

UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx    /tmp    xfs    defaults,nofail    0    2

Validate your /etc/fstab by mounting using the short form of the mount command that reads and uses the /etc/fstab:

mount /tmp

DRBD

  • awesome disk replication, used this in the mid to late 2000s
  • mainline Linux kernel now
  • dual-primary (0.9+)mount
    • requires clustered filesystem (GFS, OCFS2)
  • mount -o ro to avoid complexity of dual primary cluster filesystems
  • sync + async repl options
  • get check_drbd nagios plugin to see how far behind replica is, automatically catches up, low maintenance once set up

Distributions

Debian - the standard open source distribution, and it's derivative Ubuntu.

Redhat - used to the standard enterprise distro but has killed its open source credentials and become legacy.

Gentoo - l33t but takes time to compile.

Binaries Debugging

See the Binaries Debugging doc for commands to examine and work with binaries.

Linux Boot Process

Linux Boot Process

Linux Filesystem Layout

Linux Filesystem Layout

Ported from various private Knowledge Base pages 2002+