Sunday, 6 July 2014

Jenkins: Installation on Ubuntu/Debian Machine

Installing Jenkins on Ubuntu or Debian


* If you are installing Jenkins on Debian or Ubuntu, it is convenient to install the native binary package for these platforms. So. First of all, you need to add the key to your system as below:
      $ wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add -

      $ sudo echo "deb http://pkg.jenkins-ci.org/debian binary/" > /etc/apt/sources.list.d/jenkins.list

* Now, we update the Debian package repository, to check whether key is set and package are easily extracted.
     $ sudo apt-get update -y

* Once this is done, you can install Jenkins using apt-get tool:
     $ sudo apt-get install -y jenkins
 
  This will install jenkins as a service, with a correclty configured script at /etc/init.d/jenkins and a        corresponding system user called "jenkins".

* By default, you will find the jenkins WAR file in the /usr/share/jenkins directory, and the Jenkins home directory in /var/lib/jenkins.

* Now, you can start the Jenkins service:
     $  sudo /etc/init.d/jenkins start
   or
     $  sudo service jenkins start
* You can see the Jenkins dashboard at http://localhost:8080/
    If you can see the dashboard that means you have correct installation on Debain/Ubuntu
 
This is way to install to Jenkins on Debian/Ubuntu Machine. Other Machines (REDHAT, CentOS) will     require some changes.

JAVA: How to install Java (JRE/JDK) on Ubuntu Machine


Installing default JRE/JDK
This is recommended and will install OpenJDK 6 on Ubuntu 12.04 and earlier and on 12.10+ it will install OpenJDK7.

* Installing java with apt-get is easy. First update the package
                 sudo apt-get update -y

* Then, check Java is installed or not
        java -version
   If it returns "The program java can be found in the following packages" then you need to install it. For that      you need to execute following command: 
        sudo apt-get install default-jre

  This install Java Runtime Environment(JRE)

* Now you will also need Java Development Kit (JDK) needed to compile Java applications(say Apache        Ant , Apache Maven, Eclipse).
   Execute the following command: 
        sudo apt-get install default-jdk

This is everything need to install Java on Ubuntu Machine.

Thursday, 3 July 2014

Chef solo: Chef Installation and create first cookbook

 Install curl for installing chef
           apt-get install curl*

Installing chef using curl
      curl -L https://www.opscode.com/chef/install.sh | bash
      You can choose the chef install link from according to your OS.
      http://www.getchef.com/chef/install/
 
Checking chef is installed or not or verifing the installation
        chef-solo -v

Now you need to get the file structure of chef in order to organise the various cookbooks
        wget http://github.com/opscode/chef-repo/tarball/master
        tar zxf master
        mv opscodee-chef-repo* chef-repo

Now to get to start writing cookbook for apache
        cd chef-repo
        mkdir .chef

We use knife cli tools to create cookbooks . First we need to tell knife where to fetch the cookbook
         echo "cookbook_path [  '/root/chef-repo/cookbooks'  ] "  >   .chef/knife.rb

Now we will create a phpapp cookbook
         knife cookbook create phpapp
         cd cookbooks

Now we download cookbook which acts a library for our cookbook
    Apache2
         knife cookbook site download apache2
         tar zxf  apache2*
 
    Apt - which ensure that chef-solo mkaes a apt-get update before we install any packages.
         knife cookbook site download apt
         tar zxf apt*
    Iptables

        knife cookbook site download iptables
        tar zxf iptables*
 
   Logrotate -
        knife cookbook site download logrotate
        tar zxf logrotate*
   Pacman
        knife cookbook site download pacman
        tar zxf pacman*

Now we configure these things
         cd phpapp/

Now we need to make changes in different configuration files
     open metadata.rb
     add line
     depends "apache2"

Open recipe/default.rb add lines
        include_recipe "apache2"
         apache_site "default" do
              enable true
         end

       cd ../..
    create a file solo.rb and add lines
    file_cache_path "/root/chef-solo"
    cookbook_path "/root/chef-repo/cookbooks"

Again create a file name web.json
    add lines
    {
         "run_list" :   ["recipe[apt]", "recipe[phpapp]"]
      }


Now finally execute below command to run the code
     chef-solo -c solo.rb -j web.json


 Note: using Ubuntu machine as OS in rackspace


Knife-solo: CLI tool for chef


knife-solo adds a handful of Knife commands that aim to make working with chef-solo as powerful as chef-server.
Usage: Having the gem installed will add knife chef subcommands.
Run knife solo with no arguments to know all the commands.
Knife-solo is a command-line tool that provides an interface between a  local chef-repo and chef-server.
It include 5 subcommands to knife tools:
*  knife solo init myapp: This will create a chef standard directory (i.e. kitchen) structure which will be used for build and store recipes. It's like initialising 
*  knife solo prepare: Installs chef on a given host. It auto detect the targeted OS. 
*  knife solo cook:   Uploads the kitchen to target host and run chef-solo.
*  knife solo bootstrap: combines the two previous ones.
*  knife solo clean: removes the uploaded kitchen from the target host.
This actually helps you create a directory structure of chef and also it integrates with Berkshelf and Libraian-Chef and bootstraps the process of the nodes.