Tuesday, June 18, 2013

Install Jenkins on Ubuntu and Setting up it on port 80

How to install Jenkins on Ubuntu

You can find the best instruction from Jenkins official site https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu

Setting up it on any other port

Be default Jenkins will run on port 8080 which is also the default port used by Tomcat. So For Java developer, it is not a good idea to let Jenkins use port 8080. 

To modify the default port of Jenkins is very simple, do it by modifying /etc/default/jenkins.

# port for HTTP connector (default 8080; disable with -1)
HTTP_PORT=8080 

Change the post number to any port you want rather than 80 which will be covered in the following content.


The following content is a modification of Hans Häggström's  post

Setting up it on port 80

To set up jenkins to run on port 80 (the normal http port) instead of 8080 you could edit /etc/default/jenkins and add --httpPort=80 to JENKINS_ARGS and the modified content will looks like:

JENKINS_ARGS="--webroot=/var/cache/jenkins/war --httpPort=$HTTP_PORT --ajp13Port=$AJP_PORT --httpPort=80 --prefix=/jenkins"

Jenkins Prefix

We want to see jenkins running on servername/jenkins/.  The first step is to change the prefix jenkins uses, so we get from servername:8080/ to servername:8080/jenkins/.  To do that, add
  
    --prefix=/jenkins


and the modified content will looks like:

JENKINS_ARGS="--webroot=/var/cache/jenkins/war --httpPort=$HTTP_PORT --ajp13Port=$AJP_PORT --httpPort=80 --prefix=/jenkins"


to the JENKINS_ARGS string in /etc/default/jenkins and restart Jenkins with e.g.:

    sudo /etc/init.d/jenkins force-reload


Apache

If you don't have apache installed, use

    sudo apt-get install apache2

to install it.


mod_proxy

In many distributions it should be included by default with apache, but you may need to install the mod_proxy module separately:

    sudo apt-get install libapache2-mod-proxy-html

In any case you need to enable it with:

    sudo a2enmod proxy
    sudo a2enmod proxy_http   

In your /etc/apache2/sites-enabled/ directory there should be some file like 000-default or similar, with settings for the site.  Add proxy configurations in it for mapping the /jenkins path on the website to localhost:8080/jenkins:

    ProxyPass /jenkins http://127.0.0.1:8080/jenkins

In my case the file looks something like:

    <VirtualHost *:80> 
        ....
        ProxyPass /jenkins http://127.0.0.1:8080/jenkins
    </VirtualHost>

You can stop and restart apache to enable the new configuration, or just use:

    /etc/init.d/apache2 force-reload

And you can follow the apache logs for troubleshooting by running

    tail -f /var/log/apache2/error.log

And you probably will get this error message:


$ sudo /etc/init.d/apache2 force-reload
 * Reloading web server config apache2                                                                                                                                                                       apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName



This just because you have not edit /etc/apache2/httpd.conf which is by default a empty file. 
Add the following line to it and then reload apache2 configuration.

ServerName localhost

/etc/init.d/apache2 force-reload

DONE and good luck!

1 comment:

  1. Hi how to change to https??

    How to configure jenkins from HTTP to HTTPS ?

    ReplyDelete