Asterisk权威指南/第四章 初始化配置任务

维基教科书,自由的教学读本

在上一章中,我们介绍了如何安装Asterisk。但是你应该从哪里开始配置?答案就在本章。无论你使用星号完成什么,有一些常见的配置文件都会被用到。在一些情况下,它们可能不需要任何修改,但你需要了解它们。

asterisk.conf[编辑]

asterisk.conf配置文件允许你调整可能影响Asterisk整体运行的各种设置。 Asterisk源中包含一个示例asterisk.conf文件。这个在/ etc / asterisk文件夹中的文件对系统工作不是必要的,但你可能会发现里面可能有一些选项将对你有用。

Asterisk将在默认配置位置(通常是/ etc / asterisk)中查找asterisk.conf。要为asterisk.conf指定不同的位置,请使用-C命令行选项:

 $ sudo asterisk -C /custom/path/to/asterisk.conf

[directories]小节[编辑]

对于大多数安装的Asterisk来说是不需要更改目录的。但是,对于同时运行多个Asterisk实例或者希望将文件存储在非标准位置上这一小节非常有用。

默认目录位置和选项列在表4-1中,你可以使用并改变它们。有关这些目录使用的更多信息,请参阅第2章的文件结构部分。

Table 4-1. asterisk.conf [directories] section

 Option       Value/Example      Notes
 astetcdir    /etc/asterisk     The location where the Asterisk configuration files are stored.
 astmoddir /usr/lib/asterisk/modules   The location where loadable modules are stored.
 astvarlibdir /var/lib/asterisk  The base location for variable state information used by various parts of Asterisk. This includes items that are written out by Asterisk at runtime.
 astdbdir   /var/lib/asterisk   Asterisk will store its internal database in this directory as a file called astdb.
 astkeydir  /var/lib/asterisk   Asterisk will use a subdirectory called keys in this directory as the default location

for loading keys for encryption.

 astdatadir  /var/lib/asterisk  This is the base directory for system-provided data, such as the sound files that come with Asterisk.
 astagidir    /var/spool/asterisk  The Asterisk spool directory, where voicemail, call recordings, and the call orig- ination spool are stored.
 astrundir    /var/run/asterisk    The location where Asterisk will write out its UNIX control socket as well as its process ID (PID) file.
 astlogdir    /var/log/asterisk    The directory where Asterisk will store its log files.

[options] 小节[编辑]

asterisk.conf文件中的这一小节配置了全局运行选项的默认值。可用的选项如表4-2所示。 这些大多数也可以通过Asterisk应用程序的命令行参数来控制。有关与这些选项相关的命令行选项的完整列表,请参阅Asterisk命令手册:

 $ man asterisk

Table 4-2. asterisk.conf [options] section


[files] 小节[编辑]

asterisk.conf的这一小节包括了与Asterisk控制套接字有关的选项。它主要由远程控制台(asterisk-r)使用。可用的选项列在表4-3中。

Table 4-3. asterisk.conf [files] section

 Option     Value/Example    Notes
 astctlpermissions  0660      Sets the permissions for the Asterisk control socket.
 astctlowner        root       Sets the owner for the Asterisk control socket.
 astctlgroup        apache     Sets the group for the Asterisk control socket.
 astctl             asterisk.ctl  Sets the filename for the Asterisk control socket. The default is asterisk.ctl.

[compat]小节[编辑]

Asterisk开发团队认为,前进最好的方法是进行不能向后兼容的改变。本节包含一些选项(列于表4-4中),允许将某些模块的行为恢复到上一个版本。

Table 4-4. asterisk.conf [compat] section

 Option     Value/Example     Notes
 pbx_realtime   1.6    In versions earlier than Asterisk 1.6.x, the pbx_realtime module would automatically convert pipe characters into commas for arguments to Asterisk applications. This is no longer done by default. To enable this previous behavior, set this option to 1.4.
 res_agi        1.6    In versions earlier than Asterisk 1.6.x, the EXEC AGI command would automatically convert pipe characters into commas for arguments to Asterisk applications. This is no longer done by default. To enable this previous behavior, set this option to 1.4.
 app_set        1.6    Starting with the Asterisk 1.6.x releases, the Set() application only allows setting the value of a single variable. Previously, Set() would allow setting more than one variable by separating them with a &. This was done to allow any characters in the value of a variable, including the & character, which was previously used as a separator. MSet() is a new application that behaves like Set() used to. However, setting this option to 1.4 makes Set() behave like MSet().

modules.conf[编辑]

在Asterisk安装中并不严格要求此文件;然而,没有任何模块,Asterisk无法工作的,所以为了实际目的,在/etc/asterisk文件夹中需要modules.conf文件。如果你在modules.conf文件中简单地定义autoload = yes,Asterisk将搜索/usr/lib/asterisk/modules文件夹中的所有模块,并在启动时加载它们。

虽然大多数模块并没有使用太多资源方面,而且它们都加载很快,但我们只加载计划在系统中使用的那些模块会更明确。此外,不加载连接网络的模块会更安全。

