Linux System Administration involves procedures and tasks that are required to keep a computer system up and running and in usable order. Usually, it includes :
- installing new programs
- creating / deleting user accounts
- ensuring file system is not corrupted
- taking backups and restoring the backup when required
- monitor system resources, users, status of critical processes and file system usage
- starting and stopping the system
- configuring run levels, boot process, init, etc.
Let us take a look at the tasks and commands that are generally used by the system administrators.
-
Monitoring the system
In order to check the health of a Linux machine, we can us commands such as :
- w – this command shows which users are logged on
- uptime – shows how long the system has been running
- iostat – shows CPU statistics
1 2 3 4 5 |
# w 10:07:51 up 23 min, 2 users, load average: 0.08, 0.11, 0.12 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT al tty8 :0 09:44 23:45 15.90s 0.12s cinnamon-sessio al pts/1 :0 10:05 3.00s 0.17s 0.65s gnome-terminal |
1 2 |
# uptime 10:07:54 up 23 min, 2 users, load average: 0.07, 0.10, 0.12 |
1 2 3 4 5 6 7 8 |
# iostat Linux 3.19.0-32-generic (al-T420) 17-06-06 _x86_64_ (4 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 3.19 0.02 0.91 0.34 0.00 95.54 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 23.85 743.50 209.36 1067758 300672 |
-
Process Management
The top command displays the status of the processes, their resource usage, etc. Apart from that, commands like “ps -auxw” and “pstree” will give detailed information about the processes running. Also, the “kill” command can be used to stop a specific process using its PID (process id – which is a unique number associated with each process).
top command :
pstree command :
“ps -auxw” command :
“ps -ef” command :
-
Monitoring Memory Usage
There are many commands used for monitoring the memory usage. Following are the frequently used ones.
- vmstat – used for monitoring virtual memory
- free – displays the amount of free and used memory in the system
- pmap – examines the memory map and libraries
- sar – System Activity Report – used to collect, report & save CPU, Memory, I/O usage
Examples :
1 2 3 4 |
# vmstat procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 14078400 71444 1371344 0 0 77 27 91 381 4 1 95 0 0 |
1 2 3 4 5 |
# free total used free shared buffers cached Mem: 16313312 2247436 14065876 263704 71452 1385180 -/+ buffers/cache: 790804 15522508 Swap: 0 0 0 |
1 2 3 4 5 6 7 |
# sar 2 2 Linux 3.19.0-32-generic (al-T420) 17-06-06 _x86_64_ (4 CPU) 10:49:36 AM CPU %user %nice %system %iowait %steal %idle 10:49:38 AM all 1.38 0.00 0.13 0.00 0.00 98.49 10:49:40 AM all 0.63 0.00 0.13 0.00 0.00 99.25 Average: all 1.00 0.00 0.13 0.00 0.00 98.87 |
-
Monitoring the File System
The file system has to be monitored to see whether the diskspace has reached the maximum allocated size, file system corruption, etc. Some of the useful commands to monitor file system are :
- “df -k” – to find out the disk space usage
- “du -sh” – to calculate file space for a given directory
- “mount” – displays all mounted devices
These commands can be used with many other options. A detailed list of options regarding how to use these commands can be obtained from the man pages of these commands.
Examples :
1 2 3 4 5 6 7 8 9 |
# df -k Filesystem 1K-blocks Used Available Use% Mounted on udev 8139956 4 8139952 1% /dev tmpfs 1631332 1392 1629940 1% /run /dev/sda4 403041768 102761624 279783780 27% / none 4 0 4 0% /sys/fs/cgroup none 5120 0 5120 0% /run/lock none 8156656 72300 8084356 1% /run/shm none 102400 20 102380 1% /run/user |
1 2 |
# du -sh 6.2M . |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# mount /dev/sda4 on / type ext4 (rw,errors=remount-ro) proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) none on /sys/fs/cgroup type tmpfs (rw) none on /sys/fs/fuse/connections type fusectl (rw) none on /sys/kernel/debug type debugfs (rw) none on /sys/kernel/security type securityfs (rw) udev on /dev type devtmpfs (rw,mode=0755) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620) tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755) none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880) none on /run/shm type tmpfs (rw,nosuid,nodev) |
-
Displaying System Information
The Linux system information can be displayed using “uname -a” command. Another command is “dmesg”, which shows the kernel ring buffers. These messages contain valuable information about device drivers loaded into the kernel at the time of booting as well as when we connect a hardware to the system on the fly.
Examples :
1 2 |
# uname -a Linux al-T420 3.19.0-32-generic #37~14.04.1-Ubuntu SMP Thu Oct 22 09:41:40 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# dmesg [ 0.000000] Initializing cgroup subsys cpuset [ 0.000000] Initializing cgroup subsys cpu [ 0.000000] Initializing cgroup subsys cpuacct [ 0.000000] Linux version 3.19.0-32-generic (buildd@lgw01-43) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #37~14.04.1-Ubuntu SMP Thu Oct 22 09:41:40 UTC 2015 (Ubuntu 3.19.0-32.37~14.04.1-generic 3.19.8-ckt7) [ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-3.19.0-32-generic root=UUID=da2e47d7-4860-412f-af38-332cbd8add32 ro quiet splash vt.handoff=7 [ 0.000000] KERNEL supported cpus: [ 0.000000] Intel GenuineIntel [ 0.000000] AMD AuthenticAMD [ 0.000000] Centaur CentaurHauls [ 0.000000] Disabled fast string operations [ 0.000000] e820: BIOS-provided physical RAM map: [ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009d7ff] usable [ 0.000000] BIOS-e820: [mem 0x000000000009d800-0x000000000009ffff] reserved |