Monday, March 28, 2011

Use Gmail Account To Relay Email From a Shell Prompt

yum install ssmtp

vi /etc/ssmtp/ssmtp.conf
AuthUser=username@gmail.com
AuthPass=Your-Gmail-Password
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
:wq!
make sure sendmail is disabled
# service sendmail stop

# chkconfig sendmail off

# mkdir /bakup

# mv /usr/sbin/sendmail /bakup

#  ln -s /usr/sbin/ssmtp /usr/sbin/sendmail

  echo "This is a test" | mail -s "Test" user@domain.com

#######################################################


to get alerts when root logins

add the followings in .bash_profiles in the root home

vi .bash_profile

echo 'ALERT - Root Shell Access on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" user@domain.com


:wq! 

Tuesday, March 15, 2011

Load balance your application in Tomcat


1.Installing Tomcat
2.Installing Apache HTTP Server
3.setting up multiple instances of Tomcat
4.setting up Apache HTTP server


Tomcat 5.5

Download Site: http://tomcat.apache.org/download-55.cgi
Apache HTTP Server 2.0

Download Site: http://httpd.apache.org/download.cgi
Mod JK (Tomcat connector) 1.2.27

Download Site: http://tomcat.apache.org/download-connectors.cgi


I have tested in fedora 13 with default httpd .


Tomcat 5.5 Installation



Extract the Tomcat zip file. Hereafter, the directory you extracted to will be referred to as /INSTANCE1


Test Tomcat to see that it works. Go to /INSTANCE1/bin and run startup.sh. You may need to add an environment variable called JAVA_HOME, CATALINA_HOME which is set to /INSTANCE1 in case Tomcat fails to start.


Open up your browser and access http://localhost:8080/. If you see the default page, then Tomcat Instance 1 is working fine. Shut down Tomcat.

Setting up multiple Tomcat instances


Make a dir called /INSTANCE2

cp -r /INSTANCE1/* /INSTANCE2/

Open up /INSTANCE2/conf/server.xml in a text editor. We’ve got to change the port numbers so that they don’t conflict with the first instance.

In /INSTANCE1

8005” shutdown=”SHUTDOWN”>
8080” maxHttpHeaderSize=”8192″…
8009” enableLookups=”false” redirectPort=”8443” protocol=”AJP/1.3″ />
!!!!!!!!!!!!!!!
In /INSTANCE2

9005” shutdown=”SHUTDOWN”>
9090” maxHttpHeaderSize=”8192″…
9009” enableLookups=”false” redirectPort=”9443” protocol=”AJP/1.3″ />

!!!!!!!!!!!!!!!!!!!!!!!!!!!
Now stop the first instance of Tomcat and start the second instance. This is to verify the second is starting up and running.

Access http://localhost:9090 in your browser. If you see the default page, then Tomcat Instance 2 is working fine. Shut down Tomcat.

Till now we ran Tomcat instances individually. Now start both the instances using their startup.sh respectively.

Once both started with out any problem, open up two browser clients and enter http://localhost:8080/ and http://localhost:9090. If you see the default page, in both the browser clients then both Tomcat Instance1 and Instance 2 are working fine with out any conflicts.
 

Setting up Apache HTTP Server for load balance

First, download the correct binary for your architecture and install it:

wget http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.23/mod_jk-1.2.23-apache-2.2.x-linux-i686.so

chmod +x mod_jk-1.2.23-apache-2.2.x-linux-i686.so

cp -r mod_jk-1.2.23-apache-2.2.x-linux-i686.so /etc/httpd/modules/mod_jk.so
##############################################
vi /etc/httpd/conf/worker.properties
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# The advanced router LB worker
workers.tomcat_home=/INSTANCE1
workers.java_home=JAVA_HOME
worker.list=balancer

# Define a worker using ajp13
# Mention the AJP connector port defined in Tomcat server.xml
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1

# Define another worker using ajp13
# Mention the AJP connector port defined in Tomcat server.xml
worker.worker2.port=9009
worker.worker2.host=localhost
worker.worker2.type=ajp13
worker.worker2.lbfactor=1

worker.balancer.type=lb
worker.balancer.balance_workers=worker1,worker2
worker.balancer.method=B

# Add the status worker to the worker list
worker.list=jkstatus
# Define a ‘jkstatus’ worker using status
worker.jkstatus.type=statu
!!!!!!!!!!!!!!!!!!!!!!
:wq!
#############################
vi /etc/httpd/conf.d/mod_jk.conf
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
LoadModule jk_module modules/mod_jk.so

JkWorkersFile /etc/httpd/conf/workers.properties

JkShmFile /var/log/httpd/mod_jk.shm

JkLogFile /var/log/httpd/mod_jk.log

JkLogLevel info

JkMount /* balancer

JkMount /jkmanager/* jkstatus
:wq!
#######################
Create a test folder under the webapp folder on INSTANCE2
under that create a file index.jsp
 vi index.jsp
Hello, I am a jsp script!
:wq!



Restart httpd and open the link http://localhost/test/

Wednesday, March 9, 2011

Simple http load balancing with Apache.

 Since version 2.2 the Apache web server ships a load balancer module called mod_proxy_balancer. All you need to do is to enable this module and the modules mod_proxy and mod_proxy_http:
 
vi /etc/httpd/conf/httpd.conf
LoadModule proxy_module mod_proxy.so
LoadModule proxy_http_module mod_proxy_http.so
LoadModule proxy_balancer_module mod_proxy_balancer.so

:wq!

Please don't forget to load mod_proxy_http, because you wouldn't get any error messages if it's not loaded. The balancer just won't work.

Because mod_proxy makes Apache become an (open) proxy server, and open proxy servers are dangerous both to your network and to the Internet at large, I completely disable this feature: 

vi /etc/httpd/conf/httpd.conf
 
ProxyRequests Off

Order deny,allow
Deny from all

:wq!


The load balancer doesn't need this feature at all.

now create a index.html file on all servers



And here's the actual load balancer configuration:
############################

vi /etc/httpd/conf/httpd.conf

{Proxy balancer://clusterABCD}
BalancerMember http://serverA
BalancerMember http://serverB
BalancerMember http://serverC
BalancerMember http://serverD
Order allow,deny
Allow from all
{/Proxy}
ProxyPass / balancer://clusterABCD/

:wq!
/etc/init.d/httpd restart

The {Proxy}...{/Proxy} container defines which backend servers belong to my balancer. I chose the name clusterABCD for this server group, but you are free to choose any name you want.
And the ProxyPass directive instructs the Apache to forward all incoming requests to this group of backend servers.

Tuesday, March 1, 2011

Websvn How to on fedora


Install the packages with yum

  yum install websvn.noarch
  yum install subversion

Create a directory
mkdir -p /srv/svn

svnadmin create --fs-type fsfs /srv/svn/nix


Now open the conf file [vi /etc/websvn/config.php]
and add the following

$config->parentPath('/srv/svn/');


$extEnscript[".pl"] = "perl";
$extEnscript[".py"] = "python";
$extEnscript[".sql"] = "sql";
$extEnscript[".java"] = "java";
$extEnscript[".html"] = "html";
$extEnscript[".xml"] = "html";
$extEnscript[".thtml"] = "html";
$extEnscript[".tpl"] = "html";
$extEnscript[".sh"] = "bash";

#################

Then save it and restart httpd and open the url

http://urip/websvn

now you can see the repo nix ..................