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一起使用。

獲得免費音樂

有幾個網站提供已根據創用CC或其他許可證發布的音樂。最近,我們一直在享受開源在線音樂的音樂。 每首歌曲可能都有自己的許可要求,因為您可以免費下載歌曲並不意味著您有權將其用作等待音樂。請注意您計劃用於等待音樂的音樂的許可條款。

將音樂轉換為符合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提供的許多功能。