Wednesday 6 November 2013

Install JAVA on CentOS 5/6 or RHEL 5/6


Step 1: Download Archive File

Download latest version of java from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html.

# cd /opt/ 
# wget http://download.oracle.com/otn-pub/java/jdk/7u25-b15/jdk-7u25-linux-i586.tar.gz?AuthParam=1372657186_d532b6d28fdb7f35ec7150a1d6df6778

After completing download, Extract archive using following command.

# tar xzf jdk-7u25-linux-i586.tar.gz

Step 2: Install JAVA using Alternatives

After extracting java archive file, we just need to setup to use newer version of java using alternatives. Use the following commands to do it.

# cd /opt/jdk1.7.0_25 
# alternatives --install /usr/bin/java java /opt/jdk1.7.0_25/bin/java 2 
# alternatives --config java 

 There is 1 program that provides 'java'. 

 Selection                                       Command 

-----------------------------------------------
 *+ 1                                             /opt/jdk1.7.0_25/bin/java 

 Enter to keep the current selection[+], or type selection number: 1

Step 3: Check Version of JAVA .

# java -version
java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b15) Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode)

Step 4: Setup Environment Variables

Most of java based application’s uses environment variables to work. Use following commands to setup it.
Setup JAVA_HOME Variable
# export JAVA_HOME=/opt/jdk1.7.0_25

Setup JRE_HOME Variable
# export JRE_HOME=/opt/jdk1.7.0_25/jre

Setup PATH Variable
# export PATH=$PATH:/opt/jdk1.7.0_25/bin:/opt/jdk1.7.0_25/jre/bin

Thursday 18 April 2013

Zabbix Installation on RHEL/CentOS 6 Linux Server



These are my instructions for installing Zabbix 2.0.x on CentOS6 using the ZabbixZone repository. I have opted to use MySQL.

Server Install

