Tuesday, May 13, 2014

Install FFMPEG and FFMPEG-PHP in CentOS 6

Installing FFMpeg


 Add dag's repository by adding the following to /etc/yum.repos.d/dag.repo
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
gpgkey=http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt
enabled=1
protect=0
next import dag's rpm gpg key by
wget http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt -P /tmp
rpm --import /tmp/RPM-GPG-KEY.dag.txt
Proceed with installing FFMPEG and some development packages
yum install ffmpeg-devel php-devel re2c php-xml ffmpeg
verify FFMPEG is installed successfully by executing
ffmpeg
you should get something like
FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.4.5-6)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdc1394 --enable-libdirac --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libx264 --enable-gpl --enable-nonfree --enable-postproc --enable-pthreads --enable-shared --enable-swscale --enable-vdpau --enable-version3 --enable-x11grab
libavutil 50.15. 1 / 50.15. 1
libavcodec 52.72. 2 / 52.72. 2
libavformat 52.64. 2 / 52.64. 2
libavdevice 52. 2. 0 / 52. 2. 0
libavfilter 1.19. 0 / 1.19. 0
libswscale 0.11. 0 / 0.11. 0
libpostproc 51. 2. 0 / 51. 2. 0
Hyper fast Audio and Video encoder


Compile and install the FFMPEG-PHP extension
mkdir /srv/build
cd /srv/build
wget http://downloads.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2
tar -xjf ffmpeg-php-0.6.0.tbz2
cd ffmpeg-php-0.6.0/

phpize
./configure
now run the following to prevent compilation failure with something like ffmpeg_frame.c:421: error: ‘PIX_FMT_RGBA32’ undeclared (first use in this function)
sed -i 's#PIX_FMT_RGBA32#PIX_FMT_RGB32#' ./ffmpeg_frame.c
and compile and install using
make
make install
you should end up with something like
Installing shared extensions:     /usr/lib64/php/modules/


Load the FFMPEG-PHP extension and reload Apache
Add the following at the end in php.ini.
[ffmpeg] 
extension=ffmpeg.so
restart the webserver by
/etc/init.d/httpd restart
verify that the FFMPEG-PHP extension is loaded
php -i | grep ffmpeg
php -m | grep ffmpeg


If you get the below errors:


/root/ffmpeg/ffmpeg-php-0.7.0/ffmpeg_movie.c: In function 'zim_ffmpeg_movie___construct':
/root/ffmpeg/ffmpeg-php-0.7.0/ffmpeg_movie.c:318: error: 'list_entry' undeclared (first use in this function)
/root/ffmpeg/ffmpeg-php-0.7.0/ffmpeg_movie.c:318: error: (Each undeclared identifier is reported only once
/root/ffmpeg/ffmpeg-php-0.7.0/ffmpeg_movie.c:318: error: for each function it appears in.)
/root/ffmpeg/ffmpeg-php-0.7.0/ffmpeg_movie.c:318: error: 'le' undeclared (first use in this function)
/root/ffmpeg/ffmpeg-php-0.7.0/ffmpeg_movie.c:353: error: expected ';' before 'new_le'
/root/ffmpeg/ffmpeg-php-0.7.0/ffmpeg_movie.c:363: error: 'new_le' undeclared (first use in this function)

Solution:
Please change the following lines in ffmpeg_movie.c
Changes in ffmpeg_movie.c:
row 311: list_entry *le; TO zend_rsrc_list_entry *le;
row 346: list_entry new_le; TO zend_rsrc_list_entry new_le;
row 360: hashkey_length+1, (void *)&new_le, sizeof(list_entry), TO
hashkey_length+1, (void *)&new_le,sizeof(zend_rsrc_list_entry)

Putty - Password less login

Steps to generate key and access server without passwords.
Written by : Harijith R.          
Prerequisites : Download putty-0.63-installer.exe from the URL: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html.
putty-0.63-installer.exe is a Windows installer for everything except PuTTYtel.
Step 1
Generate a public/private key pair on your local desktop. From the Start menu, run Start > All Programs > PuTTY > PuTTYgen as illustrated below.


Fig. 1 Initial PuTTYgen window.

Click the Generate button. You will be prompted to move the mouse over the blank area to generate some randomness. Do so. Shortly thereafter, the program will generate the key and display the result (see Figure 2).

Fig. 2 After keys have been generated.

click the "Save private key" button to save the private key to a file (Figure 3).

