Monday, August 17, 2015

How to install Check_Mk agent on client machine

To install Check_Mk agent on client machine

1) wget http://mathias-kettner.de/download/check_mk-1.1.12p7.tar.gz


2) tar -xvzf check_mk-1.1.12p7.tar.gz

3) Make sure 'xinetd' is installed
   rpm -qa |grep 'xinetd'

4) If not then install xinetd
  yum install xinetd

5) Start xinetd service
    service xinetd start

6) Copy the files and give the execute permissions for 'check_mk_agent'.
     cd /tmp/check_mk-x.x.x
    tar -xvzf agents.tar.gz
    cp check_mk_agent.linux /usr/bin/check_mk_agent
    cp xinetd.conf /etc/xinetd.d/check_mk
    chmod +x /usr/bin/check_mk_agent

7) Now Set the IP of Check MK master in '/etc/xinetd.d/check_mk' file.
    "only from = IP_OF_MONITORING_SERVER"

8) Add the IP to '/etc/hosts.allow'.
     "check_mk_agent : IP_OF_MONITORING_SERVER"

9) Now start xinetd service
   service xinetd start

10) Set the xinetd to start at system boot
     chkconfig xinetd on

11) Now check from Check_Mk master, if we are able to telnet client machine or not
       telnet ClientMachineIP 6556

Now, we have to add the entry in Check_Mk master machine for the client IP.

1) su - checkmktest

2) cd etc/check_mk/

3) In that open the file vi main,mk

4) Add your client entry like this
    all_hosts = [ 'agent1' ]
    ipaddresses = {
        "agent1" : "XXX.XXX.XXX.XXX",
        }

5) save the file
6) Now, we have to take the inventory of that client machine
    check_mk -u -II agent1  (agent1 is the name that we have given to our client machine)

7) Once you fire the above command it will create a file under
    cd
    cd var/check_mk/autochecks/
    In that you will find the file with name agent1.mk
    which contains all the checks

8) Now restart check_Mk and go to browser

    check_mk -v -R

9) Open the browser you will get all the default service checks available
    http://localhost/checkmkmon1/check_mk/







   



Saturday, August 15, 2015

Step by step procedure to setup Check_mk on Centos 6

Check_MK

Check_MK Multisite, a comprehensive tool that addresses many of Nagios's shortcomings. It provides a web interface for easy administration and configuration, a user-friendly dashboard, a robust notification system, and easy-to-install monitoring agents for many Linux distributions. If it weren't for Check_MK Multisite we would have to use different views for different tasks and it wouldn't be possible to configure all the settings without resorting to working with configuration files.
Open Monitoring Distribution with Check_MK makes it easy and accessible for everyone to set up their own monitoring system

Check_MK architecture




Step by step setup of Check_Mk on CentOS 6.0

1) Download the rpm of omd. I have tested it on omd-1.10

    wget "http://files.omdistro.org/releases/centos_rhel/omd-1.10-rh61-31.x86_64.rpm"

2) Now install the rpm and glibc package
    rpm -ivh omd-1.10-rh61-31.x86_64.rpm
    yum install glibc

3) If above rpm says some packages are missing in the system, then

    rpm -ivh omd-1.30-rh66-35.x86_64.rpm 2>> /tmp/list
    xargs yum -y install < /tmp/list

4) After complete installation check the omd version to verify the installation
    [root@localhost ~]# omd version
    OMD - Open Monitoring Distribution Version 1.10

5) Now we have to create a directory in which all our    
     configuration files will get saved. You can give any name.
 
     [root@localhost opt]# omd create checkmktest

6) Once you fire the above create command it will create a     user with your directory name and you can login    
   through it.
      [root@localhost opt]#su - checkmktest

7) You can check the directories and files which are  
     created in that dir.
     OMD[checkmktest]:~$ ls
   
8) Now start the omd. It will start apache, nagios,    
    rrdcache
    OMD[checkmktest]:~$omd start

