Установка Asterisk From Source

One popular option for installing Asterisk is to download the source code and compile it yourself. While this isn't as easy as using package management or using an Asterisk-based Linux distribution, it does let you decide how Asterisk gets built, and which Asterisk modules are built.

Alexcr2

Asterisk

Downloads of Asterisk are available at http://downloads.asterisk.org/pub/telephony/asterisk/. The currently supported versions of Asterisk will each have a symbolic link to their related release on this server, named asterisk-{version}-current.tar.gz. All releases ever made for the Asterisk project are available at http://downloads.asterisk.org/pub/telephony/asterisk/releases/.

The currently supported versions of Asterisk are documented on the Asterisk Versions page. It is highly recommended that you install one of the currently supported versions, as these versions continue to receive bug and security fixes.

Review Asterisk's System Requirements in order to determine what needs to be installed for the version of Asterisk you are installing. While Asterisk will look for any missing system requirements during compilation, it's often best to install these prior to configuring and compiling Asterisk.

Asterisk does come with a script, install_prereq, to aid in this process. If you'd like to use this script, download Asterisk first, then see Checking Asterisk Requirements for instructions on using this script to install prerequisites for your version of Asterisk.

Downloading Asterisk

Browse to http://downloads.asterisk.org/pub/telephony/asterisk, select asterisk-11-current.tar.gz, and save the file on your file system.

You can also get the latest releases from the downloads page on asterisk.org.

Alternatively, you can use wget to retrieve the latest release:

[root@server:/usr/local/src]# wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz
--2014-04-15 15:36:45--  http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz
Resolving downloads.asterisk.org (downloads.asterisk.org)... 76.164.171.238
Connecting to downloads.asterisk.org (downloads.asterisk.org)|76.164.171.238|:80... connected.

HTTP request sent, awaiting response... 200 OK
Length: 34794750 (33M) [application/x-gzip]
Saving to: `asterisk-11-current.tar.gz'

100%[==============================================================================>] 34,794,750  6.82M/s   in 4.6s    

2014-04-15 15:36:49 (7.16 MB/s) - `asterisk-11-current.tar.gz' saved [34794750/34794750]

Other Projects

libpri

The libpri library allows Asterisk to communicate with ISDN connections.You'll only need this if you are going to use DAHDI with ISDN interface hardware (such as T1/E1/J1/BRI cards).

DAHDI

The DAHDI library allows Asterisk to communicate with analog and digital telephones and telephone lines, including connections to the Public Switched Telephone Network, or PSTN.

DAHDI stands for Digium Asterisk Hardware Device Interface, and is a set of drivers and utilities for a number of analog and digital telephony cards, such as those manufactured by Digium. The DAHDI drivers are independent of Asterisk, and can be used by other applications. DAHDI was previously called Zaptel, as it evolved from the Zapata Telephony Project.

