Monday, March 30, 2009

Ubuntu Admin Commands

Adding Users, Groups and Changing password

Adding the new created user to sudoer file

sudo useradd -d /home/admin -m admin

sudo gedit /etc/sudoers

Ubuntu Commands
cat /etc/issue : to check the current version of ubuntu

APT(Advance Packaging Tool) COMMANDS
apt-get update && apt-get upgrade -y (** Neeed to get the packages list and upgrade done before other apache files can be submittied)
**Some Other packaging commands which might be useful
apt-cache search

To search fro a particular keyword on all files and subdirectories use following command
grep -nr 'ServerName' /etc/apache2

Creating directories and subdirectories
mkdir -p public_html/{public,private,logs,cgi-bin,backup}
Check which ports are in use
netstat -ant : displays are listening ports

Thursday, March 26, 2009

Apache2 Tomcat5 Conf on Fedora

1. Install and start apache2
  • sudo yum install httpd
  • sun yum upgrade httpd
  • Find the service name that is installed for apache to start it
sudo /sbin/chkconfig --list | grep httpd
sudo service httpd start
2. Install and start tomcat5
  • sudo yum install tomcat5
  • sudo yum upgrade tomcat5
  • sudo /sbin/chkconfig --list | grep tomcat
  • sudo service tomcat5 start
3. Note : to automatically start httpd and tomcat5 on reboot, add following lines
sudo/sbin chkconfig httpd on
sudo/sbin chkconfig tomcat5 on

Monday, March 23, 2009

Apache2 Tomcat6 Java MySql on Ubuntu

Check the list of Ubuntu EC2 AMIS available at
Click here to get started with launching EC2 AMIs click here

Installing JDK6, Apache And Tomcat
  • apt-get update && apt-get upgrade -y
  • Install APACHE: sudo apt-get install apache2
  • Install JDK6 : sudo apt-get install sun-java6-jdk
  • Install Tomcat :
export JAVA_HOME=/usr/lib/jvm/java-6-sun
sudo apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-examples

Test if tomcat is running
/etc/init.d/tomcat6 status

Tomcat is installed in /var/lib/tomcat6 with main files linked in /etc/tomcat6
check more about tomcat6 configuration here

Configuring Apache2 with Tomcat6
Congiruation Setup for Apache2 Virtual Host Configuration setup,by SlicetHost clicking here

At this point, I am assuming Apache2 , Java6 and Tomcat6 are installed and running fine independantly.

1. In Order to, Apache and Tomcat to talk, Mod jk connector is needed

sudo apt-get install libapache2-mod-jk
sudo a2enmod jk

2. After that, check whether there is jk.load in the apache 2 modules
sudo ls /etc/apache2/mods-enabled/

5. Edit and save the two lines of
sudo vi /etc/libapache2-mod-jk/

6. Edit and save the two lines in tomcat-users.xml
sudo vi /etc/tomcat6/tomcat-users.xml

Mod_Jk configuration
  • cd /etc/apache2
  • cp /usr/share/doc/libapache2-mod-jk/httpd_example_apache2.conf mods-available/jk.conf
  • vi jk.conf and add the following
  • JkWorkersFile /etc/libapache2-mod-jk/
    JkShmFile /var/run/apache2/jk-runtime-status
    JkLogFile /var/log/apache2/mod_jk.log
    JkLogLevel debug

8. Lets also configure Apache2 to server for Virtual Hosts

  • mkdir -p /var/www/public_html/{public,private,logs,cgi-bin,backup}
  • mkdir -p /var/www/public_html/{public,private,logs,cgi-bin,backup}
  • add some index.html files in the public directory
  • create a file in /etc/apache2/sites-available
vi /etc/apache2/
#domain :
#public /var/www/public_html/


#index file sand doc root
DirectoryIndex index.html
DocumentRoot /var/www/public_html/
AllowOverride All allow from all Options +Indexes
#custom log file

LogLevel info
ErrorLog /var/www/public_html/
CustomLog /var/www/public_html/ combined

  • a2ensite
  • /etc/init.d/apache2 reload
  • Follow the same steps for too..
9. Test the Apache2 Virtual Hosts
  • edit the /etc/hosts file and add entries for domain1.come and
  • Open the browser and type , you should see the page

/var/lib/tomcat6/lib (CATALINA_BASE)
/usr/share/tomcat6/lib (CATALINA_HOME) (Classes are loaded from here)

Reference Links
UBuntu's apache2 file structure is different with the addition of apache2.con, mods-available, mods-enables, sites-available, sites-enabled convention. Here is a good blog which explains this direcotry structure in details, click here

Good Article on How to Configure Apache2 with Tomcat, click here

Research Links
Configuring Apache2 with Multiple Instances of Tomcat, clikc here

