Install Tokyo cabinet on ubuntu + ruby

Every came across a task where in you get a task to insert 1 million + records in few hours? than the answer is NOSQL
Use Tokyo Cabinet. Here are the installation steps for the same.

First of all download the latest version of tokyocabinet via the following url

wget http://fallabs.com/tokyocabinet/tokyocabinet-1.4.47.tar.gz
tar xvf tokyocabinet-1.4.47.tar.gz
cd tokyocabinet-1.4.47
./configure
make
make install

Next step is to install the ruby library which you can download from the url below

wget http://fallabs.com/tokyocabinet/rubypkg/tokyocabinet-ruby-1.31.tar.gz

tar xvf tokyocabinet-ruby-1.31.tar.gz
cd tokyocabinet-ruby-1.31
ruby extconf.rb
make
make install

Now to verify you installation go to irb

irb(main):001:0> require ‘rubygems’
=> true

irb(main):002:0> require ‘tokyocabinet’
=> true

Done. If you get any errors while doing this please free to comment. Thanks

Be Sociable, Share!

solve libxslt is missing error when installing omniauth or nokogiri

I was trying to install omniauth and was getting error for nokogiri libxslt is missing. If you are facing the same issue you may solve it using the following command. I have tested it with ubuntu and it worked for me. Its not tested on Fedora but should work.

on Ubuntu 10

sudo apt-get install libxml2 libxml2-dev libxslt libxslt-dev

on Ubuntu 11

sudo apt-get install libxml2 libxml2-dev libxslt1-dev

On fedora

sudo yum install libxml2-devel libxslt-devel

If you still face issues do write to me.

Thanks

Be Sociable, Share!

solving sudo: /etc/sudoers is mode 0777, should be 0440 error

Today one of my team mate accidently gave chmod -R 777 on all folders. So he was not able to do sudo su and login as a root user.

Now as a normal user it wont allow you to change the rights. This is a big headache. Ultimately I found the solution to this issue. Restart ur pc and press shift key which will give u an option to start your system in recovery mode.

Select that and you will get an option to login as root with command prompt. Now change the rights of /etc/sudoers to 0440 by using the command chmod 0440 /etc/sudoers. Exit and restart your system.

Now start your terminal and try sudo su to login as a root user. Ah! finally the problem got solved.

If you are still not able to solve this issue. Just write back to me and I shall help you out.

Njoi

Be Sociable, Share!

Generate self signed certificates for nginx

As i mentioned in my previous post that I will let u know how to generate self signed certificates here is the procedure for it.

First of all install ssl-cert using

sudo aptitude install ssl-cert

Next step is to create a private key using the command below.

openssl genrsa -des3 -out myssl.key 1024

Now create a CSR where you need to provide details such as Country, State, City, Orgainzation name, Unit Name, Common Name and Email id

openssl req -new -key myssl.key -out myssl.csr

And the last step is the actual certificate

openssl x509 -req -days 365 -in myssl.csr -signkey myssl.key -out myssl.crt

Thats it. So its just 3-4 steps. Now start configuring it with nginx using the link below

http://blog.dhavalparikh.co.in/2011/06/configure-self-signed-certificates-with-nginx-and-rails/

If you have any doubts please feel free to ask.

Be Sociable, Share!

Configure Self Signed Certificates with Nginx and Rails

Guys,

I was given a task to setup https using self signed certificate using nginx in our latest rails app. This was basically for the paypal page where we were accepting credit card details on our site.

Below is the nginx.conf file configuration which u require in order to implement SSL certificate. If you see closely there are 2 port defined. 1) port 80 2) port 443. Port 80 is for standard http request and port 443 is for https request.

#————————code starts below————————————-

#user nobody;

worker_processes 4;

pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;

default_type application/octet-stream;

log_format main ‘$remote_addr – $remote_user [$time_local] ‘
‘”$request” $status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

sendfile on;
tcp_nopush on;
tcp_nodelay off;
#keepalive_timeout 0;
keepalive_timeout 65;

gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript ;

upstream main{
server 127.0.0.1:8000;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
}

server {
listen 80;
#server_name yourdomain.com;

#client_max_body_size 4M;
client_body_buffer_size 128k;
root /var/www/yourapplication/public/;

# needed to forward user.s IP address to rails
proxy_set_header X-Real-IP $remote_addr;

# needed for HTTPS
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
proxy_max_temp_file_size 0;

location ~ ^/(images|javascripts|stylesheets|product)/ {
expires 10y;
}

# If the file exists as a static file serve it directly without
# running all the other rewite tests on it
if (-f $request_filename) {
break;
}

# check for index.html for directory index
# if its there on the filesystem then rewite
# the url to add /index.html to the end of it
# and then break to send it to the next config rules.
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
# redirect the traffic to the upstream mongrel defined as .main.
proxy_pass http://main/;
}
}

