Blogs on System Administration, Scripting, System Monitoring, Cloud Computing & Virtualizaton, VoIP Systems, SMS Systems and Web Applications Development.

How to install FreeSWITCH in Centos 7?


Introduction

This article is to give an overview to install FreeSWITCH with its default settings.
$ sudo yum update
$ sudo yum groupinstall "Development tools" -y
$ sudo yum install git autoconf automake libtool gcc-c++ libuuid-devel zlib-devel libjpeg-devel ncurses-devel openssl-devel sqlite-devel.x86_64 curl-devel pcre-devel speex-devel ldns ldns-devel libedit-devel gtk+-devel gtk2-devel ntpdate yasm-devel.x86_64 lua-devel opus-devel libshout-devel  libsndfile-devel

Following is the step by step guide for installing FreeSWITCH.

Step # 1

Download and extract FreeSWITCH source:
$ cd /usr/local/src/
$ sudo git clone https://freeswitch.org/stash/scm/fs/freeswitch.git

Step # 2

Compile & Install FreeSWITCH with libyuv:
$ cd /usr/local/src/freeswitch
$ cd libs
$ sudo git clone https://freeswitch.org/stash/scm/sd/libyuv.git
$ cd libyuv
$ sudo make -f linux.mk CXXFLAGS="-fPIC -O2 -fomit-frame-pointer -Iinclude/"
$ sudo make install
$ sudo cp /usr/lib/pkgconfig/libyuv.pc /usr/lib64/pkgconfig/
$ cd ../../
$ sudo ./bootstrap.sh
# If you want to change installation directory the use following command:
$ sudo ./configure --prefix=<desired location path>
# If you are facing issues of libyuv then you can use following command:
$ sudo ./configure
$ sudo make cd-sounds-install cd-moh-install
$ sudo make
$ sudo make install
If you encounter below error while compiling Freeswitch:
making all mod_opus
make[4]: Entering directory '/usr/local/src/freeswitch/src/mod/codecs/mod_opus'
Makefile:884: *** You must install libopus-dev to build mod_opus.  Stop.
make[4]: Leaving directory '/usr/local/src/freeswitch/src/mod/codecs/mod_opus'
Makefile:645: recipe for target 'mod_opus-all' failed
make[3]: *** [mod_opus-all] Error 1
make[3]: Leaving directory '/usr/local/src/freeswitch/src/mod'
Makefile:555: recipe for target 'all-recursive' failed
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory '/usr/local/src/freeswitch/src'
Makefile:2948: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/usr/local/src/freeswitch'
Makefile:1346: recipe for target 'all' failed
make: *** [all] Error 2
You need to comment following lines in source and then recompile again:
vi freeswitch/src/mod/codecs/mod_opus/Makefile
# Comment line 889 & 890
#install: error
#all: error

-------------------------- FreeSWITCH configuration --------------------------
  Locations:
      prefix:          /usr/local/freeswitch
      exec_prefix:     /usr/local/freeswitch
      bindir:          ${exec_prefix}/bin
      confdir:         /usr/local/freeswitch/conf
      libdir:          ${exec_prefix}/lib
      datadir:         /usr/local/freeswitch
      localstatedir:   /usr/local/freeswitch
      includedir:      /usr/local/freeswitch/include/freeswitch
      certsdir:        /usr/local/freeswitch/certs
      dbdir:           /usr/local/freeswitch/db
      grammardir:      /usr/local/freeswitch/grammar
      htdocsdir:       /usr/local/freeswitch/htdocs
      fontsdir:        /usr/local/freeswitch/fonts
      logfiledir:      /usr/local/freeswitch/log
      modulesdir:      /usr/local/freeswitch/mod
      pkgconfigdir:    ${exec_prefix}/lib/pkgconfig
      recordingsdir:   /usr/local/freeswitch/recordings
      imagesdir:       /usr/local/freeswitch/images
      runtimedir:      /usr/local/freeswitch/run
      scriptdir:       /usr/local/freeswitch/scripts
      soundsdir:       /usr/local/freeswitch/sounds
      storagedir:      /usr/local/freeswitch/storage
      cachedir:        /usr/local/freeswitch/cache