Configure the ZabbixZone package repository and GPG key
# rpm --import http://repo.zabbixzone.com/centos/RPM-GPG-KEY-zabbixzone
# rpm -Uv http://repo.zabbixzone.com/centos/zabbixzone-release-0.0-1.noarch.rpm
Install the necesarry server packages (and agent, since you'll want to monitor your server too, right?)
# yum install mysql-server zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-java-gateway
edit timezone in /etc/httpd/conf.d/zabbix to read this, or your own time zone:
php_value date.timezone Europe/London
Restart the httpd
# service httpd start

Database

Start MySQL Database Server and secure
# service mysqld start
# mysql_secure_installation
# mysql -u root -p
In the MySQL console:
mysql> create database zabbix character set utf8;
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'password';
mysql> flush privileges;
Back in the shell we load the Zabbix SQL in the database we just created:
# mysql -u zabbix -p zabbix < /usr/share/doc/zabbix-server-mysql-2.0.2/create/schema.sql
# mysql -u zabbix -p zabbix < /usr/share/doc/zabbix-server-mysql-2.0.2/create/images.sql
# mysql -u zabbix -p zabbix < /usr/share/doc/zabbix-server-mysql-2.0.2/create/data.sql

Zabbix Server

edit /etc/zabbix/zabbix_server.conf to set up zabbix database users' password
vim /etc/zabbix/zabbix_server.conf
Edit the below lines
-------------------------
DBUser=zabbix
DBPassword=password
DBPort=3306
Start the zabbix-server process
# service zabbix-server start
http://serverurl/zabbix

Java Gateway

The Java gateway service is used for JMX monitoring of servers like JBoss, Tomcat, Weblogic or Websphere.
We need to specify the address of the gateway in the zabbix server config (/etc/zabbix/zabbix-server.conf or zabbix-proxy.conf):
JavaGateway=10.150.164.214
StartJavaPollers=5

Start on Reboot

# chkconfig zabbix-server on
# chkconfig mysqld on
# chkconfig httpd on
# chkconfig zabbix-java-gateway on

Agent Install

Linux

#rpm --import http://repo.zabbixzone.com/centos/RPM-GPG-KEY-zabbixzone
#rpm -Uv http://repo.zabbixzone.com/centos/zabbixzone-release-0.0-1.noarch.rpm
 #yum install zabbix-agent -y
#chkconfig zabbix-agent on
#mv /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.default
#sed 's/Server=127.0.0.1/Server=10.150.164.214/' /etc/zabbix/zabbix_agentd.default > /etc/zabbix/zabbix_agentd.conf
#service zabbix-agent start

Tuesday 29 January 2013

Redis Install/Master-Slave on RHEL/Cent OS Linux Server

Redis Install
-------------
Introduction
*    redis-server - is the Redis Server itself.
*    redis-cli - is the command line interface utility to talk with Redis.
*    redis-benchmark - is used to check Redis performances.
*    redis-check-aof - and redis-check-dump are useful in the rare event of corrupted data files.

#wget http://download.redis.io/redis-stable.tar.gz
#tar xvzf redis-stable.tar.gz
#cd redis-stable
#make
#make install

Configuring redis
-----------------
#mkdir /etc/redis
#mkdir /var/redis
#cp utils/redis_init_script /etc/init.d/redis_6379

#vim /etc/init.d/redis_6379
Make sure to modify REDIS_PORT accordingly to the port you are using. Both the pid file path and the configuration file name depend on the port number

#cp redis.conf /etc/redis/6379.conf
#mkdir /var/redis/6379

Edit the configuration file, making sure to perform the following changes:
-------------------------------------------------------------------------
        Set daemonize to yes (by default it is set to no).
        Set the pidfile to /var/run/redis_6379.pid (modify the port if needed).
        Change the port accordingly. In our example it is not needed as the default port is already 6379.
        Set your preferred loglevel.
        Set the logfile to /var/log/redis_6379.log
        Set the dir to /var/redis/6379 (very important step!)


To start the redis
------------------
/etc/init.d/redis_6379 start

To start the redis
------------------
/etc/init.d/redis_6379 stop

To Restart the redis
--------------------
redis-cli -p 6379 save
redis-cli -9 6379 shutdown
/etc/init.d/redis_6379 start

Check if Redis is working
--------------------------
$ redis-cli ping
PONG
$ redis-cli                                                               
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379> set mykey somevalue
OK
redis 127.0.0.1:6379> get mykey
"somevalue"

Shutdown redis
--------------
$ redis-cli shutdown

Master/Slave Configuration for Redis
------------------------------------

Add the master ip and port in slave configuration file

slave>vim /etc/redis/6479.conf

slaveof <masterip> <masterport>

Ex: slaveof 192.168.2.14 6379

#Restart server for both master and slave

Setting security password for master/slave replication
------------------------------------------------------
redis-master# vim /etc/redis/6379.conf

#Add the below line
requirepass <any_password>

redis-slave# vim /etc/redis/6479.conf
masterauth <above_set_password>

#Restart server for both master and slave

Wednesday 23 January 2013

Install Monit & MMonit on RHEL/Cent OS From Source

Installation
----------------
@Prerequists@

#yum install pam-devel
#yum install openssl-devel

@Get and install Monit@
#cd /usr/local/src
#wget http://mmonit.com/monit/dist/monit-5.5.tar.gz
#tar -zxvf monit-5.5.tar.gz
#cd monit-5.5
#./configure (If this fails, fix as necessary, then re-unpack the tar and try again)
#make
#make install

@Setup monitrc@

#cp monitrc /etc/
#vim /etc/monitrc  # At the end of monitrc add or uncomment: include /etc/monit.d/*
#mkdir /etc/monit.d

Create the service files (this will repeat for every service you monitor)
vim /etc/monit.d/apache

#Now Inside the apache file:
check process httpd with pidfile /var/run/httpd/httpd.pid
group apache
start program = "/etc/init.d/httpd start"
stop program = "/etc/init.d/httpd stop"
if failed host 127.0.0.1 port 80 protocol http
 and request "/index.html"
then restart
if 5 restarts within 5 cycles then timeout

@To see more services, chec out this http://mmonit.com/wiki/Monit/ConfigurationExamples@

@Now setup the init.d file@
#cp contrib/rc.monit /etc/init.d/monit
#chmod 755 /etc/init.d/monit

You may need to fix the line inside the above file thats pointing at /usr/bin/monit to /usr/local/bin/monit.
After this is in place you should have the service monit restart command available.

To start Monit at boot, edit vim /etc/rc.d/rc.local and add in the next line

Go ahead and run the above line in the console to see if monit works.
If so, a call to service httpd stop should cause monit to restart apache.

@Finished@
Monit should be all setup. You can check with service monit status or ps aux | grep monit.

Another cool feature of monit is the web interface. Go to http://localhost:2812/ and
enter the username and password form your monitrc file, it should look something like this, feel free to change it:

set httpd port 2812
  allow hauk:password

@Main Files@

/etc/monitrc - Monit's control file

/etc/monit.d/* - all services Monit will track

/etc/init.d/monit - service control file

/usr/local/src/monit-5.5 - source code

/usr/local/bin/monit


Edit below settings based on our requirements
----------------------------------------------------------------

vim /etc/monitrc

set alert sysop@fak3r.com (to get alert email)

Lastly I changed the email format to be a little more user friendly for support and the other users. While I’ve grown fond of the simple/to the point alert system monit has by default, it’s easy to format the message so they’re a bit more specific, and easier to categorize. In the top, global section of monitrc, we add something like:

set mail-format {
     from: monit@somebigserver.com
     subject: [ $SERVICE ] $EVENT - $DATE
     message: This is an $ACTION: $DESCRIPTION [$SERVICE], tested remotely from $HOST }

To add remote host(192.168.2.14) http service in monit
------------------------------------------------------

check host 192.168.2.14-http  with address www.mansoor.com
  if failed port 80 proto http then alert

For multiple alert
------------------
check host fak3r.com with address fak3r.com
if failed url http://fak3r.com and content == "look out honey"
timeout 30 seconds for 1 cycles then alert
alert it.support@company.com { connection, timeout }
alert debbie.developer@company.com { connection, timeout }
alert dave.developer@company.com { connection, timeout }

For Adding Process list refer the below:
------------------------------------------------------

http://mmonit.com/wiki/Monit/ConfigurationExamples

Install MMonit:
--------------------

Check out the http://mmonit.com/wiki/MMonit/Setup

Tuesday 22 January 2013

OpenPOM how-to - Alert Monitoring tool for Nagios


1) Requirements
---------------

Either:
  - Nagios (http://nagios.org/) installation with a contact_name admin
  - Icinga (http://www.icinga.org/)

- MySQL
- NdoUtils  (NDOUtils : http://www.nagios.org/download/addons)
- A web server (Apache/Apache2) with php5

#mysql -u root -p
mysql> grant select on ndoutils.* to 'openpom'@'localhost' identified by 'my_password';
#(Above ndoutils database is created when installating NdoUtils)
mysql> flush privileges;

For performance reason you have to set up index on some ndoutils tables.
Connect to your mysql server and use the correct database then inject these lines :
ALTER TABLE `nagios_commenthistory` ADD INDEX ( `comment_source` );
ALTER TABLE `nagios_hosts` ADD INDEX ( `display_name` );
ALTER TABLE `nagios_hosts` ADD INDEX ( `address` );
ALTER TABLE `nagios_services` ADD INDEX ( `display_name` );
ALTER TABLE `nagios_notifications` ADD INDEX ( `object_id` );
ALTER TABLE `nagios_notifications` ADD INDEX ( `start_time` );
ALTER TABLE `nagios_notifications` ADD INDEX ( `end_time` );
ALTER TABLE `nagios_downtimehistory` ADD INDEX ( `object_id` );
ALTER TABLE `nagios_downtimehistory` ADD INDEX ( `scheduled_end_time` );
ALTER TABLE `nagios_downtimehistory` ADD INDEX ( `entry_time` );
ALTER TABLE `nagios_acknowledgements` ADD INDEX ( `object_id` );
ALTER TABLE `nagios_acknowledgements` ADD INDEX ( `entry_time` );
ALTER TABLE `nagios_statehistory` ADD INDEX ( `object_id` );
ALTER TABLE `nagios_statehistory` ADD INDEX ( `state_time` );
ALTER TABLE `nagios_contactnotifications` ADD INDEX ( `notification_id` );
ALTER TABLE `nagios_contactnotifications` ADD INDEX ( `contact_object_id` );
ALTER TABLE `nagios_flappinghistory` ADD INDEX ( `event_time` );
ALTER TABLE `nagios_flappinghistory` ADD INDEX ( `object_id` );
ALTER TABLE `nagios_scheduleddowntime` ADD INDEX ( `object_id` );

ALTER TABLE `nagios_commenthistory` ADD INDEX ( `object_id` );
ALTER TABLE `nagios_commenthistory` ADD INDEX ( `entry_time` );
ALTER TABLE `nagios_commenthistory` ADD INDEX ( `author_name` );
ALTER TABLE `nagios_commenthistory` ADD INDEX ( `deletion_time` );
ALTER TABLE `nagios_commenthistory` ADD INDEX ( `entry_type` );
ALTER TABLE `nagios_commenthistory` ADD INDEX ( `comment_data` );
ALTER TABLE `nagios_contactgroup_members` ADD INDEX ( `contactgroup_id` );
ALTER TABLE `nagios_contactgroups` ADD INDEX ( `contactgroup_object_id` );
ALTER TABLE `nagios_contacts` ADD INDEX ( `contact_object_id` );
ALTER TABLE `nagios_downtimehistory` ADD INDEX ( `actual_end_time` );
ALTER TABLE `nagios_host_contactgroups` ADD INDEX ( `host_id` );
ALTER TABLE `nagios_hostgroup_members` ADD INDEX ( `hostgroup_id` );
ALTER TABLE `nagios_hostgroup_members` ADD INDEX ( `host_object_id` );
ALTER TABLE `nagios_hostgroups` ADD INDEX ( `hostgroup_object_id` );
ALTER TABLE `nagios_objects` ADD INDEX ( `objecttype_id` );
ALTER TABLE `nagios_objects` ADD INDEX ( `name1` );
ALTER TABLE `nagios_scheduleddowntime` ADD INDEX ( `downtime_type` );
ALTER TABLE `nagios_service_contactgroups` ADD INDEX ( `service_id` );
ALTER TABLE `nagios_service_contactgroups` ADD INDEX ( `contactgroup_object_id` );
ALTER TABLE `nagios_services` ADD INDEX ( `host_object_id` );



2) Configure OpenPom
#cd /var/www/html/
#wget http://openpom.googlecode.com/files/openpom-1.5.0.tar.gz
#tar xzvf openpom-1.5.0.tar.gz
#mv openpom-1.5.0 openpom


--------------------

Adjust the following variables in /var/www/html/openpom/config.php:

/* SQL */
$SQL_HOST           = "127.0.0.1";
$SQL_USER           = "openpom";
$SQL_PASSWD         = "my_password";
$SQL_DB             = "ndoutils";

/* NAGIOS OR ICINGA VARIABLES */
$EXEC_CMD           = "./send-order";
$CMD_FILE           = "/usr/local/nagios/var/rw/nagios.cmd";
$LINK               = "/" . $BACKEND . "/cgi-bin/extinfo.cgi";
$LOG                = "/" . $BACKEND . "/cgi-bin/showlog.cgi";


3) Apache local authentification
-----------------------------------
vim /etc/httpd/conf/httpd.conf

