Monday, August 10, 2009

Create Session table in (RoR) Ruby on Rails .!

CREATE TABLE `sessions` (
`id` int(11) NOT NULL auto_increment,
`session_id` varchar(255) default NULL,
`data` varchar(255) default NULL,
`updated_at` datetime default NULL,
`created_at` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


To change Session cookie to Active records do following setting:
cat config/initializers/session_store.rb

* un-comment line
ActionController::Base.session_store = :active_record_store

Tuesday, August 4, 2009

MySQL Backups using LVM snapshots

lvcreate -L40G -s -n dbbackup /dev/VolGroup00/LogVol03


lvm> lvremove /dev/VolGroup00/dbbackup
Do you really want to remove active logical volume "dbbackup"? [y/n]:

----------------------------------------------------------------------------

Stapes to Install and configure LVM.
fdisk -l
fdisk /dev/hdb
:p to print partition
:n to Extend partition

:e
Last cylender _______ enter

:n to new partition

Last cylender : +10G

Again create +10G partition
:n
choose: e
Last cylender :+10G

Command:l for list.

---------------------------
Command: t
partition number : 5
hexadecimal number: 8e

again create:
command: t
partition number: 6
hexadecimal number: 8e
command: w to save.
-------------------------
# partprobe

take hdb drive and make two partition if you want 1 is ok.

pvcreate /dev/hdb1 /dev/hdb2
vgcreate test1 /dev/hdb1

mkdir /mnt/Backup_disk/snap0 or
mkdir /snap0

lvcreate -L1000M -s -n /mnt/Backup_disk/snap0 /dev/test1/data

mount /dev/test1/data /mnt/Backup_disk/snap0
or
mount /dev/test1/snap0 /snap0 dependupmon path you can mount any where in disk just


mysql -uroot -p passwd > FLUSH TABLES WITH READ LOCK

create TAR
tar -cvf /mnt/Backup_disk/snap0/mysql`date +%Y%m%d%H`.tar /var/lib/mysql/

login to you mysql
and
mysql > UNLOCK TABLES;

cd /snap0
ls mysql2009080419.tar

tar -xvf mysql2009080419.tar

this is your hot backup.

Now you can umount LVM
root@localhost ~]# umount /mnt/Backup_disk/snap0


Check with command: lvdisplay

--- Logical volume ---
LV Name /dev/test1/snap0
VG Name test1
LV UUID ZCYdo5-RinV-EJ4L-03Tq-Snk1-i1Qt-pkQG1X
LV Write Access read/write
LV snapshot status active destination for /dev/test1/data
LV Status available
# open 0
LV Size 1.00 GB
Current LE 256
COW-table size 1000.00 MB
COW-table LE 250
Allocated to snapshot 0.01%
Snapshot chunk size 8.00 KB
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:3


[root@localhost ~]# lvremove /dev/test1/snap0
Do you really want to remove active logical volume "snap0"? [y/n]: y
Logical volume "snap0" successfully removed

Whenerver you want just crete LVM useing this command:

lvcreate -L1000M -s -n /mnt/Backup_disk/snap0 /dev/test1/data

and mount same process.

Saturday, August 1, 2009

Ruby On Rails : "God Monitoring With backgroundrb".

vi config/backgroundrb.god
#--------------------------------------------------------------
#run on command line with 'god -c backgroundrb.god -D'
RAILS_ROOT = '/mnt/app/application/current'
#load required rails and backgroundrb files
require File.dirname(__FILE__) + '/boot'
require File.dirname(__FILE__) + '/environment'
require 'erb'
$LOAD_PATH << "#{RAILS_ROOT}/vendor/plugins/backgroundrb/lib"
require "#{RAILS_ROOT}/vendor/plugins/backgroundrb/lib/backgroundrb.rb"

#create custom condition for checking that QueryProcessingWorker is running
# MiddleMan = BackgrounDRb::ClusterConnection.new
module God
module Conditions
class Backgroundrb < PollCondition
def initialize; super; end
def valid?; true; end

