一、基础环境
操作系统:centos7
数据库:mysql5.6,5.6版本集成freeswitch存在索引长度限制错误,后面有解决办法,mysql7不存在这个问题
freeswitch: 1.6.0
操作系统本身安装了mysql5.6,所以后续可以手动创建freeswitch对应的数据库
下面开始改造流程,有疑问可邮箱联系[email protected]或主页有联系信息
二、freeswitch集成mysql
1:安装odbc和mysql-connector
yum install mysql-connector-odbc.x86_64 unixODBC-devel.x86_64
2:配置mysql的DSN
a)mysql创建个数据库realtime,名字自己取,系统本身安装了mysql,可以通过可视化工具创建数据库,如果没有自带mysql,可以通过命令创建
b)编辑/etc/odbc.ini文件添加内容,含义为指定数据源,后续更改配置文件的数据源
[MYSQLTP]Description=MySQL realtime database
Driver=MySQL
SERVER = 192.168.1.2
PORT = 3306
DATABASE = realtime
OPTION = 67108864
PASSWORD = xxxxx
CHARSET = UTF8
保存后测试配置是否成功,引号内为数据库密码,同上面配置的PASSWORD
isql -v MYSQLTP root 'AA39noway'
配置成功会出现如下界面
4:修改freeswitch数据源文件
修改、添加以下配置文件的数据源,将这段
的value改为咱们的数据源“MYSQLTP:账号:密码”,如果以下文件没有这段自行填上
/usr/local/freeswitch/conf/jingle_profiles/server.xml
/usr/local/freeswitch/conf/sip_profiles/external.xml
/usr/local/freeswitch/conf/sip_profiles/internal.xml
/usr/local/freeswitch/conf/skinny_profiles/internal.xml
/usr/local/freeswitch/conf/autoload_configs/odbc_cdr.conf.xml
/usr/local/freeswitch/conf/autoload_configs/odbc_cdr.conf.xml
/usr/local/freeswitch/conf/autoload_configs/switch.conf.xml
/usr/local/freeswitch/conf/autoload_configs/directory.conf.xml
/usr/local/freeswitch/conf/autoload_configs/callcenter.conf.xml
/usr/local/freeswitch/conf/autoload_configs/lcr.conf.xml
/usr/local/freeswitch/conf/autoload_configs/lcr.conf.xml
/usr/local/freeswitch/conf/autoload_configs/db.conf.xml
/usr/local/freeswitch/conf/autoload_configs/nibblebill.conf.xml
/usr/local/freeswitch/conf/autoload_configs/voicemail.conf.xml
/usr/local/freeswitch/conf/autoload_configs/cidlookup.conf.xml
不同版本可能修改的xml有多有少,可以进入freeswitch目录,查找带“odbc-dsn”字样的xml文件
cd /usr/local/freeswitch
find . -name '*.xml'|xargs grep 'odbc-dsn'
查到的文件都做修改。
5:删除遗留DB文件
rm -f /usr/local/freeswitch/db/*.db
6:创建channel表,在创建的数据库中创建channel表,其它表表在自动创建的时候依赖于该表
CREATE TABLE `channels` (
`uuid` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`direction` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`created` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`created_epoch` int(11) NULL DEFAULT NULL,
`name` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`state` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`cid_name` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`cid_num` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`ip_addr` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`dest` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`application` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`application_data` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`dialplan` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`context` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`read_codec` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`read_rate` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`read_bit_rate` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`write_codec` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`write_rate` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`write_bit_rate` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`secure` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`hostname` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`presence_id` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`presence_data` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`accountcode` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`callstate` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`callee_name` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`callee_num` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`callee_direction` varchar(5) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`call_uuid` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`sent_callee_name` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`sent_callee_num` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`initial_cid_name` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`initial_cid_num` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`initial_ip_addr` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`initial_dest` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`initial_dialplan` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`initial_context` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
7:启动fs
控制台启动freeswitch
freeswitch -c -nonat -rp
启动会自动在所对应的数据库中创建表,如果报sip_subscriptions、sip_registrations表Index column size too large. The maximum column size is 767 byte,错误,基本是因为使用5.6的mysql导致的,因为表中索引有长度限制,解决办法如下(sql中涉及表的语句换成相应表名)
a)mysql数据库修改
innodb_large_prefix 的值改为(ON)
innodb_file_format 的值改为 (Barracuda)
查看命令:show variables like 'innodb_large_prefix';
修改命令:set global innodb_large_prefix = ON;
查看命令:show variables like 'innodb_file_format';
修改命令:set global innodb_file_format = BARRACUDA;
b)修改响应表Row_format
查看sip_subscriptions表的配置信息:
主要看Row_format的值是不是Dynamic,
如果不是就修改成Dynamic
查看命令:show table status like 'sip_subscriptions'
修改Row_format命令:ALTER TABLE sip_subscriptions ROW_FORMAT=DYNAMIC;
c)修改相应表长度
修改索引字段长度由原来的255(或小于255的)改成大于255的例如:512(有些字段改了报错,这种字段 就不用改了)
重新启动fs基本就没有错误了,重启后fs自动在数据库创建表
cdr开头的表是落话单后创建的,暂时可以忽略,这步完成后fs改为mysql基本完成了,下面记录fs通话记录入库流程
三、freeswitch通话记录话单入库
1:fs源码编译mod_odbc_cdr模块
进入freeswitch源码目录,编译mod_odbc_cdr
cd /usr/local/src/freeswitch-1.6.0/src/mod/event_handlers/mod_odbc_cdr
make&&make install
2:添加mod_odbc_cdr功能模块
修改/usr/local/freeswitch/conf/autoload_configs/modules.conf.xml文件添加
在/usr/local/freeswitch/conf/autoload_configs目录创建odbc_cdr.conf.xml文件,内容如下
odbc-dsn数据源记得替换成自己的账号密码
同时在数据库中创建这三张表cdr_table_a、cdr_table_b、cdr_table_ab,三张表分别是a-leg表、b-leg表、所有通话记录。后续通话测试下就一目了然了,字段类型大小根据自身情况定义。各字段含义如下
uuid: 唯一ID
call_uuid: 关联ID,同主叫方UUID
caller_id_name: 主叫方昵称
caller_id_number: 主叫号码
destination_number: 被叫号码
start_stamp: 呼叫发起的日期/时间
answer_stamp: 实际应答呼叫远端的日期/时间 如果未接听电话,则为空字符串
end_stamp: 呼叫终止的日期/时间
uduration: 总呼叫持续时间(以微秒为单位)
billsec: 可计费的通话时长(秒)可计费时间不包括在远端接听电话之前在“早期媒体”中花费的通话时间
hangup_cause: 挂断原因
sip_network_ip:网络IP
4:重启freeswitch
重启FreeSWITCH后,注册座机,外呼通话结束后,查看表中记录就会出现