Thursday, October 02, 2014

How to use yum command to download package without installing it?

There are two ways to download a package without installing it.

First - use "downloadonly" plugin of yum.

1] Install the package including "downloadonly" plugin.

RHEL-5
[root@server ~]# yum install yum-downloadonly

RHEL-6
[root@server ~]# yum install yum-plugin-downloadonly

2] Now use downloadonly plugin with following yum command.

[root@server ~]# yum install --downloadonly --downloaddir=<directory-path> <package-name>

3] Confirm the downloaded package in specified download directory.

Note: 
  • This is only applicable to "yum install" and not for "yum groupinstall" .
  • If you specified only package name then latest package will be downloaded, to download
  • specific package type full package name and version.
  • If you do not use --downloaddir option files are saved by default in /var/cache/yum/.
Second - use "yumdownloader" utility to download package

1] Install the yum-utils package which includes "yumdownloader" utility.

[root@server ~]# yum install yum-utils

2] Now use the following command with desired package name.

[root@server ~]# yumdownloader <package-name>

Note:
  • The package is saved in the current working directly by default; use the --destdir option to specify an alternate location.
  • Be sure to add --resolve if you need to download dependencies.

Monday, October 14, 2013

11 Tar Command Examples




1. Create tar Archive File
Following command will create a mytest.tar file for a directory "/home/anup/test".

[root@server ~]# tar -cvf mytest.tar /home/anup/test
Description of above options we have used to create .tar file.
c – Creates a new .tar archive file.
v – Verbosely show the .tar file progress.
f – File name type of the archive file. 

2. Create tar.gz Archive File 

To create tar.gz archive file we used option z. [Note: .tar.gz and .tgz both are similar]. 

[root@server ~]# tar -cvzf mytest.tar.gz /home/anup/test OR
[root@server ~]# tar -cvzf mytest.tgz /home/anup/test
3. Create tar.bz2 Archive File

To create highly compressed tar file we use option as j. [Note: tar.bz2 and tar.tbz is similar as tb2]

[root@server ~]# tar -cvjf mytest.tar.bz2 /home/anup/test OR

[root@server ~]# tar -cvjf mytest.tar.tbz /home/anup/test OR

[root@server ~]# tar -cvjf mytest.tar.tb2 /home/anup/test
 
4. Untar tar Archive File 

Untar files in Current Directory. 
[root@server ~]# tar -xvf mytest.tar

Untar files in specified Directory
[root@server ~]# tar -xvf mytest.tar -C /tmp/

5. Uncompress tar.gz Archive File

Following command will untar .tar.gz file at current location. If you want to untar in different directory then use -C option as we used in above command.

[root@server ~]# tar -xvf mytest.tar.gz

6. Uncompress tar.bz2 Archive File

[root@server ~]# tar -xvf mytest.tar.bz2

7. List Content of .tar / .tar.gz / .tar.bz2 Archive File

[root@server ~]# tar -tvf mytest.tar

[root@server ~]# tar -tvf mytest.tar.gz

[root@server ~]# tar -tvf mytest.tar.bz2

8. Untar Single file from .tar / .tar.gz / .tar.bz2 Archive File
 
[root@server ~]# tar -xvf mytest.tar test/mytextfile OR
[root@server ~]# tar -xvf --extract --file=mytest.tar test/mytextfile
 
[root@server ~]# tar -xvzf mytest.tar.gz test/mytextfile OR
[root@server ~]# tar -xvzf --extract --file=mytest.tar.gz test/mytextfile
 
[root@server ~]# tar -xvjf mytest.tar.bz2 test/mytextfile OR
[root@server ~]# tar -xvjf --extract --file=mytest.tar.bz2 test/mytextfile
 
9. Untar Multiple files from .tar, .tar.gz and .tar.bz2 Archive File
[root@server ~]# tar -xvf mytest.tar "test/mytextfile1" "test/mytextfile2”

[root@server ~]# tar -xvzf mytest.tar.gz "test/mytextfile1" 
"test/mytextfile2"
 
[root@server ~]# tar -xvjf mytest.tar.bz2 "test/mytextfile1" "test/mytextfile2"

10. Untar Single directory from .tar, .tar.gz and .tar.bz2 Archive File
 
[root@server ~]# tar -xvf mytest.tar test/directoryname

[root@server ~]# tar -xvf mytest.tar.gz test/directoryname

[root@server ~]# tar -xvf mytest.tar.bz2 test/directoryname

11. To see the content of a particular file in .tar / .tar.gz / .tar.bz2 archive without unzipping the contents
 