Fig. 3 Saving the private key in file mykey.ppk.
Step 2
Install the public key on the remote host to which you want to connect. Do this by pasting the public key from the Clipboard into the the authorized_keys file, which is located in the .ssh directory in your home directory on the remote host.
Step 3
Verify that public key authentication works. Basic public key authentication is enabled for a particular session in the Connection > SSH > Auth window. You must load the session profile (Figure 6) before configuring the Auth window (Figure 7).

Fig. 6 Load the appropriate session profile.

Fig. 7 Connection > SSH > Auth window.
Browse to select the saved private key which we saved in step 1 in the "Private key file for authentication" text box.
Be sure to go back to the Session window and click Save to update the profile. The session will use public key authentication as demonstrated in Figure 8.

Fig. 8 Logging in using basic public key authentication.


Saturday, January 4, 2014

Troubleshooting high server loads on Linux servers

Technical support analysts often receive tickets about high server loads. The cause of high server loads is very rarely attributed to defects in the cPanel software or the applications it installs. High server loads are something that should be initially investigated by the server owner, their system administrator, or server provider.

What causes high server loads?

Excessive usage of any of the following items can typically cause this issue:

  • CPU
  • memory (including swap)
  • disk I/O


How can I check these items?

That depends whether you want to review their current resource usage, or historical resource usage. This tutorial will cover both.

A brief lesson on "sar"

Historical resource usage can be viewed using the "sar" utility, which should exist by default on all cPanel servers from the sysstat package. The stats are collected when sysstat runs from cron (/etc/cron.d/sysstat). If crond is not running, sysstat will not be able to collect historical statistics.

To view resource usage histories from sar, you must provide the path to the file that corresponds with the date of the stats.

For example, if you wanted to view the load averages for your server from the 23rd of the month, you would run this command:

Code:
[user@host ~]$ sar -q -f /var/log/sa/sa23
The command above uses '-q' to obtain the load average information, and '-f' to specify which sar file to obtain the information from. Note that sar may not have historical data going back more than a week or so.

You do not need to specify the date when viewing the statistics for the current day. As such, this command would show the load average for today:

Code:
[user@host ~]$ sar -q
You are strongly encouraged to read the documentation for sar:

Code:
[user@host ~]$ man sar
It provides statistics for many things that can be helpful to know about.


Current CPU usage

Run "top", and on the line that says "Cpu(s)", check the "%id" section which shows the percentage of which your CPUs are idle. The higher the number the better. A 99% idle CPU is not doing much of anything, and a 1% idle CPU is heavily tasked.

Code:
[user@host ~]$ top c
Tip: hit "P" to sort by processes that are currently consuming the most CPU.

Historical CPU usage

Check the "%idle" column:

Code:
[user@host ~]$ sar -p
Current memory usage

Code:
[user@host ~]$ free -m
Tip: run "top c" and hit "M" to see which processes are consuming the most memory.

Historical memory usage

This depends on the version of sar, which used to use '-r' to show %memused and %swpused (swap memory used), but later changed to '-S' to show %swpused.

Check "%memused" and "%swpused":

Code:
[user@host ~]$ sar -r
OR:

Code:
[user@host ~]$ sar -r
Code:
[user@host ~]$ sar -S

A note about memory usage: it is normal to see much of the server's memory being used. Why? Because the OS loves to cache things in memory. Why? Because accessing data from memory is extremely fast and far more efficient than using the server's disk(s).

As such, %memused isn't generally going to be much of an issue (unless perhaps you don't have a swap partition, but that's an issue in and of itself). You should focus on %swpused, which is what gets used when your server's physical memory is full. The lower the number, the better. A %swpused percentage of 0% would mean that your server currently has sufficient physical memory to perform its tasks.

How much %swpused is too much? That depends on your opinion of "too much". Generally speaking, a consistent low percentage of swap usage may not be an issue on your server. If you observe the %swpused increasing over time (e.g., from 1%, to 7%, to 32%), something on your server is consuming too much memory, and it would be wise to determine what that is (rather than just installing more memory). If your server ends up using all of its physical memory and swap memory, it may become unresponsive, requiring a reboot.

Current disk I/O usage

Note: this does not work on OpenVZ/Virtuozzo containers.

This will print the disk usage statistics 10 times, every 1 seconds. Check the %util column:

Code:
[user@host ~]$ iostat -x 1 10
Historial disk I/O usage

Code:
[user@host ~]$ sar -d

