Wednesday, September 19, 2012

How to install ruby, rubygems and libyaml


Following are the commands which can be used to install the ruby with rubygems and libyaml:

To install ruby use the following commands:
  wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz  
  tar -xvf ruby-1.9.3-p194.tar.gz  
  cd ruby-1.9.3-p194  
  ./configure  
  make  
  make install  
  ruby -v  


To check if your ruby is correctly working or not create a test ruby script and run it:
  vi test.rb  
Use the following code for test purpose:
  #!/usr/bin/env ruby  
   
 puts "Ruby working Fine:)"  
Give the ruby script execute permission and run the script to see if ruby is working fine or not:
 chmod +x test.rb  
 ./test.rb  


To install rubygems use the following commands:
 wget http://rubyforge.org/frs/download.php/76073/rubygems-1.8.24.tgz  
 tar -xvzf rubygems-1.8.24.tgz  
 cd rubygems-1.8.24  
 ruby setup.rb  
 gem -v  

If you get an error regarding the libyaml dependency, follow the following steps:
 wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz  
 tar -xvzf yaml-0.1.4.tar.gz  
 cd yaml-0.1.4  
 ./configure  
 make  
 make install  

Now again install the ruby again, make clean is used to do fresh ruby install after removing the previous one:
 cd ruby-1.9.3-p194  
 make clean  
 ./configure  
 make  
 make install  

After successful installation you will be getting following outputs:
 # ruby -v  
 ruby 1.9.3p194 (2012-04-20) [x86_64-linux]  
   
 # ./test.rb  
 Ruby working Fine:)  
   
 # gem -v  
 1.8.24  
   



Saturday, June 9, 2012

How to apply Apache(HTTP) authentication on any Domain

HTTP authentication is a process of applying authentication to our Domain so that only authorized people can access it.

The following command is used to create the password file in the doc root which is used to store the passwords of the users to whom you want to give the access.

/usr/local/apache/bin/htpasswd -c /var/www/yourdomain.com/passwd username  
or
htpasswd -c /var/www/yourdomian.com/passwd username


  • Use  /usr/local/apache/bin/htpasswd if you are using a Apache with source installation so that it can locate the htpasswd command to create the password file.
  • htpasswd can be directly used if you have done default installation by using tools like yum, rpm etc.
  • -c is used to create the passwd file in the doc root.
  • If you want to add a new user to current file don't use -c as it will create the new file, use the same command without -c and new user name.
  • /var/www/yourdomain.com/passwd is the destination of the file where you want to create the password file and passwd is the file name created to store the password.
  • passwd is the standard password file naming used to store the passwords it can vary according to your need.
  • username is the name of the user to whom you want to give access.

 Create the file name .htaccess in doc root of the domain to whom you want to give authentication.

#vi .htaccess

Add the following lines to the .htaccess

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /var/www/yourdomain.com/passwd
Require valid-user

  • AuthType Basic -- Its used to request password in encrypted format.
  • AuthName "Restricted Files" -- Its used to display the message on the login form, as in this case " Restricted Files" will be showed  on the form.
  • AuthUserFile /var/www/yourdomain.com/passwd -- path where the password file is located.
  • Require valid-user -- its implies only users registered are allowed to get the access.

There are few alternative methods also to set the users having access.

  • Require user abc -- It can be used to give access to one user only name as abc.
  • Require group grp1 -- It can be used to define any group to whom you want to give the access.
  • Add the AuthGroupFile /var/www/yourdomain.com/groups
  • In that file mention as groups add the group members to whom you want to give access in plain text file. 
  • For ex: grp1: tom law jack


You can check whether your authentication is working properly or not by curl command as well.


Tuesday, March 6, 2012

Command to delete file older than n number of days

Following command can be used to delete files older than n number of days:

find /usr/local/apache/logs -type f -mtime +15 -exec rm -f {} \;

find - It will search the files in the directory.
/usr/local/apache/logs - destination of the directory.
type f - type is used to search by type of file syatem & f is to find the files only in directory.
-mtime +15 - mtime used to search files according to time & +15  to search files older than 15 days.
-exec rm -f - exec is used to run any command & rm -f to forcefully delete the files.
{} - it will hold the result from the find command and will pass it to exec as input. General syntax -exec <command> {}
\; - '\' will tell the find command to take ; as the end of command else it will also include the ; in find command. '\' is works as "escapes" and tell bash to take ; as new argument.

How to redirect a URL which consists of any specific word.

To redirect  URL which has any specific word in it to any other URL the following redirect rule can be used:

RedirectMatch "ravi$" http://ravigadgil.com/hello.html [R=301,NC]

ravi- Is the word which we are finding in the URL and if it appears than it will redirect to the desired URL.

http://ravigadgil.com/hello.html- Is the site to which we are redirecting in given example.

How to check Apache redirect using CURL command.

To check the Apache redirect we can use the CURL command which can tell us whether our reidrect is working correct or not in terminal it self.

curl -H "Host:ravigadgil.com" http://localhost/                       //it will tell us where our site is redirecting

curl -H "Host:ravigadgil.com" http://1.2.3.4/                         //it can be used if you know the IP of vhost

curl -H "Host:ravigadgil.com" http://localhost/abc.html          // it will tell where ravigadgil.com/abc.html is redirecting.

Monday, March 5, 2012

How to put permanent redirect in vhost


Following is the example of permanent redirect in which we are directing our site to another location.

<VirtualHost *>

        ServerName ravigadgil.com
        ServerAlias www.ravigadgil.com
        Redirect permanent / http://www.sitewheretoredirect.com       //destination address

</VirtualHost>

Simple vhost to redirect one site to another.

To create a vhost which does not have any doc root and is redirecting to any other site.

Following vhost will just redirect your site to any other site.


<VirtualHost *>
    ServerAdmin webmaster@ravigadgil.com                   //server admin email ID
    ServerName ravigadgil.com                                        //server name
    ServerAlias www.ravigadgil.com
    RewriteEngine On
    RewriteRule ^/(.*) http://www.yourdesiredsiteaddress.com [R=301,L]        //destination address
    RewriteCond %{REQUEST_METHOD} ^TRACE
    RewriteRule .* - [F]
</VirtualHost>

Setup fully configurable EFK Elasticsearch Fluentd Kibana setup in Kubernetes

In the following setup, we will be creating a fully configurable Elasticsearch, Flunetd, Kibana setup better known as EKF setup. There is a...