Linux Architecture




Kernel: It is a program. Kernel is a Core component of operating system, interacts directly with hardware and provides low level services to upper layer components.
Shell: An interface to kernel, hiding complexity of kernel’s functions from users. Takes commands from user and executes kernel’s functions.
User Interface: In information technology, the user interface (UI) is everything designed into an information device with which a human being may interact. Two types CLI (Command line interface) and GUI (Graphical User Interface).
System Library - System libraries are special functions or programs using which application programs or system utilities accesses Kernel's features. These libraries implements most of the functionality of the operating system and do not requires kernel module's code access rights.
System Utility - System Utility programs are responsible to do specialized, individual level tasks.

Kernel Mode vs User Mode


        Kernel component code executes in a special privileged mode called kernel mode with full access to all resources of the computer. This code represents a single process, executes in single address space and do not require any context switch and hence is very efficient and fast. Kernel runs each processes and provides system services to processes, provides protected access to hardwares to processes.

        Support code which is not required to run in kernel mode is in System Library. User programs and other system programs works in User Mode which has no access to system hardwares and kernel code. User programs/ utilities use System libraries to access Kernel functions to get system's low level tasks.
Basic Features

Following are some of the important features of Linux Operating System.

    Portable - Portability means softwares can works on different types of hardwares in same way.Linux kernel and application programs supports their installation on any kind of hardware platform.

    Open Source - Linux source code is freely available and it is community based development project. Multiple teams works in collaboration to enhance the capability of Linux operating system and it is continuously evolving.

    Multi-User - Linux is a multiuser system means multiple users can access system resources like memory/ ram/ application programs at same time.

    Multiprogramming - Linux is a multiprogramming system means multiple applications can run at same time.

    Hierarchical File System - Linux provides a standard file structure in which system files/ user files are arranged.

    Shell - Linux provides a special interpreter program which can be used to execute commands of the operating system. It can be used to do various types of operations, call application programs etc.

    Security - Linux provides user security using authentication features like password protection/ controlled access to specific files/ encryption of data.


 

Linux System Architecture is consists of following layers

    Hardware layer - Hardware consists of all peripheral devices (RAM/ HDD/ CPU etc).

    Kernel - Core component of Operating System, interacts directly with hardware, provides low level services to upper layer components.

    Shell - An interface to kernel, hiding complexity of kernel's functions from users. Takes commands from user and executes kernel's functions.

    Utilities - Utility programs giving user most of the functionalities of an operating systems.

Windows Vs Linux


Windows Vs Linux

                                Windows
                                      Linux
    • It is a proprietary software everything need to buy
    • It is an open source software everything is free
    • Less Secure
    • More Secure
    • More costly
    • Less Cost compare to windows
    • Chance to get a carpal tunnel syndrome
    • There is no chance to get carpal tunnel syndrome
    • Developed by Microsoft corporation
    • Developed by Linus Torvalds
    • Options need to select
    • You can develop anything as per your requirement
    • Kernel is not editable
    • Kernel is editable

NagiosXI Login Notification

If you want to monitor who is logged in to the NagiosXI web console then schedule this below script in your crontab it will check for User Activities and it will send you a Mail alert.

#!/bin/bash
# Purpose: To get alerts when user is logged in to Nagiosxi console
# Author: Ankam Ravi Kumar
# Date: 13-Feb-2015
# NagiosXI Console Login check Script START
DT=`date +%Y-%m-%d`
psql -U nagiosxi -d nagiosxi -t -A -F"," -c "select * from xi_auditlog;" > /tmp/auditlog.txt
cat /tmp/auditlog.txt |grep $DT > /tmp/today.txt
EPOCTIME=`cat /tmp/today.txt |awk -F, '{print $2}' |tail -1`
ENDTIME=$(date +%s)
STARTIME=$(date +%s -d"$EPOCTIME")
echo $((ENDTIME-STARTIME)) | awk '{print int($1/60)}' > /tmp/value1
count=`cat /tmp/value1`
if [ $count -lt 8 ]
then
        cat /tmp/auditlog.txt |grep $DT |tail -1 > /tmp/mail
        mail -s "NagiosXI Login ALERT: User `cat /tmp/mail | awk -F, '{print $4}'` `cat /tmp/mail | awk -F, '{print $6}'` to `hostname`" aravikumar48@gmail.com < /tmp/mail