Good system administration involves knowing when your server's load is higher than acceptable. The main reason for this (other than preventing your server from becoming unresponsive and requiring a reboot) is tosee what's taking place on the server while the load is high. Fast actions will enable you to troubleshoot the issue while it is occurring.

If your server's load was high from 2AM - 4AM while you were sleeping, you would have missed what took place. While sar can be helpful to show you what specific resources were high during that time, it won't tell you the cause of the high usage. There can be many causes, including DoS attacks, spam attacks, poorly designed php scripts which consume large amounts of memory, web spiders that crawl sites too aggressively, hardware issues, massive amounts of disk writes to a user's MySQL database, and much, much more.

The good news is that you can have much of this information collected and sent to you automatically while the load is high, which you can review later as needed. How? From your process list:

Code:
[user@host ~]$ ps auxwwwf

Install mod_security on CentOS6 with DirectAdmin

Packages to be pre installed.
yum install gcc make
yum install libxml2 libxml2-devel pcre-devel
if error lexpat (while make install) :
yum install expat expat-devel
Install mod_security
cd /usr/src
wget https://www.modsecurity.org/tarball/2.7.5/modsecurity-apache_2.7.5.tar.gz
tar zxvf modsecurity-apache_2.7.5.tar.gz
cd modsecurity-apache_2.7.5
./configure
make install
cp modsecurity.conf-recommended /etc/httpd/conf.d/modsecurity.conf

Downloading OWASP Mod_Security Core Rule Set :

cd /etc/httpd/
wget http://pkgs.fedoraproject.org/repo/pkgs/mod_security_crs/modsecurity-crs_2.2.5.tar.gz/aaeaa1124e8efc39eeb064fb47cfc0aa/modsecurity-crs_2.2.5.tar.gz
tar zxvf modsecurity-crs_2.2.5.tar.gz
mv modsecurity-crs_2.2.5 modsecurity-crs
cd modsecurity-crs
cp modsecurity_crs_10_setup.conf.example modsecurity_crs_10_config.conf
OR
git clone https://github.com/SpiderLabs/owasp-modsecurity-crs.git
mv owasp-modsecurity-crs modsecurity-crs
cd modsecurity-crs
cp modsecurity_crs_10_setup.conf.example modsecurity_crs_10_config.conf

Configuring Mod_Security

vi etc/httpd/conf/extra/httpd-includes.conf

and add this : 


LoadModule security2_module /usr/lib/apache/mod_security2.so
Include conf.d/modsecurity.conf
Include modsecurity-crs/modsecurity_crs_10_config.conf
Include modsecurity-crs/base_rules/*.conf

compile into apache with custombuild :

vi custom/ap2/configure.apache
add this :
"--with-mod_security2"


service httpd restart

Monday, November 11, 2013

Kernel compile with Grsec module in CentOS 6

Linux kernel is the life force of all Linux family of operating systems including Ubuntu, CentOS, and Fedora.
For most part, you don’t need to compile the kernel, as it is installed by default when you install the OS. Also, when there is a critical update done to the kernel, you can use yum, or apt-get to update the kernel on your Linux system.
However you might encounter certain situation, where you may have to compile kernel from source. The following are few situation where you may have to compile Kernel on your Linux system.
To enable experimental features that are not part of the default kernel.
To enable support for a new hardware that is not currently supported by the default kernel.
To debug the kernel
Or, just to learn how kernel works, you might want to explore the kernel source code, and compile it on your own.

(1) Download the kernel source
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.2.52.tar.bz2
tar xjf linux-3.2.52.tar.bz2
(2)Copy the config file from /boot
cp /boot/config-`uname -r` .config
(3) Download grsecurity patch
wget http://mirrors.muarf.org/grsecurity/stable/grsecurity-2.9.1-3.2.52-201311071633.patch.gz
gunzip grsecurity-2.9.1-3.2.52-201311071633.patch.gz
cd linux-3.2.52
(4) installed the patch
patch -p1
cd ../
mv linux-3.2.52 linux-3.2.52-grsec
cd linux-3.2.52-grsec
(5) Configured the new kernel with grsecurity 
make menuconfig
make bzImage && make modules
make modules_install && make install
(6) Verify the file /etc/grub.conf  for new kernel and boot proirity
(7) Disable selinux
cat /etc/selinux/config 
ip a
(7)Reboot the server two newly installed kernel
reboot
(8) Verify the kernel once the server is back online.
uname -r

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews