Showing posts with label LINUX. Show all posts
Showing posts with label LINUX. Show all posts

Monday, December 16, 2013

Install Packages via yum using CentOS Media repo

when need to install new packages using yum, you can use either online repo or dvd repo. If there is no internet connection, possible solution is DVD repo. Here is simple way to configure DVD repo on Centos.

1) View Centos media repo file.

Since I use Centos 6.3 it is similar to following.you can use either less or cat command to view the file content. Some  lines are removed due to brevity

less /etc/yum.repos.d/CentOS-Media.repo
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
        file:///media/cdrom/
        file:///media/cdrecorder/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


give more attention to following parameters
repo name -> c6-media
baseurl -> there is 3 file paths, those are the mount point of Centos DVD. you can customize it.




2) Create mount point if not exist

since this is demo, I create DVD mount location as first base URL. possible use any location which is defined in baseurl.
[root@localhost ~]# mkdir /media/CentOS


3) mount centos cdrom

mount /dev/cdrom /media/CentOS/

4)Install your package using yum

yum --disablerepo=\* --enablerepo=[repo name] install [pakage name]

ex:-
yum --disablerepo=\* --enablerepo=c6-media install cpan

if this is not working, you may need to clean repo using following command
[root@localhost ~]# yum clean all

Sunday, November 17, 2013

Installing vpnc - Linux VPN Client for Cisco VPN

This tutorial, I will show you how to configure vpnc on Linux and  connect  Cisco devices through vpn using pcf file. The vpnc is an alternative Linux software for Cisco vpn client.
all the things are done on centos 6.3 but steps should be same for any Linux system.


1) Installing EPEL repo

Since centos repo doesn't contain the vpnc, we need to configure additional repo call EPEL.
It is straightforward installation and  document can be found form here.

http://fedoraproject.org/wiki/EPEL/FAQ#How_can_I_install_the_packages_from_the_EPEL_software_repository.3F

Please find "How can I install the packages from the EPEL software repository? " from content and install it. you may need to enable EPEL repo sometime.

2) Installing vpnc

once you enabled the rpmforge repo, type following command to install vpnc  
[root@localhost ~]#yum install vpnc

3)Chang folder permission

I installed the vpnc as root.if you wish to run vpnc as normal user other than root .change file permission of vpnc installaion directory
/etc/vpnc/vpnc-script

4)Download pcf2vpnc

[root@localhost ~]#wget http://svn.unix-ag.uni-kl.de/vpnc/trunk/pcf2vpnc

5)Convert pcf file

[root@localhost ~]#perl pcf2vpnc demopcf.pcf demovpnc.conf
change ownership of *.conf file if you need

6)copy *.conf to /etc/vpnc/ 

[root@localhost ~]#cp demovpnc.conf /etc/vpnc/

7)Start vpnc

[root@localhost ~]#vpnc demovpnc
Enter password for user@A.B.C.D:
(A.B.C.D is public ip address where you need to connect, user is username , you need to enter password )

8)disconnect vpnc

[root@localhost ~]#vpnc-disconnect

Sunday, October 27, 2013

nagios snmptt configuration

Hi folks after long time !. Today I'm going to demonstrate how to configure SNMP trap inside Nagios using SNMPTT. This simulation is done at Virtualbox 4.1.26 using two guest OS ( one guest act as server and running Nagios and snmptt, other is to generate SNMP trap and it is the client)

both guest are running Centos 6.3 32bit.

Server info :- ip 192.168.56.103
Client info :- 1p 192.168.56.104

I hope you have installed and configured the Nagios, If not you can follow installation guide
http://nagios.sourceforge.net/docs/nagioscore/4/en/quickstart-fedora.html

-----

So let's install snmptt. :)
download and extract latest version of SNMPTT. you can find official installation document from here
http://www.snmptt.org/docs/snmptt.shtml#Installation-Overview

For both server and client require net-snmp-lib , net-snmp-util so install them using using yum
yum install net-snmp-lib
yum install net-snmp-util


AT Server


1)Install prerequirement such as net-snmp, perl ,perl modules


[root@nagios ~]# yum install net-snmp
[root@nagios ~]# yum install perl

