为了研究VoIP的通话容量,保证交换系统的可伸缩性,需要组建集群,比较能想到的,就是opensips或者Kamailio,他们结构比较类似,使用习惯也比较类似,我用的是opensips,没有深入研究kamailio。今天简单介绍下opensips的部署。
1. 安装
1.1 预备环境
我这里使用的opensips的版本是V2.3.4,可以从这里下载:https://opensips.org/pub/opensips/2.3.4/opensips-2.3.4.tar.gz
基础信息配置
yum install mysql-libs mysql-devel
yum install gcc make
yum install flex bison ncurses libncurses-dev ncurses-devel
1.2 安装opensips并配置mysql数据库
解压后,切换到opensips的目录
[root@tkiot-dmpcc-adaptor1 opensips-2.3.4]#make menuconfig
Configure Compile Options -> Configure Excluded Modules -> db_mysql
按照此顺序选择db_mysql (空格键为选择键方向键为前进后退和确定)
选择db_mysql后一定要save。
最后选择”Compile And Install Opensips” 等待安装完毕
下面就是对mysql数据进行基本配置,因为opensips工作时,支持用户注册,需要数据库存储;也可以工作在纯粹的负载均衡(load_balance)和转发(dispatcher)模式,这些都是基于数据库进行的数据同步
[root@tkiot-dmpcc-adaptor1 opensips-2.3.4]# cd /usr/local/etc/opensips/ [root@tkiot-dmpcc-adaptor1 opensips]# vi opensipsctlrc # $Id$ # # The OpenSIPS configuration file for the control tools. # # Here you can set variables used in the opensipsctl and opensipsdbctl setup # scripts. Per default all variables here are commented out, the control tools # will use their internal default values. ## your SIP domain SIP_DOMAIN=10.95.198.24 ## chrooted directory # $CHROOT_DIR="/path/to/chrooted/directory" ## database type: MYSQL, PGSQL, ORACLE, DB_BERKELEY, DBTEXT, or SQLITE ## by default none is loaded # If you want to setup a database with opensipsdbctl, you must at least specify # this parameter. DBENGINE=MYSQL ## database port (PostgreSQL=5432 default; MYSQL=3306 default) DBPORT=3306 ## database host DBHOST=10.95.198.30 ## database name (for ORACLE this is TNS name) DBNAME=opensips # database path used by dbtext, db_berkeley, or sqlite # DB_PATH="/usr/local/etc/opensips/dbtext" ## database read/write user DBRWUSER=opensips ## password for database read/write user DBRWPW="opensipsrw" ## engine type for the MySQL/MariaDB tabels (default InnoDB) # MYSQL_ENGINE="MyISAM" ## database super user (for ORACLE this is 'scheme-creator' user) DBROOTUSER="mysql"
1.3 配置opensips
[root@tkiot-dmpcc-adaptor1 opensips]# osipsconfig
依次选择–> Generate OpenSIPS Script –> Residential Script–> Configure Residential Script
选中(选择键为空格键)
____________________________________________
| |
| [*] ENABLE_TCP |
| [ ] ENABLE_TLS |
| [ ] USE_ALIASES |
| [*] USE_AUTH |
| [*] USE_DBACC |
| [*] USE_DBUSRLOC |
| [*] USE_DIALOG |
| [ ] USE_MULTIDOMAIN |
| [ ] USE_NAT |
| [ ] USE_PRESENCE |
| [ ] USE_DIALPLAN |
| [ ] VM_DIVERSION |
| [ ] HAVE_INBOUND_PSTN |
| [ ] HAVE_OUTBOUND_PSTN |
| [ ] USE_DR_PSTN |
| [ ] USE_HTTP_MANAGEMENT_INTERFACE |
|____________________________________________|
选择 –> Generate Residential Script 回车,生成新的配置文件(在/usr/local/etc/opensips/目录下)
拷贝和替换原有配置文件
cd /usr/local/etc/opensips/
mv opensips.cfg opensips.cfg.old
mv opensips_residential_2020-7-27_16:43:29.cfg opensips.cfg
修改opensips.cfg
主要是将opensips.cfg中的带有CUSTOMIZE ME的部分修改一下,包括SIP对应的IP和端口。另外就是db_uri对应的信息。
[root@tkiot-dmpcc-adaptor1 opensips]# vi opensips.cfg listen=udp:10.95.198.24:5060 # CUSTOMIZE ME listen=tcp:10.95.198.24:5060 # CUSTOMIZE ME #### USeR LOCation module loadmodule "usrloc.so" modparam("usrloc", "nat_bflag", "NAT") modparam("usrloc", "db_mode", 2) modparam("usrloc", "db_url", "mysql://opensips:opensipsrw@10.95.198.30:3306/opensips") # CUSTOMIZE ME #### REGISTRAR module loadmodule "registrar.so" modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT") /* uncomment the next line not to allow more than 10 contacts per AOR */ #modparam("registrar", "max_contacts", 10) #### ACCounting module loadmodule "acc.so" /* what special events should be accounted ? */ modparam("acc", "early_media", 0) modparam("acc", "report_cancels", 0) /* by default we do not adjust the direct of the sequential requests. if you enable this parameter, be sure the enable "append_fromtag" in "rr" module */ modparam("acc", "detect_direction", 0) modparam("acc", "db_url", "mysql://opensips:opensipsrw@10.95.198.30:3306/opensips") # CUSTOMIZE ME #### AUTHentication modules loadmodule "auth.so" loadmodule "auth_db.so" modparam("auth_db", "calculate_ha1", yes) modparam("auth_db", "password_column", "password") modparam("auth_db|uri", "db_url", "mysql://opensips:opensipsrw@10.95.198.30:3306/opensips") # CUSTOMIZE ME modparam("auth_db", "load_credentials", "") #### DIALOG module loadmodule "dialog.so" modparam("dialog", "dlg_match_mode", 1) modparam("dialog", "default_timeout", 21600) # 6 hours timeout modparam("dialog", "db_mode", 2) modparam("dialog", "db_url", "mysql://opensips:opensipsrw@10.95.198.30:3306/opensips") # CUSTOMIZE ME
2.启动操作
2.1 配置数据库
[root@tkiot-dmpcc-adaptor1 opensips]# opensipsdbctl create MySQL password for mysql: INFO: test server charset WARNING: Your current default mysql characters set cannot be used to create DB. Please choice another one from the following list: big5 dec8 cp850 hp8 koi8r latin1 latin2 swe7 ascii ujis sjis hebrew tis620 euckr koi8u gb2312 greek cp1250 gbk latin5 armscii8 cp866 keybcs2 macce macroman cp852 latin7 cp1251 utf16 utf16le cp1256 cp1257 utf32 binary geostd8 cp932 eucjpms gb18030 Enter character set name: latin1 INFO: creating database opensips ... INFO: Using table engine InnoDB. INFO: Core OpenSIPS tables successfully created. Install presence related tables? (y/n): y INFO: creating presence tables into opensips ... INFO: Presence tables successfully created. Install tables for imc cpl siptrace domainpolicy carrierroute userblacklist b2b cachedb_sql registrant call_center fraud_detection emergency? (y/n): y INFO: creating extra tables into opensips ... INFO: Extra tables successfully created.
2.2 启动opensips
[root@tkiot-dmpcc-adaptor1 opensips]# opensipsctl start INFO: Starting OpenSIPS : INFO: started (pid: 14933)
启动过程中,若遇到错误,启动不了,请通过/var/log/messages文件,查看具体原因。通常情况下,是配置错误,主要是osipconfig这步出现错误。当然,你也可以自己配置opensips的日志路径,这个不是重点,可以参考opensips官方文档。
2.3 创建分机账号,主要是用来注册
[root@tkiot-dmpcc-adaptor1 opensips]# opensipsctl add 1101 1101 new user '1101' added [root@tkiot-dmpcc-adaptor1 opensips]# opensipsctl add 1102 1102 new user '1102' added
接下来,用yate这个SIP的客户端,进行注册测试,显示成功,状态都是online的。然后,用opensipsctl ul show命令看看对应的Endpoint的状态
[root@tkiot-dmpcc-adaptor1 opensips]# opensipsctl ul show Domain:: location hash_size=512 AOR:: 1102 Contact:: sip:1102@10.94.100.131:54542 Q= ContactID:: 3210785059338453390 Expires:: 596 Callid:: 2128509608@10.95.198.24 Cseq:: 3 User-agent:: YATE/5.4.0 State:: CS_NEW Flags:: 0 Cflags:: Socket:: udp:10.95.198.24:5060 Methods:: 63 AOR:: 1101 Contact:: sip:1101@10.94.100.131:5060 Q= ContactID:: 3210996165571000118 Expires:: 529 Callid:: 1451652798@10.95.198.24 Cseq:: 3 User-agent:: YATE/5.4.0 State:: CS_SYNC Flags:: 0 Cflags:: Socket:: udp:10.95.198.24:5060 Methods:: 63
下面这两个指令,可能会用的比较多,控制日志的开启和关闭:
sofia profile internal siptrace on sofia profile internal siptrace off
这里,就简单的介绍opensips的安装过程,下一博文,将结合opensips的load_balance,及SIP Trunk,实现外呼到坐席的模拟操作。
下面备注上opensips里面比较常用参考信息:
MI(Management Interface):https://www.opensips.org/Documentation/Interface-CoreMI-2-3