#———————–https————

server {
listen 443;
server_name yourdomain.com;
ssl on;
ssl_certificate /etc/ssl/certs/myssl.crt;
ssl_certificate_key /etc/ssl/private/myssl.key;

#client_max_body_size 4M;
client_body_buffer_size 128k;
root /var/www/yourapplication/public/;

# needed to forward user.s IP address to rails
proxy_set_header X-Real-IP $remote_addr;

# needed for HTTPS
proxy_set_header X_FORWARDED_PROTO https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Url-Scheme $scheme;
proxy_redirect off;
proxy_max_temp_file_size 0;

location ~ ^/(images|javascripts|stylesheets|product)/ {
expires 10y;
}

# If the file exists as a static file serve it directly without
# running all the other rewite tests on it
if (-f $request_filename) {
break;
}

# check for index.html for directory index
# if its there on the filesystem then rewite
# the url to add /index.html to the end of it
# and then break to send it to the next config rules.
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
# redirect the traffic to the upstream mongrel defined as .main.
proxy_pass http://main/;
}
}

#—————————-https———————–

In the code above the most important part is

ssl on;
ssl_certificate /etc/ssl/certs/myssl.crt;
ssl_certificate_key /etc/ssl/private/myssl.key;

Now how to generate self signed certificates i will let u know in my next post. (Though i should have covered it b4 but ne ways will do it now)

Thats all. You can add and remove basic paraments you want from the above given nginx.conf file.
Let me know if you find any issues in implementing SSL for your app.

Be Sociable, Share!

you are being redirected error with rails 2.3.8, mongrel and nginx

Guys if you get this error you are being redirected while working with rails 2.3.7 + nginx + mongrel
in production mode. Just add the code below in the initializer folder in a file called mongrel.rb

if Rails.version == ‘2.3.8’ && Gem.available?(‘mongrel’, Gem::Requirement.new(‘~>1.1.5’))
&& self.class.const_defined?(:Mongrel)

# Pulled right from latest rack. Old looked like this in 1.1.0 version.
#
# def [](k)
# super(@names[k] ||= @names[k.downcase])
# end
#
module Rack
module Utils
class HeaderHash < Hash
def [](k)
super(@names[k]) if @names[k]
super(@names[k.downcase])
end
end
end
end

# Code pulled from the ticket above.
#
class Mongrel::CGIWrapper
def header_with_rails_fix(options = ‘text/html’)
@head[‘cookie’] = options.delete(‘cookie’).flatten.map { |v| v.sub(/^\n/,”) } if options.class != String and options[‘cookie’]
header_without_rails_fix(options)
end
alias_method_chain :header, :rails_fix
end

# Pulled right from 2.3.8 ActionPack. Simple diff was
#
# if headers.include?(‘Set-Cookie’)
# headers[‘cookie’] = headers.delete(‘Set-Cookie’).split(“\n”)
# end
#
# to
#
# if headers[‘Set-Cookie’]
# headers[‘cookie’] = headers.delete(‘Set-Cookie’).split(“\n”)
# end
#
module ActionController
class CGIHandler
def self.dispatch_cgi(app, cgi, out = $stdout)
env = cgi.__send__(:env_table)
env.delete “HTTP_CONTENT_LENGTH”
cgi.stdinput.extend ProperStream
env[“SCRIPT_NAME”] = “” if env[“SCRIPT_NAME”] == “/”
env.update({
“rack.version” => [0,1],
“rack.input” => cgi.stdinput,
“rack.errors” => $stderr,
“rack.multithread” => false,
“rack.multiprocess” => true,
“rack.run_once” => false,
“rack.url_scheme” => [“yes”, “on”, “1”].include?(env[“HTTPS”]) ? “https” : “http”
})
env[“QUERY_STRING”] ||= “”
env[“HTTP_VERSION”] ||= env[“SERVER_PROTOCOL”]
env[“REQUEST_PATH”] ||= “/”
env.delete “PATH_INFO” if env[“PATH_INFO”] == “”
status, headers, body = app.call(env)
begin
out.binmode if out.respond_to?(:binmode)
out.sync = false if out.respond_to?(:sync=)
headers[‘Status’] = status.to_s
if headers[‘Set-Cookie’]
headers[‘cookie’] = headers.delete(‘Set-Cookie’).split(“\n”)
end
out.write(cgi.header(headers))
body.each { |part|
out.write part
out.flush if out.respond_to?(:flush)
}
ensure
body.close if body.respond_to?(:close)
end
end
end
end

end

Thats all just restart your server nginx and mongrel cluster and the error should be gone.

Be Sociable, Share!
1 2 3 4 5 6 23