Saturday 7 May 2016

Linux Directory Structure

Overview
Everything in Linux can be reduced to a file. Partitions are associated with files such as /dev/hda1. Hardware components are associated with files such as /dev/modem. The Filesystem Hierarchy Standard (FHS) is the official way to organize files in Unix and Linux directories.
Linux file system and directory structure
Several major directories are associated with all modern Unix/Linux operating systems. These directories organize user files, drivers, kernels, logs, programs, utilities, and more into different categories. The standardization of the FHS makes it easier for users of other Unix-based operating systems to understand the basics of Linux. All of the other directories shown in Table are subdirectories of the root directory, unless they are mounted separately.
Directory
Description
/
The root directory, the top-level directory in the FHS. All other directories are subdirectories of root, which is always mounted on some partition. All directories that are not mounted on a separate partition are included in the root directory’s partition.
/bin
Essential command line utilities. Should not be mounted separately; otherwise, it could be difficult to get to these utilities when using a rescue disk.
/boot
Includes Linux startup files, including the Linux kernel. Can be small; 16MB is usually adequate for a typical modular kernel. If you use multiple kernels, such as for testing a kernel upgrade, increase the size of this partition accordingly.
/etc
Most basic configuration files.
/dev
Hardware and software device drivers for everything from floppy drives to terminals. Do not mount this directory on a separate partition.
/home
Home directories for almost every user.
/lib
Program libraries for the kernel and various command line utilities. Do not mount this directory on a separate partition.
/mnt
The mount point for removable media, including floppy drives, CD-ROMs, and Zip disks.
/opt
Applications such as WordPerfect or Star Office.
/proc
Currently running kernel-related processes, including device assignments such as IRQ ports, I/O addresses, and DMA channels.
/root
The home directory of the root user.
/sbin
System administration commands. Don't mount this directory separately.
/tmp
Temporary files. By default, Red Hat Linux deletes all files in this directory periodically.
/usr
Small programs accessible to all users. Includes many system administration commands and utilities.
/var
Variable data, including log files and printer spools.

Bash Shell features

BASH Features


BASH: Bourne again shell

 when you login to the Server using any CLI based tool OR login to the CLI mode you can see as like below screen. 

$ sign = local user/non-privilege user
# sign = Administrator/Privileged user
 

 [root@sankar ~]#


Shells can be changed based the user compatibility and requirements, most of default shell is 'BASH' 


[root@sankar ~]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/tcsh
/bin/csh
/bin/dash
You have new mail in /var/spool/mail/root
[root@sankar ~]#



Command Line Completion:
Single Tab – it will provide the best option
Double Tab – it will provide all the possible options (Autocompletes)
Command Line Editing:
Ctrl+a            -           It moves cursor to the Home line position
Ctrl+b            -           Moves the cursor back one character
Ctrl+c            -           Sends the signal SIGINT to the current task, which aborts and close it.
Ctrl+d            -           Close current shell prompt
Ctrl+e            -           It will move a cursor to end of the bash
Ctrl+f             -           Moves cursor forward one character
Ctrl+g            -           Abort the research and restore the original file
Ctrl+h            -           Deletes the previous character (Same as backspace)
Ctrl+k            -           It is used to delete the command from the courser to line home position
Ctrl+l             -           Clear the screen
Ctrl+u            -           Clears the line content before the cursor and copies it into the clipboard
Ctrl+y            -           Yank the content from the cursor position
Ctrl+z            -           Sends the signal SIGTSTP to the current task, which suspend it
Ctrl+Shift+c -           Copy selected text
Ctrl+Shift+v            -           Paste the copied content
Ctrl+Shift+t             -           Tab
Ctrl+Shift+n            -           New Terminal
Ctrl+Shift+w            -           Close Tab
Ctrl+Shfift+q           -           Close a Terminal
Alt+b              -           Moves the cursor backward one word
Alt+c              -           Capitalizes the character under the cursor and moves to the end of word
Alt+d              -           Cut the word after the cursor
Alt+f               -           Moves the cursor forward one word
Alt+l               -           Lowers the case of every character from the cursor’s position to the end
Alt+.               -           Insert the last argument to the previous command
Command Line History: Command line history will be saved, when you execute any command in terminal.
 
$ history        -           this command will display all the previous executed commands
$ history –c   -           Clear the command history
$ !<number> -          it executes mentioned number command
Note: Default history size is 1000 commands

[root@sankar ~]# history





$ !<charectar>         -           it will display/execute matching character command
$ !!                              -           it will execute last executed command
Sophisticated prompt control:
?          -           It will replace a single character
Example:       rm –rf a?        -           it will delete the files with two characters
                        Rm –rf a??     -           it will delete the three characters files after “a”
*          -           replace multiple number of characters

Example:       rm –f  a*        - it will remove all the files which are starting with “a”

Piping and Redirecting:
Redirecting input and output from standard stream to user defined place
1.    Input RD       -0                                 <         
2.    Output RD -1              Values        >          Symbols
3.    Error RD       -2                                 >

Example:       $ sort < <file name>
                        $ wc < <file name>
                        $ history > f2
                        $mkdir d1 2> e1




Piping sending output or one command as a input to the another command

| pipe
pipe Symbol





Page related command:
            Less: is used to see the command output page by page in up and down way
            More: we can’t go upward downward, just see the output fit to the screen
 

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

Linux Architecture

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.

Linux Introduction

Linux Introduction


     UNIX is the first Operating system in the world, developed by Kem Thompson and Dennis Ritchie in 1969 at Bell Lab by AT&T Company
            IBM    :           AIX
            SGI     :           IRIX
            Sun     :           Solaris
            Free software foundation organization, they start a project by name GNU. The main aim of this project is to develop such an operating system that can run on any platform.
    In 1991, a student Linuz Torvalds developed a kernel named Linux’s kernel plus GNU application called Linux operating system.
Linux is an open source technology.
Different companies that provide Linux in Market are Redhat, SuSe, Scientific, Centos, and Knoppix etc.

Features:


Ø  Linux is the fastest Operating system in the world. It runs 2 to 3 times fast than windows OS.
Ø  Linux is the much secured OS because there is no any problem of virus.
Ø  Linux file format is text format and windows file format is binary format.
Ø  Linux is very reliable OS because kernel of Linux is very stable as compare to windows kernel not crashed easily.
Ø  Kernel of Linux is very small in size it can be stored in floppy.
Ø  Linux uses the x-Window system which is advanced network windowing system. Using this system we can display output of any workstation monitor attached in the network.

Advantages:


Ø  Virus Proof
Ø  Crash Proof
Ø  Economical
Ø  Multiuser, Multi-Tasking and Multi processing capacity

Login Modes:

Two modes:  

1.Text mode (CLI)   - All the commands can be executed   

2.Graphical Mode (GUI)
Login to Text mode we have use (Ctrl+Alt+F1…..F6, F8….F12) (Ctrl+Alt+F7) for Graphical Mode


Open Source

       The idea behind Open Source software is rather simple: when programmers can read, distribute and change code, the code will mature. People can adapt it, fix it, debug it, and they can do it at a speed that dwarfs the performance of software developers at conventional companies. This software will be more flexible and of a better quality than software that has been developed using the conventional channels, because more people have tested it in more different conditions than the closed software developer ever can.

        The Open Source initiative started to make this clear to the commercial world, and very slowly, commercial vendors are starting to see the point. While lots of academics and technical people have already been convinced for 20 years now that this is the way to go, commercial vendors needed applications like the Internet to make them realize they can profit from Open Source. Now Linux has grown past the stage where it was almost exclusively an academic system, useful only to a handful of people with a technical background. Now Linux provides more than the operating system: there is an entire infrastructure supporting the chain of effort of creating an operating system, of making and testing programs for it, of bringing everything to the users, of supplying maintenance, updates and support and customizations, etcetera. Today, Linux is ready to accept the challenge of a fast-changing world.

Monday 25 April 2016

Script to gather server information



Create a file called systeminfo.sh
# touch systeminfo.sh
 


#!/bin/bash
## Purpose: Collecting system Information Gather server information within a second
## Author Name: Sankar
## Date: 26th Apr 2016
MAILIST=sankarrhcss@gmail.com
DOMAIN=domain
TEMP=/tmp/temp
FILE=/tmp/asset/info.txt
USERID=`id -g`
if [ $USERID == 0 ]; then
echo "Script is Running ..."
else
echo "Please run the script using root user"
exit
fi
mkdir /tmp/asset
touch /tmp/temp
touch /tmp/asset/info.txt
echo -e "\n" > $FILE
echo "Collecting System Information" >> $FILE
echo -e "\n" >> $FILE
echo "collecting information...."
echo "Date: `date`" >> $FILE
echo "HostName: `hostname`" >> $FILE
echo "Installed OS Version: `cat /etc/issue |head -1`" >> $FILE
echo "`/sbin/ifconfig -a |grep "inet addr" | awk 'BEGIN { FS = ":" } ; { print $2 }'`" > $TEMP
echo "IP Address : `egrep '^10' $TEMP |awk '{ print $1}'`" >> $FILE
## Identifying Hardware Platform ##
HF=`uname -i`
if [ $HF == i386 ]; then
echo "Hardware Platform: 32Bit" >> $FILE
else if [ $HF == x86_64 ]; then
echo "Hardware Platform: 64Bit" >> $FILE
else
echo "Hardware Not Matched" >> $FILE
fi
fi
## Colleting Hardware Details ##
echo " " >> $FILE
echo "## Hardware Information" >> $FILE
echo " " >> $FILE
echo "Serial Number     : `lshal |grep system.hardware.serial`" >> $FILE
echo "Serial Number     : `/usr/sbin/dmidecode -s system-serial-number`" >> $FILE
echo "Model Number      : `lshal |grep system.hardware.product`" >> $FILE
echo "Model Number      : `/usr/sbin/dmidecode |grep "SKU Number"`" >> $FILE
echo "Hardware Vendor   : `lshal |grep system.hardware.vendor`" >> $FILE
echo "Hardware Info     : `dmesg |grep DMI`" >> $FILE
## Redhat Version ##
echo " " >> $FILE
echo "## OS Version" >> $FILE
head -n1 /etc/issue >> $FILE
echo -en '\n' >> $FILE
uname -a >> $FILE
## CPU Info ##
echo " " >> $FILE
echo " " >> $FILE
echo "## CPU Information" >> $FILE
grep "model name" /proc/cpuinfo >> $FILE
## RAM/MEMORY Info ##
echo " " >> $FILE
echo " " >> $FILE
echo "## Memory Information" >> $FILE
grep MemTotal /proc/meminfo >> $FILE
y=`grep MemTotal /proc/meminfo |awk '{ print $2 }'`
mb="$(( $y / 1024 ))"
gb="$(( $mb / 1024 ))"
echo "RAM : $gb GB" >> $FILE
## Verify the machine is using NIS ##
echo -e '\n' >> $FILE
cat /etc/yp.conf |grep $DOMAIN > /tmp/yptemp.txt
count=`cat /tmp/yptemp.txt | wc -l`
if [ $count -gt 0 ];
then
echo "`hostname` is part of NIS Domain" >> $FILE
cat /etc/yp.conf |grep finnis >> $FILE
else
echo "`hostname` is not part of NIS" >> $FILE
fi
echo -e '\n' >> $FILE
cat /etc/yp.conf |grep domain >> $FILE
echo -e '\n' >> $FILE
echo "Hard Disk Info" >> $FILE
fdisk -l 2>&1 | grep Disk | grep -v "identifier" | grep -v "valid partition" | awk '{print $2,$3,$4}' >> $FILE
echo -e '\n' >> $FILE
echo "Running Services" >> $FILE
service --status-all |grep running. |awk '{ print $1,$5}' >> $FILE
/bin/mail -s "Linux Asset Inventory `hostname`" $MAILIST < $FILE

Top 5 Enterprise opensource monitoring tools

1. Nagios

Nagios project is started in 1999. Nagios Enterprise monitoring tool will monitor your entire IT infrastructure to ensure systems, applications, services and business process are functioning properly. Which has two types of Software’s one is Nagios Core which is fully free (opensource) we have to configure everything by our own. Another one is Nagios XI which has beautiful GUI interface it is very easy to configure monitoring.
Nagios monitors your entire IT infrastructure to ensure systems, applications, services, and business processes are functioning properly. In the event of a failure, Nagios can alert technical staff of the problem, allowing them to begin remediation processes before outages affect business processes, end-users, or customers. With Nagios you’ll never be left having to explain why an unseen infrastructure outage hurt your organization’s bottom line.

Few Advantages using Nagios Core

  1. Monitor your entire IT infrastructure
  2. Spot problems before they occur
  3. Know immediately when problems arise
  4. Share Available data with stakeholders
  5. Detect security breaches
  6. Plan and budget for IT upgrades
  7. Schedule Planed down times

Download Nagios Core

Nagios Core Installation and configuration Guide
nagios core
Nagios Webconsole - Tech Tutorials

2. Icinga