[root@server ~]# tar -xvf mytest.tar --to-command=cat test/mytextfile

[root@server ~]# tar -xvf mytest.tar.gz --to-command=cat test/mytextfile

[root@server ~]# tar -xvf mytest.tar.bz2 --to-command=cat test/mytextfile

Monday, September 30, 2013

Install and configure AWStats on CentOS and RHEL System

AWStats (Advanced Web Statistics) is a free powerful and featureful tool that generates advanced web (but also ftp or mail) server
statistics, graphically.

Following are the steps to configure AWStats on CentOS and RHEL system.

1] Download the awstats

[root@server ~]# wget http://sourceforge.net/projects/awstats/files/AWStats/7.0/awstats-7.0-1.noarch.rpm

2] Install awstats

[root@server ~]# rpm -ivh awstats-7.2-1.noarch.rpm
error: Failed dependencies:
    perl(LWP::UserAgent) is needed by awstats-7.2-1.noarch

If you receive above error then install below package :

[root@server ~]# yum install perl-libwww-perl.noarch

Now Again run the command :

[root@server ~]# rpm -ivh awstats-7.2-1.noarch.rpm
Preparing...             ############################## [100%]
   1:awstats              ############################## [100%]

----- AWStats 7.2 - Laurent Destailleur -----
AWStats files have been installed in /usr/local/awstats

If first install, follow instructions in documentation
(/usr/local/awstats/docs/index.html) to setup AWStats in 3 steps:
Step 1 : Install and Setup with awstats_configure.pl (or manually)
Step 2 : Build/Update Statistics with awstats.pl
Step 3 : Read Statistics

3] Now configure and setup AWstats with awstats_configure.pl

[root@server ~]# cd /usr/local/awstats/tools

[root@server tools]# perl awstats_configure.pl
----- AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).

-----> Running OS detected: Linux, BSD or Unix

-----> Check for web server install

Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
> /etc/httpd/conf/httpd.conf    --> Enter Apache configuration path

-----> Check and complete web server config file '/etc/httpd/conf/httpd.conf'
  Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
  Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"'
  Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'
  Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'
  Add '<Directory>' directive
  AWStats directives added to Apache config file.

-----> Update model config file '/etc/awstats/awstats.model.conf'
  File awstats.model.conf updated.

-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y

-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> www.anup.co.in                -->  Enter your website name

-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
>                               --> Press Enter

-----> Create config file '/etc/awstats/awstats.www.anup.co.in.conf'
 Config file /etc/awstats/awstats.www.anup.co.in.conf created.

-----> Restart Web server with '/sbin/service httpd restart'
Stopping httpd:                                            [  OK  ]
Starting httpd:                                             [  OK  ]

-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.anup.co.in
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue...


A SIMPLE config file has been created: /etc/awstats/awstats.www.anup.co.in.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.anup.co.in' with command:
> perl awstats.pl -update -config=www.anup.co.in
You can also read your statistics for 'www.anup.co.in' with URL:
> http://localhost/awstats/awstats.pl?config=www.anup.co.in

Press ENTER to finish...

4] Now update awstat

[root@server ~]# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update --config=www.anup.co.in
Error: AWStats database directory defined in config file by 'DirData' parameter (/var/lib/awstats) does not exist or is not writable.
Setup ('/etc/awstats/awstats.www.anup.co.in.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).

[root@server ~]# mkdir -p /var/lib/awstats

Now configure your website config file:

vi /etc/awstats/awstats.www.anup.co.in.conf

LogFile="/var/log/httpd/access_log"

and save the file.

Now Again run the command :

[root@server ~]# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update --config=www.anup.co.in

5] Add crontab entry to update awstat for every 15 minute.

[root@server ~]# crontab -e
15 * * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.www.anup.co.in

6] Now we configure apache file to enable http based authentication.

Open the httpd.conf file and following lines at the end of file.

[root@server ~]# vi /etc/httpd/conf/httpd.conf

<Directory "/usr/local/awstats/cgi-bin">
  Order allow,deny
  Allow from all
</Directory>

# This is to force authentication when trying to access /awstats

<Location /awstats>
AuthType Basic
AuthName "AWStats Admin Access Required"
AuthUserFile /etc/httpd/conf.d/awstats.passwd
require valid-user
</Location>

7] Set username and password for awstat link.

[root@server ~]# htpasswd -c  /etc/httpd/conf.d/awstats.passwd admin

8] Restart the httpd.

[root@server ~]# service httpd restart

That's it, access awstats url and check it.
http://localhost/awstats/awstats.pl?config=www.anup.co.in

