Friday, 31 January 2014

Recover MySQL root password


Stop the MySQL server process
 
/etc/init.d/mysql stop

Start again with no grant tables
 
mysqld_safe --skip-grant-tables &

Login to MySQL as root
 
mysql -u root

Set new password
 
mysql> use mysql;
mysql> update user set password=PASSWORD("password") where User='username';
mysql> flush privileges;

Exit MySQL and restart MySQL server

mysql> quit
/etc/init.d/mysql stop
/etc/init.d/mysql start

Set root password if there is no root password
OR
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
 
mysql>SET PASSWORD = PASSWORD('new_password');

Allow the user to connect to the server from localhost using the password

mysql>grant usage on *.* to 'username'@'%' identified by 'password';


Wednesday, 15 January 2014

Open Soruce Distributions and Applications

 Open-Source Software (OSS) is computer software with its source code made available and licensed with a license in which the copyright holder provides the rights to study, change and distribute the software to anyone and for any purpose. Open-source software is very often developed in a public, collaborative manner. Open-source software is the most prominent example of open-source development and often compared to user-generated content or open-content movements.

1. Desktop Distribution

Arch
Bodhi
Chakra
CrunchBang
Debian
Fedora
Fuduntu
Gentoo
Linux Mint
Mageia
Mandriva
Manjaro
MEPIS
openSuse
PClinuxOS
Puppy
Sabayon
Salix
Slackware
SolusOS
SparkyLinux
SUSE Linux
Ubuntu
VectorLinux
Zorin OS

2. Browser

Chrome
Chromium
Conkeror
Dillo
dwb
Epiphany
Firefox
Konqueror
links/elinks
Luakit
lynx
Midori
Opera
QupZilla
rekonq
SeaMonkey
SlimBoat
Uzbl
w3m

3. Open Source Web Framework

Apache Wicket
CakePHP
Cappuccino
CodeIgniter
Django
Express
Flask
Grails
Pyramid
Ruby on Rails
Sinatra
Spring
Struts
Symfony
web2py
Yii
Zend Framework
mojolicious
Laravel

4. IDE/Web Development Editor


Anjuta
Aptana Studio
Bluefish
Code::Blocks
Eclipse
Emacs
eric
Geany
IDLE
Kdevelop
Komodo
Kompozer
Lazarus
Leo
MonoDevelop
Netbeans
Qt Creator
Quanta
Quanta Plus
SeaMonkey Composer
Zend Studio

5. Audio Media Player Application

amaroK
Aqualung
aTunes
Audacious
Banshee
Clementine
cmus
DeaDBeef
Exaile
gmusicbrowser
MOC
MPD
mpg123
mpg321
Nightingale
Pogo
Quod Libet
RhythmBox
Sonata
VLC
XMMS
XMMS2

6. Video Media Player Application

Dragon Player
DVD-Player (XBMC)
FFplay
kaffeine
Miro
mplayer
mplayer2
Parole
Totem
VLC
xine

7. X Terminal Emulator

aterm
Eterm
GNOME Terminal
gtkterm
Guake
Konsole
Kuake
LilyTerm
LXTerminal
Roxterm
rxvt
Sakura
stjerm-terminal
Terminal (Xfce)
Terminator
Tilda
urxvt
xterm
Yakuake
Terminology
Termit

8. Mobile Distribution

Android
Chrome OS
CyanogenMod
Firefox OS
MeeGo
Mer
Replicant
Sailfish OS
Tizen
Ubuntu Phone
webOS

9. Programming Language

Ada
Assembly
AWK
C
C#
C++
Clojure
COBOL
Common Lisp
Erlang
Fortran
Free Pascal
Go
Haskell
Java
Javascript
Lua
Objective-C
Perl
PHP
Python
R
Ruby
Scala
Scheme
Tcl

10. Text Editor

Emacs
Geany
gedit
jEdit
joe
Kate
KWrite
leafpad
medit
Midnight Commander Editor
Mousepad
nano
Nedit
pico
RedCar
Scite
Scribes
vi
vim

11. Desktop Environment

Cinnamon
Gnome Shell
KDE
LXDE
MATE
Razor-qt
rox
Trinity-DE
Unity
Xfce

12. Virtualization Product

KVM
Linux-VServer
OpenVZ
Oracle VM
Parallels Workstation
QEMU
VirtualBox
VMware
Xen
LXC

13. File Manager

Caja
Dolphin
Double Commander
emelFM2
gentoo
Gnome Commander
Konqueror
Krusader
Midnight Commander
muCommander
Nautilus
Nemo
PCManFM
ranger
ROX-Filer
SpaceFM
Thunar
vifm
Worker
Xfe

14. Backup Application

AMANDA
Areca-Backup
Back In Time
BackupPC
Bacula
Clonezilla
cpio
Deja Dup
dump
Duplicity
FSArchiver
G4L
luckyBackup
partimage
rdiff-backup
Redo Backup and Recovery
rsnapshot
rsync
tar
Time Vault
Burp

15. Network Monitoring Application

Big Brother
Ganglia
GroundWork Monitor
Icinga
mon
monit
munin
Nagios Core
Nagios XI
NetXMS
OpenNMS
OpenQRM
Opsview
Shinken
Zabbix
Zenoss