The DAHDI code can be downloaded as individual pieces (dahdi-linux for the DAHDI drivers, and dahdi-tools for the DAHDI utilities. They can also be downloaded as a complete package called dahdi-linux-complete, which contains both the Linux drivers and the utilities.

You will only need to install DAHDI if you are going to utilize DAHDI compatible analog or digital telephony interface boards.

Download Locations

Project

Location

Asterisk

http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz

libpri

http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4-current.tar.gz

dahdi-linux

http://downloads.asterisk.org/pub/telephony/dahdi-linux/dahdi-linux-current.tar.gz

dahdi-tools

http://downloads.asterisk.org/pub/telephony/dahdi-tools/dahdi-tools-current.tar.gz

dahdi-complete

http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz

Untarring the Source

When you download the source for libpri, DAHDI, and Asterisk you'll typically end up with files with a .tar.gz or .tgz file extension. These files are affectionately known as tarballs. The name comes from the tar Unix utility, which stands for tape archive. A tarball is a collection of other files combined into a single file for easy copying, and then often compressed with a utility such as GZip.

To extract the source code from the tarballs, we'll use the tar command. The commands below assume that you've downloaded the tarballs for libpri, DAHDI, and Asterisk to the /usr/local/src directory on a Linux machine. (You'll probably need to be logged in as the root user to be able to write to that directory.) We're also going to assume that you'll replace the letters X, Y, and Z with the actual version numbers from the tarballs you downloaded. Also please note that the command prompt may be slightly different on your system than what we show here. Don't worry, the commands should work just the same.

First, we'll change to the directory where we downloaded the source code:

[root@server ~]# cd /usr/local/src

Next, let's extract the source code from each tarball using the tar command. The -zxvf parameters to the tar command tell it what we want to do with the file. The z option tells the system to unzip the file before continuing, the x option tells it to extract the files from the tarball, the v option tells it to be verbose (write out the name of every file as it's being extracted, and the f option tells the tar command that we're extracting the file from a tarball file, and not from a tape.

[root@server src]# tar -zxvf libpri-1.X.Y.tar.gz
[root@server src]# tar -zxvf dahdi-linux-complete-2.X.Y+2.X.Y.tar.gz
[root@server src]# tar -zxvf asterisk-11-current.tar.gz

You should now notice that a new sub-directory was created for each of the tarballs, each containing the extracted files from the corresponding tarball. We can now compile and install each of the components.

Building and Installing DAHDI

Let's install DAHDI!

On Linux, we will use the DAHDI-linux-complete tarball, which contains the DAHDI Linux drivers, DAHDI tools, and board firmware files. Again, we're assuming that you've untarred the tarball in the /usr/local/src directory, and that you'll replace X and Y with the appropriate version numbers.

See What to Download? for more information on downloading the DAHDI tarballs.

Starting with DAHDI-Linux-complete version 2.8.0+2.8.0, all files necessary to install DAHDI are available in the complete tarball. Therefore, all you need to do to install DAHDI is:

[root@server src]# cd dahdi-linux-complete-2.X.Y+2.X.Y
[root@server dahdi-linux-complete-2.X.Y+2.X.Y]# make
[root@server dahdi-linux-complete-2.X.Y+2.X.Y]# make install
[root@server dahdi-linux-complete-2.X.Y+2.X.Y]# make config 

Building and Installing LibPRI

As in the other build and install sections, we'll assume that you'll replace the letters X, Y, and Z with the actual version numbers from the tarballs you downloaded.

[root@server src]# cd libpri-1.X.Y

This command changes directories to the libpri source directory.

[root@server libpri-1.X.Y]# make

This command compiles the libpri source code into a system library.

[root@server libpri-1.X.Y]# make install

This command installs the libpri library into the proper system library directory

Checking Asterisk Requirements

Configuring Asterisk

Now it's time to compile and install Asterisk. Let's change to the directory which contains the Asterisk source code.

[root@server]# cd /usr/local/src/asterisk-11.X.Y

Next, we'll run a command called ./configure, which will perform a number of checks on the operating system, and get the Asterisk code ready to compile on this particular server.

[root@server asterisk-11.X.Y]# ./configure

This will run for a couple of minutes, and warn you of any missing system libraries or other dependencies. Unless you've installed all of the System Requirements for your version of Asterisk, the configure script is likely to fail. If that happens, resolve the missing dependency manually, or use the install_prereq script to resolve all of the dependencies on your system.

Once a dependency is resolved, run configure again to make sure the missing dependency is fixed.

If you have many missing dependencies, you may find yourself running configure a lot. If that is the case, you'll do yourself a favour by checking the System Requirements or installing all dependencies via the install_prereq script.

Upon successful completion of ./configure, you should see a message that looks similar to the one shown below. (Obviously, your host CPU type may be different than the below.)

configure: Package configured for: 
configure: OS type  : linux-gnu
configure: Host CPU : x86_64
configure: build-cpu:vendor:os: x86_64 : unknown : linux-gnu :
configure: host-cpu:vendor:os: x86_64 : unknown : linux-gnu :

Cached Data

The ./configure command caches certain data to speed things up if it's invoked multiple times. To clear all the cached data, you can use the following command to completely clear out any cached data from the Asterisk build system.

[root@server asterisk-11.X.Y]# make distclean

You can then re-run ./configure.

Using install_prereq

The install_prereq script is included with every release of Asterisk in the contrib/scripts subdirectory. The script has the following options:

  • test - print only the libraries to be installed.
  • install - install package dependencies only. Depending on your distribution of Linux, version of Asterisk, and capabilities you wish to use, this may be sufficient.
  • install-unpacakged - install dependencies that don't have packages but only have tarballs. You may need these dependencies for certain capabilities in Asterisk.

 

[root@server asterisk-11.X.Y]# cd contrib/scripts
[root@server asterisk-11.X.Y/contrib/scripts]# ./install_prereq install
[root@server asterisk-11.X.Y/contrib/scripts]# ./install_prereq install-unpackaged

Using Menuselect to Select Asterisk Options

Using Menuselect

The next step in the build process is to tell Asterisk which modules to compile and install, as well as set various compiler options. These settings are all controlled via a menu-driven system called Menuselect. To access the Menuselect system, type:

[root@server asterisk-11.X.Y]# make menuselect

The Menuselect menu should look like the screen-shot below. On the left-hand side, you have a list of categories, such as Applications, Channel Drivers, and PBX Modules. On the right-hand side, you'll see a list of modules that correspond with the select category. At the bottom of the screen you'll see two buttons. You can use the Tab key to cycle between the various sections, and press the Enter key to select or unselect a particular module. If you see [*] next to a module name, it signifies that the module has been selected. If you see *XXX next to a module name, it signifies that the select module cannot be built, as one of its dependencies is missing. In that case, you can look at the bottom of the screen for the line labeled Depends upon: for a description of the missing dependency.

When you're first learning your way around Asterisk on a test system, you'll probably want to stick with the default settings in Menuselect. If you're building a production system, however, you may not wish to build all of the various modules, and instead only build the modules that your system is using.

 

When you are finished selecting the modules and options you'd like in Menuselect, press F12 to save and exit, or highlight the Save and Exit button and press enter.

Module Support Levels

Menuselect will also show the support level for a selected module or build option. The support level will always be one of coreextended, or deprecated. For more information on these support levels, see Asterisk Module Support States.

Menuselect Categories


Add-ons    Modules that link with libraries that have licensing restrictions beyond what is allowed via the GPLv2 and Asterisk's dual licensing model. See README-addons.txt, delivered with Asterisk, for more information.
Applications   Modules that provide call functionality to the system. An application might answer a call, play a sound prompt, hang up a call, and so forth.
Bridging Modules   Modules that provide various bridge mixing technologies and other bridge related functionality.
Call Detail Recording   Modules that provide Call Detail Record (CDR) drivers for various permanent storage backends.
Channel Event Logging   Modules that provide Channel Event Logging (CEL) drivers for various permanent storage backends.
Channel Drivers   Modules that provide communications with devices outside of Asterisk, and translate that particular signalling or protocol to the core.
Codec Translators   Modules that provide encoding/decoding for audio or video. Typically codecs are used to encode media so that it takes less bandwidth.
Format Interpreters    Modules used to save media to disk in a particular file format, and to convert those files back to media streams on the network.
Dialplan Functions    Modules that are used to retrieve or set various settings on a call. A function might be used to set the Caller ID on an outbound call, for example.
PBX Modules    Modules that implement dialplan functionality or enhancements.
Resource Modules    Modules that provide additional resources to Asterisk. This can includes music on hold, calendar integration, database integration, various protocol stacks, etc.
Test Modules    Unit test modules. These are typically only available when Asterisk has:

  • Been configured with the --enable-dev-mode setting
  • The TEST_FRAMEWORK compilation option has been selected in Compiler Flags - Development

Compiler Flags - Development   Various compilation flags that alter Asterisk's behaviour. These flags are often useful in debugging Asterisk, or obtaining information for Asterisk developers.
Voicemail Build Options    Compilation flags that enable different Voicemail (via app_voicemail) storage backends.
Utilities    Various utilities for Asterisk. These include Asterisk Database upgrade utilities, Asterisk monitoring utilities, and other potentially useful tools.
AGI Samples    Sample AGI applications.
Module Embedding    Compilation flags to enable embedding of Asterisk dynamic modules into the Asterisk binary.
Core Sound Packages    Core sounds used by Asterisk. Different sound formats can be selected in this menu; when Asterisk is installed, these sounds will be downloaded and installed.
Music On Hold File Packages    Sample Music on Hold media used by Asterisk. Different formats can be selected in this menu; when Asterisk is installed, the various media samples will be downloaded and installed.
Extras Sound Packages    Extra sounds that can be used by Asterisk integrators. Different sound formats can be selected in this menu; when Asterisk is installed, these sounds will be downloaded and installed.

Controlling Menuselect

Options in Menuselect can be controlled from the command line. Menuselect can be built without invoking the user interface via the menuselect.makeopts target:

[root@server asterisk-11.X.Y]# make menuselect.makeopts

Available options can be viewed using the --help command line parameter:

[root@server asterisk-11.X.Y]# menuselect/menuselect --help

Some of the more common options are shown below.

Listing Options

To list all options in Menuselect, use the --list-options command line parameter:

[root@server asterisk-11.X.Y]# menuselect/menuselect --list-options

To list only the categories, use the --category-list command line parameter:

[root@server asterisk-11.X.Y]# menuselect/menuselect --category-list
MENUSELECT_ADDONS
MENUSELECT_APPS
MENUSELECT_BRIDGES
MENUSELECT_CDR
MENUSELECT_CEL
MENUSELECT_CHANNELS
MENUSELECT_CODECS
MENUSELECT_FORMATS
MENUSELECT_FUNCS
MENUSELECT_PBX
MENUSELECT_RES
MENUSELECT_TESTS
MENUSELECT_CFLAGS
MENUSELECT_OPTS_app_voicemail
MENUSELECT_UTILS
MENUSELECT_AGIS
MENUSELECT_EMBED
MENUSELECT_CORE_SOUNDS
MENUSELECT_MOH
MENUSELECT_EXTRA_SOUNDS

To list the options in a category, use the --list-category command line parameter:

[root@server asterisk-11.X.Y]# menuselect/menuselect --list-category MENUSELECT_OPTS_app_voicemail
+ FILE_STORAGE
- ODBC_STORAGE
- IMAP_STORAGE

Enabling an Option

To enable an option in Menuselect, use the --enable command line parameter:

[root@server asterisk-11.X.Y]# menuselect/menuselect --enable IMAP_STORAGE menuselect.makeopts

Chaining Options

 Multiple options can be chained together:

[root@server asterisk-11.X.Y]# menuselect/menuselect --enable app_voicemail --enable IMAP_STORAGE menuselect.makeopts

Disabling an Option

To disable an option in Menuselect, use the --disable command line parameter:

[root@server asterisk-11.X.Y]# menuselect/menuselect --disable app_voicemail menuselect.makeopts

Enabling a Category

An entire category can be enabled in Menuselect using the --enable-category command line parameter:

[root@server asterisk-11.X.Y]# menuselect/menuselect --enable-category MENUSELECT_ADDONS menuselect.makeopts

Build and Install Instructions

Now we can compile and install Asterisk. To compile Asterisk, simply type make at the Linux command line.

[root@server asterisk-11.X.Y]# make

The compiling step will take several minutes, and you'll see the various file names scroll by as they are being compiled. Once Asterisk has finished compiling, you'll see a message that looks like:

+--------- Asterisk Build Complete ---------+
+ Asterisk has successfully been built, and +
+ can be installed by running:              +
+                                           +
+                make install               +
+-------------------------------------------+
+--------- Asterisk Build Complete ---------+

As the message above suggests, our next step is to install the compiled Asterisk program and modules. To do this, use the make install command.

[root@server asterisk-11.X.Y]# make install

When finished, Asterisk will display the following warning:

+---- Asterisk Installation Complete -------+
+                                           +
+    YOU MUST READ THE SECURITY DOCUMENT    +
+                                           +
+ Asterisk has successfully been installed. +
+ If you would like to install the sample   +
+ configuration files (overwriting any      +
+ existing config files), run:              +
+                                           +
+                make samples               +
+                                           +
+-------------------------------------------+
+---- Asterisk Installation Complete -------+

Security Precautions

As the message above suggests, we very strongly recommend that you read the security documentation before continuing with your Asterisk installation. Failure to read and follow the security documentation can leave your system vulnerable to a number of security issues, including toll fraud.

Advanced Build and Install Options

Customizing the Build/Installation

In some environments, it may be necessary or useful to modify parts of the build or installation process. Some common scenarios are listed here

Passing compilation and linkage flags to gcc

Specific flags can be passed to gcc when Asterisk is configured, using the CFLAGS and LDFLAGS environment variables:

[root@server asterisk-11.X.Y]# ./configure CFLAGS=-pg LDFLAGS=-pg

Debugging compilation

To see all of the flags passed to gcc, build using the NOISY_BUILD setting set to YES:

[root@server asterisk-11.X.Y]# make NOISY_BUILD=yes

Building for non-native architectures

Generally, Asterisk attempts to optimize itself for the machine on which it is built on. On some virtual machines with virtual CPU architectures, the defaults chosen by Asterisk's compilation options will cause Asterisk to build but fail to run. To disable native architecture support, disable the BUILD_NATIVE option in menuselect:

[root@server asterisk-11.X.Y]# menuselect/menuselect --disable BUILD_NATIVE menuselect.makeopts
[root@server asterisk-11.X.Y]# make

Installing to a custom directory

While there are multiple ways to sandbox an instance of Asterisk, the preferred mechanism is to use the --prefix option with the configure script:

[root@server asterisk-11.X.Y]# ./configure --prefix=/usr/local/my_special_folder

Note that the default value for prefix is /usr/local.

Other Make Targets

all    Compiles everything everything selected through the configure and menuselect scripts.
full   This is equivalent to make or make all, save that it will perform a more thorough investigation of the source code for documentation. This is needed to generate AMI event documentation. Note that your system must have Python in order for this make target to succeed. This build target is only available in Asterisk 11 and later versions.
install    Installs Asterisk, building Asterisk if it has not already been built. In general, this should be executed after Asterisk has successfully compiled.
uninstall    Removes Asterisk binaries, sounds, man pages, headers, modules and firmware builds from the system.
uninstall-all    Same as the uninstall target, but additionally removes configuration, spool directories and logs. All traces of Asterisk. As just noted, this will remove all Asterisk configuration from your system. Do not execute uninstall-all unless you are sure that is what you want to do.
clean    Remove all files generated by make.
dist-clean    Remove pretty much all files generated by make and configure.
samples    Install all sample configuration files (.conf files) to /etc/asterisk/. Overwrites existing config files.
config    Install init scripts (startup scripts) on your system.
progdocs    Uses doxygen to locally generate HTML development documentation from the source code.  Generated in the doc/ subdirectory of the source; see doc/index.html.

Installing Sample Files

Asterisk Sample Configs: not a sample PBX configuration

For many of the sample configuration files that make samples installs, the configuration contains more than just an example configuration. The sample configuration files historically were used predominately for documentation of available options. As such, they contain many examples of configuring Asterisk that may not be ideal for standard deployments.

While installing the sample configuration files may be a good starting point for some people, they should not be viewed as recommended configuration for an Asterisk system.

To install a set of sample configuration files for Asterisk, type:

[root@server asterisk-11.X.Y]# make samples

Any existing sample files which have been modified will be given a .old file extension. For example, if you had an existing file named extensions.conf, it would be renamed to extensions.conf.old and the sample dialplan would be installed as extensions.conf.

Installing Initialization Scripts

Now that you have Asterisk compiled and installed, the last step is to install the initialization script, or initscript. This script starts Asterisk when your server starts, will monitor the Asterisk process in case anything bad happens to it, and can be used to stop or restart Asterisk as well. To install the initscript, use the make config command.

[root@server asterisk-11.X.Y]# make config

As your Asterisk system runs, it will generate logfiles. It is recommended to install the logrotation script in order to compress and rotate those files, to save disk space and to make searching them or cataloguing them easier. To do this, use the make install-logrotate command.

[root@server asterisk-11.X.Y]# make install-logrotate

Validating Your Installation

Before continuing on, let's check a few things to make sure your system is in good working order. First, let's make sure the DAHDI drivers are loaded. You can use the lsmod under Linux to list all of the loaded kernel modules, and the grep command to filter the input and only show the modules that have dahdi in their name.

[root@server asterisk-11.X.Y]# lsmod | grep dahdi

If the command returns nothing, then DAHDI has not been started. Start DAHDI by running:

[root@server asterisk-11.X.Y]# /etc/init.d/dadhi start

Different Methods for Starting Initscripts

Many Linux distributions have different methods for starting initscripts. On most Red Hat based distributions (such as Red Hat Enterprise Linux, Fedora, and CentOS) you can run:

[root@server asterisk-11.X.Y]# service dahdi start

Distributions based on Debian (such as Ubuntu) have a similar command, though it's not commonly used:

[root@server asterisk-11.X.Y]# invoke-rc.d dahdi start

If you have DAHDI running, the output of lsmod | grep dahdi should look something like the output below. (The exact details may be different, depending on which DAHDI modules have been built, and so forth.)

[root@server asterisk-11.X.Y]# lsmod | grep dahdi
dahdi_transcode  7928 1 wctc4xxp
dahdi_voicebus  40464 2 wctdm24xxp,wcte12xp
dahdi          196544 12 wctdm24xxp,wcte11xp,wct1xxp,wcte12xp,wct4xxp
crc_ccitt        2096 1 dahdi

Now that DAHDI is running, you can run dahdi_hardware to list any DAHDI-compatible devices in your system. You can also run the dahdi_tool utility to show the various DAHDI-compatible devices, and their current state.

To check if Asterisk is running, you can use the Asterisk initscript.

[root@server asterisk-11.X.Y]# /etc/init.d/asterisk status

asterisk is stopped

To start Asterisk, we'll use the initscript again, this time giving it the start action:

[root@server asterisk-11.X.Y]# /etc/init.d/asterisk start

Starting asterisk:

When Asterisk starts, it runs as a background service (or daemon), so you typically won't see any response on the command line. We can check the status of Asterisk and see that it's running using the command below. (The process identifier, or pid, will obviously be different on your system.)

[root@server asterisk-11.X.Y]# /etc/init.d/asterisk status

asterisk (pid 32117) is running...

And there you have it! You've compiled and installed Asterisk, DAHDI, and libpri from source code.