9) Now open your browser and fire below link
     http://localhost/checkmktest/check_mk/
     It will ask for username and password
     username: omdadmin
     password: omd

10) Your check_mk setup is done. You can change your    
       password through UI

11) Below is the snapshot of check_mk UI
     

   
    12) Check_Mk agent installation and other check_mk commands will post in my next blog.











    

Thursday, July 30, 2015

How to create a HTTP YUM repository

YUM is a tool for automating package maintenance for a network of workstations running any operating system that use the Red Hat Package Management (RPM) system for distributing packaged tools and applications. It is derived from YUP, an automated package updater originally developed for Yellowdog Linux, hence its name: yum is "Yellowdog Updater, Modified".

YUM stands for Yellow dog UpdaterModified because it is based on YUP, the Yellow dog UpdaterYellow Dog is a version of Linux for the Power Architecture hardware. YUP, and later YUM, were written by the Linux community as a way to maintain an RPM-based system.

To setup a YUM server we should have following packages installed

deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
createrepo-0.9.8-4.el6.noarch.rpm

In CentOs-6.5 mostly these packages are installed by default.

Now first install httpd and from httpd we will point our yum repository

yum install httpd

Now open httpd.conf file i.e vi /etc/httpd/httpd.conf

In that search for DocumentRoot check the path provided in that. If you want you can change the path, basically it will serve the data from there.
Suppose i set the path to /var/www/html
i.e
DocumentRoot "/var/www/html"
Also in Directory the above should be mentioned
<Directory "/var/www/html">

Now, go under /var/www/html and create a html file to test the page are serving from our path or not.
cd /var/www/html/
vi index.html
<html><body><h1>It works!</h1></body></html>
:wq

Now restart httpd if its already running 
service httpd restart

Now open the page in browser "http://localhost" and check "It works" is coming or not.

If our index.html is working fine it means our data is properly serving from /var/www/html

Now we will create our own repository
Go under /var/lib/www
cd /var/lib/www

Create a dir with name yum

mkdir yum

In that create your own repo dir by any name that you want
For ex: 
mkdir myrepo

In that create our repo file
Ex; my.repo

vi my.repo

# Huzefa YUM Repository
# Please contact at huzefa.hamdard@gmail.com
# version- 10072013

# Default Base packages
# $YUM0 is exported through deployment script in /etc/profile  and /root/.bashrc
# export YUM0=`cat /etc/redhat-release | cut -d " " -f3`
# $basearch is the yum varibale which is equal to `uname -i`


#Additional packages required huz-repo
[huz-repo]
name=huz-repo
baseurl=http://192.168.236.132/yum/huzrepo/$YUM0
failovermethod=priority
enabled=1

gpgcheck=0
#END OF FILE


In that add the create a dir for every rpm versions
Suppose you want to add repo for centos version 6 then create dir with name 6
mkdir 6
In that create directory for 64 bit and 32 bit
mkdir x86_64 
mkdir i386

Suppose we have a rpm file for 64 bit then put it in x86_64 folder
and in the x86_64 folder fire this below command
createrepo .
This command will create repodata directory.

Full directory structure is as follows



Now our rpm server is setup, just restart httpd server once
service httpd restart

Now go to the browser and check you are able to see the rpm that we have uploaded

http://localhost/yum/myrepo/

Now on Client Side

Go to ur  CLIENT machine from where you want to access the repo.

Go to
cd /etc/yum.repos.d
Here you will see by default Centos repos, If you want for testing puporse you can rename all the repos which are present bydefault
ex: 
mv CentOS-Base.repo CentOS-Base.repo.bck

Now we will download our own repo that we have created on client machine

wget "http://localhost/yum/myrepo/my.repo"

Now clean the yum 

yum clean all

Now check by using command repolist

yum repolist