def test
begin
queue_worker = MiddleMan.all_worker_info.values.flatten.select { |w| :queue_processing_worker == w[:worker] }
queue_worker.empty?
rescue #if all_worker_info raises exception, then bdrb isn't running and we were unable to connect
true
end
end
end
end
end
God::Contacts::Email.message_settings ={
:from => 'shrii@gmail.com'
}


God::Contacts::Email.server_settings = {
:address => "Ipaddress_of mail server",
:port => 25,
:domain => "Ipaddress_of mail server",
:user_name => "user",
:password => "passwd",
:authentication => :login
}


God.contact(:email) do |c|
c.name = 'Username'
c.email = 'shrikant@gmail.com'
end
God.watch do |w|
w.name = 'backgroundrb'
w.interval = 1.minute
w.restart = "cd #{RAILS_ROOT} && /usr/local/bin/ruby script/backgroundrb stop && /usr/local/bin/ruby script/backgroundrb -e production start"
w.stop = "cd #{RAILS_ROOT} && /usr/local/bin/ruby script/backgroundrb stop"
w.start = "cd #{RAILS_ROOT} && /usr/local/bin/ruby script/backgroundrb -e production start"
w.grace = 1.minute
w.pid_file = "#{RAILS_ROOT}/tmp/pids/backgroundrb_11006.pid"
w.start_if do |start|
start.condition(:process_running) do |c|
c.running = false
c.notify = "username"
end
end
w.restart_if do |restart|
restart.condition(:cpu_usage) do |c|
c.above = 70.percent
c.times = [3,5]
c.notify = "username"
end
end
end

#----------------------------------------------------------

* To Start God. in RAILS_ROOT

god -c config/backgroundrb.god

* To Check Prosess id of GOD:

ps -aufx| grep god

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
root 11219 0.0 0.0 60260 732 ttyp1 S+ 07:48 0:00 \_ grep god
root 26944 0.2 0.3 163240 61476 ttyp0 S 07:14 0:05 /usr/local/bin/ruby /usr/local/bin/god -c config/backgroundrb.god

Thats It.. Please let me know if there is any issue.

Friday, July 31, 2009

(98)Address already in use: make_sock: could not bind to address [::]:8000 (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80

If You facing Problem:
(98)Address already in use: make_sock: could not bind to address [::]:8000
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:8000
no listening sockets available, shutting down

Fix as follows :

netstat -tulpn| grep :80
tcp 0 0 0.0.0.0:8028 0.0.0.0:* LISTEN 5476/(squid)
tcp 0 0 :::80 :::* LISTEN 5474/squid

It means 80 port running for Squid service. Solution is Stop squid service.

killall -9 squid

and restart Apache/httpd

/etc/init.d/httpd restart

Cool Enjoy... if issue ping to me. ;)

Wednesday, July 29, 2009

How To Read File In .gz Format.

Just Use This commands:
---------------------------------------------------
zcat maillog.1.gz | less

zcat maillog.1.gz | grep '@yahoo.co'


---------------------------------------------------

Tuesday, July 28, 2009

Postfix SMTP installation on CentOs/Linux

This is Postfix configuration on CentOs/Linux with relay, Usually people want to send bulk mail with mail server, so it will really help this post 
----------------------------------------------------------------------------------------------------
yum install postfix


* then change default main.cnf to main.cnf.Bak, your config file as follows: /etc/postfix/main.cf
---------------------------------------------------------------------------
myhostname = mail.example.com
mydomain = mail.example.com
myorigin = $mydomain

smtpd_banner = $myhostname ESMTP $mail_name
biff = no
append_dot_mydomain = yes

alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = localdomain, localhost, localhost.localdomain, localhost.$mydomain, $mydomain
mynetworks = 202.78.56.89, 127.0.0.1, 127.0.0.0/8
mailbox_size_limit = 0
recipient_delimiter = +

# SECURITY NOTE: Listening on all interfaces. Make sure your firewall is
# configured correctly
inet_interfaces = all

