Zakiir's Blog

May 4, 2010

FFMPEG installation

Filed under: php — zakiir @ 9:11 am
FFMPEG is an open source application that allows you to convert video and audio files easily between a variety of different formats. It supports most industry-standard codec and can convert from one file format to another quickly and easily. This article will guide you to installing FFMPEG and other codec on Linux.

FFMPEG Installation Requirements:

    * FFMPEG
    * LAME Mp3 Audio Codec (Requred for mpg, flv, avi, wmv etc files)
    * AMR Audio Codec (Required for 3gp video files)
    * XVID Audio Codec
    * FFMPEG-PHP

Note on installing FFMPEG:

    * All the Audio Codec getting used in FFMPEG are not part of FFMPEG Source base

FFMPEG Download URL:
On the download page of FFMPEG they have geven the download link from SVN and checkout-snapshot but i would suggest to use SVN source code base.
FFMPEG Download Page FFMPEG
The url for the SVN source code for FFMPEG is: svn://svn.mplayerhq.hu/ffmpeg/trunk

To download from SVN you will have to install subversion located at subversion.tigris.org, or you can use “TortoiseSVN” located at tortoisesvn.tigris.org.

LAME Mp3 Codec download URL: Lame Mp3 Codec

AMR Audio Download URL: AMR Audio Codec
To install the AMR codec you will require both AMR-WB and AMR-NB files.

XVID Audio Download URL: XVID Audio Codec

FFMPEG-PHP Download URL: FFMPEG-PHP

Installation Steps:
It is a good practice to install all the external audio codec libraries first and then install the FFMPEG.

Installing LAME MP3 Encoder

    * Untar the lame file by using tar zxvf lametarfile
    * Assign 777 permission rights to the lame folder by typing chmod 777 lamefolder -R
    * Traverse to the root of lame folder and type
      ./configure
      make
      make install

Installing AMR Codec
For installing the AMR codec there are two separate files that needs to be installed are AMR-WB and AMR-NB.

    * Untar the AMR file by using tar zxvf tarfile
    * Assign 777 permission rights to the amr folder by typing chmod 777 amrfolder -R
    * Traverse to the root of amr folder and type
      ./configure
      make
      make install

Note on Installing AMR:
You might get errors installing AMR codec on Autoconf utility of linux. To resolve this problem will have to install the latest version of Autoconf utility from Download AutoConf

Installing Xvid Codec

    * Untar the xvid file bu using tar zxvf tarfilename
    * Assign 777 permission rights to the lame folder by typing chmod 777 xvidfolder -R
    * Traverse to the root of xvid folder
    * Goto Build/generic folder and type
      ./configure
      make
      make install

