1. 程式人生 > 實用技巧 >VoIP語音通話研究【進階篇(三):opensips安裝】

VoIP語音通話研究【進階篇(三):opensips安裝】

為了研究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:[email protected]: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:[email protected]: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:[email protected]: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:[email protected]: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

操作手冊:https://www.opensips.org/Documentation/Manual-2-3