Friday, March 20, 2009

Gitweb on EC2

  • Setup EC2 with a debian image, this example is based on AMI - ami-7cfd1a15
  • apt-get upgrade
  • apt-get install git-core gitk gitweb
  • Setup up gitosis and test the git works with a client
Follow the article in this link
Also, check the gitosis documentation, click here
To setup git repository with gitosis, here are some excellent articles to get started with

Sample Gitosis conf can be found at;a=blob;f=example.conf;hb=master

  • So now gitosis is working fine and gitweb has been installed. Lets assume following values * Git trees are in /srv/git/repositories
  • Lets configiure apache for virtual hosts, so that gives us the gitweb
  • In /var/www create following dirs mkdir -p /var/www/ {cgi-bin}
  • In the cgi-bin directory, copy the , git-favicon.png, git-logo.png, gitweb.cgi and gitweb.css files.
  • Configure the /etc/gitweb.conf file for gitweb settings
vi /etc/gitweb.conf
# path to git projects (.git)
$projectroot = "/srv/git/repositories";

# directory to use for temp files
$git_temp = "/tmp";

# target of the home link on top of all pages
#$home_link = $my_uri || "/";

# html text to include at home page
$home_text = "indextext.html";

# file with project list; by default, simply scan the projectroot dir.
$projects_list = $projectroot;

# stylesheet to use
$stylesheet = "/gitweb.css";

# logo to use
$logo = "/git-logo.png";

# the 'favicon'
$favicon = "/git-favicon.png";

#Enable blame, pickaxe search, snapshop, search, and grep
# support, but still allow individual projects to turn them off.
# These are features that users can use to interact with your Git trees. They
# consume some CPU whenever a user uses them, so you can turn them off if you
# need to. Note that the 'override' option means that you can override the
# setting on a per-repository basis.
$feature{'blame'}{'default'} = [1];
$feature{'blame'}{'override'} = [1];

$feature{'pickaxe'}{'default'} = [1];
$feature{'pickaxe'}{'override'} = [1];

$feature{'snapshot'}{'default'} = [1];
$feature{'snapshot'}{'override'} = [1];

$feature{'search'}{'default'} = [1];

$feature{'grep'}{'default'} = [1];
$feature{'grep'}{'override'} = [1];

  • Now lets create the virtual host setting in apache2
1. vi /etc/apache2/sites-available/

DocumentRoot "/var/www/"
DirectoryIndex gitweb.cgi
SetEnv GITWEB_CONFIG /etc/gitweb.conf

ScriptAlias /cgi-bin/ /var/www/

Options Indexes FollowSymlinks ExecCGI
Allow from all
AllowOverride None
Order allow,deny

SetHandler cgi-script

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.* /gitweb.cgi/$0 [L,PT]

2. a2ensite

3. Restart apache service apache2 restart

This should get you going on gitweb, Make sure you are running apache2 from a different user and not as a root.
To tell apache to use a different user , vi /etc/apache2/envvars and add the users settings there

Reference Links

EC2 Command line and Unix Commands reference

This blog assumes the user is already familiar with Amazon EC2, this is just a quick reference guide.

EC2 Commad Line API Tools
  • ec2-describe-images -x all : to display all available ec2 images
  • ec2-add-key mb-keypair : generates a keypair which will be instead of a root password
  • ec2-run-instances ami-a9fe1bc0 -k mbkeypair starts running a EC2 Instance, this is when billing starts
  • ec2-authorize default -p 22 : opens up the port 22 for ssh, similary 80 for port 80
  • ec2-describe-instances : displays list of ec2 instances running
  • ec2-terminate-instances ami-a9fe1bc0 : terminates a ec2 running instances. This is where billing ends
More Summary cheat sheet for EC2 click here
Unix Comands to Run Apache , Tomcat and Deploy war files

Putty is a client program for SSH, Telnet and Rlogin Protocols used to run remote sessions over a network.
SSH protocol allows to remote login to a system, unlike telnet SSH encrypts the login session, making it impossible for intruders to collect clear text passwords.In short SSH, ecrypts everything it sends and recieves.
SSH is often required to login to remote systems without requiring passowrd. ssh-keygen is used to generate that key pair for you.

SSH uses public key cryptography to secure transactions and data exchange. Public key cryptography consists of a set of two keys: a public key-private key pair. A public key or a private key is a complex algorithm. The keys are:

  • Public key: A key that is distributed publicly to other parties and partners to access data without compromising security. It is used to decrypt data.

  • Private key: Used to generate messages. It is used to encrypt data. Access to the private key is possible only for authentic users who have the rights to initiate the data exchange

To learn about sshkeys click here

Grails Plugin

Screencast on Grails EC2 Plugin by Chris Richardson
A very good EC2 Presentation by Chris Richardson