install perl cpan
[root@nagios ~]# yum install perl-CPAN

launch the CPAN using following command
[root@nagios ~]# perl -MCPAN -e shell

install following perlmodules 
(Getopt::Long,  Text::ParseWords ,SNMP, Config::IniFiles, Time::HiRes , Sys::Hostname , File::Basename, Text::Balanced )
for an instance
cpan[1]> install Text::ParseWords


This demonstration is done with Standard handler – with standlone mode which is straightforward (remember there is daemon mode)


2) Copy snmptt to /usr/sbin/ and ensure it is executable (chmod +x snmptt)

[root@nagios snmptt_1.3]# cp s[root@nagios snmptt_1.3]# chmod +x /usr/sbin/snmptt nmptt /usr/sbin/

3) Copy snmptthandler to /usr/sbin/ and ensure it is executable (chmod +x snmptthandler)

[root@nagios snmptt_1.3]# cp snmptthandler /usr/sbin/
[root@nagios snmptt_1.3]# chmod +x /usr/sbin/snmptthandler

4) Copy snmptt.ini to /etc/snmp/ or /etc/ and edit the options inside the file.

[root@nagios snmptt_1.3]# cp snmptt.ini /etc/snmp/

5) Create the log folder /var/log/snmptt/.

[root@nagios snmptt_1.3]# mkdir -p /var/log/snmptt/


6) For standlone mode:  Modify the Net-SNMP snmptrapd.conf file by adding the following line:

[root@nagios ~]# vim /etc/snmp/snmptrapd.conf
traphandle default /usr/sbin/snmptt
disableAuthorization yes

7) Edit the /etc/logrotate.d/snmptt and update the paths and rotate frequency as needed.

[root@nagios snmptt_1.3]# cp snmptt.logrotate /etc/logrotate.d/snmptt


8) Start snmptrapd using the command line:  snmptrapd -On.

[root@nagios snmptt_1.3]# snmptrapd –On

--

9) Convert MIB file


Copy eventhandler
[root@nagios ~]# cp /home/shehan/Downloads/nagios-4.0.1/contrib/eventhandlers/* /usr/local/nagios/libexec/eventhandlers

copy snmpttconvertmib into /usr/sbin/ folder
[root@nagios ~]# cp /home/shehan/Downloads/snmptt_1.3/snmpttconvertmib /usr/sbin/

then issue below command
[root@nagios ~]#snmpttconvertmib --in=/usr/share/snmp/mibs/SNMPv2-MIB.txt --out=/etc/snmp/snmptt.conf.SNMPv2-MIB \
--exec='/usr/local/nagios/libexec/eventhandlers/submit_check_result $r TRAP 1'


10) Edit /etc/snmp/snmptt.ini, and change below settings

[General]
mode = standalone
net_snmp_perl_enable = 1
unknown_trap_log_enable = 1

At end of file you can find line similar to this Add /etc/snmp/snmptt.conf.NET-SNMP-EXAMPLES-MIB like below

snmptt_conf_files = <<END
/etc/snmp/snmptt.conf
/etc/snmp/snmptt.conf.NET-SNMP-EXAMPLES-MIB
END


11) create host cfg file

[root@nagios ~]# vim /usr/local/nagios/etc/objects/remote-host.cfg
And add below (you may need to change ip host_name)


define host {
        use     linux-server
        host_name       remote-host
        alias           remote-host-alias
        address         192.168.56.104
        }

define service{
        use                        generic-service
        name                       trap-service
        register                   0
        service_description        TRAP
        is_volatile                1
        check_command              check-host-alive
        max_check_attempts         1
        normal_check_interval      1
        retry_check_interval       1
        notification_interval      31536000
        active_checks_enabled      0
        passive_checks_enabled     1
    check_period           24x7
        }

define service{
        use                        trap-service
        host_name                  remote-host
        }



12) Add blow command to nagios.cfg

[root@nagios ~]# vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/remote-host.cfg


13)allow snmp trap from firewall

[root@nagios ~]# iptables -I INPUT 1 -p udp --dport snmptrap -j ACCEPT

confirm the changes and then save using below command
[root@nagios ~]# iptabless –list
[root@nagios ~]# service iptables save

14) start service at server

[root@nagios ~]# service snmptrapd start
[root@nagios ~]# service snmpd start

configure to start at boot
[root@nagios ~]#chkconfig snmptrapd on
[root@nagios ~]#chkconfig snmpd on


AT Client,

generate SNMP trap message, this is SNMP v2 message

[root@localhost ~]# snmptrap -v 2c -c public 192.168.56.101 "" SNMPv2-MIB::coldStart coldStart  s "start"


AT Server


check below log messages
/var/log/messages
/var/log/snmptt/snmptt.log
And check nagios web interface.If everything works fine you can have similar output like below


nagios and  snmptt








----


Reference URLS

http://xavier.dusart.free.fr/nagios/en/snmptraps.html
http://hummy.wikidot.com/how-to-send-and-receive-snmp-traps
http://socketubs.org/docs/sysadmin/snmp_traps_nagios.html


Friday, March 8, 2013

sharing folders using nfs on rhel

This tutorial guide you how to configure nfs share on rhel system.
Below is the details of nfs Server and client, both running Redhat enterprise Linux 6.2 64-bit

NFS Server :- host-name is server and ip address is 192.168.5.5/24
NFS Client :-  host-name is client and ip address is  192.168.5.3/24

NFS Server Configuration

[1]  Edit /etc/sysconfig/nfs

 To allow nfs traffic , should need to uncomment following variable LOCKD_TCPPORT ,LOCKD_UDPPORT, MOUNTD_PORT,  STATD_PORT on /etc/sysconfig/nfs as following


# TCP port rpc.lockd should listen on.

LOCKD_TCPPORT=32803



# UDP port rpc.lockd should listen on.

LOCKD_UDPPORT=32769



# Port rpc.mountd should listen on.

MOUNTD_PORT=892



# Port rpc.statd should listen on.

STATD_PORT=662



[2] Configure Firewall to allow nfs traffic .


TCP port 2049 for NFS.
TCP and UDP port 111 (rpcbind/sunrpc).

So let's edit the iptables file
[root@server ~]# vim /etc/sysconfig/iptables

By default this file contain few rules . Find following rule 
-A INPUT -j REJECT --reject-with icmp-host-prohibited
and insert bellow rules before that line

-A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT

-A INPUT -m state --state NEW -m udp -p udp --dport 111 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 32803 -j ACCEPT

-A INPUT -m state --state NEW -m udp -p udp --dport 32769 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 892 -j ACCEPT

-A INPUT -m state --state NEW -m udp -p udp --dport 892 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 662 -j ACCEPT

-A INPUT -m state --state NEW -m udp -p udp --dport 662 -j ACCEPT


save and quit the iptabales file, then issue follwing command apply the new rules to system
[root@server ~]# service iptables restart

you can verify it by using following command
[root@server ~]#iptables -L


[3] Create a direcory to share with client


my share folder is /svrfile and i have assigned 
rwx (read write execute) permission for ugo (user group others).
[root@server ~]# mkdir /svrfile
[root@server ~]# chmod 777 /svrfile

[4] Edit exports file

[root@server ~]# vim  /etc/exports
and insert following line

/svrfile 192.168.5.3(rw,sync,no_root_squash)


192.168.5.3 is nfs client where i'm going share /svrfile . you can specify client host as  192.168.5.3/24
however /24 is default for class C network. If you wish to share with any host you can use '*' (without qutoes) instead of ipaddress.
Several parameters are available.I used rw,sync and no_root_squash . here is brief explanation.

rw :- enable read write
sync :-  Syncs write operations on request. Active by default
no_root_squash :- Treat remote root user as local root; remote root users get root privileges
on the shared directory

[5] restart rpcbind and nfs 

By default RHEL system is installed this services , If it is not you should have
to install .

[root@server ~]# service rpcbind restart

Stopping rpcbind:                                          [  OK  ]

Starting rpcbind:                                          [  OK  ]

[root@server ~]# 



[root@server ~]# 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  ]

[root@server ~]#



[6] refresh the export file


[root@server ~]# exportfs -r
if it is successful , no message will be displayed
please remember to refresh export file by issuing above command, If you are done any modification to export file.

further you can verify export file using following commands

[root@server ~]# exportfs -rv
exporting 192.168.5.3:/svrfile
[root@server ~]# 


[root@server ~]# showmount -e
Export list for server:
/svrfile 192.168.5.3
[root@server ~]#




NFS Client configuration


[7] enable services and create folder on client

we are done with NFS server configuration , so lets configure client, first of all create directory to share with server and then restart rpcbind and nfs services.

[root@client ~]# mkdir /clientfile

[root@client ~]# service rpcbind restart
[root@client ~]# service nfs restart


[8] Finally let's mount the nfs

[root@client ~]#mount -t nfs 192.168.5.3:/svrfile /clientfile



That's all , Don't hesitate to comment if you have question . have a nice day  !

Wednesday, February 6, 2013

Fixed Missing eth0 after creating a clone vm on linux kvm

Recently I have created a cloned virtual machine using redhat linux kvm, once the system is booted up
virtual machine  was unable to connect to system eth0 instead it's connected to Auto eth0 interface as below,
after doing some google search and reading some forums I have found a reason for this error.
this is due to cloned VM is using original VM mac address. in this tutorial I'm going to
show you how i solved that problem



Auto eth0 on kvm cloned virtual machine



















1) Edit ifcfg-eth0

go to /etc/sysconfig/network-scropts/ifcfg-eth0
and remove or comment the HWADDR line as following



ifcfg-eth0



if you want check newly cloned vm NIC mac address pls follow this steps
select guest os click edit  -->  virtual machine details --> show virtual hardware detils -->
select NIC --> view the mac adds.


2) Remove 70-persistent-net.rules

 command is  #rm /etc/udev/rules.d/70-persistent-net.rules
you may have different name for persistent-net file

persistent-net.rules







3)Reboot the system

 now system eth0 should be available also there should be new persistent-net.rules file with actual NIC mac address of cloned vm.


Friday, January 25, 2013

virtualbox seamless mouse pointer integration and install guest additions

While running the Redhat linux on Virtual box, every time when I want to leave from
guest OS to host system I need to press "Ctrl" key (my Host key is Ctrl) .This is because seamless mouse pointer integration is not enable. This is painful and takes time to jump between guest OS and host system. After reading some forums post and web articles I have come across with a solution.In this method there will be one mouse pointer and pressing the Host key is no longer required to "free" the mouse from being captured by the guest OS and vice-versa. Following steps guide how to enable seamless mouse support on linux based guest system.


[1] install gcc and kernel-devel

install the GNU C compiler and the kernel development packages using

#yum install gcc

followed by

#yum install kernel-devel


[2] Reboot guest system

Reboot your guest system in order to activate the updates.

[3]Install Guest Additions

Click "Devices" --> "Install Guest Additions"




install guest additions

















[4] Follow the installation wizard
you will get window similar to below and click "OK" , you may need provide authentication




VBOXADDITIONS





















[5] It will be prompted with terminal window similar to following, Press Return and close that window... that's all , Now seamless mouse integration should be enabled . have a nice day!




virtualbox guest additions installation














Friday, December 14, 2012

How to set a crontab job for a perl script

In this tutorial I’m going describe how to set a crontab job for perl script on a linux system. The following example I'm going to demonstrate, how to  execute perl script every five minutes. below is the steps


[1] list the existing crontab using following command. If you have not set any crontab jobs it will display noting.
[shehan@localhost ~]$ crontab -l



crontab job





[2] issue following command to create a new crontab or edit previously created crontab 
[shehan@localhost ~]$ crontab -e


[3] add following line of code to crontab and don't forget to edit your perl script path.
*/5 means script will be executed every 5 minutes time , for ex :- 10.00 , 10.05 , 10.10 etc

*/5 * * * * perl /path/to/your/perlscript/yourscript.pl


some tricky example
3-58/5 * * * * perl /path/to/your/perlscript/yourscript.pl

This would still execute perl script every five minutes, but it would run on the 3's and 8's - e.g. 12:03, 12:08, 12:13, 12:18, etc.


