Thứ Tư, 20 tháng 6, 2012

HOW-TO: Manually Installing Mediaproxy 2.5 on Ubuntu 12.04 server 64 bits


      Media-proxy is a media relay for RTP/RTCP and UDP streams that works in tandem with OpenSIPS to provide NAT traversal capability for media streams from SIP user agents located behind NAT. Mediaproxy supports ICE negotiation by behaving like a TURN relay candidate and the policy can be controlled from OpenSIPS configuration.
       Mediaproxy 2 is a Python project from AG-projects which is consisted of  (at least) two components: A dispatcher and a relay.
       For more details, please skim at http://mediaproxy.ag-projects.com/
       If you want to install Mediaproxy by a Debian repository, you can refer to http://mediaproxy.ag-projects.com/projects/mediaproxy/wiki/InstallationGuide.
       There are many installation guide found on Internet such as
       But none of it is perfect for my case, Ubuntu server 12.04 64 bits, I tried to search on Google for solution and had this hand-on experience. This article is aimed to provide good example for installing Mediaproxy in Ubuntu server 64 bits. Try to do it step by step,  do it smoothly you need some knowledge about basic GNU installation and python installation.

Install kernel support
#apt-get install iptables
#apt-get install gcc
#apt-get install g++

Development libraries and headers for some existing packages
#apt-get install libgpg-error-dev
#apt-get install python-dev

Install Linux libnetfilter_conntrack
Libnfnetlink
Suggestion version: libnfnetlink-1.0.0.tar.bz2
Unzip #tar xvjf libnfnetlink-1.0.0.tar.bz2
Change to the sub-directory created when you unzipped the tarball: #cd libnfnetlink-1.0.0/
#./configure
#make
#make install

libnfnetlink-dev
#apt-get install libnfnetlink-dev

libnetfilter_conntrack
Similarly, we do the same thing with previous one.
libnetfilter_conntrack-dev
#apt-get install libnetfilter-conntrack-dev


Install Python 3.2.3
Install the new release of Python from the URL.
#tar -xf Python-3.2.3.tgz
#./configure
#make

Install some Python packages
Ctypes
Suggested version: ctypes-1.0.2.tar.gz
#wget http://downloads.sourceforge.net/project/ctypes/ctypes/1.0.2/ctypes-1.0.2.tar.gz
Unzip: #tar -xvzf ctypes-1.0.2.tar.gz
Change to the sub-directory created when you unzipped the tarball:
#cd ctypes-1.0.2/
Build and install the library:
./setup.py build
./setup.py install

Python-application
Suggested version: python-application-1.3.1.tar.gz
#wget http://pypi.python.org/packages/source/p/python-application/python-application-1.3.1.tar.gz#md5=615d670fcda2aa5a01de7bc12baa1fdf
Unzip: #tar -xvzf python-application-1.3.1.tar.gz
Change to the sub-directory created when you unzipped the tarball:
#cd python-application-1.3.1/
Build and install the library:
./setup.py build
./setup.py install

Python-cjson
Suggested version: python-cjson-1.0.5.tar.gz
#wget http://pypi.python.org/packages/source/p/python-cjson/python-cjson-1.0.5.tar.gz#md5=4d55b66ecdf0300313af9d030d9644a3
Unzip: #tar -xvzf python-cjson-1.0.5.tar.gz
Change to the sub-directory created when you unzipped the tarball:
#cd python-cjson-1.0.5/
Build and install the library:
#./setup.py build
#./setup.py install


Python-gnutls
Suggested version: python-gnutls-1.2.4.tar.gz
#wget http://pypi.python.org/packages/source/p/python-gnutls/python-gnutls-1.2.4.tar.gz#md5=e3536c421291a791869d875a41dcb26a
Unzip: #tar -xvzf python-gnutls-1.2.4.tar.gz
Change to the sub-directory created when you unzipped the tarball:
#cd python-gnutls-1.2.4/
Build and install the library:
#./setup.py build
#./setup.py install
Install Python-Zope Interface
Similarly, we do install this package from this url:
#wget http://old.zope.org/Products/ZopeInterface/3.3.0/zope.interface-3.3.0.tar.gz



Install Twisted
#wget http://pypi.python.org/packages/source/T/Twisted/Twisted-12.1.0.tar.bz2#md5=f396f1d6f5321e869c2f89b2196a9eb5
Install both of them similarly with other installation.

Install libgcrypt, gmp and gnutls from source tarball
In order to escape some unnecessary when installing media-proxy, you should install libgcrypt from source, albeit you can do in apt-get.
Libgcrypt
Suggested version: libgcrypt-1.5.0.tar.bz2
Unzip: #tar -xvjf libgcrypt-1.5.0.tar.bz2
Change to the sub-directory created when you unzipped the tarball:
#cd libgcrypt-1.5.0/
Build and install the library:
./configure --libdir=/usr/local/lib
make
make install

