Wednesday, September 19, 2012

convert bmp to jpg


if [ -z "$1" ];then
        echo "Error: please put a file path to convert"
        exit 1
else
        CPATH="$1"
fi

find $CPATH -type f -iname \*.bmp | while read filename; do

    convert "$filename" -quality 100% "$filename".jpg && rename .bmp.jpg .jpg "$filename".jpg && rm "$filename"
done


script thanks to my Manager Lye

mod_evasive


mod_evasive is a plugin for Apache Web Server to prevent DOS attack.

After a few weeks of trial and error, research. mod_evasive is able to work with iptables.

Here is the installation steps:

1) yum install mod_evasive
2) vi /etc/httpd/conf.d/mod_evasive.conf

<------------------------------ mod_evasive.conf content ----------------------------------->
LoadModule evasive20_module modules/mod_evasive20.so

<IfModule mod_evasive20.c>
    DOSHashTableSize    3097
    DOSPageCount        2
    DOSSiteCount        50
    DOSPageInterval     1
    DOSSiteInterval     1
    DOSBlockingPeriod   10
    DOSEmailNotify      sat.server@my.offgamers.lan
    DOSSystemCommand    "bash /var/lock/mod_evasive/evasive.sh %s"
    DOSLogDir           "/var/lock/mod_evasive"
    #DOSWhitelist       127.0.0.1
    #DOSWhitelist       192.168.0.*
</IfModule>
<------------------------------ mod_evasive.conf content ----------------------------------->

3) mkdir /var/lock/mod_evasive
4) chown apache:apache /var/lock/mod_evasive
* mod_evasive need to record the DOS IP address to this directory
5) vi /var/lock/mod_evasive/evasive.sh
<------------------------------ evasive.sh content ----------------------------------->
sudo /sbin/iptables -I INPUT -s $1 -j DROP
sleep 600
sudo /sbin/iptables -D INPUT -s $1 -j DROP
sudo /bin/rm -f /var/lock/mod_evasive/dos-$1
<------------------------------ evasive.sh content ----------------------------------->
How evasive.sh work?
mod_evasive detected DOS, it will execute the evasive.sh and create a file like dos-172.30.10.223 under /var/lock/mod_evasive.
the dos-* files are used to keep track the blocked IP address.
Execute evasive.sh will do the following things:
Issue iptables too drop the IP address, sleep for ten minutes, and then remove the blocked IP address, after that delete the dos-* file
under /var/lock/mod_evasive, otherwise it wouldn't re-block again.

6) visudo
Change:
Defaults requiretty -> #Defaults requiretty

Add:
Cmnd_Alias EVASIVE = /sbin/iptables, /bin/rm
apache   ALL=(ALL)   NOPASSWD: EVASIVE

7) finally restart httpd service, use watch -n 1 -d iptables -nvL and watch -n 1 -d ls -lsa /var/lock/mod_evasive to monitor how the process working


Information thanks to my Senior Voo

Friday, August 3, 2012

Setup nagios

Nagios Server

add rpmforge into the server repo

# yum install nagios nagios-nrpe nagios-plugins nagios-plugins-nrpe perl-Nagios-Plugin
# chkconfig nagios on
# chkconfig nrpe on

Edit the /etc/httpd/conf.d/nagios.conf to remove the SSL and user authentication
# vim /etc/httpd/conf.d/nagios.conf


  1  ScriptAlias /nagios/cgi-bin "/usr/lib64/nagios/cgi"
  2
  3  <Directory "/usr/lib64/nagios/cgi">
  4  #  SSLRequireSSL
  5     Options ExecCGI
  6     AllowOverride None
  7     Order allow,deny
  8     Allow from all
  9  #   AuthName "Nagios Access"
 10  #   AuthType Basic
 11  #   AuthUserFile /etc/nagios/htpasswd.users
 12  #   Require valid-user
 13  </Directory>
 14
 15  Alias /nagios "/usr/share/nagios"
 16
 17  <Directory "/usr/share/nagios">
 18  #  SSLRequireSSL
 19     Options None
 20     AllowOverride None
 21     Order allow,deny
 22     Allow from all
 23  #   AuthName "Nagios Access"
 24  #   AuthType Basic
 25  #   AuthUserFile /etc/nagios/htpasswd.users
 26  #   Require valid-user
 27  </Directory>
-----------------------------------------------------------------------------------

Edit /etc/nagios/cgi.cfg
# vim /etc/nagios/cgi.cfg


 use_authentication=0
 use_ssl_authentication=0
----------------------------------------------------------------------------------
# vim  /etc/nagios/objects/server.cfg



define hostgroup{
        hostgroup_name  linux-server
        alias           Linux Servers
        members         localhost,my-dns2
        }


define host{
        use                     linux-server
        host_name               my-dns2
        alias                   my-dns2
        address                 my-dns2.offgamers.lan
        }

define service{
        use                     local-service
        host_name               my-dns2
        service_description     Swap
        check_command           check_nrpe!check_swap
        }




# vim  /etc/nagios/nagios.cfg

add the location of the hosts file in the object folder


Format: cfg_file=<file_name>
Example: cfg_file=/usr/local/nagios/etc/hosts.cfg
                cfg_file=/usr/local/nagios/etc/services.cfg
                cfg_file=/usr/local/nagios/etc/commands.cfg





Nagios Client


# yum install nagios-nrpe nagios-plugins nagios-plugins-nrpe perl-Nagios-Plugin
# chkconfig nrpe on

# vim /etc/nagios/nrpe.cfg
allowed_hosts=127.0.0.1,172.30.10.218

at the bottom, edit the check command to suit your environment
----------------------------------------------------------------------------------





If you start Nagios server having error
use
# nagios -v /etc/nagios/nagios.cfg 
to check whats wront




Nagios Option available

http://nagios.sourceforge.net/docs/3_0/objectdefinitions.html

smokeping 2.6.8 for Centos 6.3

add rpmforge into your linux repo

yum install:

  • mod_fcgid
  • httpd
  • httpd-devel
  • rrdtool
  • perl-CGI-SpedtCGI
  • fping
  • perl-RRD-Simple
  • perl
# yum install mod_fcgid httpd httpd-devel rrdtool perl-CGI-SpeedCGI fping perl-RRD-Simple perl
# yum groupinstall "Development tools"

download the smokeping package from
http://oss.oetiker.ch/smokeping/pub/

# wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.8.tar.gz
# tar -zxvf smokeping-2.6.8.tar.gz
# mv smokeping-2.6.8  /opt/smokeping
# cd smokeping-2.6.8

then manual install perl package manually

#perl -MCPAN -e shell

> install FCGI
> install CGI::Fast
> install Config::Grammar
> install Digest::HMAC_MD5
> install Net::Telnet
> install Net::OpenSSH
> install Net::SNMP
> install Net::LDAP
> install Net::DNS
> install IO::Pty
> install LWP


other from manually install, you can run the script locate at smokeping /opt/smokeping/setup
# cd  /opt/smokeping/setup
# ./build-perl-modules.sh

after done, run to configure and make install
# cd /opt/smokeping
# ./configure --prefix=/opt/smokeping
# make install


now we go for preparing for the configuration file
# cd /opt/smokeping/etc
# for foo in *.dist; do cp $foo `basename $foo .dist`; done

#vim /etc/httpd/conf/httpd.conf

change:
DirectoryIndex index.html index.html.var
to:
DirectoryIndex index.html index.html.var smokeping.fcgi

then enable this
AddHandler cgi-script .cgi

-------------------------------------------------------------------------------------------
# vim /etc/httpd/conf.d/smokeping.conf

<Directory "/var/www/html/smokeping">
    Options +ExecCGI
</Directory>
-------------------------------------------------------------------------------------------

# mkdir /opt/smokeping/img
# chown -R apache:apache /opt/smokeping/img
# ln -s /opt/smokeping/htdocs /var/www/html/smokeping
# ln -s /opt/smokeping/img /var/www/html/smokeping

# mkdir /opt/smokeping/data

# mkdir /opt/smokeping/var

# chmod 600 /opt/smokeping/etc/smokeping_secrets
# chown -R apache:apache /var/www/html/smokeping

restart the httpd
# /etc/init.d/httpd restart

edit the smokeping config to your need
# vim /opt/smokeping/etc/config

start the smokeping services
# ./bin/smokeping --config=/opt/smokeping/etc/config --logfile=smoke.log


Reference and help thanks to Tony from http://ai.net.nz

Tuesday, July 31, 2012

Install VMware-tools for Centos 6.3

At EXSi there, right click on the server > Guest > install/upgrade VMware tools
after that enter to the server console

# mount /dev/cdrom /mnt
# cd /mnt
# cp VMwareTools-xxx.tar.gz  /root/
# cd  /root
# tar -zxvf VMwareTools-xxx.tar.gz
# cd vmware-tools-distrib
# ./vmware-install.pl

just click enter until the end

if you received error saying to locate the c compiler
just make a yum update kernel and kernel-devel, then re-run the installer again

# yum update kernel
# /sbin/shutdown -r now

# ./vmware-install.pl

squidview

download the latest package from 
http://www.rillion.net/squidview/

# tar -xzvf squidview-0.7x.tar.gz
# cd squidview-0.7x

before this, make sure you have all the package needed
# yum groupinstall "Development tools"
# yum install ncurses-static

proceed to compile and install
# ./configure
# make 
# cp Makefile.old Makefile
# make oldgcc
# make install




Wednesday, July 18, 2012

Remove squid cache manually


Stop squid using the command /etc/init.d/squid stop

Next Delete cache directory using rm -rf /var/spool/squid

Create new cache directory using mkdir /var/spool/squid

Change ownership to squid user chown squid:squid /var/spool/squid

Create cache again using the command squid -z

Finally start Squid using the command /etc/init.d/squid start