fi
rm -rf /tmp/auditlog.txt /tmp/today.txt /tmp/value1 /tmp/mail
#END


FS Monitoring

::::::::::::: Script to Monitor File system :::::::::::::::

No need to configure any mail server just send a mail/messages using sendEmail..

Download sendEmail Program from below link

http://caspian.dotconf.net/menu/Software/SendEmail/

------------------
Installation
------------------

SendEmail is a perl script/program, and only needs to be copied to a directory
in your path to make it accessible.  Most likely the following steps will
be sufficient:

1) Extract the package
    tar -zxvf sendEmail-v1.XX.tar.gz

2) Copy the sendEmail script to /usr/local/bin
    cp -a sendEmail-v1.XX/sendEmail /usr/local/bin

3) Make sure its executable
    chmod +x /usr/local/bin/sendEmail

4) Run it
    sendEmail
      or
    /usr/local/bin/sendEmail

NOTES:
  * Running sendEmail without any arguments will produce a usage summary.
  * SendEmail is written in Perl, so no compilation is needed.
  * On a Unix/Linux OS if your perl binary is not installed at /usr/bin/perl
    you may need to edit the first line of the script accordingly.

#------------------------------------------------------------------
# Script Starts................
#------------------------------------------------------------------
#!/bin/bash
# Purpose: Disk Space Monitoring
# Author: Ravi Kumar
# Script Start
# Variables #
MAILLIST="aravikumar48@gmail.com"
CRITICAL=95
HOSTNAME=`hostname`
MAIL=sendEmail
PERCENTAGE=`df -hP | egrep '^/dev/' | awk '{ print $6 "_:_" $5 }' | awk -F"_:_" '{ print $2 }' | cut -d'%' -f1 | head -n 1`
PERCENTAGE1=`df -hP | egrep '^/dev/' | awk '{ print $6 "_:_" $5 }' | awk -F"_:_" '{ print $2 }' | cut -d'%' -f1 | tail -1`
BODY=`df -hP | egrep '^/dev/'`

if [ $PERCENTAGE -ge $CRITICAL ];
then
        sendEmail -f alert@gmail.com -t $MAILLIST -u "$HOSTNAME - File System is CRITICAL $PERCENTAGE%" -m $BODY -s MAIL-EXCHANGE.com
elif [ $PERCENTAGE1 -ge $CRITICAL ];
then
        sendEmail -f alert@gmail.com -t $MAILLIST -u "$HOSTNAME - File System is CRITICAL $PERCENTAGE1%" -m $BODY -s MAIL-EXCHANGE.com
else
        echo ""
fi
#END

Redhat Linux Installation




After booting from RHEL bootable CD/DVD, We will get above screen
           Ø  If you want to install OS using GUI then hit ENTER key
           Ø  If you want to install OS using TEXT mode (CLI) then type linux test hit ENTER key
Currently we are installing Operating system using GUI mode.



If you want to verify you installation media (OS CD/DVD) press OK (It will take long time to verify). Press SKIP to jump next screen.



Click NEXT



Select the Language then click NEXT



Select Keyboard Language then click NEXT



Click OK



It will give you a WARNNING since you don’t have a key click on SKIP

 Click on YES to continue


Options:
Remove all partitions on selected drives and create default layout this options will delete all the drive partitions and install OS
Remove all Linux Partitions this option will only remove Linux partitions and creates default layout, install OS
Use free space this option will install on free space of the drive creates default layout
Create Custom layout this option will not create any layout you have to create as per your requirement
This option will give more customization you to create your own layout (Selected Customize Layout)


Now you can able to see HDD space to create partitions follow click on NEW


After clicking on NEW you will see above popup
First create /boot because it needs normal partition to store MBR (master boot record). 100MB is enough for /boot partition.
Mount point /boot
File system Type: ext3 OR ext4

Select fixed size Click OK




