此篇將說明 Voicemail如何整合進資料庫,這個整合主要目的有兩項:
檢查需要的模組
root@pbx:/usr/src/asterisk $ asterisk -rx "module show like odbc" Module Description Use Count res_odbc.so ODBC resource 0 func_odbc.so ODBC lookups 0 cdr_odbc.so ODBC CDR Backend 0 res_config_odbc.so Realtime ODBC configuration 0 cdr_adaptive_odbc.so Adaptive ODBC CDR backend 0 5 modules loaded
如果缺少這些模組,必須重編安裝 Asterisk。
cd /usr/src cd asterisk ./configure make menuselect
Voicemail Build Options > [*] ODBC_STORAGE
Notes:
* 如果此項出現 XXXX,請確定 Linux 已經安裝 unixODBC-devel, libtool。
* 預設是 FILE_STORAGE,編譯時兩者只能選擇其一。
make clean make amportal stop make install amportal start
編輯 vm_general.inc(如果是 vanilla asterisk 改成 voicemail.conf)
format=wav49 odbcstorage=asterisk odbctable=voicemessages
安裝 ODBC driver for MySQL
root@pbx:/usr/src/asterisk $ rpm -q mysql-connector-odbc mysql-connector-odbc-3.51.26r1127-1.el5
編輯 /etc/odbcinst.ini
# Example driver definitinions # # # # Included in the unixODBC package #[PostgreSQL] #Description = ODBC for PostgreSQL #Driver = /usr/lib/libodbcpsql.so #Setup = /usr/lib/libodbcpsqlS.so #FileUsage = 1 # # # Driver from the MyODBC package # Setup from the unixODBC package [MySQL] Description = ODBC for MySQL Driver = /usr/lib/libmyodbc.so Setup = /usr/lib/libodbcmyS.so FileUsage = 1
重要:在 CentOS 5.5,找不到檔案 /usr/lib/libmyodbc.so,但有 /usr/lib/libmyodbc3.so,所以必須修改如下:
# Driver from the MyODBC package # Setup from the unixODBC package [MySQL] Description = ODBC for MySQL Driver = /usr/lib/libmyodbc3.so <----- 改這裡 Setup = /usr/lib/libodbcmyS.so FileUsage = 1
選擇:如果有需要連接到 MS-SQL,可以再加上
[ms-sql] Description = TDS connection Driver = /usr/lib/libtdsodbc.so Setup = /usr/lib/libtdsS.so UsageCount = 1 FileUsage = 1
編輯 /etc/odbc.ini
[asterisk-connector] Driver = MySQL Database = asterisk_vm_recording Server = localhost Socket = /var/lib/mysql/mysql.sock User = db_user Password = db_pass
Notes:
* Driver 必須與 odbcinst.ini 內容相同。
* Database 要儲存錄音檔的資料庫名稱
驗證設定
isql -v asterisk-connector +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL> show databases; +-----------------------------------------------------------------+ | Database | +-----------------------------------------------------------------+ | information_schema | | Hotel | | asterisk | | asterisk_vm_recording | | asteriskcdrdb | | mya2billing | | mysql | | test | | vtigercrm520 | | vtigercrm_evs | +-----------------------------------------------------------------+ SQLRowCount returns 10 10 rows fetched SQL> quit
編輯 /etc/asterisk/res_odbc.conf
[asterisk] enabled => yes dsn => asterisk-connector pre-connect => yes
驗證設定
# amportal stop # amportal start # asterisk -rx "odbc show" ODBC DSN Settings ----------------- Name: asterisk DSN: asterisk-connector Pooled: No Connected: Yes
編輯 /etc/asterisk/func_odbc.conf
建立資料庫 asterisk_vm_recording
mysql>create database asterisk_vm_recording; mysql>exit