Thursday, 30 January 2014

Mongodb service wont start

I recently come accros this situation, when  i start the mognod service, i  was getting the below error.

[root@ip-xx-xx-xxx-xx mongo]# /etc/init.d/mongod start
Starting mongod: about to fork child process, waiting until server is ready for connections.
forked process: 19972
all output going to: /var/log/mongo/mongod.log
ERROR: child process failed, exited with error number 45
                                                           [FAILED]
[root@ip-xx-xx-xxx-xx mongo]# /etc/init.d/mongod restart
Stopping mongod:                                           [FAILED]
Starting mongod: about to fork child process, waiting until server is ready for connections.
all output going to: /var/log/mongo/mongod.log
forked process: 20004
ERROR: child process failed, exited with error number 45
                                                           [FAILED]


To fix this issue, I   got some fixes to repair the mongodb instance.  So in screeen i tried the repair command with the mongodb db path(in my case it is /var/lib/mongo/ ),

[root@ip-xx-xx-xxx-xx mongo]# mongod --dbpath /var/lib/mongo/ --repair

Then i run

[root@ip-xx-xx-xxx-xx mongo]# mongod --dbpath /var/lib/mongo/&



This will fix the issue partially,  mongodb   service will start after this.  But this is not the  actual fix to this issue.

This  is an error due to the permission on the db path of mongodb.

In my case when i check,  the location /var/lib/mongo  it was owned by root and group root.  We need to chnage this to mongod

So i ran this command and  fixed the issue.

[root@ip-xx-xx-xxx-xx mongo]# cd /var/lib/
[root@ lib]# chown -R mongod.mongod mongo

Then you can start the mongod  service.

[root@ip-xx-xx-xxx-xx mongo]# /etc/init.d/mongod start
Starting mongod: Thu Jan 30 18:22:11.350
Thu Jan 30 18:22:11.370 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Jan 30 18:22:11.370
about to fork child process, waiting until server is ready for connections.
all output going to: /var/log/mongo/mongod.log
forked process: 10293
child process started successfully, parent exiting
                                                           [  OK  ]
[root@ip-xx-xx-xxx-xx mongo]#

Tuesday, 10 December 2013

How to create and use an AWS S3 bucket with s3cmd tool


Amazon S3 is a reasonably priced data storage service. Ideal for off-site backups, archiving and other data storage needs.  S3cmd is a command line tool for uploading, retrieving and managing data in Amazon S3. S3cmd is an open source project available under GNU Public License v2 (GPLv2) and is free for both commercial and private use. You will only have to pay Amazon for using their storage.

Installation of s3cmd package

 S3tools / S3cmd project homepage:
    http://s3tools.sourceforge.net

Amazon S3 homepage:
    http://aws.amazon.com/s3

Installation of RPM package
---------------------------
As user "root" run:

        rpm -ivh s3cmd-X.Y.Z.noarch.rpm

where X.Y.Z is the most recent s3cmd release version.


Installation of source .tar.gz package
--------------------------------------
There are three options to run s3cmd from source tarball:

1) S3cmd program as distributed in s3cmd-X.Y.Z.tar.gz
   can be run directly from where you untar'ed the package.

2) Or you may want to move "s3cmd" file and "S3" subdirectory
   to some other path. Make sure that "S3" subdirectory ends up
   in the same place where you move the "s3cmd" file.

   For instance if you decide to move s3cmd to you $HOME/bin
   you will have $HOME/bin/s3cmd file and $HOME/bin/S3 directory
   with a number of support files.

3) The cleanest and most recommended approach is to run

        python setup.py install

   You will however need Python "distutils" module for this to
   work. It is often part of the core python package (e.g. in
   OpenSuse Python 2.5 package) or it can be installed using your
   package manager, e.g. in Debian use

        apt-get install python2.4-setuptools



Configure  S3cmd:


To configure s3cmd, you need two information: • Access Key • Secret Key
You can get these credentials from: •
https://aws-portal.amazon.com/gp/aws/securityCredentials
Run “s3cmd –configure” command

[root@ip-XXX-XX-XX-XX ~]# s3cmd --configure

Enter new values or accept defaults in brackets with Enter.
Refer to user manual for detailed description of all options.

Access key and Secret key are your identifiers for Amazon S3
Access Key: __[Your Access Key]__
Secret Key: __[Your Secret Key]__

Encryption password is used to protect your files from reading
by unauthorized persons while in transfer to S3
Encryption password: __[Your passphrase to protect your Secret Key]__
Path to GPG program [/usr/bin/gpg]:

When using secure HTTPS protocol all communication with Amazon S3
servers is protected from 3rd party eavesdropping. This method is
slower than plain HTTP and can't be used if you're behind a proxy
Use HTTPS protocol [No]: yes

New settings:
  Access Key: [Your Access Key]
  Secret Key: [Your Secret Key]
  Encryption password: [Your passphrase to protect your Secret Key]
  Path to GPG program: /usr/bin/gpg
  Use HTTPS protocol: True
  HTTP Proxy server name:
  HTTP Proxy server port: 0

Test access with supplied credentials? [Y/n]
Please wait...
Success. Your access key and secret key worked fine :-)

Now verifying that encryption works...
Success. Encryption and decryption worked fine :-)

Save settings? [y/N] y
Configuration saved to '/root/.s3cfg'
[root@ip-XXX-XX-XX-XX ~]#


Create the S3 bucket:

[root@ip-XXX-XX-XX-XX ~]#s3cmd mb s3://test123
Bucket 's3://test123/' created
[root@ip-XXX-XX-XX-XX ~]#



Put a public file on this bucket:

[root@ip-XXX-XX-XX-XX ~]#s3cmd --acl-public put video1.mp4 s3://test123
video1.mp4 -> s3://test123/video1.mp4  [1 of 1]
 1685 of 1685   100% in    0s     4.12 kB/s  done
Public URL of the object is: http://test123.s3.amazonaws.com/video1.mp4
[root@ip-XXX-XX-XX-XX ~]#


Or can use the below command

s3cmd --config=/root/.s3cfg put --acl-public videos1.mp4 s3://test123 
 
Listing files:

[root@ip-XXX-XX-XX-XX ~]# s3cmd ls s3://test123
2012-02-09 03:26      1685   s3://test123/video1.mp4
[root@ip-XXX-XX-XX-XX ~]#


Get files through s3cmd:

[root@ip-XXX-XX-XX-XX ~]# s3cmd get s3://test123/video1.mp4



For more details please  go through the url, http://s3tools.org/s3cmd

Thursday, 17 October 2013

Difference between rewrite and redirect

The main difference between rewriting and redirecting is,  Redirecting sends a HTTP 301 or 302 to the client, telling the client that it should try to access the page using another URL. This means that the client knows that there is another URL that should be used. The communication between the server and client is like:

Request 1 (from client):     Get index.php
Response 1 (from server).  The file is moved, please request the file temp_index.php
Request 2 (from client):     Get temp_index.php
Response 2 (from server):  Here is the content of temp_index.php

Rewriting happens on the server, and simply is a translation of one URL to another, that is used by your web application. The client does not know that internally there is another URL, it just sees the one it sent to the server.

Request 1 (from client):       Get  index.php
URL Rewriting (on server):   Translate the URL  index.php  to temp_index.php
Web application (on server): Process the request (run any code in temp_index.php)
Response 1 (from server):    Here is the content of index.php (note that the client does not know that this is the content of temp_index.php)

Monday, 7 October 2013

MediaWiki Installation

MediaWiki is a free, open source wiki software developed by Wikimedia Fountation.

Prerequisites

Install Apache, MySQL, PHP and necesary PHP modules.

