Wednesday, April 20, 2011

Can't umount on RHEL/CENTOS Error: device is busy

[root@sandbox1 ~]# umount /dev/sdb1
umount: /mnt/pen: device is busy
umount: /mnt/pen: device is busy

Solution :

[root@sandbox1 ~]# lsof | grep /mnt/pen
esd       23711   root  cwd       DIR       8,17      4096    1228794 /mnt/pen/720p BRRip x264 - HDMiCRO by Mr. KickASS
esd       23711   root    3r      REG       8,17 942758269    1229005 /mnt/pen/ - HDMiCRO by Mr. KickASS/ Mr. KickASS.mp4

[root@sandbox1 ~]# kill -9 23711


[root@sandbox1 ~]# umount /dev/sdb1

Done.

Wednesday, April 13, 2011

/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory

While compiling any sources in linux if you got above Error.
----------------------------------------------------
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
make[2]: *** [boot.o] Error 1
make[2]: Leaving directory `/mnt/resin-4.0.16/modules/c/src/resin_os'
make[1]: *** [plugins] Error 2
make[1]: Leaving directory `/mnt/resin-4.0.16/modules/c/src'
make: *** [all] Error 2

--------------------------------------------------
Please do install following lib package from YUM:
 yum -y install glibc-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons: mirror.stanford.edu
 * base: mirrors.kernel.org
 * extras: mirrors.kernel.org
 * updates: mirrors.kernel.org
Setting up Install Process
Package glibc-devel-2.5-58.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package glibc-devel.i386 0:2.5-58 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================
 Package                              Arch                          Version                            Repository                     Size
===========================================================================================================================================
Installing:
 glibc-devel                          i386                          2.5-58                             base                          2.0 M

Transaction Summary
===========================================================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Friday, April 8, 2011

postfix/postdrop warning: uid=48: Illegal seek postfix/sendmail: fatal: (48): queue file write error

If you got the error. And you are not able to send large size/ mail attachment from postfix please do above config.

postfix/postdrop warning: uid=48: Illegal seek
postfix/sendmail: fatal: (48): queue file write error

Edit the postfix mailserver file:
vi /etc/postfix/main.cf 
Change/Add this option to  send large file size.

message_size_limit = 100000000
mailbox_size_limit = 800000000

Tuesday, April 5, 2011

[On Ubuntu Mod_proxy added to apache2] BalancerMember Can't find 'byrequests' lb method

Mod_proxy added to apache2.

apt-get install libapache2-mod-proxy-html

apt-get install libxml2-dev

Add following lines to /etc/apache2/apache2.conf :


LoadModule  proxy_module         /usr/lib/apache2/modules/mod_proxy.so
LoadModule  proxy_http_module    /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule  headers_module       /usr/lib/apache2/modules/mod_headers.so
LoadModule  deflate_module       /usr/lib/apache2/modules/mod_deflate.so
LoadFile    /usr/lib/libxml2.so

/etc/init.d/apache2 restart

Friday, April 1, 2011

Compare two file and find diff between two file in sort form.

Compare two file and find diff between two file in sort form.

It will list both file content and diff.
sdiff -s File1 File2

It will do Sort and showing complete diff.

grep -vf File2 File1

Monday, March 14, 2011

Permission denied: /.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable

If you got error with passenger +httpd Please check a log and change permission as follows. its just permission issue.

------------------------------------------------------------------------------
 tail -f /var/log/httpd/error_log
[Mon Mar 14 02:16:36 2011] [crit] [client 125.18.56.179] (13)Permission denied: /home/user/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
-------------------------------------------------------------------------------


[root@server conf]# chmod  -R 755 /home/user/*
[root@server conf]# /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]



Monday, February 21, 2011

Master-Master Replication

Master-Master Replication
Master1 - 1.1.1.1
Master3 - 2.2.2.2


Master1
Edit /etc/my.cnf

