1 of 37

​

WEEK 11

System Monitoring

​

2 of 37

�����System Monitoring��������

System monitoring involves 

  • the continuous monitoring of an infrastructure
  • It includes the monitoring of CPU, server, memory, routers, switches, bandwidth, and applications
  • the performance and availability of important network devices.

3 of 37

�����������

Linux system monitoring programs ensure that

​

  • The hardware is working
  • The server is up and running
  • No resources bottlenecks are slowing things down
  • Data is presented in a visual manner

​

Linux system monitors look at

  • Memory Usage
  • CPU Usage
  • Storage Usage
  • Network Usage

4 of 37

���Linux System Monitoring Tools/Commands����

Commands

Description

top

Process activity monitoring command

vmstat

Virtual memory statistics

w

displays information about the users currently on the machine, and their processes.

uptime

Tell how long the Linux system has been running

5 of 37

  • Log files are files that contain messages about the system, including the kernel, services, and applications running on it.
  • There are different log files for different information.
  • For example, there is a default system log file, a log file just for security messages, and a log file for cron tasks etc.
  • Log files can be very useful when trying to troubleshoot a problem with the system such as trying to load a kernel driver or when looking for unauthorized login attempts to the system.
  • It is essential that user know where the log files are located, and what is contained in them. Such files are usually in /var/log.

​

Log Maintenance

​

6 of 37

Few Log Files

File name

Information

/var/log/messages

Contains global system messages, including the messages that are logged during system startup.

/var/log/auth.log

Contains system authorization information, including user logins and authentication mechanism that were used.

/var/log/boot.log

Contains information that are logged when the system boots

/var/log/lastlog

Displays the recent login information for all the users

/var/log/user.log

Contains information about all user level logs

/var/log/btmp

This file contains information about failed login attemps

7 of 37

  • When using Linux, we may need to know details about the system we are running or the hardware specifications we are using.
  • The Linux command line contains several built-in commands to know system information we are working on.

System Information

option

action

-v

displays version of kernel

-m

to know the hadware architecture

-o

name of the OS

The uname Command

$uname -option

8 of 37

Get hardware Information with lshw: The lshw utility enables user to fetch important hardware information such as memory, CPU, disks, etc. from system. Run the following command as a super user in order to view this information:�

Get CPU Information with lscpu: The lscpu utility lists detailed CPU information from the files sysfs and /proc/cpuinfo to your screen�

9 of 37

System Architecture

  • The Linux operating system's architecture mainly contains following components: 
  • The Kernel
  • System Library
  • Hardware layer
  • System
  • Shell utility

10 of 37

Kernel: The kernel is one of the core section of an operating system. It is responsible for each of the major actions of the Linux OS. The kernel hides details of low-level hardware or application programs to the system.

System Libraries: These libraries can be specified as some special functions. These are applied for implementing the operating system's functionality

System Utility Programs: It is responsible for doing specialized level and individual activities.

Hardware layer: Linux operating system contains a hardware layer that consists of several peripheral devices like monitor,Keyboard,HDD,RAM

Shell: It is an interface among the kernel and user. Ex. Korn shell,c shell,bash shell

11 of 37

System Maintenance

System Maintenance means

  • performing hardware and software installation
  • diagnostic and correction and similar activities that are performed in the usual custom and practice by a manufacturer or vendor or system user to establish or maintain the basic operational functionality of a computer system.
  • Today systems maintenance is an activity that is becoming more and more important

12 of 37

Levels of System Maintenance

​

Hardware maintenance : 

maintaining physical components that make up the system.

Software maintenance :

Configuration and update of the operating system.

Database maintenance

Protection, detection and cleaning of malware (viruses, Trojans, spyware, etc.) that can be found on computers.

Documentation maintenance:

will ensure that the documentation is up to date and available for use.

13 of 37

System Maintenance commands

​

Shutdown

  • “Shutdown” refers to the process of stopping and shutting down a computer or server.
  • Linux operating systems can easily be stopped, shut down, and restarted using the shutdown command and its various options.
  • Standard command for shutting down Linux

shutdown –h

  • Linux will shut down in under a minute. The “-h” option explicitly stands for the shutting down or powering off of a system.

14 of 37

System Maintenance commands

Rebooting

  • Booting is starting a computer's operating system, so rebooting is to start it for a second or third time.
  • Rebooting is usually necessary after a computer crashes, meaning it stops working because of a malfunction.
  • sudo reboot
  • sudo systemctl reboot
  • sudo shutdown -r

halt

  • This command in Linux is used to instruct the hardware to stop all the CPU functions.
  • Basically, it reboots or stops the system.
  • halt [OPTION]

15 of 37

LINUX BOOT PROCESS AND RUN LEVELS

16 of 37

�����What is Booting ?�������

Booting is the process which is initiated once the computer system starts and executes small set of instructions present in the ROM which will setup system hardware by testing them and load the operating system so that computer system can carry out further tasks.

17 of 37

�����Types of Booting��������

There are two types of Booting available:

  • Cold Booting/ Hard Booting: Cold booting is the process when our computer system moves from shut down state to the start by pressing the power button. The system reads the BIOS from ROM and will eventually load the Operating System.
  • Warm Booting/ Soft Booting: Warm booting is the process in which the computer gets restart due to reasons like setting the configuration for newly installed software or hardware. Warm booting is called as rebooting(restarting).

18 of 37

����Boot Sequence in OS (Steps in Booting)����

  • When computer is powered on, all the hardware components receive the power and they get initialized. After that, the computer system goes through 6 step booting process as shown above.

19 of 37

Linux Boot Process (step by step)

20 of 37

BIOS

  • BIOS stands for Basic Input/Output System
  • Performs some system integrity checks
  • Searches, loads, and executes the boot loader program.
  • It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2, but it depends on your system) during the BIOS startup to change the boot sequence.
  • Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.

21 of 37

MBR

  • MBR stands for Master Boot Record.
  • It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
  • MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.
  • It contains information about GRUB
  • So, in simple terms MBR loads and executes the GRUB boot loader.

22 of 37

  • GRUB stands for Grand Unified Boot loader.
  • If you have multiple kernel images installed on your system, you can choose which one to be executed.
  • GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
  • GRUB has the knowledge of the filesystem
  • Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this).

GRUB

23 of 37

  • Mounts the root file system as specified in the “root=” in grub.conf
  • Kernel executes the /sbin/init program
  • Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grep init’ and check the pid.
  • initrd stands for Initial RAM Disk.
  • initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted.
  • It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware

KERNEL

24 of 37

  • Looks at the /etc/inittab file to decide the Linux run level.
  • Following are the available run levels

0 – halt

1 – Single user mode

2 – Multiuser, without NFS

3 – Full multiuser mode

4 – unused

5 – X11

6 – reboot

  • Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.

INIT

25 of 37

  • Depending on your default init level setting, the system will execute the programs from one of the following directories.

Run level 0 – /etc/rc.d/rc0.d/

Run level 1 – /etc/rc.d/rc1.d/

Run level 2 – /etc/rc.d/rc2.d/

Run level 3 – /etc/rc.d/rc3.d/

Run level 4 – /etc/rc.d/rc4.d/

Run level 5 – /etc/rc.d/rc5.d/

Run level 6 – /etc/rc.d/rc6.d/

  • Programs starts with S are used during startup. S for startup.
  • Programs starts with K are used during shutdown. K for kill.
  • There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.

Run level Programs

26 of 37

LINUX Run Levels

27 of 37

  • A run level is an operating state on the Linux-based system. Run levels are numbered from zero to six.
  • Run levels determine which programs can execute after the OS boots up. The run level defines the state of the machine after boot.
  • Some system administrators use run levels to define which subsystems are working, e.g., whether X is running, whether the network is operational, and so on.
  • By default, a system boots either to run level 3 or to runlevel 5.
  • Runlevel 3 is CLI, and 5 is GUI.
  • The default run level is specified in /etc/inittab file in most Linux operating systems.

28 of 37

Changing run level

  • init is the program responsible for altering the run level which can be called using telinit command.
  • For example, to change a runlevel from 3 to runlevel 5 which will actually allow the GUI to be started in multi-user mode the telinit command can be used as :

// using sudo to execute telinit

# sudo telinit 5

​

  • The default runlevel for a system is specified in /etc/initab file which will have an entry id : 5 : initdefault
  • if the default runlevel is set to 5 or will have an entry id : 3 : initdefault 
  • if the default runlevel is set to 3.

29 of 37

Need for changing the run level

​

    • There can be a situation when you may find trouble in logging in in case you don’t remember the password or because of the corrupted /etc/passwd file (have all the user names and passwords), in this case the problem can be solved by booting into a single user mode i.e runlevel 1.
    • You can easily halt the system by changing the runlevel to 0 by using telinit 0

echo $RUNLEVEL

30 of 37

System Updates

  • An update is new, improved, or fixed software, which replaces older versions of the same software.
  • A software update generally refers to the update of optional software components that a system might have.
  • A system update refers to an update of the operating system itself - particularly the parts of the system about which you have no discretion about whether you take the update or not.

SYSTEM UPDATES AND REPOSITORIES

31 of 37

System Repositories(repo)

  • Repository is a storage location from which system retrieves and installs OS updates and applications.
  • Each repository is a collection of software hosted on a remote server and intended to be used for installing and updating software packages on systems
  • Repositories contain thousands of programs.
  • Standard repositories provide a high degree of security, since the software included is thoroughly tested and built to be compatible with a particular distribution and version.

32 of 37

Benefits of repository

  • Provides reliable locations to get software with confidence, knowing that it's free from malware and properly tested
  • Simple installations without concerns for dependencies (all the required packages are provided)
  • Easy ways to find and download what you need
  • Knowing which repositories you are using can shed light on how your system manages updates.

33 of 37

Types of repositories in Ubuntu

  • Main: the repository installed by default. It consists of free FOSS software that can be distributed freely and without restrictions.
  • Universe : Includes free and open source software, but cannot guarantee regular security updates.
  • Multiverse : Includes software that is from FOSS. It must be the user who analyzes the licenses and decides whether or not they can use these programs legally.
  • Restricted : within this channel you can find closed source software. It is used, for example, to distribute NVIDIA drivers, among many others.
  • Partner : Includes proprietary software that has been packaged by Canonical.

In addition to these repositories, you can also add third-party repositories

To see the list of repositories that you have in your Ubuntu distro, open up a Terminal session (Control + Alt + T) and execute the following command:

sudo nano /etc/apt/sources.list

​

34 of 37

Linux package management with YUM and RPM

  • Package management is a method of installing, updating, removing, and keeping track of software updates from specific repositories (repos) in the Linux system.
  • Linux distributions often use different package management tools.
  • Yum and RPM are both package managers for Linux systems.

35 of 37

YUM

  • yum stands for Yellowdog Updater Modified. They are packaging managers for RPM-based Linux systems.
  • They are a high-level front end management package managers for Linux distributions that are RPM-based(Red Hat Package Manager)
  • It can sense and resolve dependencies.
  • Yum can only install the packages available in its repository.
  • Yum can also scan and upgrade the packages to the latest versions. It also entirely relies on online repositories.
  • It can sense and resolve dependencies.
  • Yum can only install the packages available in its repository.
  • Yum can also scan and upgrade the packages to the latest versions. It also entirely relies on online repositories.

36 of 37

RPM

  • RPM stands for Redhat Packaging Manager.
  • It can be considered one of the oldest packaging managers that do basic functions like uninstalling, updating, archiving the packages received by the Linux systems.
  • It cannot sense and resolve dependencies on its own.
  • It can install multiple packages with the condition that we give the correct file name with the .rpm extension.
  • RPM does not depend on online repositories for any of its services and it cannot scan or upgrade itself or its packages to the latest versions.
  • RPM maintains a database of installed packages, which enables powerful and fast queries.

37 of 37

  • The RPM database is inside /var/lib, and the file is named __db*
  • RPM has some basic modes: query, verify, install, upgrade, erase, show query tags, show configuration.
  • At least one of these modes needs to be selected to perform package management tasks.

For example, install mode 

-i  installs package

-U upgrades package