环境:CentOS7
FS版本:V1.8.5
安装unixODBC
yum install -y unixODBC unixODBC-devel mysql-connector-odbc
配置数据源
数据源
编辑/etc/odbc.ini
[freeswitch]
Driver = MySQL
SERVER = localhost
PORT = 3306
DATABASE = freeswitch
OPTION = 67108864
USER = root
PASSWORD = password
数据库驱动
编辑/etc/odbcinst.ini
# Driver from the mysql-connector-odbc package
# Setup from the unixODBC package
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc5.so
Setup = /usr/lib/libodbcmyS.so
Driver64 = /usr/lib64/libmyodbc5.so
Setup64 = /usr/lib64/libodbcmyS.so
FileUsage = 1
测试数据源
isql -v freeswitch
内核数据库用远程mysql替代本地的sqlite
编译时,configure加参数enable-core-odbc-support
./configure --enable-core-odbc-support
安装后,修改sip_profiles 配置:
以sip_profiles/internal.xml 为例:
找到这一行,把参数设置为自己的实例
<param name="odbc-dsn" value="dsn:user:pass"/>
在远程数据库上建立对应的数据库和表,操作这里就不描述了。
使用ODBC写CDR
编译mod_odbc_cdr
编译时,缺省不编译mod_odbc_cdr
打开modules.conf
找到event_handlers/mod_odbc_cdr一行,把注释去掉,然后重新编译安装
配置mod_odbc_cdr
编辑autoload_configs/modules.conf.xm,添加一行,内容如下:
<load module="mod_odbc_cdr"/>
在autoload_configs/添加一个配置文件,名为odbc_cdr.conf.xml,内容模板:
<configuration name="odbc_cdr.conf" description="ODBC CDR Configuration">
<settings>
<!-- <param name="odbc-dsn" value="database:username:password"/> -->
<param name="odbc-dsn" value="pgsql://hostaddr=192.168.0.100 dbname=freeswitch user=freeswitch password='freeswitch' options='-c client_min_messages=NOTICE'"/>
<!-- global value can be "a-leg", "b-leg", "both" (default is "both") -->
<param name="log-leg" value="both"/>
<!-- value can be "always", "never", "on-db-fail" -->
<param name="write-csv" value="on-db-fail"/>
<!-- location to store csv copy of CDR -->
<param name="csv-path" value="/usr/local/freeswitch/log/odbc_cdr"/>
<!-- if "csv-path-on-fail" is set, failed INSERTs will be placed here as CSV files otherwise they will be placed in "csv-path" -->
<param name="csv-path-on-fail" value="/usr/local/freeswitch/log/odbc_cdr/failed"/>
<!-- dump SQL statement after leg ends -->
<param name="debug-sql" value="false"/>
</settings>
<tables>
<!-- only a-legs will be inserted into this table -->
<table name="cdr_table_a_leg" log-leg="a-leg">
<field name="CallId" chan-var-name="call_uuid"/>
<field name="orig_id" chan-var-name="uuid"/>
<field name="term_id" chan-var-name="sip_call_id"/>
<field name="ClientId" chan-var-name="uuid"/>
<field name="IP" chan-var-name="sip_network_ip"/>
<field name="IPInternal" chan-var-name="sip_via_host"/>
<field name="CODEC" chan-var-name="read_codec"/>
<field name="directGateway" chan-var-name="sip_req_host"/>
<field name="redirectGateway" chan-var-name="sip_redirect_contact_host_0"/>
<field name="CallerID" chan-var-name="sip_from_user"/>
<field name="TelNumber" chan-var-name="sip_req_user"/>
<field name="TelNumberFull" chan-var-name="sip_to_user"/>
<field name="sip_endpoint_disposition" chan-var-name="endpoint_disposition"/>
<field name="sip_current_application" chan-var-name="current_application"/>
</table>
<!-- only b-legs will be inserted into this table -->
<table name="cdr_table_b_leg" log-leg="b-leg">
<field name="CallId" chan-var-name="call_uuid"/>
<field name="orig_id" chan-var-name="uuid"/>
<field name="term_id" chan-var-name="sip_call_id"/>
<field name="ClientId" chan-var-name="uuid"/>
<field name="IP" chan-var-name="sip_network_ip"/>
<field name="IPInternal" chan-var-name="sip_via_host"/>
<field name="CODEC" chan-var-name="read_codec"/>
<field name="directGateway" chan-var-name="sip_req_host"/>
<field name="redirectGateway" chan-var-name="sip_redirect_contact_host_0"/>
<field name="CallerID" chan-var-name="sip_from_user"/>
<field name="TelNumber" chan-var-name="sip_req_user"/>
<field name="TelNumberFull" chan-var-name="sip_to_user"/>
<field name="sip_endpoint_disposition" chan-var-name="endpoint_disposition"/>
<field name="sip_current_application" chan-var-name="current_application"/>
</table>
<!-- both legs will be inserted into this table -->
<table name="cdr_table_both">
<field name="CallId" chan-var-name="uuid"/>
<field name="orig_id" chan-var-name="Caller-Unique-ID"/>
<field name="TEST_id" chan-var-name="sip_from_uri"/>
</table>
</tables>
</configuration>