------------------------------------------------------------------------------

Step # 3

Create freeswitch user for running freeswitch:
# create user 'freeswitch'
# add it to group 'daemon'
# change owner and group of the freeswitch installation
$ cd /usr/local
$ sudo useradd --system --home-dir /usr/local/freeswitch -G daemon freeswitch
$ sudo passwd -l freeswitch
  
$ sudo chown -R freeswitch:daemon /usr/local/freeswitch/
$ sudo chmod -R 770 /usr/local/freeswitch/
$ sudo chmod -R 750 /usr/local/freeswitch/bin/*
  
$ sudo mkdir /var/run/freeswitch
$ sudo chown -R freeswitch:daemon  /var/run/freeswitch
  
$ sudo ln -s /usr/local/freeswitch/bin/freeswitch /usr/bin/ # needed by /etc/init.d/freeswitch

Step # 4

Edit codecs priority and SIP Port for running Freeswitch as desired:
$ sudo vi /usr/local/freeswitch/conf/vars.xml
....
#Adding VP8 Video Codec
<X-PRE-PROCESS cmd="set" data="global_codec_prefs=OPUS,G722,PCMU,PCMA,GSM,VP8"/>
<X-PRE-PROCESS cmd="set" data="outbound_codec_prefs=PCMU,PCMA,GSM,VP8"/> 
.....
#Change SIP Port
<X-PRE-PROCESS cmd="set" data="internal_sip_port=6000"/>

Step # 5

Create symbolic links for FreeSWITCH executables:
$ sudo ln -s /usr/local/freeswitch/bin/freeswitch /usr/local/bin/freeswitch
$ sudo ln -s /usr/local/freeswitch/bin/fs_cli /usr/local/bin/fs_cli

Step # 6

Create FreeSWITCH init script:
$ sudo touch /etc/init.d/freeswitch
$ sudo chmod a+x /etc/init.d/freeswitch
$ sudo vi /etc/init.d/freeswitch
Add following code in init script of FreeSWITCH:
#! /bin/sh
#
# freeswitch:       Starts the freeswitch Daemon
#
# chkconfig: 345 96 02
# processname: freeswitch
# description: Freeswitch centos init script \
# config:
# Author: gled
# Source function library.
. /etc/init.d/functions
. /etc/sysconfig/network
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/freeswitch/bin
DESC="FreeSwitch Voice Switching System"
NAME=freeswitch
DAEMON=/usr/local/freeswitch/bin/$NAME
PIDFILE=/usr/local/freeswitch/log/$NAME.pid
do_setlimits() {
        ulimit -c unlimited
        ulimit -d unlimited
        ulimit -f unlimited
        ulimit -i unlimited
        ulimit -n 999999
        ulimit -q unlimited
        ulimit -u unlimited
        ulimit -v unlimited
        ulimit -x unlimited
        ulimit -s 244
        ulimit -l unlimited
        return 0
}
base=${0##*/}
do_start() {
        do_setlimits
        $DAEMON -nc
        RETVAL=$?
        if [ $RETVAL = 0 ]; then
                success $"$base startup"
        else
                failure $"$base startup"
        fi
        echo
        return $RETVAL
}
do_stop() {
        $DAEMON -stop
        RETVAL=$?
        [ $RETVAL = 0 ] && success $"$base shutdown" || failure $"$base shutdown"
        rm -f $LOCKFILE
        echo
        return $RETVAL
}
# See how we were called.
case "$1" in
  start)
        do_start
        ;;
  stop)
        do_stop
        ;;
  restart)
        do_stop
        echo "Waiting for daemon to exit..."
        sleep 5
        do_start
        ;;
  *)
        echo $"Usage: $0 {start|stop}"
        exit 2
        ;;
esac
exit $RETVAL

Step # 7

