1. 安装opensips
ubuntu下安装:
1)执行以下的脚本
openSIPS | APT Repository
2)apt-get install opensips
安装完毕后,再选择需要的module继续安装,不需要编译
如果只是用作load balancer,那么只需要安装
apt-get install opensips-mysql-module opensips-auth-modules opensips-http-modules opensips-tls-openssl-module opensips-tlsmgm-module
3)执行osipsconfig获取新的脚本
保存好脚本后,会看到新的脚本在哪里,编辑脚本
4)重启opensips
opensips restart
2. 安装opensips-cli
apt-get install opensips-cli
vi ~/.opensips-cli.cfg
将以下的配置黏贴到.opensips-cli.cfg里面
[default]
log_level: WARNING
prompt_name: opensips-cli
prompt_intro: Welcome to OpenSIPS Command Line Interface!
prompt_emptyline_repeat_cmd: False
history_file: ~/.opensips-cli.history
history_file_size: 1000
output_type: pretty-print
communication_type: fifo
fifo_file: /tmp/opensips_fifo
# 选择模块添加数据库表结构
database_modules: ALL
# 数据库脚本目录
database_schema_path: /root/soft/opensips-3.3.1/scripts
# 数据库管理员账号
#database_admin_url: postgres://root@localhost
database_admin_url: mysql://root@localhost
# 会新建数据库账号:opensips,密码:opensipsrw
# database_url: postgres://opensips:opensipsrw@localhost
database_url: mysql://opensips:opensipsrw@localhost
# 数据库名称
database_name: opensips
domain: 10.10.3.153
plain_text_password: true
3. 安装mysql
apt install mysql-server
apt install mysql-client
apt install libmysqlclient-dev
vim /etc/mysql/mysql.conf.d/mysqld.cnf
将bind-address后的127.0.0.1 改为0.0.0.0
bind-address = 0.0.0.0
打开vim /etc/mysql/my.cnf文件 增加
[mysqld]
sql_mode=''
character-set-server = latin1
service mysql restart
初始化mysql命令:
mysql_secure_installation
创建用户
CREATE USER 'opensips'@'localhost' IDENTIFIED BY 'opensipsrw';
GRANT ALL PRIVILEGES ON opensips.* TO 'opensips'@'localhost';
flush privileges;
4. 创建并配置数据库
opensips-cli -x database create
5. 插入dispatcher模块的需要负载均衡的mrcpserver
INSERT INTO `dispatcher` (`setid`, `destination`, `state`, `weight`, `priority`, `attrs`, `description`) VALUES
(19, 'sip:10.129.39.88:7010', 0, 1, 100, 'pstn=100', 'TTS_MRCP_CLIENT_FS_7010'),
(19, 'sip:10.129.39.88:7011', 0, 1, 100, 'pstn=100', 'TTS_MRCP_CLIENT_FS_7011');
6. 将dispatcher对应的route代码加入到/etc/opensips/opensips.cfg的配置文件中
loadmodule "dialog.so"
modparam("dialog", "profiles_with_value", "caller ; domain")
modparam("dialog", "profiles_no_value", "progress ; active")
modparam("dialog", "db_mode", 2)
modparam("dialog", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
route {
# 省略无关代码 ...
if (is_method("INVITE")) {
xlog("ua = $ua , callid = $ci, fu = $fu , tu = $tu , ru = $ru , du =$du src:$si, $(rb{sdp.line,m})");
$var(dlgPingTag) = "Pp";
if ( $ua == "OPENSIPS_TTS_MRCP_CLIENT" ) {
$var(dlgPingTag) = ""; # TTS 的SIP通道不能做 OPTION 探测
}
if ( !create_dialog("$var(dlgPingTag)")) {
send_reply(500,"Internal Server Error");
exit;
}
if ( $ua == "OPENSIPS_TTS_MRCP_CLIENT" ) {
# 指定 setid 为 19,与插入 dispatcher 表的数据相匹配,选择可用的节点
$var(lbRst) = ds_select_dst(19, 4);
if($var(lbRst) == -1) {
xlog("Failed by dispatcher group_id: 19");
t_reply(480, "MRCP server Unavailable");
exit();
}
if ( $var(lbRst) > 0) {
$ru = "sip:" + $(du{uri.host}) + ":" + $dp;
xlog("[$fU->$rU] Route to $ru");
} else {
xlog("[$fU->$rU] No available server now");
t_reply(480, "$var(node_type) Unavailable");
exit();
}
} else {
# 其他类型 INVITE 处理 .....
}
}
route(relay);
}
route[relay] {
# for INVITEs enable some additional helper routes
if (isflagset("NAT")) {
add_rr_param(";nat=yes");
}
if (!t_relay()) {
send_reply(500,"Internal Error");
}
exit;
}
7. FreeSWITCH 的配置
在 FreeSWITCH 的 conf/mrcp_profiles 目录 下新增一个配置文件,将其指向 OpenSIPS 服务器并指定 UA 名称,然后重启 FreeSWITCH
<include>
<!-- UniMRCP Server MRCPv2 -->
<profile name="opensips-tts-mrcp2" version="2">
<!-- OpenSIPS 服务器地址 端口号-->
<param name="server-ip" value="127.0.0.1"/>
<param name="server-port" value="8060"/>
<!-- FreeSWITCH IP、端口以及 SIP 传输方式 -->
<param name="client-ip" value="$${local_ip_v4}" />
<param name="client-port" value="5072"/>
<param name="sip-transport" value="udp"/>
<param name="speechsynth" value="speechsynthesizer"/>
<param name="speechrecog" value="speechrecognizer"/>
<!-- SIP 请求携带的 ua 名称 -->
<param name="ua-name" value="OPENSIPS_TTS_MRCP_CLIENT"/>
<!-- Add any default MRCP params for SPEAK requests here -->
<synthparams>
</synthparams>
<!-- Add any default MRCP params for RECOGNIZE requests here -->
<recogparams>
<!--param name="start-input-timers" value="false"/-->
</recogparams>
</profile>
</include>
参考资料:
Opensips 3.3.1安装配置_ubuntu 18.04 安装opensips-CSDN博客
OpenSIPS 3.1 负载均衡 MRCP 服务器的实现_opensips 负载均衡_谈谈1974的博客-CSDN博客