16. Network Security Application

aircrack-ng
Bro IDS
ClamAV
dsniff
fail2ban
Firestarter
fwBuilder
Guarddog
kismet
Metasploit
Nessus
Nikto
Nmap Security Scanner
OpenVAS
p0f
Shorewall
snort
tcpdump
UFW/Gufw
Wireshark

17. Server Distribution

CentOS
Debian
Gentoo
Mandriva Enterprise Server
Oracle Enterprise Linux
Red Hat Enterprise Linux
Scientific Linux
Slackware
SUSE Linux Enterprise Server
Ubuntu LTS

18. Office Suite

Calligra
LibreOffice
OpenOffice.org

19. Window Manager

awesome
Compiz
dwm
Enlightenment
Fluxbox
FVWM
i3
IceWM
JWM
KWin
Marco
MetaCity
Mutter
Openbox
Ratpoison
Sawfish
spectrwm
Window Maker
wmii
xfwm4
xmonad
Notion
twm

20. Graphics Application

Art of Illusion
Blender
CinePaint
Darktable
GIMP
ImageMagick
Inkscape
Kolourpaint
Krita
LazPaint
LightZone
mtPaint
MyPaint
Pinta
RawTherapee
Scribus
Tux Paint
GrafX2
G'MIC

21. Open Source Game

0 A.D.
Armagetron Advanced
AssaultCube
Battle for Wesnoth
BZFlag
FlightGear
Freeciv
Frets On Fire
Frozen Bubble
GNU Chess
LBreakout2
MegaGlest
Minetest
NetHack
Neverball
Open Arena
OpenClonk
OpenTTD
Pingus
Pioneer
PokerTH
Red Eclipse
StepMania
SuperTux
SuperTuxKart
The Mana World
TORCS
Trigger Rally
Tux Racer
UFO: Alien Invasion
Ur Quan Masters
Warzone 2100
World of Padman
Xonotic
FreeOrion

22. Privacy Solution

Adblock Plus
Disconnect
Ghostery
GnuPG
NoScript
Privoxy
Tor Browser Bundle
TrueCrypt
LastPass
HTTPS Everywhere
PasswordMaker
DoNotTrackMe

23. Open Source CMS/Blogging platform

Alfresco
b2evolution
CMS Made Simple
Dotclear
DotNetNuke
Drupal
eZ Publish
Joomla!
MODx
Movable Type
Octopress
Plone
Roller
Serendipity
SilverStripe
Textpattern
TYPO3
WordPress
XOOPS
Ghost

24. VoIP Application

Blink Qt
Ekiga
Empathy
Jitsi
KPhone
Linphone
Mangler
Mumble
opensoftphone
QuteCom
SFLphone
Skype
TeamSpeak
Twinkle

25. Database

DB2
Drizzle
EnterpriseDB
Firebird
MariaDB
MySQL
Oracle
Percona
PostgreSQL
sqlite

26. Revision Control System

Bazaar
BitKeeper
CVS
Fossil
git
Mercurial
Perforce
Subversion

27. Messaging Application

aMSN
BitlBee
CenterIM
EKG2
Empathy
Finch
Gajim
Gwibber
Gyachi
Irssi
Jitsi
Kadu
KDE-Telepathy
KMess
konversation
Kopete
Pidgin
Psi
qutIM
WeeChat
XChat
Hexchat

28. Configuration Management Tool


Bcfg2
cdist
Cfengine
Chef
Puppet
Salt stack
Spacewalk
Ansible

29. Host Security Application

AIDE
AppArmor
Bastille
chkrootkit
grsecurity
Lynis
Osiris
OSSEC
Rootkit Hunter
Samhain
SELinux
TOMOYO
Tripwire

30. NoSQL Database

Cassandra
CouchDB
HBase
Hypertable
Membase Server
MongoDB
Redis
Riak
Voldemort
Neo4j
Couchbase

Ref:- http://www.linuxquestions.org


Friday, 3 January 2014

Immutable files in Linux

Chattr

chattr is a command in the Linux operating system that allows a user to set certain attributes on a file residing on many Linux filesystems.

touch filetest.txt

To display the attributes
lsattr filetest.txt
------------- filetest.txt

To set file attributes
chattr +i filetest.txt

lsattr filetest.txt
----i-------- filetest.txt

To test the functionality
mv filetest.txt file.txt
mv: cannot move `filetest.txt' to `file.txt': Operation not permitted

rm -rf filetest.txt
rm: cannot remove `filetest.txt': Operation not permitted

echo "HI" > filetest.txt
-bash: filetest.txt: Permission denied

To remove the immutable attribute
chattr -i filetest.txt
lsattr filetest.txt
------------- filetest.txt

To append operations
chattr +a filetest.txt
lsattr filetest.txt
-----a------- filetest.txt

test the functionality
rm -rf filetest.txt
rm: cannot remove `filetest.txt': Operation not permitted
mv filetest.txt file.txt
mv: cannot move `filetest.txt' to `file.txt': Operation not permitted
echo "replacing content" > filetest.txt
-bash: filetest.txt: Operation not permitted
echo "appending new content" >> filetest.txt
appending new content

