Tomcat -Virtual hosts and Access logging

In CategoryComputer Networks, Linux
Bysreekanth

Some times we may need to run multiple websites on single ip address with the same port number ,for example http( tcp-80 ) port .

If I have 2 websites called  www.example1.com and  www.example2.com pointing to same webserver 10.0.0.10,  then i will configure my tomcat webserver( 10.0.0.10 )following way .

 

Using vim editor i will  edit /tomcat_directory/conf/server.xml and add seperate  virtual host entries for each domain .

 

<Host name=”www.example1.com” debug=”0″ appBase=”example1″
unpackWARs=”true” autoDeploy=”true”
xmlValidation=”false” xmlNamespaceAware=”false”>
<Context path=”” docBase=”.”/>
<Logger className=”org.apache.catalina.logger.FileLogger”
directory=”logs” prefix=”localhost_log.” suffix=”.txt”
timestamp=”true”/>
<Valve className=”org.apache.catalina.valves.AccessLogValve” directory=”logs”

prefix=”localhost_access_log.” suffix=”.txt” pattern=”common” resolveHosts=”false”/>

<Host name=”www.example2.com” debug=”0″ appBase=”example2″
unpackWARs=”true” autoDeploy=”true”
xmlValidation=”false” xmlNamespaceAware=”false”>
<Context path=”” docBase=”.”/>
<Logger className=”org.apache.catalina.logger.FileLogger”
directory=”logs” prefix=”localhost_log.” suffix=”.txt”
timestamp=”true”/>
<Valve className=”org.apache.catalina.valves.AccessLogValve” directory=”logs”

prefix=”localhost_access_log.” suffix=”.txt” pattern=”common” resolveHosts=”false”/>

</Host>

</Engine>

</Service>

</Server>

 

 

example1 and example2  are root directories  where we  can copy webpages .

<Valve className=”org.apache.catalina.valves.AccessLogValve” directory=”logs”

prefix=”localhost_access_log.” suffix=”.txt” pattern=”common” resolveHosts=”false”/>  ……. this entry will log  website access logs  in /tomcat_directory/logs .

 

 

Crontab in centos 6

In CategoryLinux
Bysreekanth

 

 

 

Getting  -bash: crontab: command not found  when i enter crontab -e  command ,

I figured it out after googling around ,  that crontab package is replaced by “cronie” in enterprise linux 6.

I confirmed it

[root@localhost ~]# rpm -qf `which crontab`
cronie-1.4.4-7.el6.x86_64

So i did…………….. # yum install cronie

 

 

Installing htop on centOS

In CategoryLinux
Bysreekanth

Htop is a linux processes viewing utility which is similar to built in ps –aux commands.

Isntalling htop is simple if we have  gcc c++ ,ncurses-devel  ready on the mechain.

cd /
# wget-c http://internode.dl.sourceforge.net/project/htop/htop/0.8.3/htop-0.8.3.tar.gz
# tar-xvf htop-0.8.3.tar.gz
# cd htop-0.8.3
# yum install gcc c + +
# yum install ncurses-devel
#. / configure
# make
# make install

 

#htop  command will print the running processes information something like below.

Save yum packages for later offline installation

In CategoryLinux
Bysreekanth

 

 

Sometimes we may need to save installation packages which are installed by using  yum.

This is useful if we want to reinstall the rpm packages when  internet is not available .

 

# vi /etc/yum.conf

cachedir=/var/cache/yum

keepcache=1

 

 

 

 

 

 

 

 

 

 

Now we have all packages saved in /var/cache/yum directory  and we can install all packages including dependencies with the command rpm -ivh *.rpm

# cd /var/cache/yum

#rpm -ivh *.rpm

 

If any dependencies are missing , we can insert the OS installation disk and type the command ‘ yum localinstall *.rpm’.

#yum localinstall *.rpm

Receive Linux command history to mail automatically

In CategoryLinux
Bysreekanth

——————————————————————————————————

 

Basically i am a tech-enthusiastic.

When we seek for any support, Linux admins used to connect and work remotely on our servers which are hosted in a remote location.

I was so interested to know how they fix the issues , So i came up with this idea of getting the history of terminal commands they typed in to terminal into my mailbox automatically.

I tried this small script and it worked well.

I first created a script which will send a mail with the history contents.

#cd /tmp

#vi hist.sh

and typed the below lines.

#!/bin/bash
NOW=$(date)
mail -s “Log $HOSTNAME @ $NOW” balusreekanth@gmail.com <$HOME/.bash_history

entered !wq to save and quit from vi editor and to make it executable

#chmod -x hist.sh

Now the script is ready to send email with the bash history.

We can test it by executing the script #./hist.sh

Now We can add the script to crontab and schedule it to send email periodically .

I wanted make it to send the command history automatically whenever  the .history file is modified whichmeans ,

whenever someone connected to terminal ,I should receive an mail with a copy of the terminal commands history.

To achive this I used incrontab . Incrontab is just like cron scheduler , but with additional capabilities

-which allows us to configure like file ,directory watch etc.,.

 

I downloaded incron rpm from http://pkgs.repoforge.org/incron/_buildlogs/ and

 

 

After adding root user to /etc/incron.allow , I typed incrontab -l  which returnded “no table for root’  ,because I dont have any jobs configured yet.

I typed #incrontab -e to create a user table and added this line ~/.bash_history IN_MODIFY /tmp/./hist.sh

( assuming we have the script file in temp directory) .

 

Voila thats all ! I just received an email

 

 

 

 

 

 

—————————————————————————————————