简要:opensips提供了一个视频教程http://www.opensips.org/Documentation/Tutorials-GettingStarted,
以下主要是针对ubuntu系统的安装和使用,
之前看过一些文档总会遇到许多问题,按照视频教程使用make menuconfig以及osipsconfig配置对应的配置文件和脚本,基本没有什么问题,一步一步来,
一次成功!
下载opensips最新版本:
tar zxvf
cd opensips-2.2.2
apt-get install flex bison libncures-dev
make menuconfig
|---- configure excluded modules
|---- *db_mysql
|---- configure install prefix
|---- /usr/local/
save changes
|---- You have enabled the 'db_mysql' module, so please install '
development libraries of mysql-client , tipically libmysqPress any key to continue
解决方法: apt-get install libmysqlclient-dev
make menuconfig
Compile and install opensips
运行mysql:/usr/bin/mysqld_safe 或 service mysqld restart
/usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
logger -t mysqld -p daemon.error
cd /usr/local/etc/
vim opensipsctlrc
|----
去除以下字段#
DEENGINE
DBPORT
DBHOST
DBNAME
DBRWUSER
DBRWPW
DBROOTUSER
cd /usr/local/sbin
./opensipsdbctl create
选择项都选n
mysql -u root -p //查看opensips 数据库
>show databases;
>use opensips
>show tables;
apt-get install m4
./osipsconfig
|---- Residential Script
|---- Configure Residential Script
|---- Enable TCP
USE_AUTH
USE_DBACC
USE_DBUSRLOC
USE_DIALOG
cd /usr/local/etc/opensips
vim opensips_residential_2017-1-10_10:39:5.cfg
|---- 修改listen=udp:127.0.0.1:5060 为listen=udp:
192.168.1.122:5060 //修改为本机IP
listen=tcp:127.0.0.1:5060 为listen=tcp:
192.168.1.122:5060
cd /opt/yjl/src/opensips-2.2.2/
cd packaging/
cat /etc/debian_version
cd debian/common/
cp opensips.init /etc/init.d/opensips
chmod +x /etc/init.d/opensips
ls /usr/local/sbin/opensips
vim /etc/init.d/opensips
|---- DAEMON=/usr/sbin/opensips ---> DAEMON=/usr/local/sbin/opensips
CFGFILE=/usr/local/etc/opensips/opensips_residential_2017-1-10_10:39:5.cfg ---> /etc/opensips/opensips.cfg
cp opensips.default /etc/default/
cd /etc/default/
mv opensips.default opensips
vim opensips
|---- RUN_OPENSIPS=no ---> RUN_OPENSIPS=yes
USER=OPENSIPS ---> USER=root
GROUP=OPENSIPS ---> GROUP=root
S_MEMORY=64 ---> S_MEMORY=128
vim /usr/local/etc/opensips/opensips_residential_2017-1-10_10:39:5.cfg
|---- log_facility=LOG_LOCAL0 ---> log_facility=LOG_LOCAL1
vim /etc/rsyslog.conf
|---- 末尾增加 local1.* -/var/log/opensips.log
//opensips 启动log文件
service rsyslog restart
ls /var/log/opensips.log
/etc/init.d/opensips start
|--- less /var/log/opensips.log
|--- ERROR: URI *******
//opensips-2.2.2版本好像没有该问题
|--- 修改/usr/local/etc/opensips/opensips_residential_2017-1-10_10:39:5.cfg
#### URI module
loadmodule "uri.so"
modparam("uri", "use_uri_table", 0)
modparam("uri", "db_url","mysql://opensips:opensipsrw@localhost/opensips") //增加
ps aux | grep opensips
//查看opensips是否启动成功?
netstat -ulpn | grep opensips
netstat -tlpn | grep opensips
cd /usr/local/sbin
./osipsconfig
|---- Trunking Script
|---- Configure Trunking Script
|---- Enable TCP
USE_DIALOG
DO_CALL_LIMITATION
|---- Generate Trunking Script
|---- /usr/local//etc/opensips/opensips_trunking_2017-1-10_12:38:8.cfg
vim /usr/local//etc/opensips/opensips_trunking_2017-1-10_12:38:8.cfg
安装apache2
apt-get apache2
启动:sudo /usr/sbin/apache2 -k start
启动时提示:
apache2: Could not reliably determine the server's fully qualified domain name
解决方法: vim /etc/apache2/apache2.conf
最后加入一句 ServerName localhost:80
cd /var/www/
ps aux | grep apache
访问opensips-cp.sourceforge.net
|---- download
|---- opensips-cp-6.2.zip
或者
svn co opensips-cp
cd opensips-cp/
//安装时apache2默认有个html文件夹,必须将opensips-cp都放到该文件夹下才能通过浏览器登录
apt-get install libapache2-mod-php5 php5 php5-cli php5-gd php5-mysql php-pear
pear install mdb2#mysql
vim config/db.inc.php
|---- $config->db_pass = " "; ---> $config->db_pass = "opensips";
vim config/boxes.global.inc.php
|---- $boxes[$box_id]['mi']['conn']="127.0.0.1:8000"; ---- //$boxes[$box_id]['mi']['conn']="127.0.0.1:8000"; |
//$boxes[$box_id]['mi']['conn']="/tmp/opensips_fifo"; ---- $boxes[$box_id]['mi']['conn']="/tmp/opensips_fifo";
$boxes[$box_id]['monit']['conn']="192.168.0.1:2812"; ---- //$boxes[$box_id]['monit']['conn']="192.168.0.1:2812";
$boxes[$box_id]['monit']['user']="admin"; ---- //$boxes[$box_id]['monit']['user']="admin";
$boxes[$box_id]['monit']['pass']="pass"; ---- //$boxes[$box_id]['monit']['pass']="pass";
$boxes[$box_id]['monit']['has_ssl']=1; ---- //$boxes[$box_id]['monit']['has_ssl']=1;
vim INSTALL (查看安装方法)
mysql -u root -p opensips < config/tools/admin/add_admin/ocp_admin_privileges.mysql
mysql -u root -p
>use opensips;
>desc ocp_admin_privileges;
>INSERT INTO ocp_admin_privileges (username,password,ha1,available_tools,permissions) values ('admin','admin',
md5('admin:admin'),'all','all');
/etc/init.d/apache2 restart
192.168.1.122/opensips-cp
|---- web
|---- OpenSIPS Control Panel
|---- Username: admin
Password: admin
System
|--- Domains
|--- New Domain Name
|--- 192.168.1.122 Add Domain
Users
|--- User Management
|--- Add New User
|--- Username: test1
Domain: 192.168.1.122
Email: test1@test.com
Alias Username: 1234
Alias Type: dbaliases
Password: 1234
Confirm Password: 1234
|--- Add New User
|--- Username: test2
Domain: 192.168.1.122
Email: test2@test.com
Alias Username: 2234
Alias Type: dbaliases
Password: 2234
Confirm Password: 2234
使用linphone或Xlite 客户端注册 ,注册成功后则可以通话了。
less /var/log/opensips.log //查看客户端注册log信息
cd /usr/local/sbin/
./opensipsctl fifo ul_dump //查看客户端注册信息
cd /var/www/opensips-cp/
vim config/boxes.global.inc.php
vim config/tools/system/dialog/local.inc.php
|--- $box[1]['mi']['conn']="tmp/opensips_fifo";;
修改上面的配置文件后,
192.168.1.122/opensips-cp/web/main.php
|--- System
|---- Dailog 可以查看到通话记录和当前状态
也可以通过数据库查看
mysql -u root -p
>use opensips;
>select * from acc;
测试过程中遇到问题:
在局域网内测试中没有问题,采用公网转发后客户端注册出现Too Many Hops问题:
sip: 483 Too Many Hops 错误,跳数过多。
原因:VIA回环所致。
以下出自:
http://blog.csdn.net/commander_officer/article/details/16946781
1、现在很难申请到公网地址,所以大多opensips都放在nat后面,这样的话通过路由器的DMZ功能的话,opensips会造成回环via路由,直接连注册登录都不行。解决方法就是在opensips.cfg中增加两个变量:
advertised_address="public_ip"
alias="public_ip"
或者
listen=udp:private_ip:5060 as public_ip:5060 (这种方式可解决36秒问题和主叫方挂断被叫方不挂现象)
但是这种方式通话中没有语音传输,是要走rtp代理才可以
2、关于rtp代理的问题
opensips在1.9.1版本中提供了rtpproxy模块,走rtp代理可以实现所有nat类型的穿透,包括复杂的对称型nat。不过把rtpproxy代理放到nat后面的话会很麻烦,最近在网上看到了一个解决方案,更新rtpproxy-1.2.1下面几个文件。给大家参考一下:
(1)修改main.c文件
131 bh[0] = bh[1] = bh6[0] = bh6[1] = NULL;
132
133 cf->advertised = NULL;
134 cf->port_min = PORT_MIN;
135 cf->port_max = PORT_MAX;
if (getrlimit(RLIMIT_NOFILE, &(cf->nofile_limit)) != 0)
149 err(1, "getrlimit");
150
151 while ((ch = getopt(argc, argv, "vf2Rl:6:s:S:t:r:p:T:L:m:M:u:Fin:Pad:A:")) != -1)
152 switch (ch) {
153 case 'A':
154 cf->advertised = strdup(optarg);
155 break;
156 case 'f':
157 cf->nodaemon = 1;
158 break;
(2)修改rtpp_command.c文件
if (lia[0] == NULL || ishostnull(lia[0]))
203 len += sprintf(cp, "%d\n", lport);
204 else{
205 if(cf->advertised != NULL)
206 len += sprintf(cp, "%d %s%s\n", lport, cf->advertised,
207 (lia[0]->sa_family == AF_INET) ? "" : " 6");
208 else
209 len += sprintf(cp, "%d %s%s\n", lport, addr2char(lia[0]),
210 (lia[0]->sa_family == AF_INET) ? "" : " 6");
211 doreply(cf, fd, buf, len, raddr, rlen);
212 }
213 }
(3)在rtpp_define.h中增加定义
136
137 int log_level;
138 int log_facility;
139 char *advertised;
140 };
(4)使用如下命令启动rtpproxy代理
rtpproxy -A public_IP -l privite_ip -s udp:localhost:7890 -L 8192 -F -d INFO LOG_LOCAL0
我是参考下面方式(rtpproxy -A you_public_ip -l 0.0.0.0 -s udp:localhost:7722 -L 8192 -m 25000 -M 34999 -F -d INFO LOG_LOCAL0)
(5)同样修改opensips.cfg配置文件,设置rtp连接
modparam("rtpproxy", "rtpproxy_sock", "udp:localhost:7890") # CUSTOMIZE ME