#Primary Master server
server-id=1
auto_increment_offset=1
# total number of master servers
auto_increment_increment=2
# local slave replication options
# remote master replication options
master-host=2.2.2.2
master-port=3306
master-user=repl
master-password=replpass
master-connect-retry=10

Master3
#Secondry Master server
server-id=3
auto_increment_offset=1
# total number of master servers
auto_increment_increment=2
# local slave replication options
# remote master replication options
master-host=2.2.2.2
master-port=3306
master-user=repl
master-password=replpass
master-connect-retry=10


Loggin to Master1:

GRANT ALL ON *.* TO  root@'2.2.2.2' IDENTIFIED BY 'email#secure';
GRANT ALL ON *.* TO  repl@'2.2.2.2' IDENTIFIED BY 'replpass';
GRANT ALL ON *.* TO  repl@'%' IDENTIFIED BY 'replpass';

mysql> SHOW MASTER STATUS\G
mysql> FLUSH TABLES WITH READ LOCK;

[root@localhost]mysqldump -A -uroot -p password > master1.sql


On Master3

[root@localhost]mysql -uroot -ppassword  < master1.sql

CHANGE MASTER TO MASTER_HOST='1.1.1.1',MASTER_PORT=3666, MASTER_USER='repl', MASTER_PASSWORD='replpass',  MASTER_LOG_FILE='mysql-bin.000015', MASTER_LOG_POS=1190;

mysql> START SLAVE;
mysql> SHOW MASTER STATUS\G


On Master1

CHANGE MASTER TO MASTER_HOST='2.2.2.2',MASTER_PORT=3666, MASTER_USER='repl', MASTER_PASSWORD='replpass', MASTER_LOG_FILE='mysql-bin.000009', MASTER_LOG_POS=220776001;
mysql> START SLAVE;

Master-Master Replication done.

Do add slave for master, use same post from this blog.
"http://shriikant.blogspot.com/2009/10/mysql-master-slave-replication.html"

Tuesday, February 15, 2011

Production Server/Mailserver Maintanace.

At first, allocate enough space for log partition. Linux system having default log rotation if you want to change you can do customize log rotation automatically.







See here maillog in GB, if no need just clear old log.
Log rotate.

drwxr-xr-x 2 root  root  4.0K Dec  8  2009 mail
-rw------- 1 root  root  504M Feb 15 00:49 maillog
-rw------- 1 root  root  1.1G Feb 10 02:37 maillog.1
-rw------- 1 root  root  469M Jan 31 22:23 maillog.2
-rw------- 1 root  root  1.9G Jan 30 04:17 maillog.3
-rw------- 1 root  root  1.9G Jan 23 04:17 maillog.4

Some of log rotating example:
Create the script name of /usr/bin/rotateapplog:
vi /usr/bin/rotateapplog

#! /bin/bash

TIMESTAMP=$(date +%Y-%m-%d)
cd /home/app/

cp log/production.log log/production.$TIMESTAMP.log

echo "$TIMESTAMP" > log/production.log

echo "done"

Add script as cron:

1 00 * * * /usr/bin/rotateapplog
--------------------------------------------------------------------------------------

Tuesday, February 1, 2011

Mysql Won't start (two instance on same server)

A Solution:

Install mysql db again at new location,use following command:
 
/usr/bin/mysqld_safe --defaults-file /etc/my.cnf

Restart Mysql:
     /etc/init.d/mysqld restart

/usr/local/bin/mysqld_safe --defaults-file /usr/local/etc/my.cnf
 
mysql_install_db --user=mysql --ldata=/new-data-location
mysqld_safe --datadir=/new-data-location --user=mysql &

/usr/local/mysql/share/mysql/mysql.server start


Monday, January 24, 2011

/usr/bin/ld: cannot find -lperl collect2: ld returned 1 exit status make: *** [blib/arch/auto/Image/Magick/Magick.so] Error 1