#add below lines
  Alias    /openpom    /var/www/html/openpom
  <Directory /var/www/openpom>
     Options ExecCGI Indexes
     AllowOverride None
     Order allow,deny
     Allow from all

     AuthName "OpenPom Access"
     AuthType Basic
     AuthUserFile /usr/local/nagios/etc/htpasswd.users
## (This above line must be same as(cat /etc/httpd/conf.d/nagios.conf) nagios authentication##
     Require valid-user
  </Directory>

4) Graph
--------

You can show graph from external sources (like rrdgraph, pnp, cacti, ...)
Edit config.php and add the following two arrays:

/**
 * SHOW GRPAH FROM EXTERNAL SOURCE
 * 
 * Default images are generated by Nagios' trends.cgi
 * Image at URI defined in $GRAPH_HOST will be displayed for hosts
 * Image at URI defined in $GRAPH_SVC will be displayed for services
 *
 * Keywords:
 * @@define_host@@ will be replaced by the selected host name
 * @@define_service@@ will be replaced by the selected service name
 */
$GRAPH_HOST = '/' . $BACKEND . '/cgi-bin/trends.cgi'
  . '?createimage'
  . '&backtrack=4'
  . '&zoom=4'
  . '&host=@@define_host@@';

$GRAPH_SVC = '/' . $BACKEND . '/cgi-bin/trends.cgi'
  . '?createimage'
  . '&backtrack=4'
  . '&zoom=4'
  . '&host=@@define_host@@'
  . '&service=@@define_service@@';