smtp_sasl_auth_enable = yes
smtpd_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtpd_sasl_security_options = noanonymous
smtpd_sasl_authenticated_header = yes
smtpd_sasl_local_domain = $myhostname
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions =
 #Following three lines Very imp set as it is or see maillog for error
            permit_sasl_authenticated,   
            permit_mynetworks,
            check_relay_domains
default_destination_concurrency_limit = 4

smtpd_enforce_tls = no
smtpd_tls_loglevel = 1
smtpd_use_tls = no

soft_bounce = yes
bounce_template_file = /etc/postfix/bounce.cf

readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
html_directory = no
setgid_group = postdrop
command_directory = /usr/sbin
manpage_directory = /usr/local/man
daemon_directory = /usr/libexec/postfix
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
queue_directory = /var/spool/postfix
mail_owner = postfix
----------------------------------------------------------------------

* Create file /etc/postfix/sasl_passwd host username:passwd

cat /etc/postfix/sasl_passwd
202.78.56.89 shrii:shrii

* Very Imp:  Make sure user "shrii" is available on your server. if not you have to create it
with useradd do add same password which you have given to sasl file.

then

chmod 600 /etc/postfix/sasl_passwd
[root@localhost postfix]# ll /etc/postfix/sasl_passwd
-rw------- 1 root root 38 Jul 28 12:54 /etc/postfix/sasl_passwd

Imp stapes:

postmap hash:/etc/postfix/sasl_passwd

restart services :
[root@localhost postfix]# /etc/init.d/saslauthd restart
Stopping saslauthd: [ OK ]
Starting saslauthd: [ OK ]
[root@localhost postfix]# /etc/init.d/postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]

* If issue is :

[root@d]# testsaslauthd -u gimpif -p fbetter
0: NO "authentication failed"

* Do


[root@d] yum install imapd imap dovecot cyrus-imapd cyrus-imapd-perl cyrus-imapd-utils db4-utils libsysfs lm_sensors net-snmp-libs perl cyrus-sasl-plain

yum install courier-imap


Fixed.
testsaslauthd -umail -ppasswd
0: OK "Success."

Let us check mails.

Test Mail from server:
echo "hi" | mail -s " test from local" youremail@domain.com

ezcrypto segmentation fault error (Rails 2.3.2)

There is dependency of openssl version for ezcrypto gem, fix as follows.
=======================
gem install ezcrypto

gem list
==>
*** LOCAL GEMS ***

ezcrypto (0.7.2)

*Check openssh Version.!

rpm -q openssl-devel openssl
openssl-devel-0.9.8b-10.el5
openssl-devel-0.9.8e-7.el5
openssl-0.9.8b-10.el5
openssl-0.9.8e-7.el5

* if found openssl-devel-0.9.8b-10.el5 and openssl-0.9.8b-10.el5. Please remove from repository.
Using this command.

rpm -e openssl-devel-0.9.8b-10.el5 openssl-0.9.8b-10.el5

*If not present install this package.
rpm -ivh --force /var/cache/yum/base/packages/openssl-0.9.8e-7.el5.i386.rpm
rpm -ivh --force /var/cache/yum/base/packages/openssl-devel-0.9.8e-7.el5.i386.rpm

* if not found in package in /var/cache/yum/base/packages/ then download from
http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/ and copy in /var/cache/yum/base/packages/
and install again.

* check the package and version.

rpm -q openssl-devel openssl
openssl-devel-0.9.8e-7.el5
openssl-0.9.8e-7.el5


Thanks- Now Its Fixed.

Tuesday, July 21, 2009

Monday, July 20, 2009

When PHP code showing on your Site (mod_php).

If you compile apache but php is not Support, Here are the relevant lines from my httpd.conf file


AddType application/x-httpd-php .php .php4 .php3
AddType application/x-httpd-php-source .phps


AddType application/x-httpd-php .php4 .php3 .phtml .php
AddType application/x-httpd-php-source .phps

The following is for PHP3:

AddType application/x-httpd-php3 .php3
AddType application/x-httpd-php3-source .phps

The following is for PHP/FI (PHP2):

AddType application/x-httpd-php .phtml

