Sunday, 10 May 2015

CORS:- Cross Origin Resource Sharing

Earlier, developers having the difficulty in order to make a request to a different domain from javascript. Everyone setup proxies on their websites, which was one of the onset of a new host of open redirect problems, as a way to get around the restriction. Although developers were working around this limitation using server-side proxies as well as number of techniques.

Almost all browser now support CORS (Includes IE 8+, Firefox 3.5+, Chrome)

Cross-Origin Resource Sharing (CORS)


* It is W3C Working draft that defines how the browser and server must communicate when accessing sources across origin. It is specification recommended by the Web Applications Working Group within the W3C.It provides a way for script running in clients browsers to use the XMLHttpRequest API object and make direct HTTP Requests to resources on domains other than from where the script was first loaded. say Zuora REST API.

* CORS provides following features:
Guarantees the data integrity of the API request- Nothing chenaged on its way from your server to customer.
Provides authentication - ensures that the person who generated the request is who they say they are.
The Basic idea behind CORS is to use custome HTTP headers to allow both the browser and the server to know enough about each otherin order to determine if the request or response should suceed or fail.

For a simple request, one that uses either GET or POST with no custom headers and whose body is text/plain, the request is sent with extra header called Origin, The Origin header contains the origin (protocol, domain name, and port) of the requesting page, in order to make the request to serve.

An example Origin header looks like:

 Origin: http://www.domainA.com  

If the server decides that the request should be allowed, it sends a Access-Control-Allow-Origin header echoing back the same origin that was sent or "*" if it's a public resource. Say,

 Access-Control-Allow-Origin: http://www.domainB.net  

This way we can do sharing of resources against different origin.

Sunday, 17 August 2014

MongoDB: Installation on Ubuntu/Debian Machine


  • Before making an installation of Mongodb on ubuntu we need to add sources list to local repository.
  • First of all, we need to add MongoDB Public GPG Key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

  • Next, we need to update source list /etc/apt/source.list.d/mongodb.list file using following command

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list


  •  Now, we need to update the repository...
 sudo apt-get update

  •  Now , we are ready to install our MongoDB installation
 apt-get install mongodb-10gen=2.2.3

  •  Now we had installed MongoDB , we need to start the service

service mongodb start

  • To login into mongodb prompt, we give command 
 mongo

  • If you need mongodb help, use command

 db.help()

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.

Friday, 18 April 2014

Ruby On Rails Installation using RVM (Ubuntu)

For the installation of ruby on rails follow below steps

* Ruby Version Manager: Firstly, we need to install ruby version manager.

$ apt-get install curl
$ \curl -sSL https://get.rvm.io | bash -s stable
$ source ~/.rvm/scripts/rvm


* Ruby: Next, Once you are using RVM , we need to install ruby


$ rvm install 2.1

you can make the recently installed ruby version as default as there may be more than one ruby installed.

$ rvm use ruby --default


* Rubygems: The next step is to install rubygems with current version/

$ rvm rubygems current 

* Rails: Once everything is setup, it's time to install rails


$ gem install rails

This is how, the ruby on rails get installed on your ubuntu machine.