Suresh Payankannur

Showing posts with label tomcat. Show all posts
Showing posts with label tomcat. Show all posts

Tuesday, August 18, 2015

Ubuntu + Jenkins + Gradle + Embedded Tomcat + Port 80

Port 80 is a privileged port and normal users cannot listen on this port. I had a recent requirement to run some test cases on an embedded tomcat running on Port 80 during Jenkins build. Here is the steps worked for me to achieve this.

Gradle File

apply plugin: 'java'
apply plugin: 'war'

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.2'
  }
}

apply plugin: 'com.bmuschko.tomcat'

tomcat {
  httpPort = 80
  contextPath = "/"
}

Setup authbind

authbind will allow non-root user to listen on privileged ports.
sudo apt-get install authbind
sudo touch /etc/authbind/byport/80
sudo chmod 500 /etc/authbind/byport/80 
sudo chown jenkins /etc/authbind/byport/80

Configure Jenkins

Modify the Jenkins run command (last line in do_start routine)to the following
$SU -l $JENKINS_USER --shell=/bin/bash -c "$DAEMON $DAEMON_ARGS -- authbind --deep $JAVA $JAVA_ARGS -jar $JENKINS_WAR $JENKINS_ARGS" || return 2

Monday, November 18, 2013

Apache Load Balancing & Fail Over with mod_proxy

Apache mod_proxy and the extension mod_proxy_balancer can be used for load balancing and fail over. The following setup is used for two downstream Tomcat servers with a candidate web app deployed at the root.

httpd.conf (On Mac OS, Mavericks)
LoadModule proxy_module libexec/apache2/mod_proxy.so
LoadModule proxy_ajp_module libexec/apache2/mod_proxy_ajp.so
LoadModule proxy_balancer_module libexec/apache2/mod_proxy_balancer.so
ProxyRequests Off
<Proxy balancer://cluster>
    BalancerMember ajp://localhost:8009  loadfactor=1 ping=10
    BalancerMember ajp://localhost:18009 loadfactor=2 ping=10
</Proxy>
ProxyPass          /status   !
ProxyPass          /balancer !
ProxyPass          /         balancer://cluster/
ProxyPassReverse   /         balancer://cluster/

ProxyStatus On
<Location /status>
    SetHandler server-status
    Order Deny,Allow
    Deny from all
    Allow from all
</Location>

<Location /balancer>
    SetHandler balancer-manager
    Order Deny,Allow
    Deny from all
    Allow from all
</Location>

Sunday, July 31, 2011

Confluence + Tomcat + Ubuntu + MySQL

To install the EAR/WAR version of Confluence follow these steps. This assumes basic knowledge on Ubuntu, MySQL, Tomcat etc.
  1. Download the latest EAR/WAR version
  2. Unpack the distribution
        % sudo tar xvf confluence-3.4.6.tar -C /opt
    
  3. Create symlink wiki for the confluence distribution
        % cd /opt
        % sudo ln -s confluence-3.4.6 wiki
        % sudo chown -R tomcat6:tomcat6 wiki
      
  4. Create the data directory
        % sudo mkdir /var/data/wiki
        % sudo chown -R tomcat6:tomcat6 /var/data/wiki
      
  5. Edit the /opt/wiki/confluence/WEB-INF/classes/confluence-init.properties and set the value of variable confluence.home to /opt/wiki/confluence
  6. Edit /etc/default/tomcat6 and adjust the JVM settings
    JAVA_OPTS="-Djava.awt.headless=true -Xmx640m -XX:+UseConcMarkSweepGC -XX:MaxPermSize=256m"
    
  7. Modify /opt/wiki/confluence/WEB-INF/classes/log4j.properties so that the log files will be produced under /var/log/tomcat6
    • Comment the line for ConfluenceHomeLogAppender
    • Uncomment the line for RollingFileAppender
    • Set the log location to /var/log/tomcat6/atlassian-confluence.log
    • Set the debug threshold to WARN
  8. Create a confluence database
        % mysqladmin -u root -p create wiki
        % mysql -u root -p
        % mysql> grant all privileges on wiki.* to 'wikiuser'@'localhost' identified by 'wikipass' with grant option;
        % mysql> commit;
        % mysql> flush all privileges;
      
  9. Setup the confluence context: In the /var/lib/tomcat6/conf/Catalina/localhost directory, create a file called confluence.xml with the following contents:
    <Context path="/wiki" docBase="/opt/wiki/confluence" debug="0" reloadable="0"/>
    
  10. Restart tomcat
        % sudo /etc/init.d/tomcat6 restart
    

  11. Point the browser to localhost:8080/wiki and follow the instructions

Installing Apache + Tomcat on Ubuntu

  1. Install the packages
        sudo apt-get update
        sudo apt-get dist-upgrade
        sudo apt-get install apache2
        sudo apt-get install tomcat6
        sudo apt-get install libapache2-mod-jk
      
  2. Adjust the startup parameters like heap space, permgen etc. by modifying the file /etc/default/tomcat6
  3. Uncomment the AJP connector from the server configuration by modifying /var/lib/tomcat6/conf/server.xml
  4. Add the jk worker properties file by creating a new file /etc/apache2/jk_workers.properties with the following content:
        # List of workers
        worker.list = local, status
    
        # Local worker
        worker.local.type=ajp13
        worker.local.host=localhost
        worker.local.port=8009
    
        # Status worker
        worker.status.type=status
      
  5. Add a new file /etc/apache2/mods_available/jk.conf with the following content:
        JkWorkersFile /etc/apache2/jk_workers.properties
        JkShmFile     /var/log/apache2/mod_jk.shm
        JkLogFile     /var/log/apache2/mod_jk.log
        JkLogLevel    info
        JkLogStampFormat "[%a %b %H:%M:%S %Y]"
      
  6. Enable the mods
          % cd /etc/apache2/mods-enabled
          % sudo ln -s ../mods-available/jk.conf jk.conf
        
  7. Edit /etc/apache2/sites-available/default and add the JK Mount points. At the end of the file, in the same virtual host definition, add the following:
        JkMount /servlet* local
        JkMount /tomcat-status status
      
  8. Reboot the server
          % sudo reboot now
        

Blog Archive

Scroll To Top