/* POPUP CONTENT WHEN CLICKING ON THE GRAPH ICON
 *
 * Default is to use the graph.php provided with OpenPOM which display the
 * image defined in $GRAPH_HOST or $GRAPH_SVC (respectively for an host or
 * a service) and a very basic period selector.
 * 
 * Periods available are defined in the array $GRAPH_POPUP_PERIODS where each
 * element is an array of 2 elements defining the start and end value of the
 * period. The start/end values must be valid string for passing to PHP's 
 * strtotime() function.
 *
 * See PHP documentation for more information:
 * http://www.php.net/manual/en/datetime.formats.php
 *
 * The start/end timestamps are passed to the URI defined in $GRAPH_HOST and
 * $GRAPH_SVC. The name of the parameters used to pass them are defined
 * repectively in $GRAPH_POPUP_PARAM_START and $GRAPH_POPUP_PARAM_END.
 */
$GRAPH_POPUP_HOST = 'graph.php?host=@@define_host@@';
$GRAPH_POPUP_SVC = 'graph.php?host=@@define_host@@&service=@@define_service@@';
$GRAPH_POPUP_WIDTH = 800;
$GRAPH_POPUP_HEIGHT = 400;

$GRAPH_POPUP_PERIODS = array(
  'Day'   => array('-1 day',    'now'),
  'Week'  => array('-1 week',   'now'),
  'Month' => array('-1 month',  'now'),
  'Year'  => array('-1 year',   'now'));

$GRAPH_POPUP_DEFAULT = 'Week';
$GRAPH_POPUP_PARAM_START = 't1';
$GRAPH_POPUP_PARAM_END = 't2';

5) check now
------------
Browse as http://localhost/openpom
username & password same as configured in nagios

How to Install Ndoutils on nagios 3.4.3

How to install ndoutils on centos
How to Install Ndoutils on nagios version 3 above
==================================================


Install Ndoutils pre-requists
-----------------------------

# yum -y install mysql mysql-server mysql-client gcc-c++ libdbi-dbd-mysql
# /etc/init.d/mysqld start
# /sbin/chkconfig mysqld on
# /usr/bin/mysqladmin -u root password your_password


Create database for nagios
---------------------------

# mysql -u root -pyourpassword
mysql> create database ndoutils;
mysql> grant all privileges on ndoutils.* to 'nagios'@'localhost' identified by “nagios” with grant option;
mysql> flush privileges;
mysql> quit

Download ndoutils
-----------------

# mkdir /opt/downloads
# cd /opt/downloads
# wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b9/ndoutils-1.4b9.tar.gz/download
# cd /opt/downloads/ndoutils-1.4b9

Installing ndoutils
--------------------

./configure --prefix=/usr/local/nagios/ --enable-mysql --disable-pgsql --with-ndo2db-user=nagios -with-ndo2db-group=nagcmd

make

Manual install ( NO MAKE INSTALL )

-----------------------------------
# db/installdb -u nagios -p nagios -h localhost -d nagios

# cp ./src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o
# cp ./src/ndo2db-3x /usr/local/nagios/bin/ndo2db
# cp ./config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
# cp ./config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
# chmod 774 /usr/local/nagios/bin/ndo*
# chown nagios:nagios /usr/local/nagios/bin/ndo*

Install the init script
------------------------

# cp ./daemon-init /etc/init.d/ndo2db
# chmod +x /etc/init.d/ndo2db
# chkconfig -add ndo2db


Edit nagios.cfg and verify or add the following lines
------------------------------------------------------
# vim /usr/local/nagios/etc/nagios.cfg

event_broker_options=-1
broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg

Make necessary modifications in ndo2db.cfg file ( My Sample cfg file )
----------------------------------------------------------------------
# vim /usr/local/nagios/etc/ndo2db.cfg
db_user=nagios
db_pass=nagios

Start the ndo2db init script and restart the nagios
----------------------------------------------------

# /etc/init.d/ndo2db start
# /etc/init.d/nagios restart

You will get the log report like this

# tail -f /usr/local/nagios/var/nagios.log
[1296905045] LOG VERSION: 2.0
[1296905045] ndomod: NDOMOD 1.4b9 (10-27-2009) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
[1296905045] ndomod: Successfully connected to data sink. 0 queued items to flush.
[1296905045] Event broker module '/usr/local/nagios/bin/ndomod.o' initialized successfully.
[1296905045] Finished daemonizing... (New PID=7529)

Errors & Solutions:
*******************

if you get error: Could not open data sink
—————————
[1307690851] Nagios 3.2.3 starting… (PID=10660)
[1307690851] Local time is Fri Jun 10 00:27:31 PDT 2011
[1307690851] LOG VERSION: 2.0
[1307690851] ndomod: NDOMOD 1.4b9 (10-27-2009) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
[1307690851] ndomod: Could not open data sink! I’ll keep trying, but some output may get lost…
[1307690851] Event broker module ‘/usr/local/nagios/bin/ndomod.o’ initialized successfully.
[1307690851] Finished daemonizing… (New PID=10661)
—————————
Following these steps:
chmod 666 /usr/local/nagios/etc/ndomod.cfg
chmod 666 /usr/local/nagios/etc/ndo2db.cfg
/etc/init.d/ndo2db stop
/etc/init.d/nagios stop
/etc/init.d/ndo2db start
/etc/init.d/nagios start

#Again check

#tail -f /usr/local/nagios/var/nagios.log

Monday 21 January 2013

MogileFS - Installation on RHEL/Cent OS Linux