To remove the immutable attribute
lsattr filetest.txt
------------- filetest.txt

How to Recursively change attributes of directories and their contents.

chattr -R +i test
lsattr test/filetest.txt
----i-------- test/filetest.txt

chattr -R -i test
lsattr test/filetest.txt
------------- test/filetest.txt

chattr -R +a test
lsattr test/filetest.txt
-----a------- test/filetest.txt
chattr -R -a test

Ref:- http://www.adminarticles.com/file-attributes/

Wednesday, 11 September 2013

Time Stamp of a file in Linux


Every Linux file is associated with timestamps, which specifies the last access time, last modification time and last change time.

To get the timestamp of a file "ls -l" and "stat".

1. Use -c option to avoid creating new files, but will change the timestamp by present time.

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-10-18 23:42:12.000000000 -0700
Modify: 2012-10-18 23:42:12.000000000 -0700
Change: 2013-09-11 08:49:16.509859887 -0700

touch -c tgs.txt

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-09-11 08:49:25.685239864 -0700
Modify: 2013-09-11 08:49:25.685239864 -0700
Change: 2013-09-11 08:49:25.685239864 -0700

2. Change File’s Access Time using -a.

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-09-11 08:10:44.783796541 -0700
Modify: 2013-09-11 08:10:44.783796541 -0700
Change: 2013-09-11 08:10:44.783796541 -0700

touch -a tgs.txt

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-09-11 08:13:14.824798981 -0700
Modify: 2013-09-11 08:10:44.783796541 -0700
Change: 2013-09-11 08:13:14.824798981 -0700

3. Change File’s Modification Time using -m.

touch -m *.o

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-09-11 08:13:14.824798981 -0700
Modify: 2013-09-11 08:10:44.783796541 -0700
Change: 2013-09-11 08:13:14.824798981 -0700

touch -m tgs.txt

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-09-11 08:13:14.824798981 -0700
Modify: 2013-09-11 08:16:36.600236392 -0700
Change: 2013-09-11 08:16:36.600236392 -0700

4. Modification time using -t and -d.

touch -t [CCYYMMDDHHMM.SS] filename

touch -t 201212312359.59 tgs.txt 
touch -a -m -t 201212312359.59 tgs.txt 

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-12-31 23:59:59.000000000 -0800
Modify: 2012-12-31 23:59:59.000000000 -0800
Change: 2013-09-11 08:30:24.706252619 -0700

touch -d "2012-10-19 12:12:12.000000000 +0530" tgs.txt

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-10-18 23:42:12.000000000 -0700
Modify: 2012-10-18 23:42:12.000000000 -0700
Change: 2013-09-11 08:37:51.182799786 -0700

5. Copy the Time-stamp from Another File using -r.

ls -l
-rw-r--r--. 1 root root 0 Sep 11 08:43 test.txt
-rw-r--r--. 1 root root 0 Oct 19  2012 tgs.txt

touch test.txt -r tgs.txt

ls -l

-rw-r--r--. 1 root root 0 Oct 19  2012 test.txt
-rw-r--r--. 1 root root 0 Oct 19  2012 tgs.txt

ref: http://www.thegeekstuff.com/2012/11/linux-touch-command/

Executing Background Jobs in Linux

Manage Background Jobs in Linux

when you execute a find command that might take a lot time to execute, you can put it in the background as shown below.

Appending an ampersand ( & ) to the command runs the job in the background.

     find / -type f -mtime -1000 >> /root/filelist.log &

Sending the current foreground job to the background using Ctrl + Z.

     find / -type f -mtime -1000 >> /root/filelist.log
     Ctrl + Z
     bg

Taking a job from the background to the foreground.

     fg
     find / -type f -mtime -1000 >> /root/filelist.log
     Ctrl + Z

View all the background jobs.

     jobs

     [1]+  Stopped    find / -type f -mtime -1000 >> /root/filelist.log

Kill a specific background job.

     fg %1
     kill %1

ref: http://www.thegeekstuff.com/2010/05/unix-background-job/


Ganglia Monitoring System

Ganglia

Ganglia is a scalable distributed monitoring system for high-performance computing systems such as clusters and Grids.

Ganglia Installation and Configuration

yum -y install ganglia*

Edit gmetad.conf

vi /etc/ganglia/gmetad.conf

data_source "my cluster" localhost 192.168.1.100:8089

Edit ganglia.conf

vi /etc/httpd/conf.d/ganglia.conf

 Alias /ganglia /usr/share/ganglia
  <Location /ganglia>
     AllowOverride All
     DirectoryIndex index.php
  </Location>

Restart the services

/etc/init.d/httpd restart
/etc/init.d/gmetad restart
/etc/init.d/gmond restart

URL

 http://192.168.1.100/ganglia

ref: http://ganglia.sourceforge.net/


Saturday, 25 May 2013

Text Processing Tools in Linux

The following command are often used when writing scripts to automate tasks.

The diff command :- to compare the content of two files for differences.

diff file1.conf file2.conf > output.txt
cat output.txt
Options are -c, -u and -r.

The patch command :- ued to apply simple patch file to a single file.

patch -b file1.conf < output.txt