Sunday, July 19, 2009

How to login in a remote server using SSH and no password ?

Just use Two commands.
=====================================
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.0
=====================================


Simplest Way for Backup, Samba server, rsync and many more if you use.

Wednesday, July 15, 2009

Perlbal Configure Example.

--------------------------------------------------------------------
LOAD vhosts
LOAD vpaths
LOAD AccessControl
Load palimg
Load AccessControl

#SERVER aio_mode = ioaio

CREATE POOL poolserver1
POOL poolserver1 ADD 0.0.0.0:7200
POOL poolserver1 ADD 0.0.0.0:7201
POOL poolserver1 ADD 0.0.0.0:7202
POOL poolserver1 ADD 0.0.0.0:7203

CREATE SERVICE site
# NOTE: SSL mode only works for reverse_proxy, not for webserver.
# http://lists.danga.com/pipermail/perlbal/2008-April/000916.html
SET role = reverse_proxy
SET pool = poolserver1
SET listen = 0.0.0.0:443
SET persist_client = on
SET max_backend_uses = 10
SET backend_persist_cache = 2
SET persist_backend = on
SET verify_backend = on
SET balance_method = random
SET enable_ssl = on
SET ssl_key_file = /etc/perlbal/certs/server-key.pem
SET ssl_cert_file = /etc/perlbal/certs/server-cert.pem

# optionally set the cipher list. the default is "ALL:!LOW:!EXP"
SET ssl_cipher_list = ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL

ENABLE site

CREATE SERVICE web_stat
SET role = web_server
SET docroot = /mnt/app/current/public
SET dirindexing = on
ENABLE web_stat


CREATE SERVICE pub1
SET listen = 0.0.0.0:80
SET role = selector
SET plugins = vhosts
SET persist_client = on
VHOST example.com = server1
VHOST *.example.com = site
ENABLE pub1
#------------------------------
#CREATE POOL my_apache
#POOL my_apache ADD 127.0.0.1:

#CREATE SERVICE apps
# SET role = web_server
# SET docroot = /var/www/html/apps
# SET dirindexing = on
#ENABLE apps
--------------------------------------------------------------------------

Monday, February 9, 2009

How to Perlbal as Webserver with RAILS+MONGREL ..?

Hey Guys,

First Resolve All dependency with modules.
---------------------------------------------
Perl Module for Webserver and Balancer and Cpan Library.
Cpan : cpan script version 1.03, CPAN.pm version 1.7602
Danga-Socket-1.61
IO-AIO-3.17
Perlbal-XS-HTTPHeaders-0.19
libwww-perl-5.823
Sys-Syscall-0.22
FleetConf-0.01_016
Log-Dispatch-2.22
-----------------------------------------------
SSL need:
Net-SSLeay-1.35
Module-Install-0.79
IO-Socket-SSL-1.22
Net-IDN-Encode-0.02
IDNA-Punycode-0.03
IO-Compress-Zlib
-------------------------------------------------
For Gzip:
Compress::Raw::Zlib 2.015
IO::Compress::Base 2.015
IO::Uncompress::Base 2.015
IO::Compress::Zlib
-----------------------------------------------

Sunday, May 18, 2008

Apache Rewrite Rules

The Apache module mod_rewrite provides a powerful mechanism for hiding, redirecting, and reformatting request URLs. I just finished implementing a mod_rewrite scheme for timfanelli.com to accomplish 3 things:

1. Redirect old URLs with a 301 redirect code
2. Hide certain parts of the URL from my readers.
3. Optimize my Google pagerank.

Using a two simple rewrite rule
RewriteEngine on
RewriteRule ^/index.cgi(.*) /old.html [R=301]

To hide the /cgi-bin/blog.cgi portion of my URL.
RewriteRule ^/blog/(.*)$ /cgi-bin/blog.cgi/ [PT]
RewriteRule ^/$ /blog/ [R=301]
RewriteRule ^/blog$ /blog/ [R=301]

To redirect to domain name to www.domain.name
RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteRule .* http://www.yourdomain.com [QSA]