create database called mediawikidb and user called mediawikiadmin with password centos.

mysql> create database mediawikidb;
Query OK, 1 row affected (0.03 sec)

mysql> GRANT ALL PRIVILEGES ON mediawikidb.* TO 'mediawikiadmin' IDENTIFIED BY 'centos';
Query OK, 0 rows affected (0.05 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

Download the latest version from

[root@station254 src]# wget http://download.wikimedia.org/mediawiki/1.21/mediawiki-1.21.1.tar.gz
[root@station254 src]# tar zxvf mediawiki-1.21.1.tar.gz
[root@station254 src]# mv mediawiki-1.21.1 /var/www/html/mediawiki

Begin Installation

Navigate to http://ip-address or domain/mediawiki/ from your browser and follow the onscreen instructions.


Click On setup the wiki first link. Select your language and click Continue


Now the installer will perform the environment checks. If everything seems Ok, Click Continue.



Enter MySQL Settings such as Database name, user and password etc. 



Select MySQL storage engine and click Continue.


Enter your Wikipedia website name and create a  new administrative account with username, password and mail id.



Click Continue.



Now the Wikipedia website has been installed successfully. The installer will download a file called LocalSettings.php which contains all your configuration details. It is recommended to download and keep it safe, you will need it. 


Copy the downloaded LocalSettings.php file to the mediawiki directory. And set write permissions of the LocalSettings.php and WebStart.php files. 

[root@station254 mediawiki]# chmod 755 LocalSettings.php

[root@station254 mediawiki]# chmod 755 includes/WebStart.php


Now click on enter to wiki link or navigate to http://ip-address or domain/mediawiki/ from your browser. Now you will be redirected to your wikipedia home page. 



Thats it. Start uploading contents and spread the word of your new wiki website.


Thursday, 3 October 2013

How to install wkhtmltopdf on a linux based web server

64bits OS
---------

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf


32bits OS
---------

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-i386.tar.bz2
tar xvjf wkhtmltopdf-0.9.9-static-i386.tar.bz2
mv wkhtmltopdf-i386 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf



conversion: /usr/local/bin/wkhtmltopdf www.google.com google.pdf





Monday, 30 September 2013

ImageMagick and PHP extension Imagick Installation

1)Simple installation method-
------------------------------
# Yum install ImageMagick ImageMagick-devel
# pecl install imagick
add extension php.ini
extension=imagick.so

2 ) Try Latest verion using RPM
--------------------------------
For Latest Version--

http://www.imagemagick.org/script/binary-releases.php
http://www.imagemagick.org/download/linux/CentOS/i386/ImageMagick-devel-6.8.5-7.i386.rpm
ImageMagick RPM Download --
Download latest version of ImageMagick and ImageMagick-devel and try to install. After that install pecl module Imagick.

Sometimes you will face several errors, Then tyy source compilation

3) Via Source Compilation-
---------------------------
http://www.imagemagick.org/script/download.php
wget ftp://mirror.aarnet.edu.au/pub/imagemagick/ImageMagick-6.8.5-6.tar.gz

Download the latest version from Imagemagick.org

Extract and compile

#./configure --prefix=/usr/
 [ change the prefix to /usr, else the installation location of binaries and libraries will be /usr/local/bin , /usr/loca/lib etc.]

# make
# make install

Test installation
# which convert
# convert -version

Friday, 27 September 2013

SQLITE 3 installation - Linux

Donwload http://downloads.sourceforge.net/php-sqlite3/sqlite3-0.5.tgz

1. unzip & untar the package
2. move to /usr/local/src
3. run "phpize"
4. run ./configure --with-sqlite3 --with-php-config=/usr/bin/php-config
5. make
6. make test
7. make install

vi /etc/php.d/sqlite.ini
; Enable sqlite extension module
extension=sqlite3.so
SQLite-1.0.3.tgz


For installting older version use this tutorial

http://kb.parallels.com/en/5460