The grep command :- displays the lines in a files that match pattern.

grep root /etc/passwd
ps -aux | grep sshd
Options are -i, -n, -r, -c, -v and -l.

The cut command :- ued to cut fields or colomns of text from a file and display standard output.

cut -f3 -d: /etc/passwd
/sbin/ip addr | grep 'inet' | cut -d ' ' -f6 | cut -d / -f1
Options are -d, -f and -c.

The head command :- displays first few lines of a file.

head /etc/passwd
head -n 3 /etc/passwd
Options is -n.

The tail command :- displays last few lines of a file.

tail -n 3 /etc/passwd
tail -f /etc/passwd
tail -f will continue to show updates until Ctrl+c is pressed.

The wc command :- counts the number of lines(l), words(w), bytes(c) and characters(m) in a file.

wc -l file1.conf
ls /tmp | wc -l
Options are -l, -w, -c and -m.

The sort command :- used to sort text data.

grep bash /etc/passwd | cut -d: -f1 | sort
options are -n, -k and -t.

The uniq command :- removes duplicate adjacent lines from a file.

cut -d: -f7 /etc/passwd | sort | uniq -c
Options are -u and -d

The echo command :-  output strings.

echo This is a test.
echo This is a test. > output.txt
cat output.txt

The cat command :- output or concatenate files.

cat file1.conf > output.txt
cat output.txt
cat file1.conf file2.conf | less
Options are -b, -n, -s, -v, -t, -e and -A.

The paste command :- join multiple files horizontally.

paste file1.conf file2.conf
Options are -d and -s.

The split command :- split files based on context lines.

split -l 500 myfile segment
split -b 40k myfile segment
Options are -l (line no) and -b(bytes).

The comm command :- to compare two files for common and distinct lines.

comm file1.conf file2.conf

The dirname command :-  it will delete any suffix beginning with the last slash ('/') character and return the result.

dirname /etc/httpd/conf/httpd.conf

The fold command :- used for for making a file with long lines more readable on a limited width terminal.
fold -w 30 file.txt

The sed command :- reads text input, line by line, and allows midfication.

sed 'word;wordtoreplace' < file1.conf > output.txt
sed '/word/ d' filename > output.txt
sed 's/word/ /g' filename > output.txt
sed 's/firstword//g; s/secondword//g' yourfile > output.txt

The awk command :- used as a data extraction and reporting tool.

awk "/word/" filename > output.txt

The less command :- used to view the contents of a text file one screen at a time.

less /etc/passwd


Friday, 24 May 2013

How to scp, ssh and rsync without prompting for password


For example, login in to some host linux box as root 172.16.0.155 and pass the command as,

ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
35:50:28:70:2b:b0:9f:01:9a:8b:cb:0e:17:89:1d:a2 root@InVImFTSrv
The key's randomart image is:
+--[ RSA 2048]----+
|  o ... .o.      |
| o + .....       |
|+ o o ..  o      |
|o= + +   . .     |
|E + o   S        |
|.. .             |
|o..              |
|o.               |
| .               |
+-----------------+


now login to the host linux box as root 172.16.0.177 and copy,

scp -r root@172.16.0.155:/root/.ssh/id_rsa.pub /root/.ssh/

cd /root/.ssh/
cat id_rsa.pub >> authorized_keys
chmod 700 /root/.ssh/authorized_keys

now form 172.16.0.155 try ssh, scp or rsync as,

scp -r root@172.16.0.177:/usr/local/src/April /usr/local/src/

It won't prompt for any password.

Ref:-https://blogs.oracle.com/jkini/entry/how_to_scp_scp_and


Monday, 2 July 2012

Port Numbers

                          Internet socket port numbers are used by protocols of the Transport Layer of the Internet Protocol Suite for the establishment of host-to-host communications.

Well-known ports


         The port numbers in the range from 0 to 1023 are the well-known ports. They are used by system processes that provide widely-used types of network services.

Registered ports

         The range of port numbers from 1024 to 49151 are the registered ports. They are assigned by IANA for specific service upon application by a requesting entity. On most systems registered ports can be used by ordinary users.

Dynamic, private or ephemeral ports

         The range 49152–65535 is used for custom or temporary purposes and for automatic allocation of ephemeral ports.

Port        TCP/UDP      Protocol
 
20          TCP                FTP—data transfer

21          TCP                FTP—control

22          TCP                Secure Shell (SSH)

23          TCP                Telnet protocol

25          TCP                Simple Mail Transfer Protocol (SMTP

53          TCP/UDP       Domain Name System (DNS)

69          UDP               Trivial File Transfer Protocol (TFTP)

80          TCP                Hypertext Transfer Protocol (HTTP)

109        TCP                Post Office Protocol v2 (POP2)

110        TCP                Post Office Protocol v3 (POP3)

115        TCP                Simple File Transfer Protocol (SFTP)

123        UDP               Network Time Protocol (NTP)

143        TCP                Internet Message Access Protocol (IMAP)

161       UDP                Simple Network Management Protocol (SNMP)

389       TCP/UDP        Lightweight Directory Access Protocol (LDAP)

443       TCP                 HTTPS (Hypertext Transfer Protocol over SSL/TLS)

2049     TCP/UDP        NFS (Network File System)

3306     TCP/UDP        MySQL database system

2483     TCP/UDP        Oracle database listening for unsecure client connections to the listener



Reference:-http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers


Thursday, 14 June 2012

Install Nagios on CentOS/Fedora

* Nagios and the plugins will be installed underneath /usr/local/nagios
* Nagios will be configured to monitor a few aspects of your local system (CPU load, disk usage, etc.)
* The Nagios web interface will be accessible at http://localhost/nagios/

Prerequisites

Make sure that the following packages are installed

    * Apache
    * PHP
    * GCC compiler
    * GD development libraries

yum install httpd php

yum install gcc glibc glibc-common

yum install gd gd-devel

Create a new nagios user account and give it a password

/usr/sbin/useradd -m nagios

passwd nagios

Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.

/usr/sbin/groupadd nagcmd

/usr/sbin/usermod -a -G nagcmd nagios

/usr/sbin/usermod -a -G nagcmd apache

Download Nagios and the Plugins

http://www.nagios.org/download/

Compile and Install Nagios

Extract the Nagios source code tarball.
tar xzf nagios-3.2.3.tar.gz

cd nagios-3.2.3

Run the Nagios configure script, passing the name of the group created earlier
./configure --with-command-group=nagcmd

Compile the Nagios source code.

make all

Install binaries, init script, sample config files and set permissions on the external command directory.

make install

make install-init

make install-config

make install-commandmode

Customize Configuration

vi /usr/local/nagios/etc/objects/contacts.cfg

Configure the Web Interface

Install the Nagios web config file in the Apache conf.d directory.

make install-webconf


Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account – you’ll need it later.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin


Restart Apache to make the new settings take effect.

service httpd restart

Compile and Install the Nagios Plugins

Extract the Nagios plugins source code tarball.

cd ~/downloads

tar xzf nagios-plugins-1.X.tar.gz

cd nagios-plugins-1.X.

Compile and install the plugins.

./configure --with-nagios-user=nagios --with-nagios-group=nagios

make

make install

Start Nagios

Add Nagios to the list of system services and have it automatically start when the system boots.

chkconfig --add nagios

chkconfig nagios on

Verify the sample Nagios configuration files.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If there are no errors, start Nagios.

service nagios start

Modify SELinux Settings

See if SELinux is in Enforcing mode.

getenforce

Put SELinux into Permissive mode.

setenforce 0

To make this change permanent, you’ll have to modify the settings in /etc/selinux/config and reboot.

Login to the Web Interface

Access the Nagios web interface at the URL below, prompted for the username (nagiosadmin) and password you specified earlier.

http://localhost/nagios/







Reference:- http://cuongk6t.wordpress.com/2011/06/07/how-to-install-nagios-on-centos-6-or-fedora/



Wednesday, 16 May 2012

Cron in Linux

               Cron job are used to schedule commands to be executed periodically. You can setup commands or scripts, which will repeatedly run at a set time

#edit cron table
crontab -e

MIN HOUR DOM MON DOW CMD

   *        *        *        *        *    command to be executed

    OR

* * * * *    USERNAME    command to be executed
|  |  | |  |
|  |  | |  |----- Day of week (0 - 6) (Sunday=0)
|  |  | |-------- Month (1 - 12)
|  |  |---------- Day of month (1 - 31)
|  |------------- Hour (0 - 23)
|---------------- Minute (0 - 59)

#List
crontab -l
crontab -u username -l

#Erase
crontab -r
crontab -r -u username

#run every 10 minutes
*/10 * * * * command

#stop receiving email output
0 3 * * * /root/backup.sh >/dev/null 2>&1

#Backup
crontab -u root(username) -l > /home/cron.backup
0 12 * * * /usr/bin/top -n 1 -b -S >> /home/cron.backup

#Version
rpm -qa | grep cron
rpm -qil version

#Schedule
Keyword     Equivalent
@yearly      0 0 1 1 *
@daily        0 0 * * *
@hourly      0 * * * *
@reboot      Run at startup.

The asterisk (*) : specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to every hour or an asterisk in the month field would be equivalent to every month.

The comma (,) : specifies a list of values, for example: "1,5,10".

The dash (-) : specifies a range of values, for example: "5-10" days , which is equivalent to typing "5,6,7,8,9,10" using the comma operator.


NFS in Linux

                The Network File System (NFS) was developed to allow machines to mount a disk partition on a remote machine as if it were on a local hard drive. This allows for fast, seamless sharing of files across a network. It also gives the potential for unwanted people to access your hard drive over the network.

NFS Configration in RHEL 6/CentOS 6

yum install nfs*

rpm packeages
nfs-utils-lib-1.1.5-4.el6.x86_64
nfs4-acl-tools-0.3.3-5.el6.x86_64
nfs-utils-1.2.3-15.el6.x86_64

vim /etc/exports
/var/ftp/pub    *(ro,sync)    #for entire network
/data    192.168.1.5(rw,sync)    #for particular machine
/jp    192.168.1.0/24(ro,sync)    #for particular network

mkdir /data
mkdir /jp

service rpcbind status
rpcbind (pid 9905) is running...

service nfs restart
Shutting down NFS mountd:                                  [  OK  ]
Shutting down NFS daemon:                                 [  OK  ]
Shutting down NFS quotas:                                   [  OK  ]
Shutting down NFS services:                                 [  OK  ]
Starting NFS services:                                           [  OK  ]
Starting NFS quotas:                                             [  OK  ]
Starting NFS daemon:                                           [  OK  ]
Starting NFS mountd:                                            [  OK  ]

chkconfig rpcbind on
chkconfig nfs on

exportfs
/data        192.168.1.5
/jp        192.168.1.0/24
/var/ftp/pub    <world>

#see what the exported file system parameters look like
/usr/sbin/exportfs −v
exportfs -av

exporting 192.168.1.0/24:/jp
exporting 192.168.1.5:/data
exporting *:/var/ftp/pub

showmount -e 192.168.1.4
/var/ftp/pub *
/jp        192.168.1.0/24
/data        192.168.1.5

mount 192.168.1.4:/data /mnt/

#verify nfs is running
rpcinfo −p localhost run on the server
rpcinfo −p servername run on the client

#to check allow and deny
/etc/hosts.allow
/etc/hosts.deny

exportfs −ra to force nfsd to re−read the /etc/exports file.

netstat −rn should show:
Destination    Gateway        Genmask        Flags    MSS Window   irtt Iface
192.168.1.0    0.0.0.0        255.255.255.0    U               0 0                0 eth0               

nfsstat
rpm -qa | grep -i nfs
rpm -qi nfs-utils
tracepath server(IP)
# strings /sbin/portmap | grep hosts

Monday, 14 May 2012

Linux Command for System Information

uname -r
To display the info more about kernel.

free
Memory info (in kilobytes).

df -h
(disk free) Print disk info about all the filesystems in human-readable form.

du / -bh | more
(=disk usage) Print detailed disk usage for each subdirectory starting at the "/" (root) directory (in human legible form).

cat /proc/cpuinfo
Cpu info--it show the content of the file cpuinfo.

cat /proc/interrupts
List the interrupts in use.

cat /proc/version
Linux version and other info

cat /proc/filesystems
Show the types of filesystems currently in use.

cat /etc/printcap
Show the setup of printers.

lsmod
Show the kernel modules currently loaded.(As root. Use /sbin/lsmod to execute this command when you are a non-root user.)

set|more
Show the current user environment.

echo $PATH
Show the content of the environment variable "PATH". This command can be used to show other environment variables as well. Use "set" to see the full environment.

dmesg | less
Print kernel messages (the content of the so-called kernel ring buffer). Use less /var/log/dmesg  to see what "dmesg" dumped into this file right after the last system bootup.


Sunday, 13 May 2012

Kernel Version in Linux

uname --version

o/p:
uname (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie.

uname -r       

o/p:
2.6.32-220.13.1.el6.x86_64
   
Explanation,
    2   : Kernel version
    6   : The major revision of the kernel
    32  : The minor revision of the kernel
    220 : Immediate fixing / bug fixing for critical error
    generic : Distribution specific sting. For example, Redhat appends string such as EL6 to indicate RHEL 6 kernel.

uname -a

o/p:
Linux www.snk.com 2.6.32-220.13.1.el6.x86_64 #1 SMP Tue Apr 17 23:56:34 BST 2012 x86_64 x86_64 x86_64 GNU/Linux

uname -mrsn

o/p:   
Linux www.snk.com 2.6.32-220.13.1.el6.x86_64 x86_64

cat /proc/version

o/p:   
nux version 2.6.32-220.13.1.el6.x86_64(mockbuild@c6b6.bsys.dev.centos.org) (gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) ) #1 SMP Tue Apr 17 23:56:34 BST 2012

rpm -q kernel

o/p:   
kernel-2.6.32-220.el6.x86_64
kernel-2.6.32-220.13.1.el6.x86_64

dpkg --list | grep linux-image    #in Ubuntu/Debain

o/p:
ii  linux-image 2.6.22.14.21 Generic Linux kernel image.
rc  linux-image-2.6.20-15-generic 2.6.20-15.27 Linux kernel image for version 2.6.20 on x86/
ii  linux-image-2.6.20-16-generic 2.6.20-16.32 Linux kernel image for version 2.6.20 on x86/
ii  linux-image-2.6.22-14-generic  2.6.22-14.47 Linux kernel image for version 2.6.22 on x86/

cat /etc/grub.conf
cat /proc/sys/kernel/osrelease
cat /etc/issue
lsb_release -a
cat /etc/lsb-release
also see uname man page


Friday, 11 May 2012

CentOS LAMP Install via YUM

CentOS Apache Install

yum install httpd

/etc/init.d/httpd start

chkconfig httpd on


CentOS MySQL Server Install

yum install mysql-server mysql

/etc/init.d/mysqld start

chkconfig mysqld on


CentOS PHP & php-mysql Install

To install PHP and php-mysql (php-mysql is required so that PHP can talk to MySQL)

yum install php php-mysql


FYI here is the full CentOS LAMP command (this will install Apache, MySQL & PHP)

yum install httpd php php-mysql mysql mysql-server

Useradd in Linux using script

vim adduser.sh

#!/bin/bash
# Script to add a user to Linux system

if [ $(id -u) -eq 0 ]; then

    read -p "Enter username : " username
    read -s -p "Enter password : " password

    egrep "^$username" /etc/passwd >/dev/null

    if [ $? -eq 0 ]; then

        echo "$username exists!"
        exit 1

    else

        pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
        useradd -m -p $pass $username
        [ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"

    fi
else
    echo "Only root may add a user to the system"
    exit 2
fi

chmod 777 adduser.sh

[root@snk Desktop]# ./adduser.sh
Enter username : testuser
Enter password : **********
User has been added to system!


Tuesday, 8 May 2012

File Permissions in Linux


              In LINUX Each file belongs to a user and to a user group, For restricting file access Linux defines three different types of rights,

Read(r)      - file can be read
Write(w)    - content of the file can be changed
Execute(x) - file can be executed

Each of these rights are defined for three sets of users,

user(u)     - the owner of the file
group(g)   - the users who are members of the group
others(o)  - neither members of the group nor the owner

Example

ls -l testfile
-rw-r--r--. 1 annie team1 0 May  4 16:03 testfile

name           : testfile
permissions : -rw-r--r--
owner          : annie
group          : team1
other           : 0

The first character of permissions indicates,

Character   Type of file

   -           regular file
   d          directory
   l           symbolic link
   s          socket
   p          named pipe
   c          character device file (unbuffered)
   b          blocked device file (buffered)

Letter Permission

  r          Read
  w         Write
  x          Execute
  -          No permission

Letter Type of users

  u         User
  g         Group
  o         Other
  a         All (everybody)

Permission Value

  -                 0
  x                 1
  w                 2
  r                  4

Permission Value

    ---            0
    --x            1
    -w-            2
    -wx           3
    r--             4
    r-x            5
    rw-            6
    rwx           7

Changing the access mod of a file

Example

chmod 752 testfile
or
chmod u=rwx,g=rx,o=w test

chmod u+x testfile   -user execute permission
chmod +x testfile    -everyone execute permission
chmod ugo+x testfile -everyone execute permission

Changing file owner or group

Example

chown glen testfile
chgrp admin testfile
or
chown glen:admon testfile

Special permissions for executables

Setting the sticky bit on a directory

If you have a look at the /tmp permissions,

drwxrwxrwt   10 root root  4096 2006-03-10 12:40 tmp

t is called the sticky bit and indicates that in this directory, files can only be deleted by their owners, the owner of the directory or the root superuser. it is not enough for a user to have write permission on /tmp, he also needs to be the owner of the file to be able to delete it.

In order to set or to remove the sticky bit,

chmod +t tmp
chmod -t tmp

SGID attribute on a directory

chmod g+s directory
chmod g-s directory


Setting SUID and SGID attributes on executable files 

chmod g+s myscript.sh
chmod g-s myscript.sh

chmod u+s myscript.sh
chmod u-s myscript.sh

Setting the default file creation permissions

The default umask value is usually 022.

umask 022

By default umask is 000, files get mode 666 and directories get mode 777. As a result, with a default umask value of 022, newly created files get a default mode 644 (666 - 022 = 644) and directories get a default mode 755 (777 - 022 = 755).

Friday, 4 May 2012

Simple Backup & Compression in Linux


Compression reduces file to a fraction of its original size so the file can more efficiently store or transmit.

gzip -c test.txt > test.txt.gz #compress
gunzip test.txt.gz                #decompress
zcat test.txt.gz                    #view
less test.txt.gz                     #view pagewise

bzi2 -c test.txt > test.txt.bz2 #compress
bunzip2 test.txt.bz2              #decompress
bzcat test.txt.bz2                  #view
less test.txt.bz2                     #view pagewise

zip test.txt.zip test.txt #compress
unzip test.txt             #decompress

Backup 

#backup
tar -cvf filename.tar testfile

#backup with zip
tar -czvf filename.tar.gz testfile

#backup with gzip
tar -cjvf filename.tar.bz2 testfile

#uncompress tarfile
tar -xvf filename.tar

#uncompress .bz tarfile
tar -xjvf filename.tar.bz2

#uncompress .gz tarfile
tar -xzvf filename.tar.gz

c -create
v -verbose
x -extrat
f -filename
z -compress the tar file with gzip
j -compress the tar file with bzip2

#more
lzma
rar
7zip
lbzip2
xz
lrzip
PeaZip
arj

Thursday, 3 May 2012

LVM in RHEL 6


The Linux Logical Volume Manager (LVM) is a mechanism for virtualizing disks. It can create "virtual" disk partitions out of one or more physical hard drives, allowing you to grow, shrink, or move those partitions from drive to drive as your needs change. It also allows you to create larger partitions than you could achieve with a single drive.

LVM in RHEL 6

#Create Partitions
fdisk /dev/sdc
make 3 partitions
change system ID as 8e for Linux LVM

#Create physical volumes
pvcreate /dev/sdc1 /dev/sdc2

Physical volume "/dev/sdc1" successfully created
Physical volume "/dev/sdc2" successfully created

pvdisplay
pvs

#Create Virtual Group
vgcreate vg0 /dev/sdc1 /dev/sdc2

Volume group "vg0" successfully created

vgdisplay
vgs

#Create Logical Volumes
lvcreate -L 2G Vg0 -n lv0

Logical volume "lv0" created

#Create File system on logical volumes
mkfs.ext3 /dev/vg0/lv0

#Edit /etc/fstab

/dev/vg0/lv0 /lvm ext3 defaults 0 0

#Mount logical volumes
mkdir /lvm
mount -a
mount

lvdisplay
lvs
lv0     vg0      -wi-ao  2.00g

#Extend logical volume
pvcreate /dev/sdc3
Physical volume "/dev/sdc3" successfully created

vgextend vg0 /dev/sdc3
Volume group "vg0" successfully extended

lvextend -L +1G /dev/vg0/lv0
Extending logical volume lv0 to 3.00 GiB
Logical volume lv0 successfully resized

resize2fs -p /dev/vg0/lv0
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg0/lv0 is mounted on /lvm; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg0/lv0 to 786432 (4k) blocks.
The filesystem on /dev/vg0/lv0 is now 786432 blocks long.

lvs
lv0     vg0      -wi-ao  3.00g

#Reduce logical volume
lvreduce -L -500M /dev/vg0/lv0
WARNING: Reducing active and open logical volume to 2.51 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv0? [y/n]: y
Reducing logical volume lv0 to 2.51 GiB
Logical volume lv0 successfully resized

resize2fs -p /dev/vg0/lv0
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg0/lv0 is mounted on /lvm; on-line resizing required
On-line shrinking from 786432 to 658432 not supported.

lvs
lv0     vg0      -wi-ao  2.51g

#Remove logical volume
vim /etc/fstab (edit fstab to dd lvm entry line)
mount -a
umount /lvm

lvremove /dev/Vg0/lv0
Do you really want to remove active logical volume lv0? [y/n]: y
Logical volume "lv0" successfully removed

Vgremove vg0
Volume group "vg0" successfully removed


Wednesday, 2 May 2012

RAID in RHEL 6


                  Redundant Array of Independent Disks, originally Redundant Array of Inexpensive Disks is a storage technology that combines multiple disk drive components into a logical unit.

Disk arrays stripe data across multiple disks and access them in parallel to achieve:

Higher data transfer rates on large data accesses and
Higher I/O rates on small data accesses.

Level     Description

RAID 0 Block-level striping without parity or mirroring.

RAID 1 Mirroring without parity or striping.

RAID 2 Bit-level striping with dedicated Hamming-code parity.

RAID 3    Byte-level striping with dedicated parity.

RAID 4 Block-level striping with dedicated parity.

RAID 5 Block-level striping with distributed parity.

RAID 6 Block-level striping with double distributed parity.

RAID 10 Nested RAIDs or hybrid RAIDs are constructed by distributing data over mirrored sets of storage devices.


Mirroring plus striping (striped-mirror, RAID-1+0 or RAID-10)

            The combination of striping above mirroring is called a striped-mirror layout. Putting mirroring below striping mirrors each column of the stripe. If there are multiple sub disks per column, each subdisk can be mirrored individually instead of each column. A striped-mirror volume is an example of a layered volume. 

Nesting


Level Description Minimum # of disks
 
RAID 0+1     Top Level RAID 1, Bottom Level RAID 0.    3
RAID 1+0     Top Level RAID 0, Bottom Level RAID 1. 4
RAID 5+0 Top Level RAID 0, Bottom Level RAID 5.    6
RAID 5+1 Top Level RAID 1, Bottom Level RAID 5. 6
RAID 6+0     Top Level RAID 0, Bottom Level RAID 6.    8
RAID 6+1     Top Level RAID 1, Bottom Level RAID 6.    8
RAID 1+0+0   RAID 0 RAID 0 RAID 1 8


Software RAID - the RAID task runs on the CPU of your computer system.

Hardware RAID - solution has its own processor and memory to run the RAID application.


RAID in RHEL 6

The minimum number of software RAID partitions required for each RAID level:
        • RAID   0,1,10   – 2 partitions
        • RAID   4,5        – 3 partitions
        • RAID   6           – 4 partitions

#create partitions
fdisk /dev/sdb
Make 4 partitions of each 1GB
Change System ID as fd to Linux raid autodetect

#create raid
mdadm -C /dev/md0 -l 5 -n 3 /dev/sdb1 /dev/sdb2 /dev/sdb3
C-create
5-raid level
3-raid devices

#mount
mkfs.ext4 /dev/md0
mkdir /raid5

vim /etc/fstab
/dev/md0 /raid5 ext4 defaults 0 0

cd /raid5/
ls

#raid status
mdadm --detail /dev/md0
cat /proc/mkstat

#set faulty partition
mdadm -f /dev/md0 /dev/sdb3
mdadm: set /dev/sdb3 faulty in /dev/md0

#add new raid partition
mdadm -a /dev/md0 /dev/sdb4
mdadm: added /dev/sdb4

#remove faulty raid partition
mdadm -r /dev/md0 /dev/sdb3
mdadm: hot removed /dev/sdb3 from /dev/md0