MogileFS Briefly
****************
• A scalable, Fault tolerant, High performance distributed file system
• Asynchronous Replication
• No Single Point of Failure
• Automatic file replication (3 replications Tracker Storage Node recommended)
• Better22 than RAID Host1 Host4
• Data Compression (BZIP2)
• Flat NameSpace
• Share-Nothing Tracker Storage Node
• No RAID required
• Local filesystem agnostic Host2 Host5
• Tracker client transfer (mogilefsd)
   - Replication
   - Deletion
   - Query
   - Reaper
   - Monitor
• Files are broken up and spread over the Storage Node (mogstored) HTTP and WebDAV server DBNode Storage Node
• DBNode MySQL stores the MogileFS metadata (the namespace, and which files are where) Host3 Host6• Client Library : Ruby, Perl, Java, Python, PHP…

Installation:
*************
Database creation for mogilefs: IP 192.168.2.14
************************************************
# mysql -u root -p
mysql> CREATE DATABASE mogilefs;
mysql> grant all on mogilefs.* TO ‘mogile’@'localhost’ identified by ‘secret’;
mysql> grant all on mogilefs.* TO 'mogile'@'%' identified by 'secret';
mysql> flush privileges;
mysql> quit

Step 1# Download & Install MogileFS-Server
******************************************
#wget https://github.com/mogilefs/MogileFS-Server/archive/master.zip
#unzip master
#cd MogileFS-Server
#perl Makefile.PL
#make
#make test
#make install

--------------------For Your Information--------------------------------------
If you get any errors during above (make install) process it Will probably be errors telling you that a dependent module is missing. If during the 'make test' step you get the error, "t/00-startup....DBI connect('mysql','root',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at t/lib/mogtestlib.pl line 16" it can probably be ignored – it should not be necessary for MySQL to be running
-------------------------------------------------------------------------------

Step 3# Download & Install MogileFS-Utils
*****************************************
wget https://github.com/mogilefs/MogileFS-Utils/archive/master.zip
#unzip master
#cd MogileFS-Utils-master
#perl Makefile.PL
#make
#make test
#make install

Step 4# Download & Install MogileFS-Client
******************************************
wget https://github.com/mogilefs/perl-MogileFS-Client/archive/master.zip
#unzip master
#cd perl-MogileFS-Client-master
#perl Makefile.PL
#make
#make test
#make install

Step 5# Install perl modules
****************************

perl -MCPAN -e 'install Danga::Socket'
perl -MCPAN -e 'install Gearman::Client'
perl -MCPAN -e 'install Gearman::Server'
perl -MCPAN -e 'install Gearman::Client::Async'
perl -MCPAN -e 'install Net::Netmask'
perl -MCPAN -e 'install IO::WrapTie'
perl -MCPAN -e 'install IO::AIO'
perl -MCPAN -e 'install List::MoreUtils'
perl -MCPAN -e 'install Path::Class'
perl -MCPAN -e 'install Perlbal'
perl -MCPAN -e 'install ExtUtils::MakeMaker'
perl -MCPAN -e 'install DBD::mysql'

OR

#wget http://search.cpan.org/CPAN/authors/id/M/ML/MLEHMANN/Linux-AIO-1.9.tar.gz
#cd Linux-AIO-1.9
#make
#make test
#make install

Step 6# Database Configuration
******************************

#mogdbsetup --dbhost=mogiledb.yourdomain.com --dbname=mogilefs --dbuser=mogile --dbpassword=secret


---------------------------------------For Your Information-----------------
The database is empty and will need a schema applied. A utility named 'mogdbsetup' to make this process simple. By default it assumes the database is located on localhost.

The mogdbsetup utility does not specify a table type by default so your tables will match the defaults for your database. In many cases this will mean that you end up with MyISAM tables. If you prefer InnoDB tables you will either need to make sure your database defaults to InnoDB or you can manually convert the tables (both of these are outside of the scope of this document but there are plenty of examples out there).
-----------------------------------------------------------------------------

Step 7# Tracker Configuration
*****************************
On each tracker server create a configuration file at /etc/mogilefs/mogilefsd.conf with the following:


db_dsn DBI:mysql:mogilefs:mogiledb.yourdomain.com
db_user mogile
db_pass secret
conf_port 6001
listener_jobs 5


----------------For Your Information--------------------------------
1. db_dsn points to your database instance.
2. If you are running the database on the same machine as the storage server you can omit ":mogiledb.yourdomain.com: and it will use the local machine.
3.db_user and db_pass should match the user and password you configured when setting up your database.
--------------------------------------------------------------------

Step 8# Adding user to run mogilefsd service
********************************************

The program 'mogilefsd' will not run as root so you will need to run this as a non-root user. To create a user for this, enter the following command and follow the prompts to create the "mogile" user:

# adduser mogile

Step 9# Storage Server Configuration
************************************

On each storage server, create the storage directory (make sure it has access permissions for the user you will use to run mogstored):

# mkdir /var/mogdata

Configure it:

On each storage server, create a configuration file at /etc/mogilefs/mogstored.conf with the following:

httplisten=0.0.0.0:7500
mgmtlisten=0.0.0.0:7501
docroot=/var/mogdata

Commands for Administration of MogileFS
=======================================

To add domain:
**************
mogadm --trackers=192.168.2.14:6001 domain add consim

To add class domain:
********************
mogadm --trackers=192.168.2.14:6001 class add consim classconsim

To add Host
***********
mogadm --trackers=192.168.2.14:6001 host add mogilestorage --ip=192.168.2.14 --port=7500 --status=alive

To add device name for host
***************************
mogadm --trackers=192.168.2.14:6001 device add mogilestorage dev1

To delete host :
***************
mogadm --trackers=192.168.2.14:6001 host delete mogilefstorage