Wednesday, July 17, 2013

How to configure Kickstart Server

Install & Configure PXE Boot Server with Kickstart

1] Install syslinux & tftp-server
[root@server ~]# yum install tftp-server

 2] Enable syslinux at boot time
[root@server ~]# vim /etc/xinetd.d/tftp
edit the line no. 14
disable = no
:wq

3] Start service
[root@server ~]# service xinetd start
[root@server ~]# chkconfig xientd on

4] Install FTP service
[root@server ~]# yum install vsftpd

5] Start vsftpd
[root@server ~]# service vsftpd start
[root@server ~]# chkconfig vsftpd on

6] Install syslinux, require boot loader
[root@server ~]# yum install syslinux

7] Copy the needed files from syslinux to the tftpboot directory
[root@server ~]# cp -rvp /usr/share/syslinux/{pxelinux.0,menu.c32,memdisk,mboot.c32,chain.c32} /var/lib/tftpboot/

8] Create the directory for your PXE menus
[root@server ~]# mkdir /var/lib/tftpboot/pxelinux.cfg

9] Create different directory for each PXE image
[root@server ~]# mkdir –p /var/lib/tftpboot/images/centos6

10] Mount CD/DVD and copy it to FTP public directory
[root@server ~]# mount /dev/cdrom /mnt
[root@server ~]# cp -rvp /mnt/* /var/ftp/pub/
[root@server ~]# umount /mnt

11] Copy vmlinuz and initrd.img from FTP public directory
[root@server ~]# cp -rvp /var/ftp/pub/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/images/centos6/

12] Instal DHCP server
[root@server ~]# yum install dhcp

13] Configure DHCP server. Add following lines to your /etc/dhcp/dhcpd.conf
[root@server ~]# vi /etc/dhcp/dhcpd.conf
option domain-name "anup.co.in";
option domain-name-servers 192.168.1.1;
default-lease-time 600;
max-lease-time 7200;

allow booting;
allow bootp;
next-server 192.168.1.1;
filename “/pxelinux.0”;

subnet 192.168.1.0 netmask 255.255.255.0 {
        range dynamic-bootp 192.168.1.100 192.168.1.200;
    option routers 192.168.1.1;
}

14] Start dhcp service
[root@server ~]# service dhcpd start
[root@server ~]# chkconfig dhcpd on

15] Create a menu for PXE server for os selection on PXE loading
[root@server ~]#  vi /var/lib/tftpboot/pxelinux.cfg/default

default menu.c32
prompt 0
timeout 50

MENU TITLE ANUP PXE Menu

LABEL CentOS 6.4 (Final)
MENU LABEL CentOS-6.4
KERNEL images/centos6/vmlinuz
append vga=normal initrd=images/centos6/initrd.img ramdisk_size=32768
ks=ftp://192.168.1.1/pub/ks.cfg

16] Now create KickStart file in FTP public directory
[root@server ~]# vi /var/ftp/pub/ks.cfg

#It starts the installation process
Install
#configure a connection to a FTP server to locate installation files
url --url ftp://192.168.1.1/pub/
#setup language and keyboard
lang en_US.UTF-8
keyboard us
#Get network info from DHCP server
network --device eth0 bootproto dhcp
#setup encrypted root password, you can take out the encrypted password from /etc/shadow file
rootpw --iscrypted $6$NF6F/Yng442eA8oL$c/sHM
#setup firewall and open ssh port 22
firewall --service=ssh
#sets up the Shadow Password Suite
#(--enableshadow), the SHA 512 bit encryption algorithm for password encryption
#(--passalgo=sha512), and authentication with any existing fingerprint reader.
authconfig --enableshadow --passalgo=sha512 --enablefingerprint
#The selinux directive can be set to --enforcing, --permissive, or --disabled
selinux --enforcing
#setup timezone
timezone America/Toronto
#The default bootloader is GRUB. It should normally be installed on the Master
#Boot Record (MBR) of a hard drive. You can include a --driveorder switch to specify
#the drive with the bootloader and an --append switch to specify commands for
#the kernel.
bootloader --location=mbr --driveorder=sda --append=”crashkernel=auto rhgb quiet”
#Clear the Master Boot Record
zerombr yes
#This directive clears all volumes on the sda hard drive. If it hasn’t been used before,
#--initlabel initializes that drive.
clearpart --all --drives=sda --initlabel
#Changes are required in the partition (part) directives that follow.
part /boot --fstype=ext4 --size=500
part / --fstype=ext4 --size=27500
part swap --size=1000
part /home --fstype=ext4 --size=1000
#reboot machine
reboot
#skip answers to the First Boot process
firstboot --disable

 Test the PXE server:
* Make changes in the BIOS settings and boot client machine from network. OR just press F12 to boot from network.

Saturday, July 13, 2013

Install and Configure NRPE in CentOS

 Install NRPE on Linux


NRPE is called as ‘Nagios Remote Plugin Executere’. NRPE allows nagios server
to remotely execute nagios commands or plugins on other Linux/Unix machines. NRPE is also available windows servers.
Following document shows you how to install NRPE, I am installing it on CentOS 6.4

1] Install NRPE required packages.

[root@server ~]# yum install openssl-devel gcc xinetd make

2] NRPE runs under the user "nagios", so let's add that user.

[root@server ~]# useradd nagios

3] Download and install Nagios-plugins.

[root@server downloads]# wget https://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz

[root@server downloads]# tar -xvzf nagios-plugins-2.0.tar.gz

[root@server downloads]# cd nagios-plugins-2.0

[root@server nagios-plugins-2.0]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

[root@server nagios-plugins-2.0]# make install

4] Assign nagios user ownership to nagios commands.

[root@server nagios-plugins-2.0]# chown -R nagios:nagios /usr/local/nagios/libexec


5] Install and configure NRPE nagios client.

[root@server downloads]# wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz?r=&ts=1363788540&use_mirror=hivelocity

[root@server downloads]# tar -xvzf nrpe-2.15.tar.gz

[root@server downloads]# cd nrpe-2.15.tar.gz

[root@server downloads]# ./configure --enable-ssl

[root@server nrpe-2.15]# make all

[root@server nrpe-2.15]# make install-plugin

[root@server nrpe-2.15]# make install-daemon

[root@server nrpe-2.15]# make install-daemon-config

[root@server nrpe-2.15]# make install-xinetd

6] Add following line at the end of file for NRPE in /etc/services

[root@server ~]# vi /etc/services
nrpe            5666/tcp                # NRPE

7] NRPE will run under xinetd daemon. So update xinetd file.

[root@server ~]# vi /etc/xinetd.d/nrpe

# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
        flags           = REUSE
        socket_type     = stream
        port             = 5666
        wait            = no
        user            = nagios
        group           = nagios
        server          = /usr/local/nagios/bin/nrpe
        server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
        log_on_failure  += USERID
        disable         = no
        only_from       = 127.0.0.1 192.168.1.1 --> [ Your Nagios Server IP ]
}

8] Star/Restart xinetd service.

[root@server ~]# service xinetd start

[root@server ~]# chkconfig xinetd on

Friday, April 19, 2013

Install RED5 server on Linux


Install RED5 server on Linux

Following blog post will describe how to install RED5 server on Centos 5.7 (Final)

Red5 Working :

Red5 server converts the video file to the flash file and we everyone knows that flash files play instantly once someone accesses it. Here when we request or select a particular video, the video script will send the video(stream the video) to red5 server. Red5 will convert the video file to flash and sends the output to the video script to display on the browser. Lot of video scripts are being used now a days like dolphin, videowhisper etc for the site. You can configure the admin panel using the server's IP and port details.

Installation Steps:

1. Download and Install Java:
Red5 is a JAVA server. So install Java using yum.

[root@server ~]# yum -y install java-1.6.0-openjdk java-1.6.0-openjdk-devel

2. Install SVN:
SVN will required to fetch latest release of RED5 source from SVN repository at Google Code.

[root@server ~]# yum install subversion

3. Download and Install Ant & Ivy:
Ant will need to compile RED5 server code. Ant comes in binary form, so just download and install it in /usr/local directory.
First off let’s change to another directory.

[root@server ~]# cd /usr/src
[root@server src]# wget http://archive.apache.org/dist/ant/binaries/apache-ant-1.8.2-bin.tar.bz2
[root@server src]# tar jxvf apache-ant-1.8.2-bin.tar.bz2
[root@server src]# mv apache-ant-1.8.2 /usr/local/ant

[root@server src]# svn co https://svn.apache.org/repos/asf/ant/ivy/core/trunk ivy
[root@server src]# cd ivy
[root@server src]# /usr/local/ant/bin/ant jar
[root@server src]# cp build/artifact/jars/ivy.jar /usr/local/ant/lib/

4. Export Variables for Ant and Java:
So now we have JAVA installed, and ANT is in place. We need to make sure there are some environment variables set. These are global variables with paths to different binaries or applications. ANT and JAVA will need those.

[root@server src]# export ANT_HOME=/usr/local/ant
[root@server src]# export JAVA_HOME=/usr/lib/jvm/java
[root@server src]# export PATH=$PATH:/usr/local/ant/bin

5. Actually Installing the RED5 Server:
Source:
Let’s get the RED5 source:

[root@server src]# svn co http://red5.googlecode.com/svn/java/server/tags/1_0/ red5

This will fetch the complete Red5 source and save it in a new folder called, red5 (so in /usr/src/red5)

Now that we have the source, let’s move it to /usr/local/ using

[root@server src]# mv red5 /usr/local/
[root@server src]# cd /usr/local/red5

This is the folder where all the source files reside. From here on, we prepare and build the red5 source.

[root@server red5]# /usr/local/ant/bin/ant prepare
[root@server red5]# /usr/local/ant/bin/ant dist

Wait for few minutes to . After a few minutes you should end up with the last line in your terminal window looking like this:

BUILD SUCCESSFUL

This means that you now have a working RED5 build!

Copy the conf directory from the dist folder to the current directory and test the red5 installation.

[root@server red5]# cp -r dist/conf .
[root@server red5]# ./red5.sh

Make sure your server is actually running, you should be able to see the webroot of Red5 when hitting your server at port 5080 (http://yourserver.com:5080)

Note : That the server is currently only running as long as you keep that terminal window open. Once you close it RED5 stops running. Let’s make sure RED5 can run on its own from now on. Hit CTRL+C to stop the process.

6. Init Script:
Now we will create init script for red5 to start, stop and restart easily.

[root@server ~]# vi /etc/init.d/red5 [Enter the following script into vi.]
#!/bin/sh
# For RedHat and cousins:
# chkconfig: 2345 85 85
# description: Red5 flash streaming server
# processname: red5

PROG=red5
RED5_HOME=/usr/local/red5
DAEMON=$RED5_HOME/$PROG.sh
PIDFILE=/var/run/$PROG.pid

# Source function library
. /etc/rc.d/init.d/functions

[ -r /etc/sysconfig/red5 ] && . /etc/sysconfig/red5

RETVAL=0

case "$1" in
start)
echo -n $”Starting $PROG: ”
cd $RED5_HOME
$DAEMON >/dev/null 2>/dev/null &
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo $! > $PIDFILE
touch /var/lock/subsys/$PROG

fi
[ $RETVAL -eq 0 ] && success $”$PROG startup” || failure $”$PROG startup”
echo
;;
stop)
echo -n $”Shutting down $PROG: ”
killproc -p $PIDFILE
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$PROG
;;
restart)
$0 stop
$0 start
;;
status)
status $PROG -p $PIDFILE
RETVAL=$?
;;
*)
echo $”Usage: $0 {start|stop|restart|status}”
RETVAL=1
esac

exit $RETVAL

7. Assign execute permission to red5 script.

[root@server ~]# chmod +x /etc/init.d/red5

8. Now start the service

[root@server ~]# service red5 start OR /etc/init.d/red5 start
9. To start RED5 when the server boots.

[root@server ~]# chkconfig --add red5
[root@server ~]# chkconfig red5 on

10. To Install RED5 demos

[root@server ~]# cd /usr/local/red5/webapps/root
[root@server root]# svn checkout http://red5.googlecode.com/svn/java/server/tags/0_9_1/webapps/root/demos/

11. Test

Now test the RED5 installation by opening following URL in browser.

http://yourserverip:5080/

Friday, March 29, 2013

Script to find out Linux Hardware Information


How to get Hardware Information on Linux

Simple script to find out Linux Hardware Information.

exec > /root/hard_info 2>&1
date
echo "Motherboard Model Number"
dmidecode -t baseboard | grep 'Product Name'
echo "===================================="
echo "Processor Information"
dmidecode -t processor | grep 'Socket Designation\|Version:'
echo "===================================="
echo "Memory Type & Size"
dmidecode -t memory | grep 'Type\|Size' | grep -v 'Type Detail\|Error Correction Type'
echo "===================================="
echo "Total Memory"
free -t -m
echo "===================================="
echo "Hard Drive's of Machine"
fdisk -l | grep 'Disk /dev/s'
echo "===================================="
echo "Serial Number of /dev/sda"
hdparm -I /dev/sda | grep 'Model Number:\|Serial Number'
echo "===================================="
echo "Serial Number of /dev/sdb"
hdparm -I /dev/sdb | grep 'Model Number:\|Serial Number'
echo "===================================="