Starting FreeSWITCH:
$ sudo service freeswitch start
12759 Backgrounding.                                             [  OK  ]

Entering into the FreeSWITCH cli mode:
$ cd ~
$ fs_cli
.=======================================================.                                                       
|            _____ ____     ____ _     ___              |                                                    
|           |  ___/ ___|   / ___| |   |_ _|             |                              
|           | |_  \___ \  | |   | |    | |              |                              
|           |  _|  ___) | | |___| |___ | |              |                              
|           |_|   |____/   \____|_____|___|             |                              
|                                                       |                              
.=======================================================.                              
| Anthony Minessale II, Ken Rice,                       |                              
| Michael Jerris, Travis Cross                          |                              
| FreeSWITCH (http://www.freeswitch.org)                |                              
| Paypal Donations Appreciated: paypal@freeswitch.org   |                              
| Brought to you by ClueCon http://www.cluecon.com/     |                              
.=======================================================.                              
                                
.=======================================================================================================.                                       
|    ____ _             ____                   |                                       
|   / ___| |_   _  ___ / ___|___  _ __         |                                       
|  | |   | | | | |/ _ \ |   / _ \| '_ \        |                                       
|  | |___| | |_| |  __/ |__| (_) | | | |       |                                       
|   \____|_|\__,_|\___|\____\___/|_| |_|       |                                       
|                                              |                                       
|   _____    _            _                          ____             __                                |                                       
|  |_   _|__| | ___ _ __ | |__   ___  _ __  _   _   / ___|___  _ __  / _| ___ _ __ ___ _ __   ___ ___   |                                       
|    | |/ _ \ |/ _ \ '_ \| '_ \ / _ \| '_ \| | | | | |   / _ \| '_ \| |_ / _ \ '__/ _ \ '_ \ / __/ _ \  |                                       
|    | |  __/ |  __/ |_) | | | | (_) | | | | |_| | | |__| (_) | | | |  _|  __/ | |  __/ | | | (_|  __/  |                                       
|    |_|\___|_|\___| .__/|_| |_|\___/|_| |_|\__, |  \____\___/|_| |_|_|  \___|_|  \___|_| |_|\___\___|  |                                       
|                  |_|                      |___/                                                       |                                       
|   _____                           _                         _                                         |                                       
|  | ____|_   _____ _ __ _   _     / \  _   _  __ _ _   _ ___| |_                                       |                                       
|  |  _| \ \ / / _ \ '__| | | |   / _ \| | | |/ _` | | | / __| __|                                      |                                       
|  | |___ \ V /  __/ |  | |_| |  / ___ \ |_| | (_| | |_| \__ \ |_                                       |                                       
|  |_____| \_/ \___|_|   \__, | /_/   \_\__,_|\__, |\__,_|___/\__|                                      |                                       
|                        |___/                |___/                                                     |                                       
|                                       ____ _             ____                                         |                                       
|  __      ____      ____      __      / ___| |_   _  ___ / ___|___  _ __         ___ ___  _ __ ___     |                                       
|  \ \ /\ / /\ \ /\ / /\ \ /\ / /     | |   | | | | |/ _ \ |   / _ \| '_ \       / __/ _ \| '_ ` _ \    |                                       
|   \ V  V /  \ V  V /  \ V  V /   _  | |___| | |_| |  __/ |__| (_) | | | |  _  | (_| (_) | | | | | |   |                                       
|    \_/\_/    \_/\_/    \_/\_/   (_)  \____|_|\__,_|\___|\____\___/|_| |_| (_)  \___\___/|_| |_| |_|   |                                       
|                                              |                                       
.=======================================================================================================.                                       
                                
Type /help <enter> to see a list of commands                                           
                                
+OK log level  [7]            
freeswitch@internal> exit     
-ERR exit Command not found!  
                                
freeswitch@internal>

Step # 7

Now you can test extension to extension calling by registering any of the default users 1000-19 with password 1234.



1 comment:

Please Enter your Comments Here.