[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
my-repo                                                                                            | 2.9 kB     00:00
my-repo/primary_db                                                                                 | 5.8 kB     00:00
repo id                                                   repo name                                                  status
my-repo                                                  my-repo                                                   1

repolist: 1


It should show our repo name i.e my-repo and in repolist it should show 1 for our 1 rpm that we have uploaded on server.

You can also check by yum info 
yum info httpd 

[root@localhost yum.repos.d]# yum info httpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Available Packages
Name        : httpd
Arch        : x86_64
Version     : 2.4.10
Release     : 1.el6
Size        : 8.4 M
Repo        : my-repo
Summary     : Apache HTTPD
URL         : http://httpd.apache.org/
License     : GPL
Description : The Apache HTTP Server is a powerful, efficient, and extensible

            : web server.

As you can see package is coming from our repo -  my-repo.

Now you can install packages from your own yum repo

yum install httpd

It will pick the packages directly from our repo. Just upload the repo on our server and access it from anywhere.















Sunday, July 26, 2015

Running Ansible playbook for Mysql

Simple Playbook for taking mysql dump

---
#This playbook is used to take mysql dump
#Here we have to use mysql_db module

- hosts: test
  tasks:
    - name: Taking mysql dump
      mysql_db: state=dump login_user=root login_password=test name=test      target=/tmp/test.sql

To run this
ansible-playbook -i host-file mysqlbackup.yml -k




To fire mysql commands i.e dump and other queries we have to install MYSQL-python package.

When we run Playbook for Mysql Dump we will get below error

TASK: [Taking mysql dump] *****************************************************
failed: [XXX.XXX.XXX.XXX] => {"failed": true}
msg: the python mysqldb module is required

FATAL: all hosts have already failed -- aborting

To resolve this issue we have to install MYSQL-python package

1) Install python-pip package
   yum -y install python-pip

2) Then install MYSQL-python package
    pip install MYSQL-python

   If you are getting below error then
  Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-nqoOz1/MySQL-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-TZ8GC0-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-nqoOz1/MySQL-python

Install 
 yum install mysql-devel.x86_64
and
 yum install python-devel

3) Now try to run again 
    pip install MYSQL-python 

It Should work


Sunday, June 21, 2015

Shrink/Purge ibdata1 file in MySQL

1) Do a mysqldump of all databases procedures, triggers etc except the mysql and performance_schema databases
mysql -u username -p --database databasename > databasename.sql

2) Drop all databases
drop database databasename

3) Stop mysql
service mysqld stop

4) Delete ibdata1 and ib_log files
rm -rf /mnt/data/ibdata1
rm -rf /mnt/data/ib_logfile*

5) Start mysql
service mysqld start

6) Restore from dump
mysql -u username -p
You will get a mysql prompt and fire the below 2 commands there. Fire the
command where you have put the sql backup
mysql> source databasename.sql


Your database is purge :)

Saturday, June 20, 2015

How to install Apache from tar file

First download the tar file. We are installing httpd - 2.4.9

wget "http://archive.apache.org/dist/httpd/httpd-2.4.9.tar.bz2"


tar xvjf httpd-2.4.9.tar.bz2
cd httpd-2.4.9
cd srclib/
wget http://mirror.apache-kr.org//apr/apr-1.5.1.tar.gz
wget http://apache.petsads.us//apr/apr-util-1.5.4.tar.gz
tar xvfz apr-1.5.1.tar.gz
tar xvfz apr-util-1.5.4.tar.gz
mv apr-1.5.1 apr
mv apr-util-1.5.4 apr-util
cd ..

./configure --prefix=/usr/local/apache2 --enable-so --with-included-apr --enable-expires --enable-file-cache --enable-cache --enable-ratelimit --enable-log-debug --enable-usertrack --enable-unique-id --enable-remoteip --enable-proxy --enable-proxy-ajp --enable-proxy-http --enable-proxy-balancer --enable-session --enable-ssl --with-mpm=event

make
make install

Now Installtion is complete

Now start the apache
cd /usr/local/apache2/

./bin/apachectl start

Goto webbrowser and check
http://localhost