在过去,我们认为明确加载每个需要的模块是处理这个问题的最好方式,但是我们后来发现这种做法创造了额外的工作。每次升级后,我们发现必须编辑modules.conf文件,以纠正版本之间的所有模块差异,整个过程最终会被不必要地复杂化。我们现在喜欢做的是允许Asterisk自动加载它找到的模块,但明确地告诉Asterisk不要使用noload指令加载我们不想加载的任何模块。可以在第56页的“modules.conf”中找到一个示例modules.conf文件。

使用menuselect来控制哪些模块被编译和安装

另一方面,你可以选择Asterisk加载的哪些模块不用进行简单的编译和安装。在Asterisk安装过程中,make menuselect命令为你提供了一个菜单界面,允许你为编译器指定许多不同的指令,包括要编译和安装的模块。如果你从来没有编译和安装一个模块,这个加载时的效果是它不会存在,因此不会被加载。如果你是新的Linux和Asterisk,如果你以后想要使用模块并发现它不存在于系统上,这可能会给你带来困惑。

有关menuselect的更多信息,请参见第59页的“make menuselect”。

[modules]小节[编辑]

modules.conf文件包含了一个单独的小节。该小节中可用的选项列在表4-5中。除去自动加载的,所有选项都可以被指定多次。

所有可加载模块的列表在第2章中提供,包括我们对每个模块的受欢迎程度/状态的观点。

Table 4-5. modules.conf [modules] section

 Option    Value/Example    Notes
 autoload   yes       Instead of explicitly listing which modules to load, you can use this directive to tell Asterisk to load all modules that it finds in the modules directory, with the exception of modules listed as not to be loaded using the noload directive. The default, and our recommendation, is to set this option to yes.
 preload   res_odbc.so  Indicates that a module should be loaded at the beginning of the module load order. This directive is much less relevant than it used to be; modules now have a load priority built into them that solves the problems that this directive was previously used to solve.
 load      chan_sip.so    Defines a module that should be loaded. This directive is only relevant if autoload is set to no.
 noload  chan_alsa.so   Defines a module that should not be loaded. This directive is only relevant if autoload is set to yes.
 require  chan_sip.so   Does the same thing as load; additionally, Asterisk will exit if this module fails to load for some reason.
 preload-require res_odbc.so  Does the same thing as preload; additionally, Asterisk will exit if this module fails to load for some reason.

indications.conf[编辑]

世界各地的人们对电话网络的声音的期待有所不同。不同的国家或地区对于诸如拨号,信号忙,回铃,拥塞等事件呈现不同的声音。

indicators.conf文件定义了电话系统可能会产生的各种声音的参数,并允许你自定义它们。 在Asterisk的早期,这个文件只包含有限数量的国家的声音,但现在是相当全面的。

要将你所在地区的通用音频分配给频道,你可以使用CHANNEL()功能简单地分配音区,该音区将在呼叫期间适用(除非更改)

 Set(CHANNEL(tonezone)=[yourcountry]) ; i.e., uk, de, etc.

然而,由于来自呼叫的信令可能来自各个地方(从运营商,从Asterisk,甚至是集合本身),你应该注意到,简单地拨号计划中设置音区不能保证这些音调将全部呈现。

为了娱乐或者盈利修改indications.conf

如果你很闲,你可以对indications.conf文件做各种各样的毫无意义但很有趣的事情。例如,“星球大战”的粉丝可以对他的indications.conf进行以下更改:

 [starwars](us)
 description = Star Wars Theme Song
 ring = 262/400,392/500,0/100,349/400,330/400,294/400,524/400,392/500,0/100,349/400, \
 330/400,294/400,524/400,392/500,0/100,349/400,330/400,349/400,294/500,0/2000

如果你在配置文件或拨号计划中使用名为“starwars”的国家/地区,你所传回的任何铃声将听起来与你惯用的标准铃声完全不同。 尝试如下的拨号计划代码测试你的新铃声:

 exten => 500,1,Answer()
    same => n,Set(CHANNEL(tonezone)=starwars)
   same => n,Dial(SIP/0000FFFF0002) ; or whatever your channel is named in sip.conf

视此示例中用于呼叫的设备类型而定,你可能会想知道它是否会实际工作。例如,SIP电话通常会自动生成铃声,而不是使用Asterisk生成铃声。此示例经过精心制作,以确保Asterisk会向呼叫者生成回铃音。关键是首先执行的Answer()。然后,当向另一个设备发出出站呼叫时,Asterisk将呼叫指示传回呼叫者的唯一方法是生成带内音频,因为就呼叫者的电话而言,该呼叫已经被回答。

虽然Asterisk可以在没有indications.conf文件的情况下运行,但强烈建议你包含一个:从/usr/src/asterisk-complete/1.8/configs/indication.conf.sample复制样本,在[general]部分修改国家/地区参数匹配你的区域,并重新启动Asterisk。

chan_dahdi忽略indications.conf

DAHDI不使用来自Asterisk的indication.conf文件,而是使用编译好的音调。更多详细信息,请参阅第7章。

如果你的系统支持多个国家/地区(例如,如果你拥有来自不同地区的用户的集中式Asterisk系统),则可能无法简单地定义默认国家/地区。在这种情况下,你有几个选项:

1.在用户的频道定义文件中定义国家/地区。
2.使用CHANNEL(tonezone)功能定义拨号方案中的国家。

musiconhold.conf[编辑]

如果您打算销售基于Asterisk的电话系统,如果您不知道您在做什么的话,您不要更改Asterisk附带的默认音乐,您将发送响亮而清楚的消息。*

等待音乐有一个问题,在过去,通常只需将收音机或CD播放机插入电话系统,法定的现实是,大多数音乐许可证并不允许您执行此操作。没错,如果你想要播放等待音乐,有人会在某个地方,通常希望你付出代价。

那怎么处理呢? 有两种合法的方式:1)从版权持有人付钱获得音乐持有许可证,2)找到由适用于Asterisk的许可证发行的音乐来源。

我们不在这里给你法律意见; 您应该要懂得您需要什么才能使用特定的音乐作为您的音乐来源。 然而,我们将会做的是向您展示如何使用您的音乐,并使其与Asterisk一起使用。

获得免费音乐

有几个网站提供已根据知识共享或其他许可证发布的音乐。最近,我们一直在享受开源在线音乐的音乐。 每首歌曲可能都有自己的许可要求,因为您可以免费下载歌曲并不意味着您有权将其用作等待音乐。请注意您计划用于等待音乐的音乐的许可条款。

将音乐转换为符合Asterisk的格式

现在MP3格式的音乐很常见。 虽然Asterisk可以使用MP3作为音乐源,但这不是理想的方法。MP3被压缩了,为了播放它们,CPU必须做一些工作来实时解压缩它们。当您只播放一首歌曲并希望在iPod上节省空间时,这是很好的,但是对于等待音乐,正确的做法是将MP3转换为在CPU上更适合的格式。

CentOS前提条件

由于CentOS没有安装sox的MP3功能,您必须先安装mpg123,然后才能转换MP3文件以在Asterisk上使用。首先,您将需要安装rpmforge存储库。要找出您需要的版本,请打开网页浏览器,然后访问http://dag.wieers.com/rpm/FAQ.php#B。选择要安装的版本/架构的文本并将其粘贴到您的shell中:

 $ rpm -Uhv http://apt.sw.be/redhat ...

您需要确保这个新的存储库被正确使用,因此请运行以下命令

 $ yum install yum-priorities

(如果您想了解更多有关yum优先级的信息,请访问本网站:http://wiki.centos.org/PackageManagement+/Yum/Priorities

一旦存储库被添加,您可以继续获取mpg123:

 $ yum install mpg123

一旦完成,您的CentOS系统就可以将MP3文件转换Asterisk中使用的格式。

如果您熟悉文件格式,并且有使用Audacity之类的音频工程软件的经验,您可以转换PC上的文件并将其上传到Asterisk。我们发现将源MP3文件上传到Asterisk服务器(比如,/ tmp文件夹),然后从命令行转换它们更为简单。

要将MP3文件转换为Asterisk理解的格式,您需要运行下面概述的命令(在本例中,我们使用的文件名为SilentCity.mp3)。

CentOS

首先,将MP3文件转换为WAV文件:

 $ mpg123 -w SilentCity.wav SilentCity.mp3

然后,将所得到的WAV文件缩小到Asterisk理解的采样率:

 $ sox SilentCity.wav -t raw -r 8000 -s -w -c 1 SilentCity.sln

Ubuntu

如果还没有(安装这两个软件包),请安装sox和libsox-fmt-all软件包:

#sudo apt-get install sox libsox-fmt-all

然后,将MP3文件直接转换为未压缩的SLN格式:

 $ sox SilentCity.mp3 -t raw -r 8000 -s -w -c 1 SilentCity.sln

n个较新版本的sox(例如,随Ubuntu 10.10一起提供的版本14.3.0),-w选项已更改为-2。

完成文件转换

生成的文件将存在于/tmp文件夹(或你上传的任何地方),需要复制到/var/lib/asterisk/ moh文件夹中:

$ cp * .sln / var / lib / asterisk / moh

您现在需要在Asterisk中重新加载musiconhold,以便识别您的新文件:

$ asterisk -rx "module unload res_musiconhold.so" 
$ asterisk -rx "module load res_musiconhold.so"

要测试您的音乐是否正常工作,请将以下内容添加到拨号计划中的[UserServices]上下文中:

 exten => 664,1,NoOp()
    same => n,Progress() same => n,MusicOnHold()

从你的一个组中拨打664应该随机从你的moh目录中播放一个文件。

总结[编辑]

本章帮助您完成了Asterisk的一些初始配置。您可以继续设置一些手机,并利用Asterisk提供的许多功能。