Normally this error occurs when install ImageMagick on Ubuntu Linux.
-------------------------------------------------------------------------------
/usr/bin/ld: cannot find -lperl
collect2: ld returned 1 exit status
make: *** [blib/arch/auto/Image/Magick/Magick.so] Error 1
---------------------------------------------------------------------------------

And Solution is : Its need this package.

sudo apt-get install libperl-dev

after that, RMagick gem installed without any issue.
gem install rmagick
Building native extensions.  This could take a while...
Successfully installed rmagick-2.13.1
1 gem installed
Installing ri documentation for rmagick-2.13.1...

Monday, January 3, 2011

[semaphores] No space left on device: mod_rewrite: could not create rewrite_log_lock Configuration Failed

Apache haveing issue with.. semaphores many time. Solution as follow to remove
semaphores from apache.

Command to remove semaphores from apache:

ipcs -s | grep apache | perl -e 'while () { @a=split(/\s+/); print `ipcrm sem $a[1]`}'

Thanks-

Tuesday, December 28, 2010

[Exception_notification For RAILS3 ] git://github.com/rails/exception_notification.git (at master) is not checked out. Please run `bundle install` (Bundler::GitError) [RESOLVED]

[Exception_notification For RAILS3 ] git://github.com/rails/exception_notification.git (at master) is not checked out. Please run `bundle install` (Bundler::GitError) [RESOLVED]

# Add to Gemfile

gem 'exception_notification', :git => "http://github.com/rails/exception_notification.git", :require => 'exception_notifier'

# Add following to config/application.rb or  config/initializers/exception_notification.rb
bash-3.2# cat config/initializers/exception_notification.rb
puts "======Excpetion Notification LOADED"
application3::Application.config.middleware.use ExceptionNotifier,
  :email_prefix => "Staging Capture ERROR: ",
  :sender_address => '"Notifier" ',
  :exception_recipients => ['shrikant.lokhande@gmail.com']

After "git pull" run "bundle install"

if got this Error do:
"bundle install vendor/bundler"

It will Fetch all the gems to bundler, error will go.

Fixed.

Monday, December 27, 2010

[Sinatra] `union': can't convert Array into String (TypeError) [Resolved]

For The Issue Please Do Following Stapes.

First uninstall gem Rack with all version.

# gem uninstall rack
Select gem to uninstall:
 1. rack-1.0.0
 2. rack-1.0.1
 3. rack-1.2.1
 4. All versions
> 4
Successfully uninstalled rack-1.0.0
Successfully uninstalled rack-1.0.1

You have requested to uninstall the gem:
        rack-1.2.1
thin-1.2.7 depends on [rack (>= 1.0.0)]
sinatra-1.1.2 depends on [rack (~> 1.1)]
oauth-0.3.5 depends on [rack (>= 0)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn]  y
Successfully uninstalled rack-1.2.1

root@li107-124:/mnt/ntracker/ntrack# gem list rack
*** LOCAL GEMS ***

# gem install rack --version '1.2.0'
Successfully installed rack-1.2.0
1 gem installed
Installing ri documentation for rack-1.2.0...
Building YARD (yri) index for rack-1.2.0...
Installing RDoc documentation for rack-1.2.0...

Now check your application and config.ru with following content.
--------------------------
require 'sinatra'

Sinatra::Application.default_options.merge!(
  :run => false,
  :env => :production
)

require 'App'
run Sinatra.application
----------------------------

Then Start Application with web proxy thin or anything else.
(development environment)
# thin start -p 4500
>> Using rack adapter
>> Thin web server (v1.2.7 codename No Hup)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:4500, CTRL+C to stop
>> Stopping ...

#Use -e for Env. Like this:

# thin start -p 4500 -e staging
or

To start:
# thin -C config/config.yml -R config.ru -e staging start
to stop:
# thin -C config/config.yml -R config.ru -e staging stop

As well as for production.

Thanks-

Tuesday, October 26, 2010

Phusion Passenger Optimization.

If you faceing same as following issue.
Exception NameError in PhusionPassenger::Rack::ApplicationSpawner (uninitialized constant MongoMapper)

Please do the settings. It will really help you.
Also, check your Database Query and cusumption of Memroy on server.
---------------------------------------------
http {
     ..
     PassengerMaxPoolSize 3
     keepalive_timeout  120;
---------------------------------------------

Please let me know, if still you have an issue.

Monday, October 25, 2010

[RSOLVED] [Rails Crontab Not Running]`bin_path': can 't find executable rake for Cronjob not running

Hey Guys,

I have issue with some ruby script and rails, rake script not running as cronjob,
so you can use the following solution.

=============================================
[root@localhost  ] vi /usr/bin/railscron
#! /bin/bash

cd /app/production/current/

PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin/

/usr/local/bin/rake  user:details RAILS_ENV=production >> /tmp/test
echo "its running"
==============================================

* Set as Cronjob now:

* 10 * * *  /usr/bin/railscron


Fixed.
If any query, Please let me know. I am here to solve your issue.
Yo.!

Tuesday, October 19, 2010

ActionController::RoutingError No route matches .html

Added extra .html to URL in rails.

If you have added following rewiterules in apache configuration Or added in your .htaccess in your public. Basically its required for the FastCGI. if you run fastCGI server then its need, but if you running Passenger
should be remove
---------------------------------------
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
----------------------------------------

So solution is please remove that from apache config Or remove .htaccess for the passenger only. njoy.!

Tuesday, September 28, 2010

Background Jobs In Rails.

Well, We all know the Rails Deployment  if, not please read my some older post it will really help you
for that.
  Here what i am discussing it is also part of Administration/Deployment. Yes, I am Talking about Background Process. For the Rails application there is way, to run the background task with different ways i.e. as follows.  

BackgroundDrb
Delayed Job
Background Job{aka BJ}
SpawWorkling
BackgroundFu
Rufus Scheduler

You can check RailsCast for the configure and installation, and i will share with you what my experience with Background Jobs, How its works, How to manage, all things.

Monday, August 23, 2010

[PHP+FPM+NGINX] Installtion/Compilation/Confiuration.

Its  Installtion/Compilation/Confiuration of PHP+FPM+NGINX.

Please Follow The Steps One By One, Its Working Configration Tested By Me :0). IF The Any Issue Please Contact Me.

wget http://museum.php.net/php5/php-5.2.8.tar.gz
tar -xvf php-5.2.8.tar.gz
cd php-5.2.8
=========================================
./configure  --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring  --with-pgsql --with-curl --disable-debug --enable-pic  --disable-rpath --enable-inline-optimization --with-bz2 --with-xml --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-xslt --enable-memcache --enable-zip --with-pcre-regex --with-curl  --with-curlwrappers --with-ncurses --with-openssl --with-openssl-dir=/usr --with-pdo-mysql=/usr --cache-file=./config.cache' '--with-pcre-regex=/usr --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-gdbm --with-gettext --without-gmp --without-kerberos --enable-mbstring --with-mcrypt --with-mhash --enable-sockets --with-openssl --with-openssl-dir=/usr --with-gd=/usr --with-db4
=========================================
vi /etc/init.d/php-fastcgi

#!/bin/bash
BIND=127.0.0.1:9000
USER=root
PHP_FCGI_CHILDREN=8
PHP_FCGI_MAX_REQUESTS=1000

#PHP_CGI=/usr/bin/php-cgi
PHP_CGI=/usr/local/bin/php-cgi

PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
RETVAL=0

start() {
      echo -n "Starting PHP FastCGI: "
      start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
      RETVAL=$?
      echo "$PHP_CGI_NAME."
}
stop() {
      echo -n "Stopping PHP FastCGI: "
      killall -q -w -u $USER $PHP_CGI
      RETVAL=$?
      echo "$PHP_CGI_NAME."
}

case "$1" in
    start)
      start
  ;;
    stop)
      stop
  ;;
    restart)
      stop
      start
  ;;
    *)
      echo "Usage: php-fastcgi {start|stop|restart}"
      exit 1
  ;;
esac
exit $RETVAL

=============================================
vi /etc/nginx/servers/magento.conf

server {
    listen 80;
    server_name domain.com;

        root /home/magento/;

    location / {
        index index.html index.php; ## Allow a static html file to be shown first
      #  try_files $uri $uri/    @handler; ## If missing pass the URI to Magento's front handler
        expires                                 max; ## Assume all files are cachable
        error_page                              404 = @handler;
                log_not_found                   off;
    }

    location ~ /(.*)/index\.php$ { ## strip index.php from product urls
        if (!-e $request_filename) { rewrite ^(.*)/index\.php$ $1/ permanent; }
        }

    location /minify/ { ## Needed for Fooman Speedster
        rewrite ^/minify/([0-9]+)(/.*\.(js|css))$
/lib/minify/m.php?f=$2&d=$1 last;
    }

    ## These locations would be hidden by .htaccess normally
    location /app/                { deny all; }
    location /includes/           { deny all; }
    location /lib/                { deny all; }
    location /lib/minify/         { allow all; }  ## Deny is applied after rewrites so must specifically allow minify
    location /media/downloadable/ { deny all; }
    location /pkginfo/            { deny all; }
    location /report/config.xml   { deny all; }
    location /var/                { deny all; }

    location /var/export/ { ## Allow admins only to view export folder
        auth_basic           "Restricted"; ## Message shown in login window
        auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
    }

    location  /. { ## Disable .htaccess and other hidden files
        return 404;
    }

    location @handler { ## Magento uses a common front handler
        rewrite / /index.php;
    }

    location ~ \.php/ { ## Forward paths like /js/index.php/x.js to relevant handler
        rewrite ^(.*\.php)/ $1 last;
    }

    location ~ \.php$ { ## Execute PHP scripts
        expires                 off; ## Do not cache dynamic content
      #   fastcgi_param   HTTPS $fastcgi_http;
        fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param   PATH_INFO $fastcgi_script_name;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param  MAGE_RUN_CODE  base;
        fastcgi_param  MAGE_RUN_TYPE  website;
        include                 fastcgi_params; ## See /etc/nginx/fastcgi_params
    }

}

====================================

Wednesday, July 21, 2010

How to password protect PHP/Wordpress with htpasswd.

First Create .htpasswd file.

htpasswd -c  /opt/app/.htpasswd admin
New password:
Re-type new password:

After that you can add .htaccess in  your application.

vi /opt/app/.htaccess

AuthUserFile /opt/app/.htpasswd
AuthGroupFile /dev/null
AuthName admin
AuthType Basic
require valid-user

# Enable only if you want authentication less access for some specific host.
Allow from 192.168.10.160
Satisfy Any

Wednesday, June 30, 2010

Server Monitoring with ServerSTAT server.STATS (Clook Internet Ltd)

This is Popular and real time monitoring tool. mostly it used for webhosting server. It is alarming system too.
Server.STATS is develop by clook.net
and its very useful tool where you can add multiple servers and monitoring custom ports and server load.
Please check with this image. I have configure monitoring for some major services. e.g. Httpd-MySql-Ftp etc. you can add any ports and whatever you wants no limit. So when its stoped or some services down it showing you red signal immediately with  sound alarm/alerts.
      Also it gives you Server Load if its cross load 5.00 its become red and sound alarm. So no need to always check the page refresh, it send you sound alarm, if you attached spekers to your system.
    Its free tool, which is in php code, if someone need  i can provide you, help you for configuration.


Yo Guys,  lets monitor your server with serverstat. :)