Installing GCC

    * This is required only if the SVN for FFMPEG is not compatible with the existing version of GCC(3x) requires a new version for the same
    * After the installation of GCC need to convert all the files of SVN to Unix compatible by using “dos2unix ffmpegfolder/* -R”.

Installing FFMPEG

    * Download the ffmpeg from SVN
    * Assign 777 permission rights to the ffmpeg folder by typing chmod 777 ffmepgfolder -R
    * Traverse to the root of ffmpeg folder and type
      ./configure --enable-libmp3lame --enable-libvorbis --enable-libamr-nb --enable-libamr-wb --enable-libxvid --enable-gpl --enable-shared --enable-nonfree --enable-pthreads
      make
      make install

 Note:While installing FFMPEG u'll get error related to ulong.The Fix for this error is Below
     * Open /usr/include/linux/videodev.h file
     * search for ulong and replace it with unsigned long

Installing FFMPEG-PHP

    * Download the ffmpeg-php from Sourceforge
    * Unpack the archive by using following command “tar -xjf ffmpeg-php.X.XX.tar.gz”
    * Iterate inside the ffmpeg-php directory
    * Run phpize (included with your php install) to build configuration files
      ./configure
      make
      make install

Note:While installing FFMPEG-PHP u'll get error on ffmpeg_frame.c file.The fix is below
    * Open the File /usr/local/src/zakir/ffmpeg-php-0.6.0/ffmpeg_frame.c
    * Replace every instance of PIX_FMT_RGBA32 with PIX_FMT_RGB32


Note:Check below link for Your reference

http://www.eukhost.com/forums/f15/how-install-ffmpeg-ffmpeg-php-mplayer-mencoder-flv2tool-lame-mp3-encoder-4893/

Note:If you get error "Warning: Persistent movies have been disabled in php.ini" Then do the following
    * Include persistent for ffmpeg in php.ini
      ffmpeg. allow_persistent = on

April 17, 2010

Installing pdo_mysql with php in linux

Filed under: mysql — zakiir @ 7:50 am

To enable pdo_mysql in php is very simple.Just follow below steps.

1.pecl install pdo_mysql

Note:make sure you have pecl and pear configured properly on your system

2.Now compile your php with option ‘–with-pdo-mysql’

September 3, 2009

Enabling Sphinx Engine on RHEL with mysql 5.1

Filed under: mysql — zakiir @ 3:51 am

sphinx

This tutorial is mainly based on an RPM installation of MySQL, or an installation of MySQL where you prefer to have Sphinx installed as a plugin instead of statically into the MySQL server binary. Currently this installation method is the *only* safe way for servers running cPanel.

Assumed Setup:

RHEL 4.x or 5.x MySQL 5.1.30

wget http://sphinxsearch.com/downloads/sphinx-0.9.8.1.tar.gz
tar xvzf sphinx-0.9.8.1.tar.gz

Now download the MySQL 5.1 sources for the exact version of mysql that is running on the server (mysql -V) – these are only going to be used to compile the Sphinx module, as you should already have MySQL 5.1 installed.

cd /usr/src
wget http://www.percona.com/mysql/5.1.30/source/mysql-5.1.30.tar.gz
tar -xvzf mysql-5.1.30.tar.gz
cd mysql-5.1.30
cp -Rf /usr/src/sphinx-0.9.8.1/mysqlse/ storage/sphinx

Find the RPM configure command for MySQL by running ‘mysqlbug’. Copy the configure line to something like notepad and add the following line to it:

  1. -with-plugin=sphinx

Now compile the Sphinx module against the MySQL 5.1 sources, but DON’T install:

sh BUILD/autorun.sh
./configure --<copied configure line>
make

If you look in storage/sphinx/.libs you’ll find the loadable .so files that can plug in to MySQL easily. To install, create your plugins directory, copy the files, then add the directive to /etc/my.cnf and restart MySQL:

mkdir /var/lib/mysql/plugins
cp -rf storage/sphinx/.libs/ha_sphinx.so* /var/lib/mysql/plugins
cp /var/lib/mysql/plugins/ha_sphinx.so /usr/lib64/mysql/plugin/

In my.cnf:

plugin_dir=/var/lib/mysql/plugins

(Restart MySQL)

Now log into MySQL and install:

mysql -u root
mysql> INSTALL PLUGIN sphinx SONAME 'ha_sphinx.so';

To see if it has installed properly, do a listing of the active engines:

mysql> show engines;
| CSV        | YES     | CSV storage engine
.....
| SPHINX     | YES     | Sphinx storage engine 0.9.7

September 2, 2009

Why doesn’t Linux need defragmenting

Filed under: Linux — zakiir @ 3:27 am

what is fragmentation
Definition: Fragmentation occurs on a hard drive, a memory module, or other media when data is not written close enough physically on the drive.

http://en.wikipedia .org/wiki/ File:Fragmentati onDefragmentatio n.gif

what is defragment
Defragment – A process whereby discontiguous blocks of data on a
hard drive are moved to a contiguous block to speed up data reads from
a hard drive.

Now imagine your hard disk is a huge file cabinet, with millions of
drawers (thanks to Roberto Di Cosmo for this comparison). Each drawer
can only contain a fixed amount of data. Therefore, files that are
larger than what such a drawer can contain need to be split up. Some
files are so large that they need thousands of drawers. And of course,
accessing these files is much easier when the drawers they occupy are
close to one another in the file cabinet.

Now imagine you’re the owner of this file cabinet, but you don’t have
time to take care of it, and you want to hire someone to take care of
it for you. Two people come for the job, a woman and a man.

* The man has the following strategy : he just empties the drawers
when a file is removed, splits up any new file into smaller pieces the
size of a drawer, and randomly stuffs each piece into the first
available empty drawer. When you mention that this makes it rather
difficult to find all the pieces of a particular file, the response is
that a dozen boys must be hired every weekend to put the chest back in
order.

* The woman has a different technique : she keeps track, on a piece of
paper, of contiguous empty drawers. When a new file arrives, she
searches this list for a sufficiently long row of empty drawers, and
this is where the file is placed. In this way, provided there is enough
activity, the file cabinet is always tidy.

Without a doubt, you should hire the woman (you should have known it, women are much better organized
). Well, Windows uses the first method ; Linux uses the second one. The
more you use Windows, the slower it is to access files ; the more you
use Linux, the faster it is. The choice is up to you!

August 29, 2009

MySQL replication

Filed under: mysql — zakiir @ 10:44 am

# MySQL replication MASTER setting #

server-id = 1
log-bin = /var/log/mysql/binary/mysql-bin.log
binlog-do-db = student
binlog-ignore-db = mysql
log = /var/log/mysql/mysql.log

SHELL> mkdir /var/log/mysql/

SHELL> chown mysql:mysql -R /var/log/mysql/

SHELL> mysql -u root -p
Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 950
Server version: 5.0.45-community-log MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| cPanel |
| cphulkd |
| devendra |
| eximstats |
| horde |
| leechprotect |
| mysql |
| pleskmods |
+——————–+
9 rows in set (0.00 sec)

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

mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| cPanel |
| cphulkd |
| devendra |
| eximstats |
| horde |
| leechprotect |
| mysql |
| pleskmods |
| student |
+——————–+
10 rows in set (0.00 sec)

mysql> use student;
Database changed

mysql> create table class ( rollno INT(5) NOT NULL PRIMARY KEY AUTO_INCREMENT , name VARCHAR(30) );
Query OK, 0 rows affected (0.32 sec)

mysql> DESC class;
+——–+————-+——+—–+———+—————-+
| Field | Type | Null | Key | Default | Extra |
+——–+————-+——+—–+———+—————-+
| rollno | int(5) | NO | PRI | NULL | auto_increment |
| name | varchar(30) | YES | | NULL | |
+——–+————-+——+—–+———+—————-+
2 rows in set (0.03 sec)

mysql> INSERT INTO class VALUES (”, ‘Arun Bagul’);
Query OK, 1 row affected, 1 warning (0.01 sec)

mysql> SELECT * FROM class;
+——–+————+
| rollno | name |
+——–+————+
| 1 | BHAVESH |
+——–+————+
1 row in set (0.00 sec)

mysql> INSERT INTO class VALUES (”, ‘Suhail Thakur’);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> INSERT INTO class VALUES (”, ‘Bhavesh Vala’);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> SELECT * FROM class;
+——–+—————+
| rollno | name |
+——–+—————+
| 1 | BHAVESH |
| 2 | Suhail Thakur |
| 3 | Bhavesh Vala |
+——–+—————+
3 rows in set (0.00 sec)

mysql> GRANT REPLICATION SLAVE ON *.* TO ‘replication’@’192.168.0.%’ IDENTIFIED BY ‘mypwd’;
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> SHOW MASTER STATUS;
+——————+———-+—————–+——————+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+——————+———-+—————–+——————+
| mysql-bin.000002 | 98 | student,student | mysql,mysql |
+——————+———-+—————–+——————+
1 row in set (0.02 sec)

mysql>

mysql> SHOW PROCESSLIST;
+—-+——-+———–+——-+———+——+————+————————–+
| Id | User | Host | db | Command | Time | State | Info |
+—-+——-+———–+——-+———+——+————+————————–+
| 31 | root | localhost | NULL | Query | 0 | NULL | SHOW PROCESSLIST |
| 41 | horde | localhost | horde | Sleep | 0 | | NULL |
| 42 | horde | localhost | horde | Query | 1 | statistics | SELECT session_data FROM horde_sessionhandler WHERE session_id = ‘f70a7d64bd353917679814813a513c8f’ |
| 43 | horde | localhost | horde | Query | 1 | statistics | SELECT session_data FROM horde_sessionhandler WHERE session_id = ‘f70a7d64bd353917679814813a513c8f’ |
+—-+——-+———–+——-+———+——+————+————————–+
4 rows in set (0.00 sec)

mysql> SHOW PROCESSLIST\G;
*************************** 1. row ***************************
Id: 31
User: root
Host: localhost
db: NULL
Command: Query
Time: 0
State: NULL
Info: SHOW PROCESSLIST

1 row in set (0.00 sec)

mysql>

SHELL> /etc/init.d/mysql restart

Shutting down MySQL… [ OK ]
Starting MySQL [ OK ]

SHELL> cd /var/log/mysql/binary/

SHELL> ls
mysql-bin.000001 mysql-bin.index

# MySQL replication SLAVE setting #

server-id=3
master-port=3306
master-host=192.168.XXX.XXX
master-user=replication
master-password=mypwd
master-connect-retry=60
replicate-do-db=student

SHELL> mysqladmin create student -u admin -p
Enter password:

SHELL> mysql -u admin -p student show databases;
+———–+
| Database |
+———–+
| horde |
| mysql |
| pleskmods |
| psa |
| student |
+———–+
5 rows in set (0.00 sec)

mysql> use student;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+——————-+
| Tables_in_student |
+——————-+
| class |
+——————-+
1 row in set (0.00 sec)

mysql> select * from class;
+——–+—————+
| rollno | name |
+——–+—————+
| 1 | Arun Bagul |
| 2 | Suhail Thakur |
| 3 | Bhavesh Vala |
| 4 | Nishit Shah |
+——–+—————+
4 rows in set (0.00 sec)

mysql>

mysql> CHANGE MASTER TO MASTER_HOST=‘192.168.XXX.XXX’, MASTER_USER=’replication’ , MASTER_PASSWORD=’mypwd’,MASTER_LOG_FILE=’mysql-bin.000004′,MASTER_LOG_POS=412;
Query OK, 0 rows affected (0.01 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G;

*************************** 1. row ***************************
Slave_IO_State: Waiting for 192.168.XXX.XXX
Master_Host: 192.168.XXX.XXX
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000103
Read_Master_Log_Pos: 16995
Relay_Log_File: magnet-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000103
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB: auth,auth
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 16995
Relay_Log_Space: 98
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL

1 row in set (0.00 sec)

mysql> quit
Bye

SHELL> /etc/init.d/mysqld restart

Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

NIC Bonding

Filed under: Linux — Tags: , , , , , , , — zakiir @ 10:11 am

Meaning:-

The concept of NIC Bonding (or sometimes called NIC Teaming) is that you have two NICs bonded together to appear as if they are the same physical device. I.e. They will both present the same Hardware (MAC) address. This is accomplished through the ifenslave utility, which enables the kernel to see/use only one device.

NIC Bonding also be known as:

* “NIC Aggregation” (Mainly Linux world)
* “NIC Teaming” (Mainly Windows world)
* “Port Trunking” (Mainly hardware world)

It provides increased bandwidth by merging the bandwidth of the individual ports/NICs.It’s primary use _is_ to increase a network link speed beyond the limits of any one single cable or port. Although It can also be used for failover, if one link dies all traffic to and from the machine should be routed to the remaining links.

The “ifenslave” is a tool to attach and detach slave network interfaces to a bonding device. A bonding device will act like a normal Ethernet network device to the kernel, but will send out the packets via the slave devices using a simple round-robin scheduler. This allows you a simple load-balancing.

NIC Bonding Prerequiest :-

You must have an bonding support in your kernel, so you can check with following.

$ modprobe -l | grep bonding
/lib/modules/2.6.9-55.ELsmp/kernel/drivers/net/bonding/bonding.ko

$ cat /boot/config-2.6.9-55.EL | grep -i bonding
CONFIG_BONDING=m

NIC Bonding Configuration :-

(1) The “modprob.conf” file should include the followings 3 lines.

$ cat /etc/modprobe.conf

alias bond0 bonding
options bond0 max_bonds=2 miimon=100 mode=1
options bond1 miimon=100 mode=1

Here:
max_bonds = ” The number of bonding devices to create for this instance of the bonding driver e.g., if max_bonds is 3, and the bonding driver is not already loaded, then bond0,
bond1 and bond2 will be created. The default value is 1.”

miimon = ” Specifies the MII link monitoring frequency in milliseconds.This determines how often the link state of each slave is inspected for link failures. A value of zero
disables MII link monitoring. A value of 100 is a good starting point.”

mode = ” Specifies one of the bonding policies. The default is balance-rr (round robin).”
Possible values are:

0 = Round-robin policy: Transmit packets in sequential order from the first slave
through the last.

1 = Active-backup policy: Only one slave in the bond is active. A different slave
becomes active if, and only if, the active slave fails.

2 = Tries to balance traffic by splitting up outgoing packets between the adapters,
using the same one for each specific destination when possible.

3 = Broadcast policy: transmits everything on all slave interfaces. This mode
provides fault tolerance.

(2) You will have to add the following to do a working NIC Bonding.

$ vi /etc/sysconfig/network-scripts/ifcfg-bond0

## Now add the following things to the above file. ##

DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
NETWORK=
NETMASK=
IPADDR=
GATEWAY=
USERCTL=no

(3) Now just append the following lines to (eth0).

$ vi /etc/sysconfig/network-scripts/ifcfg-eth0

## nOW APPEND the following to the above file. ##

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no

(4) Now just append the following lines to (eth1).

$ /etc/sysconfig/network-scripts/ifcfg-eth1

## nOW APPEND the following to the above file. ##

DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no

August 22, 2009

MySQL – Checking & Repairing Databases

Filed under: mysql — zakiir @ 10:11 am



MySQL – Checking & Repairing Databases

1) Identifying Table Types

  • # cd /var/lib/mysql/databasename

* Where /var/lib/mysql is the mysql database directory. Can vary according to the installation. But on most of the installations its here. To check the database directory you can use the below command.

# ps -auxww|grep mysql

root 807 0.0 0.1 5032 1080 pts/4 S Feb21 0:00 /bin/sh /usr/bin/mysqld_safe –defaults-file=/etc/my.cnf –pid-file=/var/run/mysqld/mysqld.pid

mysql 840 0.0 1.9 126720 20156 pts/4 Sl Feb21 0:04 /usr/libexec/mysqld –defaults-file=/etc/my.cnf –basedir=/usr –datadir=/var/lib/mysql –user=mysql –pid-file=/var/run/mysqld/mysqld.pid –skip-locking –socket=/var/lib/mysql/mysql.sock

Here –datadir option shows that the database dir is /var/lib/mysql

* databasename is the name of the database that you need to check & repair

  • # ls -l

-rw-rw—- 1 mysql mysql 10088 Feb 23 10:38 sip_realtime.frm
-rw-rw—- 1 mysql mysql 702000 Feb 23 10:38 sip_realtime.MYD
-rw-rw—- 1 mysql mysql 165888 Feb 23 10:38 sip_realtime.MYI

Each table created in this database will have three associated files.

.frm files will have
.MYD files will have
.MYI files will have

If a table name has a .MYI file associated with it, then its a MyISAM type table.
If a table name has a .ISM file associated with it, then its a ISAM type table.

To read more about MySQL supported Database Engines read -
http://builder.com.com/5100-6388-1058872.html

2) Checking if the tables need recovery.

  • If its a MyISAM table run the below command on the database directory (/var/lib/mysql/databasename).

# myisamchk -m *.MYI

Checking MyISAM file: phpads_adclicks.MYI
Data records: 165693 Deleted blocks: 0
myisamchk: warning: 13 clients is using or hasn’t closed the table properly
- check file-size
- check key delete-chain
- check record delete-chain
- check index reference
- check data record references index: 1
- check data record references index: 2
- check data record references index: 3
- check record links
MyISAM-table ‘phpads_adclicks.MYI’ is usable but should be fixed

  • For tables of ISAM type, run the below command

# isamchk *.ISM

Checking ISAM file: record_extension.ISM
Data records: 1747 Deleted blocks: 0
- check file-size
- check delete-chain
- check index reference
- check data record references index: 1
- check data record references index: 2
- check data record references index: 3
- check data record references index: 4
- check data record references index: 5
- check data record references index: 6
- check record links

  • Both the above commands will tell you if any of the tables need recovery.
  • Note down the tables that needs to be fixed.

3) Backup the databases

# tar -cvzf /backup/.`date +%F`.tar.gz /var/lib/mysql/databasename

4) Run myisamchk or isamchk with safe recovery options

myisamchk -o tablename.MYI

or

isamchk -o tablename.ISM

5) After all tables are fixed/recovered you can start the website accessing the database.

September 3, 2007

Hats off to Solaris.

Filed under: Uncategorized — zakiir @ 11:42 pm

Solaris 10 has made it really big this time round and has raised some real questions to Redhat Customers wheather they shud stick to Redhat or not . Follow the following link :

http://www.sun.com/software/solaris/hatsoff/

Difference between LILO and Grub?

Filed under: Linux — zakiir @ 10:52 pm

I find lilo is easier but a bit less flexible compared to grub(for example, whenever you change something with lilo you have to rewrite lilo to the mbr, whereas grub you just edit it’s configuration file without writing to the mbr all the time)

what is journalling?

Filed under: Linux — zakiir @ 9:54 pm

In earlier days (ext2), a sudden power failure or another such condition could leave the filesystem in an inconsistent state. So after every boot the fsck program was run for every uncleanly unmounted filesystem. This took very long. Ext3 avoids this time consuming task by letting check only the specific areas that were recently accessed or modified. For this a log is kept which is called �Journal�. This way filesystem checking time is drastically reduced.

Older Posts »

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.