Gmp
Before installing nettle, you must install GMP. If you accidently install nettle previously, please install gmp first and then reinstall nettle.
Suggested version: gmp-5.0.5.tar.bz2
#wget  ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.5.tar.bz2
And don’t forget .sig file for untar: #wget ftp://ftp.gmplib.org/pub/gmp-5.0.5/gmp-5.0.5.tar.bz2.sig
Unzip: #tar -xvjf gmp-5.0.5.tar.bz2
Change to the sub-directory created when you unzipped the tarball:
#cd gmp-5.0.5/
Build and install the library:
./configure
make
make install

Install nettle
Suggested version: nettle-2.4.tar.gz
#wget  http://www.lysator.liu.se/~nisse/archive/nettle-2.4.tar.gz
Unzip: #tar -xvzf nettle-2.4.tar.gz
Change to the sub-directory created when you unzipped the tarball:
#cd nettle-2.4/
Build and install the library:
./configure
make
make install

Install zlib

Install p11-kit


Then install gnutls
Suggested version: gnutls-3.0.9.tar.xz
#wget  ftp://ftp.gnu.org/gnu/gnutls/gnutls-3.0.9.tar.xz
And don’t forget .sig file for untar: #wget ftp://ftp.gnu.org/gnu/gnutls/gnutls-3.0.9.tar.xz.sig
Unzip: #tar -xvzf gnutls-3.0.9.tar.xz
Change to the sub-directory created when you unzipped the tarball:
#cd gnutls-3.0.9/
Build and install the library:
./configure --with-included-libtasn1 --libdir=/usr/local/lib
make
make install

Manually copy some run-time libraries to /usr/lib
Copy the following dynamic libraries from /usr/local/lib to /usr/lib
libgcrypt.so.11.7.0 (only if you installed from source)
libgnutls.so.27
libgnutls.so.27.0.1
libgnutls-openssl.so.27
libgnutls-openssl.so.27.0.1


For the RADIUS accounting module


Mediaproxy 2
Suggested version: mediaproxy-2.5.2.tar.gz
#wget http://download.ag-projects.com/MediaProxy/mediaproxy-2.5.2.tar.gz
Suggested location to copy and then unzip the tarball: /usr/local
Unzip: #tar -xzf mediaproxy-2.5.2.tar.gz
Change to the sub-directory created when you unzipped the tarball
Build and install the library (system wide):
./setup.py build
./setup.py install

Enable IP Forwarding by making changes in /etc/sysctl.conf file... 
Permanently enable ip forwarding,,,
# gedit /etc/sysctl.conf &
...

# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1

Then, try these commands
# echo 1 > /proc/sys/net/ipv4/ip_forward
# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

Make directory, copy necessary files to proper directories, and setup ownership:
#mkdir /var/run/mediaproxy
#cp config.ini.sample /etc/mediaproxy/config.ini
#cp tls/* /etc/mediaproxy/tls/
Config.ini
OpenSIPS+MediaProxy Integration:
# mkdir /var/run/mediaproxy
# gedit config.ini &

Make following changes in file...
Change IP address according to your server.

[Relay]
dispatchers = mydomain.net:5060 _sip._udp.mydomain.net
port_range = 50000:60000
log_level = DEBUG
on_hold_timeout = 1800

[Dispatcher]
listen = 10.1.10.205:50000
management_use_tls = no
log_level = DEBUG
accounting = radius

[Radius]
; This section needs to be configured if radius accounting is enabled
; OpenSIPS RADIUS configuration file. All RADIUS cofiguration parameters will
; be read from this file, including dictionary files.
;
;config_file = /etc/opensips/radius/client.conf
config_file = /etc/freeradius/clients.conf

; Additional dictionary file with MediaProxy specific attributes.
;additional_dictionary = radius/dictionary
additional_dictionary = /etc/freeradius/dictionary

[OpenSIPS]
socket_path = '/var/run/opensips/socket'


Now edit opensips.cfg file to include MediaProxy...
#
# ----- nat_traversal
#**
loadmodule "nat_traversal.so"
#**
modparam("nat_traversal", "keepalive_interval", 90)
modparam("nat_traversal", "keepalive_method", "OPTIONS")
modparam("nat_traversal", "keepalive_from", "sip:keepalive@mydomain.com")


#
# --> nathelper
#**
loadmodule "nathelper.so"
#**
modparam("nathelper", "natping_interval", 60)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "sipping_bflag", 7)
modparam("nathelper", "received_avp", "$avp(i:801)")
modparam("nathelper", "sipping_from", "sip:pinger@mydomain.com")

#
#**
loadmodule "mediaproxy.so"
#**
#--------------- Default Values
modparam("mediaproxy", "mediaproxy_socket", "/var/run/mediaproxy/dispatcher.sock")
modparam("mediaproxy", "mediaproxy_timeout", 500)
modparam("mediaproxy", "signaling_ip_avp", "$avp(s:nat_ip)")
modparam("mediaproxy", "media_relay_avp", "$avp(s:media_relay)")

#--------------- Main Routing Logic

#

Starting MediaProxy Dispatcher...
#./media-dispatcher --no-fork
#./media-dispatcher &

The most notorious error I have met: “Libnettle 2.4 was not found” although nettle was installed.
Solution: This is because I did not install GMP before install Nettle, so Nettle did not create libhogweed for gnutls installing progress.