[4]that's it !



5MYZXMQCKJN5

How To Install Perl Modules Manually on linux


I  recently try out  perl script which is used to test download speed. when I run that script it gives me the following error saying that can’t locate Perl module called Time::Format .

Can't locate Time/Format.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 ... )....


Can't locate Time/Format.pm in @INC






Solution for this error is install the perl module, in this case by installing the Time::Format perl module. below is most required steps to install any perl module.


[1] switch to root and launch the CPAN using following command
 [root@localhost ~]# perl -MCPAN -e shell


[2] type the module name according to below format, in this example I’m going to install Time::Format perl module.
cpan[1]> install Time::Format


[3] that’s all !! . now run your perl script again :)

Friday, November 30, 2012

How to install Redhat enterprise linux from usb drive

Installing Redhat Linux from DVD is not a huge task unless not going to customize for advance installation. However if you do same using USB drive ,you have some extra work to do. First time when I installed the Redhat Linux through USB drive I faced so many difficulties, so in this tutorial I'm going describe how I avoid those obstacle to made successful installation.

1) download and install "linux live usb creator" from this link http://www.linuxliveusb.com/

2) format the USB drive with FAT32. open that application and follow the steps mention on that application to create bootable usb drive. it's better un-tick the "Hide created file on key" from options. it will helpful to view all created files on the USB later.
you can test the USB using "mobalivecd" application. link is http://mobalivecd.mobatek.net

3) I have faced the following error message in the middle of the installation

  Missing ISO 9660 Image

  The installer has tried to mount image #1, but cannot find it
  on the hard drive.
  Please copy this image to the drive and click Retry. Click
  Exit to abort the installation.

4) Solution for that error message is putting a redhat iso image into the USB drive.this is crazy but it's only solution i have found so far and it's worked :) .

   
rhel 6

















5) Restart your pc and change boot method to USB

6) Follow Redhat installation steps. after you select the "install or upgrade an existing system" from the menu.
you may get a blinking cursor screen for 10 to 15 mins.pls be patient :-) .

7) Select "Language " , "key borad" according to your preference. once you got the "Redhat installation method" screen make sure to select "Hard drive"



Redhat Linux Installation Method



















8) Click "ok" and then you get an screen similar to the following
 it will display all devices connected to your pc. for an example

/dev/sda1   <-- hard disk partition 1
/dev/sda2   <-- hard disk partition 2
/dev/sdb1   <-- USB drive

select your usb device.it's depend on your system , according to above example it is /dev/sdb1 . and click "Ok" to continue.

select partition holds the installation image for red hat linux




















9) Follow rest of the steps, and install the Redhat Linux !.



Wednesday, October 31, 2012

how to add dvd based repository in rhel 6

Problem :- yum install [package..]    gives an error message similar to the following

[root@localhost ~]# yum install gcc
Loaded plugins: product-id, refresh-packagekit, subscription-manager
Updating Red Hat repositories.
...(output ommited)
...
No package gcc available   <-- here i'm try to install pacakage called 'gcc'
Error: Nothing to do
[root@localhost ~]#

reason is we do not have access to RHN

Solution :- use DVD as base repository

[1]switch to the root

[shehan@localhost ~]$ su -
Password:
[root@localhost ~]#

[2]Create DVD based repo

[root@localhost ~]# vim /etc/yum.repos.d/iso.repo

Following text should be added to above file (iso.repo)

[base]
name=CDROM
baseurl=file:///mnt/cd/Server
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

DVD based repository rhel 6







[3]mount installation DVD
make a directory called /mnt/cd and it should be similar to baseurl

[root@localhost ~]# mkdir /mnt/cd
[root@localhost ~]# mount /dev/cdrom /mnt/cd

[4]now try previous command again. it should work !
[root@localhost ~]# yum install gcc


---
tips :- How to  mount iso image ??
baseurl of  " iso.repo " file  should be changed as
file://mnt/iso/Server     ( I created /mnt/iso directory)

mount command is
mount -o loop /home/shehan/redhatiso/h-rel62x6.iso /mnt/iso



Related Posts