1.在网站http://download.opensips.org/2.4.5/ 下载
opensips-2.4.5.tar.gz | 07-Mar-2019 17:03 | 9.7M |
工程源码文件。
2.放在目录下解压
tar -xvf opensips-2.4.5.tar.gz
cd opensips-2.4.5
3.安装mysql
apt-get install mysql-server
apt install mysql-client
apt install libmysqlclient-dev
启用httpd mi 管理相关包安装:
apt-get install libmicrohttpd-dev
apt-get install libxml2-dev
4.编译,安装
make menuconfig
---> Configure Compile Options
---> Configure Excluded Modules
[*] db_mysql
[*] httpd
[*] mi_xmlrpc_ng
[*] proto_tls
[*] proto_wss
[*] python
---> Configure Install Prefix
/usr/local/opensips/
编译:
make all
末端结束日志
Linking db_flatstore.so
make[1]: Leaving directory '/home/sambaFile/workSoft/opensips-2.4.5/modules/db_flatstore'
cd utils/opensipsunix; make all
make[1]: Entering directory '/home/sambaFile/workSoft/opensips-2.4.5/utils/opensipsunix'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/sambaFile/workSoft/opensips-2.4.5/utils/opensipsunix'
if [ "" = "yes" ]; then \
cd utils/db_berkeley; make all ; \
fi ;
if [ "" = "yes" ]; then \
cd utils/db_oracle; make all ; \
fi ;
安装:
make install
5.配置文件
vi /usr/local/etc/opensips/opensipsctlrc
SIP_DOMAIN=192.168.9.10
DBENGINE=MYSQL
DBHOST=xxx.xxx.xxx.xxx (本机地址或服务器地址)
DBNAME=opensips
DBRWUSER=opensips
DBRWPW="opensipsrw"
DBROOTUSER="root"
cd /usr/locla/
/usr/local# cp etc/opensips/opensipsctlrc opensips/etc/opensips/ -av
(无此将出现 ERROR: could not load the script in /usr/local//lib64/opensips/opensipsctl/opensipsdbctl.mysql for database engine MYSQL
ERROR: database engine not loaded - tried 'MYSQL'
错误)
6.修改opensips.cfg
/usr/local/opensips# osipsconfig
---> Generate OpenSIPS Script
---> Residential Script
---> Configure Residential Script
[*] ENABLE_TCP
[*] USE_ALIASES
[*] USE_AUTH
[*] USE_DBACC
[*] USE_DBUSRLOC
[*] USE_DIALOG
[*] USE_NAT
1、生成配置脚本
运行命令:
标准如下:
./osipsconfig
选择:Generate OpenSIPS Script --> Residential Script --> Configure Residential Script,进入
按空格键,选择:
-
[*] ENABLE_TCP
-
[*] USE_DBACC
-
[*] USE_DIALOG
-
[*] USE_NAT
按q退出返回上一级界面,选择:Save Residential Script,保存设置。
再选择:Generate Residential Script,生成脚本。
脚本生成成功,放在下面的目录:
/usr/local/opensips/etc/opensips/opensips_residential_xxx.cfg
如此错误1:
/usr/local/opensips/sbin# ./opensipsdbctl create
MySQL password for root: (安装mysql时输入的密码)
INFO: test server charset
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.9.10' (111)
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.9.10' (111)
解决方法:
/etc/mysql# grep -rn "bind-address"
mysql.conf.d/mysqld.cnf:43:bind-address = 127.0.0.1
/etc/mysql# vi mysql.conf.d/mysqld.cnf
注释掉
#bind-address = 127.0.0.1
重启mysql
service mysql restart
如此错误2:
/usr/local/opensips/sbin# ./opensipsdbctl create
MySQL password for root:
INFO: test server charset
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1130 (HY000): Host '192.168.9.10' is not allowed to connect to this MySQL server
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1130 (HY000): Host '192.168.9.10' is not allowed to connect to this MySQL server
WARNING: Failed to get the available and used character sets
解决方法:
/usr/local/opensips/sbin# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.32-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye
mysql安装的root数据库密码为(密码)
%使所有外部ip地址都能访问使用mysql
7.如果没有错误
/usr/local/opensips/sbin# ./opensipsdbctl create
MySQL password for root:
INFO: test server charset
mysql: [Warning] Using a password on the command line interface can be insecure.(在命令行界面上使用密码可以是不安全的;)
mysql: [Warning] Using a password on the command line interface can be insecure.
INFO: creating database opensips ...
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
INFO: Using table engine InnoDB.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
INFO: Core OpenSIPS tables successfully created.
Install presence related tables? (Y/n): y
INFO: creating presence tables into opensips ...
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
INFO: Presence tables successfully created.
Install tables for
b2b
cachedb_sql
call_center
carrierroute
cpl
domainpolicy
emergency
fraud_detection
freeswitch_scripting
imc
registrant
siptrace
userblacklist
? (Y/n): y
INFO: creating extra tables into opensips ...
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
INFO: Extra tables successfully created.
8.启动sip
root@yex-Ubuntu:/usr/local/opensips/sbin# ./opensipsctl start
INFO: Starting OpenSIPS :
INFO: started (pid: 12533)
错误1:
INFO: Starting OpenSIPS :
ERROR: PID file /var/run/opensips.pid does not exist -- OpenSIPS start failed
修改:
/usr/local/opensips/sbin# vi /usr/local/opensips/etc/opensips/opensips.cfg
46 #set module path
47 mpath="/usr/local//lib64/opensips/modules/"
为
46 #set module path
47 mpath="/usr/local/opensips/lib64/opensips/modules/"
9.添加sip用户
/usr/local/opensips/sbin# ./opensipsctl add user1 123456
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
new user 'user1' added
/usr/local/opensips/sbin# ./opensipsctl add user6 123456
删除用户
./opensipsctl rm user6
查询用户(输入命令一定要以“;”结尾)
/usr/local/opensips/sbin# mysql -u opensips -p
Enter password: (默认密码:opensipsrw)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 66
Server version: 5.7.32-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show tables;
ERROR 1046 (3D000): No database selected
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| opensips |
+--------------------+
2 rows in set (0.02 sec)
mysql> \q
Bye
/usr/local/opensips/sbin# ./opensipsctl start
INFO: Starting OpenSIPS :
ERROR: PID file /var/run/opensips.pid does not exist -- OpenSIPS start failed
/usr/local/opensips/sbin# tail -f /var/log/syslog
Jan 23 17:51:36 yex-Ubuntu ./opensips[19283]: INFO:core:mod_init: initializing TCP-plain protocol
Jan 23 17:51:36 yex-Ubuntu ./opensips[19283]: INFO:core:probe_max_sock_buff: using rcv buffer of 416 kb
Jan 23 17:51:36 yex-Ubuntu ./opensips[19283]: INFO:core:probe_max_sock_buff: using snd buffer of 416 kb
Jan 23 17:51:36 yex-Ubuntu ./opensips[19283]: INFO:core:init_sock_keepalive: TCP keepalive enabled on socket 47
Jan 23 17:51:36 yex-Ubuntu ./opensips[19283]: ERROR:core:tcp_init_listener: bind(2f, 0x7f8d0bb299ac, 16) on 192.168.9.10:5060 : Address already in use
Jan 23 17:51:36 yex-Ubuntu ./opensips[19283]: ERROR:core:trans_init_all_listeners: failed to init listener [192.168.9.10], proto tcp
Jan 23 17:51:36 yex-Ubuntu ./opensips[19283]: ERROR:core:main: failed to init all SIP listeners, aborting
Jan 23 17:51:36 yex-Ubuntu ./opensips[19283]: INFO:core:cleanup: cleanup
Jan 23 17:51:36 yex-Ubuntu ./opensips[19283]: NOTICE:core:main: Exiting....
Jan 23 17:51:36 yex-Ubuntu opensips: INFO:core:daemonize: pre-daemon process exiting with -1
Jan 23 17:51:47 yex-Ubuntu ./opensips[4203]: ERROR:mi_fifo:mi_fifo_check: lstat failed: No such file or directory
Jan 23 17:51:47 yex-Ubuntu ./opensips[4203]: INFO:mi_fifo:get_fifo_stream: invalid FIFO file: creating a new one (/tmp/opensips_fifo)
10.内网链接
/usr/local/opensips/sbin# ./opensipsctl ul show
Domain:: location hash_size=512
AOR:: 002
Contact:: sip:002@192.168.9.198:48317;transport=udp Q=
ContactID:: 1128925762842328342
Expires:: 3592
Callid:: Xg0nzQM2V7
Cseq:: 21
User-agent:: LinphoneAndroid/3.2.4 (belle-sip/1.5.0)
Received:: sip:192.168.9.198:48317
State:: CS_NEW
Flags:: 0
Cflags:: NAT
Socket:: udp:192.168.9.10:5060
Methods:: 4294967295
SIP_instance:: <urn:uuid:c68c012d-c564-4f93-b05c-8f216ec1736f>
AOR:: user1
Contact:: sip:user1@192.168.9.182 Q=
ContactID:: 1829798454851847426
Expires:: 2366
Callid:: puIKnkxsvT
Cseq:: 85
User-agent:: Linphone/3.9.0 (belle-sip/1.4.2)
Received:: sip:192.168.9.182:5060
State:: CS_SYNC
Flags:: 0
Cflags:: NAT
Socket:: udp:192.168.9.10:5060
Methods:: 4294967295
SIP_instance:: <urn:uuid:58b1e83c-0003-46f9-a821-041dbd4cb043>
Contact:: sip:user1@192.168.9.198:48317;transport=udp Q=
ContactID:: 1829798454851847428
Expires:: 3592
Callid:: tB9eOQKL89
Cseq:: 21
User-agent:: LinphoneAndroid/3.2.4 (belle-sip/1.5.0)
Received:: sip:192.168.9.198:48317
State:: CS_NEW
Flags:: 0
Cflags:: NAT
Socket:: udp:192.168.9.10:5060
Methods:: 4294967295
SIP_instance:: <urn:uuid:c68c012d-c564-4f93-b05c-8f216ec1736f>
安装rtpproxy代理,外网,和内网不同层次架构需要:
#svn co https://github.com/sippy/rtpproxy/branches/high-availability
#./configure&&make&&make install
#killall rtpproxy
#rtpproxy -l 192.166.65.122 -s udp:127.0.0.1:12221 -F -d INFO LOG_LOCAL0
/etc/init.d/rtpproxy start
检测服务器网络数据变化命令,可以用 apt-get install ngrep 安装此命令:
ngrep -p -q -W byline port 5060 > test.txt 检测端口发送的数据
U 192.168.9.197:5060 -> 192.168.9.10:5060
SIP/2.0 487 Request terminated.
Via: SIP/2.0/UDP 192.168.9.10;rport;branch=z9hG4bKQKc4Dp48HF2jQ.
From: "Extension 1001" <sip:1001@192.168.9.10>;tag=F38eQQ1yS123r.
To: <sip:1000@192.168.9.197>;tag=iIDsMPM.
Call-ID: f85e38e6-dbf0-1239-96b1-94c69108fbac.
CSeq: 31359895 INVITE.
User-Agent: Linphone/3.9.0 (belle-sip/1.4.2).
Supported: outbound.
.
U 192.168.9.10:5060 -> 192.168.9.197:5060
ACK sip:1000@192.168.9.197 SIP/2.0.
Via: SIP/2.0/UDP 192.168.9.10;rport;branch=z9hG4bKQKc4Dp48HF2jQ.
Max-Forwards: 69.
From: "Extension 1001" <sip:1001@192.168.9.10>;tag=F38eQQ1yS123r.
To: <sip:1000@192.168.9.197>;tag=iIDsMPM.
Call-ID: f85e38e6-dbf0-1239-96b1-94c69108fbac.
CSeq: 31359895 ACK.
Content-Length: 0.
.
U 192.168.9.197:5060 -> 192.168.9.10:5060
SIP/2.0 200 Ok.
Via: SIP/2.0/UDP 192.168.9.10;rport;branch=z9hG4bKS5yNHc6Fc1ere.
From: "1000" <sip:1000@192.168.9.10>;tag=owtu5n8rFT2l.
To: <sip:1000@192.168.9.10>;tag=Q-rgn18aR.
Call-ID: yk8FFiVnEy.
CSeq: 119848901 NOTIFY.
User-Agent: Linphone/3.9.0 (belle-sip/1.4.2).
Supported: outbound.
.
U 192.168.9.197:5060 -> 192.168.9.10:5060
SIP/2.0 200 Ok.
Via: SIP/2.0/UDP 192.168.9.10;rport;branch=z9hG4bKtereK7pK994aa.
From: "1001" <sip:1001@192.168.9.10>;tag=NoySkWQSE2eq.
To: <sip:1000@192.168.9.10>;tag=CoLDP1jL-.
Call-ID: BNGWnY~yw8.
CSeq: 119848902 NOTIFY.
User-Agent: Linphone/3.9.0 (belle-sip/1.4.2).
Supported: outbound.
.
U 192.168.9.197:5060 -> 192.168.9.10:5060