See above screen /boot partition is created.
Note:  Always remember to create LVM partitions OR RAID partitions is recommended, because later on if you want extend the ROOT file system is possible and easy.
To create LVM partition click on NEW you can able to see popup as below



For creating a LVM partition we have to create Physical Volume select file system type as physical volume (LVM)
Select Fill to maximum allowable size then click on OK

See above screen LVM PV is created now select PV and click on LVM popup will open as below screen


Change the Volume group name as required. Example: VG01

Click on ADD




As above screen select Mount point as “/” slash, provide Logical volume name “ROOT” for easy identification, provide the size as per your requirement (Minimum 10GB). Click on OK
Again click on ADD


Select File system type as SWAP, provide logical volume name as “SWAP” for easy identification. Provide the swap size is always (RAM SIZE * 2) in my case 2GB RAM. Click on OK



As you created above all the partitions are created. Click NEXT
Minimum Recommended Partitions
Slash “/”
/boot
SWAP



Select label and click NEXT (if you want to change label you can change it using edit option)



Here provide your system name (Example: ARK-IT-Solutions.localdomain)
Click on EDIT


If you are using DHCP in your network select Use dynamic IP configuration
If not using DHCP enable IP4 and provide IP address and Netmask Click on OK


Provide the gateway IP and DNS IP and Click on NEXT



Select the time zone and click on NEXT



Provide your password and confirmation password then click on NEXT



Select to install the required software’s while installing the operating system, select software development and web server and select Customize now.
Then click on NEXT


Select the required packages from all the fields click on optional packages and check all (as showed in below screen)


Selected all the optional packages as well click on CLOSE

then click on NEXT

After next dependencies will be resolved and ready for installation
 Click NEXT to install Operating system
 Installation is in process (it will take few minutes depends on selected packages)


After completion creating partitions and installing packages it will ask you to reboot the server. Click on Reboot


After reboot it will ask you to complete next options click on FORWARD


Select Yes I agree to the license agreement and click FORWARD


Firewall enabled and disabled
If you enable the firewall you have to allow the services and ports as you required
If you want to enable security click on Enable or else disable and click FORWARD



Disable the SELinux if you don’t know the usage. Click on FORWARD

 Click YES
 click Forward
 Select Date & Time Click forward
 Select Yes Click Forward
 Click on No Thanks
 Click FORWARD


Provide additional username to create and provide password click on FORWARD


Test your sound then click on FORWARD



Click on Finish


It will ask you to reboot click OK
Your server installation is successfully completed now you can use it.

Welcome Banner Linux in Server

::::: Welcome Banner in Linux Server :::::

To write user Login banner message you have to edit /etc/motd and /etc/issue file to enter the message.

[ravi@ARK-IT-Solutions ~]$ vi /etc/issue
Red Hat Enterprise Linux Server release 5 (Tikanga)
Kernel \r on an \m \n

WARNNING!! If your not authorized person to login logoff immediatly.

:wq (Save & Exit)

Then Edit

[root@ARK-IT-Solutions ~]# vi /etc/motd
Welcome to ARK IT Solutions

Server Name: Thungabhadra
IP Address :   192.168.234.123

WARNNING..!! If your not authorized person logoff immediatly.

:wq (Save & Exit)

Now Login to your server




your Done.

Login Notification When User Logged into the Linux Machine

::::Login Notification When User Logged into the Linux Machine:::::

  1. Login into the Linux machine using root.
  2. In home path of root edit .bashrc file  vi .bashrc
  3. Add below Lines
  • echo "ALERT - Root Shell Accessed on:" `date` `who` | mail -s "Alert: Root shell Accessed on `hostname`" <YOUR EMAIL ID>
 :wq
Save above file.


If you want to add for all the users when you install a Linux server freshly go to /etc/skel

# cd /etc/skel
# vi .bashrc
echo "ALERT - User `who` Logan on:" `date` `who` | mail -s "Alert: User `who am i` logged on to `hostname`" aravikumar48@gmail.com

:wq
Save and exit



when you create a new user this files will copy to his home directory and when he logged into the machine it will send you a alert.