Categories

Thursday, 21 November 2013

No module named yum

Hi ,


I got an error as below on running the command on a centos 6.3  server.




There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   No module named yum

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
2.7.3 (default, May 15 2012, 17:45:42)
[GCC 4.4.4 20100726 (Red Hat 4.4.4-13)]

If you cannot solve this problem yourself, please go to
the yum faq at:
  http://yum.baseurl.org/wiki/Faq




Some one installed installed  a new version of python for running eclypse on the machine and the system python package corrupted due to it, thereby corrupting the yum package.



Below is the steps I have done to fix it.


1)I checked the system location of python which is /usr/bin/python which is version 2.6


/usr/bin/python --version


2) I ran the command "rpm -V python" which will verify all the system packages and will report any error happened to them.


I got error as


Missing /usr/lib64/python2.6.6/*


That is all the system folder for python was some how deleted .




I have to recreate that folder for yum to work


3) I checked one of the identical server where /usr/lib64/python2.6.6 exists and then copied that folder to the other machine where folder is missing.  
The above step saved my time. Otherwise I need to reinstall the python 2.6.6 from centos repository



 cd /usr/lib64
 scp -r python2.6/ root@10.11.16.145:/usr/lib64/

But still I got one error as below


AttributeError: 'YumBaseCli' object has no attribute '_not_found_i'

 It seems that some file system atributes is still having issues. So I had to reinstall the current version of yum

First check the version of yum installed on the machine 

rpm -q yum
yum-3.2.29-40.el6.centos.noarch

Now download the same version of yum "yum-3.2.29-40.el6.centos.noarch"


wget http://mirror.centos.org/centos/6/os/i386/Packages/yum-3.2.29-40.el6.centos.noarch.rpm


Then reinstall it using the command  


rpm -ivh --replacepkgs yum-3.2.29-40.el6.centos.noarch.rpm

 
And now yum worked with out any issues .




Cheers
Syamkumar.M

Thursday, 3 October 2013

Change Postgresql Data Directory

Hi,

Currently there was some disk issue on our server in which some script is importing huge amount of data on the postgresql datbases which filled up the disk space on the machine and stopped all the services .

/ had only 20 GB of disk space .

Postgresql is installed in the directory  /var/lib/pgsql/9.3/data for the postgresql version9.3 . The configuration file of postgresql is postgresql.conf, log files and all other important files are located in that directory

As /var is not a seperate partition, the data directory got filled and which inturn filled up the / partition.

So we need to either change the data directory to /attached which had almost 5 TB of disk space.

Changing the data directory of postgresql seems to be tedious task.

One work around for that issue is to move the data directory /var/lib/pgsql/9.3/data to /data and then create a symlink to /attached/data.

Below is the procedure for it

1) First stop the postgresql service
2)move the data directory to /attached by using the command

mv /var/lib/pgsql/9.3/data /attached

3)now create a sym link to /attached/data from /var/lib/pgsql/9.3/

ln -s /attached/data /var/lib/pgsql/9.3/data

So now the postgresql will check the configuration files and datas inside the same folder /var/lib/pgsql/9.3/data , but it is symlinked to /attached/data. So the actual files will store in /attached/data and won't fill  up /.

4)Restart the postgresql service

/etc/init.d/postgresql-9.3 start

5)Test if it is working perfectly.

su - postgres
-bash-4.1$ ll
total 4
drwx------. 3 postgres postgres 4096 Oct  3 04:31 9.3
-bash-4.1$ psql
psql (9.3rc1)
Type "help" for help.

postgres=# show data_directory ;
     data_directory    
-------------------------
 /var/lib/pgsql/9.3/data
(1 row)

postgres=#



Cheers
Syamkumar.M


Tuesday, 1 October 2013

MTS Data Card Installation in ubuntu 12.04

Hi,

For configuring the MTS Mblaze Datacard on ubuntu, Please do the following steps.

1)First install the service wvdial.

sudo apt-get install wvdial


2) Then create a configuration file /etc/wvdial.conf and add the following configurations on it.

[Dialer mts]
Stupid Mode = 1 
Inherits = Modem0 
Password = mts 
Username = internet@internet.mtsindia.in 
Phone = #777 
[Modem0] 
Init1 = ATZ 
SetVolume = 0 
Modem = /dev/ttyUSB0 
Baud = 115200 
FlowControl = Hardware (CRTSCTS) 
Dial Command = ATDT 
  
3) After this just plugin the the MTS data card on the ubuntu machine. The data card will be automatically detected on the ubuntu machine.

After this run the following command

  sudo wvdial mts


 --> WvDial: Internet dialer version 1.61
--> Initializing modem.
--> Sending: ATZ
OK
--> Modem initialized.
--> Sending: ATDT#777
--> Waiting for carrier.
ATDT#777
CONNECT 3100000
--> Carrier detected.  Starting PPP immediately.
--> Starting pppd at Tue Oct  1 21:21:48 2013
--> Pid of pppd: 8718
--> Using interface ppp0
--> local  IP address 116.202.128.90
--> remote IP address 10.228.138.3
--> primary   DNS address 10.228.129.113
--> secondary DNS address 10.228.129.114








Now you will be able to connect to the machine.



Also you can configure it on the Network Manager. For this do the following steps.

1)Click on the Connections Tab on the right side of your desktop.
2)Click on Edit Connections on the bottom
3)Go to the Mobile Broad Band Tab
4)Click on Add connections and give the necessary details 
5)Select the provider as MTS Mblaze and then add
6)Give any connection name

Then on the Mobile Broad Band settings Add the following

Number - #777
username - internet@internet.mtsindia.in
password - mts

Save it and then connect it after you plugged in the Data Card





.

Unable to connect to remote host: No route to host for postgresql

Hi,

When trying to connect to an postgresql database from outside, you may get the error as below " Unable to connect to remote host: No route to host for postgresql"

Here Iam using the postgresql version 9.3
Steps to check

1) First check the iptables rules on the server. If there is any unusual logs then flush it or try after stopping the iptables service using the command

/etc/init.d/iptables stop

2)Even after this if you are still unable to connect to the postgresql server, then do check the following

The postgresql default data directory in linux is   /var/lib/pgsql/9.3/data/

The configuration file for the service is postgresql.conf.

Open that file and search for the option  listen_addresses and make it to listen on all of the interfaces or IPs on that machine as below.

 listen_addresses = '*'

Now exit the configuration file after saving it.

3)Then go the configuration file  pg_hba.conf in the data directory /var/lib/pgsql/9.3/data/

This file controls the connection information of postgresql.

Open that file  and edit the configuration options as below

# IPv4 local connections:
host    all         all         127.0.0.1/32          trust
host    all             all             192.168.0.0/16            trust
# IPv6 local connections:

Above configuration will make the postgresql to listen on all hosts with the subnet range 192.168.0.0/16 . So add it based on your requirement.

Now save the file and then restart the postgresql database using the below command.

/etc/init.d/postgresql restart

Now try to connect to the database.

Also check for any startup errors on the log file /var/lib/pgsql/9.3/pgstartup.log


Regards
Syamkumar.M




Monday, 30 September 2013

message from server: "Host 'xxx' is not allowed to connect to this MySQL server"

Hi,

If you got the error while trying to import some thing as root to the mysql database as below

Host 'xxx' is not allowed to connect to this MySQL server"

The issue is that the root user of mysql has no privileges on all host names on the local database machine,

To resolve the issue do the following

Login to mysql

mysql -u root -pxxxxx

Select the database mysql

mysql> use mysql

And run the command as below

 GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'PASSWORD'

mysql> flush privileges;


and quit. Now you should be able to login as any hostname on the mysql machine.


Regards
Syamkumar.M





Sunday, 29 September 2013

Nagios Event Handler configuration

Hi,

 Event Handler is one of the configuration options on the Nagios server monitoring tools to take an action if a state has been changed on a particular service or host. An obvious use for event handlers (especially with services) is the ability for Nagios to proactively fix problems before anyone is notified.

Types of event Handlers
----------------------------------------

There are two main types of event handlers than can be defined - service event handlers and host event handlers. Event handler commands are (optionally) defined in each host and service definition. Because these event handlers are only associated with particular services or hosts, I will call these "local" event handlers. If a local event handler has been defined for a service or host, it will be executed when that host or service changes state.

Also there is global event handlers which are executed before the service and host event handlers. This will run for every host and services configured on the nagios.

You can enable the the global event handler by adding options   global_host_event_handler and global_service_event_handler main configuration file of nagios.

When Are Event Handler Commands Executed?

Service and host event handler commands are executed when a service or host:
  • is in a "soft" error state
  • initially goes into a "hard" error state
  • recovers from a "soft" or "hard" error state

Enabling the event handler on the nagios

For enabling the event handler on the nagios. First you need to add the option
enable_event_handler = 1 on the main configuration file /usr/local/nagios/etc/nagios.cfg.\



When Are Event Handler Commands Executed?
Service and host event handler commands are executed when a service or host:
  • is in a "soft" error state
  • initially goes into a "hard" error state
  • recovers from a "soft" or "hard" error state
    Soft States
    Soft states occur for services and hosts in the following situations...
  • When a service or host check results in a non-OK state and it has not yet been (re)checked the number of times specified by the <max_check_attempts> option in the service or host definition. Let's call this a soft error state...
  • When a service or host recovers from a soft error state. This is considered to be a soft recovery. 

Hard States
Hard states occur for services in the following situations (hard host states are discussed later)...
  • When a service check results in a non-OK state and it has been (re)checked the number of times specified by the <max_check_attempts> option in the service definition. This is a hard error state.
  • When a service recovers from a hard error state. This is considered to be a hard recovery.
  • When a service check results in a non-OK state and its corresponding host is either DOWN or UNREACHABLE. This is an exception to the general monitoring logic, but makes perfect sense. If the host isn't up why should we try and recheck the service? 


Writing Event Handler Commands
Event handler commands will likely be shell or perl scripts, but they can be any type of executable that can run from a command prompt. At a minimum, the scripts should take the following macros as arguments:
For Services: $SERVICESTATE$, $SERVICESTATETYPE$, $SERVICEATTEMPT$
For Hosts: $HOSTSTATE$, $HOSTSTATETYPE$, $HOSTATTEMPT$
The scripts should examine the values of the arguments passed to it and take any necessary action based upon those values.

SERVICE STATE cane be of four types

 1. OK
2. Warning
3.Unknown
4.Critical

SERVICESTATETYPE is of two types

1.Soft
2.Hard

SERVICEATTEMPT

How many times the attemts are made based on max_check_attempts defined in the configuration file.

Here I am writing a script to change the dns entries once httpd proccess goes down on a server. I will switch the dns to other httpd server which is running the same data. This is done by editing the zone file on the dns server.

Below the script for that

#!/bin/sh

#

# Event handler script for restarting the web server on the local machine

#

# Note: This script will only restart the web server if the service is

#       retried 3 times (in a "soft" state) or if the web service somehow

#       manages to fall into a "hard" error state.

#





# What state is the HTTP service in?

case "$1" in

OK)

    # The service just came back up, so don't do anything...

    ;;

WARNING)

    # We don't really care about warning states, since the service is probably still running...

    ;;

UNKNOWN)

    # We don't know what might be causing an unknown error, so don't do anything...

    ;;

CRITICAL)

    # Aha!  The HTTP service appears to have a problem - perhaps we should restart the server...



    # Is this a "soft" or a "hard" state?

    case "$2" in

       

    # We're in a "soft" state, meaning that Nagios is in the middle of retrying the

    # check before it turns into a "hard" state and contacts get notified...

    SOFT)

           

        # What check attempt are we on?  We don't want to restart the web server on the first

        # check, because it may just be a fluke!

        case "$3" in

               

        # Wait until the check has been tried 3 times before restarting the web server.

        # If the check fails on the 4th time (after we restart the web server), the state

        # type will turn to "hard" and contacts will be notified of the problem.

        # Hopefully this will restart the web server successfully, so the 4th check will

        # result in a "soft" recovery.  If that happens no one gets notified because we

        # fixed the problem!

        3)

            echo -n "Going to edit the dns zone file in the DNS server)(3rd soft critical state)..."

            # Below command will ssh into the DNS server and will change the dns entries.

            ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@192.168.6.209 < /usr/local/nagios/libexec/eventhandlers/script_dns.sh

            ;;

            esac

        ;;

               

    # The HTTP service somehow managed to turn into a hard error without getting fixed.

    # It should have been restarted by the code above, but for some reason it didn't.

    # Let's give it one last try, shall we? 

    # Note: Contacts have already been notified of a problem with the service at this

    # point (unless you disabled notifications for this service)

    HARD)

        echo -n "Going to edit the dns zone file in the DNS server)(3rd soft critical state)..."

        # Below command will ssh into the DNS server and will change the dns entries.

        ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@192.168.6.209 < /usr/local/nagios/libexec/eventhandlers/script_dns.sh

        ;;

    esac

    ;;

esac

exit 0
-----------------------

From the above it will ssh into the dns server and then execute the commands given in the file  /usr/local/nagios/libexec/eventhandlers/script_dns.sh

  cat /usr/local/nagios/libexec/eventhandlers/script_dns.sh

/etc/init.d/named stop
cp /var/named/test.com /var/named/test.com.bk
sed -i 's/192.168.6.209/192.168.6.208/' /var/named/test.com
/etc/init.d/named restart

Once the script is ready you should need to define it in the configuration file where commands are defined

/usr/local/nagios/etc/objects/commands.cfg

 define command{

        command_name    dns-edit

        command_line    /usr/local/nagios/libexec/eventhandlers/dns-edit.sh $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$

        }

Also you need to define the script as the event handler so that it will be executed when event handler is called

 define service{
        use                             generic-service          ; Name of service template to use
        host_name                       webtest1
        service_description             HTTP
    check_command            check_http
    notifications_enabled        0
    max_check_attempts        4
    event_handler                   dns-edit
  }

Above one should be added on the configuration file of host.


Once every thing is configured correctly then the script will execute when a service is stopped.


Regards
Syamkumar,M










Thursday, 26 September 2013

Amazon Cloud Commands


Amazon Cloud
-------------------
Amazon Cloud is the place where you can create a number of ec2 instances in a Virtual Private Cloud.
You can get the complete documentation in the link http://docs.aws.amazon.com/AmazonVPC/latest/GettingStartedGuide/ExerciseOverview.html.

Here  I am listing some commands usefull to check varrious things in an amazon instance

Once you launched an ec2 instance in an VPC , there will be a default path where amazon API tools are located. The default path on my instances are is /opt/amazon/api-tool/bin/

1) How to check if an elastic ip is attached on the machine or not

GET http://169.254.169.254/latest/meta-data/public-ipv4

It will list the elastic ip on the amazon

2)To list the instance information of all machines on the amazon

ec2-describe-instances -K ~/.ec2/*.key -C ~/.ec2/*.crt

it need amazon keys to work


 

Ad