To list the host:
*****************
mogadm --trackers=192.168.2.14:6001 host list

To list the device:
*****************
mogadm --trackers=192.168.2.14:6001 device list


To Check:
*********
mogadm --trackers=192.168.2.14:6001 check


To upload:
**********
mogupload --trackers=192.168.2.14:6001 --domain="consim" --key="/hello" --file="/tmp/test2.txt"

To Download:
***********

mogfetch --trackers=192.168.2.14:6001 --domain="consim" --key="/hello" --file="/home/test2f.txt"


To Delete:
**********
mogdelete --trackers=192.168.2.14:6001 --domain="consim" --key="/hello"

To know the Statistics:
***********************

for all
-------
mogstats --db_dsn="DBI:mysql:mogilefs:host=192.168.2.14" --db_user="mogile" --db_pass="secret" --verbose --stats="all"

or

for device & files only
-----------------------
mogstats --db_dsn="DBI:mysql:mogilefs:host=192.168.2.14" --db_user="mogile" --db_pass="secret" --verbose --stats="devices,files"

To know the file Info:
*********************
mogfileinfo --trackers=192.168.2.14:6001 --domain=consim --key='/hello'

To rename the key name:
***********************
Usage: /usr/local/bin/mogrename --trackers=host --domain=foo --class=bar --old_key='/hello.jpg' --new_key='/bye.jpg'

Extra Informations:
*******************

1. If you want the tracker to use memcached:
#mogadm --trackers=192.168.1.10:6001 settings set memcache_servers memchage_installed_ip:its_port

2. To use nginx as web server Refer the below
**********************************************
http://code.google.com/p/mogilefs/wiki/nginx_webdav

3. php driver to upload/download files via php coding
*****************************************************
wget http://pecl.php.net/get/mogilefs-0.9.2.tgz

4. Script to get the host/device check through mail
***************************************************

mogadm --trackers=192.168.2.14:6001,192.168.1.10:6001 check |tee /tmp/mogadm.check |grep OK && cat /tmp/mogadm.check | mail -s "mogadm check status" mdmansoor26@gmail.com

5. To upload/download files through Web Interface
**************************************************

#wget http://mogilefs-browser.googlecode.com/files/mogilefsbrowser-1.0.0b3.tar.gz

1) Create a read-only user who has SELECT privileges to your MogileFS database

    Something like:

        GRANT SELECT ON mogilefs.* TO 'mogilero'@'localhost' IDENTIFIED BY 'password';

2) tar xzvf mogilefsbrowser-1.0.0b3.tar.gz

2) cp mogilefsbrowser /var/www/html

3) Edit config.php and supply the settings for your Mogile Database and Mogile system

3) create & Set permissions on docs/logs.txt to be writable by the web server process

4) Open in a web browser


Client Configuration: IP: 192.168.1.10
======================================

Step 1# Download & Install MogileFS-Server (as done like above)
Step 2# Download & Install MogileFS-Utils  (as done like above)
Step 3# Download & Install MogileFS-Client (as done like above)
Step 4# Install perl modules (as done like above)
Step 5# Tracker Configuration (as done like above) [in this add the ip address of MySQL DB server]

Example:
********
[root@consim tmp]# cat /etc/mogilefs/mogilefsd.conf
db_dsn DBI:mysql:mogilefs:192.168.2.14
db_user mogile
db_pass secret
conf_port 6001
listener_jobs 5

Step 6# Adding user to run mogilefsd service (as done like above)
Step 7# Storage Server Configuration (as done like above)

Step 9# Run in Mogilefs DB Server:
**********************************

Add client Host
***************
mogadm --trackers=192.168.1.10:6001 host add mogilestorage1 --ip=192.168.1.10 --port=7500 --status=alive

To add device name for client host
**********************************
mogadm --trackers=192.168.1.10:6001 device add mogilestorage1 dev2

#once device name is added please create the directory In client(192.168.1.10)
192.168.1.10#mkdir /var/mogdata/dev2

Sunday 13 January 2013

Mysql root user password recovery method


Stop the MySQL server by using either of the following command
#/etc/init.d/mysql stop

Now you need to Start MySQL server without password
# mysqld_safe --skip-grant-tables &

Connect to mysql server using mysql client with the following command
# mysql -u root

Now you should be having mysql prompt
mysql>

Now you need to Setup new MySQL root user password
mysql> use mysql;
mysql> update user set password=PASSWORD("newrootpassword") where user='root';
mysql> flush privileges;
mysql> quit

Note: Replace newrootpassword with the new root password for MySQL server. Flush Privileges is needed to making the password change effect immediately.

Now you need to Stop MySQL Server using the following command
# /etc/init.d/mysql stop

Test Your New Mysql root password
First you need to start mysql server using the following command
# /etc/init.d/mysql start
# mysql -u root -p

Now it will prompt for root password and enter your new root password

Rsync server on RedHat/Cent OS Linux

  1. Yum install rsync & xinetd
  2. Mkdir /var/www/html/share
  3. Create a file: "/etc/rsyncd.conf", with the contents:
max connections = 2
log file = /var/log/rsync.log
timeout = 300
[share]
comment = Random things available for download
path = /var/www/html/share
read only = yes
list = yes
uid = nobody
gid = nobody
auth users = pub
secrets file = /etc/rsyncd.secrets
hosts allow = 192.168.176.0/24
  1. Create a file: "/etc/rsyncd.secrets", and add the below line
pub:pub
  1. Run Setup  system services  and enable rsync
  1. vim /etc/xinetd.d/rsync
modify disable = yes To disable = no
  1. chown root.root /etc/rsyncd.*
  1. chmod 600 /etc/rsyncd.*
  1. service xinetd restart
  1. chkconfig xinetd on