Monitoring Servers and networking devices with icinga2 is very easy. You can download and add plugins as many as like. No need to make set-up or maintenance of the monitoring system itself any more complex. That’s why Icinga 2 features a new configuration format that is intuitive to write, efficient to execute and even adjusts to the changing conditions of your environment at run-time.
Clear-cut, object-based configuration
Icinga 2 introduces a new object-based, rule-driven configuration format, which offers user-friendly features such as apply rules for dynamic object generation.
Taking inspiration from Puppet formats, Icinga 2 offers clear, “one best way” configuration rules. This allows Icinga 2 to depart from Nagios(TM)’s multiple configuration formats (e.g. defining host/service dependencies and parent/child relationships for hosts) – the cause of much user confusion.
The Icinga 2 configuration format is currently set as text files, in preparation for later transition to configuration via API, or GUI and CLI. A configuration migration script that translates existing Icinga 1 / Nagios configurations into the new Icinga 2 format also makes migration easier.
Apply & assign attributes
Keep configuration work to a minimum by defining templates to ”apply” to configuration objects. Apply services and notifications to hosts, or downtimes and dependencies to services.
Clever commands & runtime macros
Commands in Icinga 2 are smarter than their Nagios™-style cousins. To begin with, Icinga 2 offers three distinct command types: Check, notification and event commands. They can be given default values, custom attributes, runtime macros and conditional behaviours. Each additional option can be given precedence over the other, so that your configuration intelligently adapts at runtime to changing monitoring conditions.
Logical Dependencies
Say goodbye to confusing parent/child relationships. Dependencies in Icinga 2 are straightforward; they can be defined as host-host, service-service or mixed (host-service and service-host) and all work in the same manner.
Dynamic Notifications
Similar to Icinga 1, event handlers and notifications are supported. Thanks to the new dynamic configuration format, users can adjust notification settings at runtime (e.g. in order to implement on-call rotation).
For example, new notification objects replace notification-specific attributes for services, while user and user groups replace contact and contact groups. This new format allows notifications to be defined more precisely and intuitively. On top of this, escalations in Icinga 2 are configured as notifications with a defined beginning and end, as are recurring downtimes.

Download Icinga

Icinga

3. OpenNMS

OpenNMS is the world’s first Enterprise opensource monitoring tool. Which is capable of monitoring Servers and Networking devices using SNMP protocol. OpenNMS has more and more features such as
  1. Automated and Directed discovery and provisioning
  2. Event and Notification Management
  3. Service Assurance
  4. Performance Measurement
Open Source: OpenNMS is 100% Free and Open Source software, with no license fees, software subscriptions or special “enterprise” versions.

Download OpenNMS

openNMS monitoring tool
openNMS monitoring tool

4. zabbix

Using zabbix enterprise level monitoring tool, we can monitorr real time thousands of servers, networking devices, virtual machines simultaneously.  Along with storing the data, visualization features are available (overviews, maps, graphs, screens, etc), as well as very flexible ways of analyzing the data for the purpose of alerting.  Zabbix offers great performance for dat gathering and can be scaled to very large environments.

Features

  1. Monitor Everything
  2. Enterprise Ready
  3. Proactive Monitoring
  4. Capacity Planning
  5. True Open Source
  6. Business Solutions

Download Zabbix

zabbix arkit
Top 5 Enterprise opensource monitoring tools

5. cacti

Cacti mainly used for Network device monitoring. We can create templates. Download performance data as CSV and we can do whatever we want. User Management and graphs. Cacti makes use of RRDTool  to generate graphs and collect data from Networking devices.  The frontend is completely PHP driven. Along with being able to maintain Graphs, Data Sources, and Round Robin Archives in a database, cacti handles the data gathering. There is also SNMP support for those used to creating traffic graphs with MRTG.

Features

  1. Graphs
  2. Datasources
  3. Data Gathering
  4. Template creation
  5. Graph Display
  6. User Management
  7. Graph templates enable common graphs to be grouped together by templating. Every field for a normal graph can be templated or specified on a per-graph basis.
  8. Data source templates enable common data source types to be grouped together by templating. Every field for a normal data source can be templated or specified on a per-data source basis.
  9. Host templates are a group of graph and data source templates that allow you to define common host types. Upon the creation of a host, it will automatically take on the properties of its template.
  10. The tree view allows users to create “graph hierarchies” and place graphs on the tree. This is an easy way to manage/organize a large number of graphs.
  11. The list view lists the title of each graph in one large list which links the user to the actual graph.
  12. The preview view displays all of the graphs in one large list format. This is similar to the default view for the 14all cgi script for RRDTool/MRTG.

Download Cacti

Top 5 Enterprise opensource monitoring tools

That’s About Top 5 Enterprise opensource monitoring tools