How to test your rsync setup:
  1. Run: "rsync rsync://pub@your-ip-or-hostname/". After entering your password (also pub), rsync should list the only available share, pub.
  2. Run: "rsync rsync://pub@your-ip-or-hostname/pub/". After entering your password, rsync should now give a file listing. If there are no files listed, place some files and directories in the directory and try again.
  3. Run: "rsync -v --progress --partial rsync://pub@your-ip-or-hostname/pub/someFile ." (you can abbreviate --partial --progress as -P). Your file should now be downloading.
  4. Run: "rsync -aPv rsync://pub@your-ip-or-hostname/pub/someDirectory .". Your directory should now be downloading.
Changelog:


2007-01-07, Ranjit Singh suggested pointing out that module parameters are usable in the global section. 2006-04-01, Franz-Robert van Vugt suggested the alternate method of restarting xinetd.
2005-10-24, added xinetd info (thanks Jeff Silverman and S. Anbalagan), and information on allowing/denying certain IP addresses (suggested by Jeff), edited various minor portions (including testing section).
2004-12-17, added note about "nogroup" (thanks Michael Farrell).
2003-05-18, fixed spelling error (rsnycd.conf).
2002-10-14, updated config (logging).

Note: To disable auth user comment the below lines in /etc/rsyncd.conf

auth users = pub
secrets file = /etc/rsyncd.secrets

Extra configuration (Optional)

Find out if selinux is running.  You can either look in the configuration file located at /etc/selinux/config or just try to look at the variable we are going to disable.
$ sudo /usr/sbin/getsebool rsync_disable_trans
rsync_disable_trans --> off
So this tells us that selinux is running and that rsync is being protected by selinux.  The on/off is a bit confusing, but off means nothing will get to your rsync daemon.  Let's change that.. and restart the xinetd service

 # setsebool -P rsync_disable_trans 1
# service xinetd restart

Mysql Master/Slave Replication on RedHat/Cent OS Linux

Linux OS: RHEL 6.0
Master IP Address: 192.168.176.218
Slave IP Address: 192.168.176.216
Master and Slave are on the same LAN Network
Master and Slave has MySQL version 5.1.47 installed
Master allows remote MySQL connections on port 3306.
Database = apex (This is the database will be replicated to slave)
Phase I: Configure Master Server (192.168.176.218) for Replication
Step 1 #yum install mysql-server mysql

Step 2 #vim /etc/my.cnf (Add the below lines in [mysqld] section)
server-id = 1
binlog-do-db=apex
relay-log = /var/lib/mysql/mysql-relay-bin
relay-log-index = /var/lib/mysql/mysql-relay-bin.index
log-error = /var/lib/mysql/mysql.err
master-info-file = /var/lib/mysql/mysql-master.info
relay-log-info-file = /var/lib/mysql/mysql-relay-log.info
log-bin = /var/lib/mysql/mysql-bin


Step 3 #Restart mysqld server
# /etc/init.d/mysqld restart
Step 4 # Login into MySQL as root user and create the slave user and grant privileges for replication. Replace slave_user with user and your_password with password.


mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'your_password';
mysql> FLUSH PRIVILEGES;
mysql> FLUSH TABLES WITH READ LOCK;






mysql> SHOW MASTER STATUS;

+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 | 11128001 | apex | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

mysql> quit;


Please write down the File (mysql-bin.000003) and Position (11128001) numbers, we required these numbers later on Slave server. Next apply READ LOCK to databases to export all the database and master database information with mysqldump command.
# mysqldump -u root -p --all-databases --master-data > /root/dbdump.db
Once you’ve dump all the databases, now again connect to mysql as root user and unlcok tables.
mysql> UNLOCK TABLES;
mysql> quit;


Upload the database dump file on Slave Server (192.168.1.2) using SCP command.
scp /root/dbdump.db root@192.168.1.2:/root/


Phase II: Configure Slave Server (192.168.176.218) for Replication
# yum install mysql-server mysql

# vi /etc/my.cnf
server-id = 2
master-host=192.168.176.216
master-connect-retry=60
master-user=slave_user
master-password=yourpassword
replicate-do-db=apex
relay-log = /var/lib/mysql/mysql-relay-bin
relay-log-index = /var/lib/mysql/mysql-relay-bin.index
log-error = /var/lib/mysql/mysql.err
master-info-file = /var/lib/mysql/mysql-master.info
relay-log-info-file = /var/lib/mysql/mysql-relay-log.info
log-bin = /var/lib/mysql/mysql-bin
Restart the MySQL service.

# /etc/init.d/mysqld restart


Login into MySQL as root user and stop the slave. Then tell the slave to where to look for Master log file, that we have write down on master with SHOW MASTER STATUS; command as File (mysql-bin.000003) and Position (11128001) numbers. You must change 192.168.176.216 to the IP address of the Master Server, and change the user and password accordingly.

# mysql -u root -p
mysql> slave stop;
mysql> CHANGE MASTER TO MASTER_HOST='192.168.176.216', MASTER_USER='slave_user', MASTER_PASSWORD='yourpassword', MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=11128001;
mysql> slave start;
mysql> show slave status\G


    Verifying MySQL Replication on Master and Slave Server
It’s really very important to know that the replication is working perfectly. On Master server create table and insert some values in it.
    On Master Server
mysql> create database apex;
mysql> use apex;
mysql> CREATE TABLE employee (c int);
mysql> INSERT INTO employee (c) VALUES (1);
mysql> SELECT * FROM employee;
+------+
| c |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
    On Slave Server
Verifying the SLAVE, by running the same command, it will return the same values in the slave too.
mysql> use apex;
mysql> SELECT * FROM employee;
+------+
| c |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
That’s it, finally you’ve configured MySQL Replication in a few simple steps



Linux Root Password Recovery Steps on RedHat/Cent OS




Step 1 #> Single User Mode
  1. Restart the Server
  2. Press Enter in Redhat Enterprise Linux (2.6.32-71.el6_64)
  3. Press e edit
  4. Select the 2nd line which will start the word from kernel
  5. Press e to edit
  6. Type single or s or 1 in end of the line (after rhgb quiet words)
  7. Enter
  8. Press b to boot in single user mode
  9. Shell will come
  10. Type the passwd command and enter the new password for root account


Step 2 #> CD Rescue Mode
  1. Bash-4.1# This shell is read only so follow the step to read/write mode
  2. chroot /mnt/sysimage (This will change the shell to sh-4.1#)
  3. Type the passwd command and enter the new password for root account
OR
  1. Vim /etc/passwd and delete the x letter only (encypted passwd) in root user line.
Ex: root:x:
Step 3 #> Account Lock Remove
  1. Do the same as Single User Mode and run the below command for Unlocking the root user account
  2. Shell> passwd –u root
Step 4 #> Password Expiry Remove
  1. Go the Single User Mode
  2. Shell>chage –l root (To check the account status of root user)
  3. If Account expired run the below command
  4. Shell>chage –E never
RedHat Linux Grub Password Recovery Steps:
  1. If you know the root password just remove the password line from /etc/grub.conf
  2. If you know the root password and want to change the grub password do the below steps
Shell> grub-md5-crypt
#copy the encrypted password and paste it in /etc/grub.conf as like below after the line “timeout”
Password - -md5 encryptedpassword
Ex:
default 0
timeout 8
password --md5 $1$lS2dv/$JOcHkLosIn7CJk9xShzzJVw/
  1. If you don’t know the grub password and root password do the following steps
#Use the CD Rescue Mode and check the grub.conf file
Shell>vim /boot/grub/grub.conf
#Correct the grub.conf file


IPtables Examples on Linux


IPtables Administration

Config File: \etc\sysconfig\iptables Add the below lines for iptables block/accept
Block Incoming Port
Syntax: -A INPUT -p tcp --dport PORT-NUMBER-HERE -j DROP

To Drop a Incoming Port

-A INPUT –p tcp --dport 80 –j DROP


To Drop port from particular ip address or subnet

-A INPUT –p tcp --dport 80 –s ipaddress –j DROP
-A INPUT –p tcp --dport 80 –s ipaddress/subnet –j DROP

Block Outgoing Port

To Drop a Outgoing Port

-A OUTPUT –p tcp --dport 80 –j DROP

To Drop port from particular ip address or subnet

-A OUTPUT –d ipaddress –p tcp --dport 80 –j DROP
-A OUTPUT –d ipaddress/subnet –p tcp --dport 80 –j DROP


To use interface for block and accept

-A INPUT –p tcp –i eth0 --dport 80 –s ipaddress –j DROP
-A OUTPUT –d ipaddress –p tcp –i eth0 --dport 80 –j DROP

Block Incoming Port 80 except for IP Address 192.168.1.1
-A INPUT –p tcp ! –s 192.168.1.1 --dport 80 –j DROP

Block Outcoming Port 80 except for IP Address 192.168.1.1
-A OUTPUT ! –d 192.168.1.1 –p tcp --dport 80 –j DROP


Accept Incoming/Outgoing Port

For Accept use ACCEPT instead of DROP in above lines

How Do I Log Dropped Port Details?
# Logging #
### If you would like to log dropped packets to syslog, first log it ###
/sbin/iptables -A INPUT -m limit --limit 5/min -j LOG --log-prefix "PORT 80 DROP: " --log-level 7

### now drop it ###
/sbin/iptables -A INPUT -p tcp --d-port 80 -j DROP


How Do I Block Cracker (IP: 123.1.2.3) Access To UDP Port # 161?

/sbin/iptables -A INPUT -s 123.1.2.3 -i eth1 -p udp -m state --state NEW -m udp --dport 161 -j DROP

# drop students 192.168.1.0/24 subnet to port 80
/sbin/iptables -A INPUT -s 192.168.1.0/24 -i eth1 -p tcp -m state --state NEW -m tcp --dport 80 -j DROP

Default Chain Policy
As you notice below, it says “(policy ACCEPT)” next to all the three chain names (INPUT, OUTPUT, and FORWARD). This indicates that the default chain policy is ACCEPT.
# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
DROP all -- anywhere anywhere

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
  1. Option 1: Add drop rules
At the end, add the following three drop rules that will drop all incoming, outgoing, and forward packets
iptables -A INPUT -j DROP
iptables -A OUTPUT -j DROP
iptables -A FORWARD -j DROP
  1. Option 2: Change the default chain policy to DROP
At the beginning, execute the following three commands that will change the chain’s default policy to DROP.
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

In the above example:
  • iptables -A INPUT: Append the new rule to the INPUT chain. For incoming connection request, this always has to be INPUT.
  • -i eth0: This refers to the input interface. For incoming connections, this always has to be ‘-i’.
  • -p tcp: Indicates that this is for TCP protocol.
  • –dport 22: This refers to the destination port for the incoming connection. Port 22 is for ssh.
  • -m state: This indicates that the “state” matching module is used. We’ll discuss more about “-m” option (and all available matching modules for iptables) in future article.
  • –state NEW, ESTABLISHED: Options for the “state” matching module. In this example, only NEW and ESTABLISHED states are allowed. The 1st time when a SSH connection request is initiated from the client to the server, NEW state is used. ESTABLISHED state is used for all further request from the client to the server.