源码包下载并编译安装
wget http://10.130.36.117/Deploymentpackage/opensips-1.8.2_src.tar.gz
wget http://10.130.36.117/Deploymentpackage/opensips.cfg 配置文件
#前提:
1、需要本地部署mysql服务,并启动成功,切需要mysql root用户密码
[root@my-dev ~]# yum install gcc make -y
[root@my-dev ~]# yum install flex bison ncurses libncurses-dev ncurses-devel -y
[root@my-dev ~]# yum install openssl openssl-devel mysql-devel -y
[root@my-dev ~]# tar xvf opensips-1.8.2_src.tar.gz
[root@my-dev ~]# cd opensips-1.8.2-tls/
[root@my-dev opensips-1.8.2-tls]# make all include_modules="db_mysql"
[root@my-dev opensips-1.8.2-tls]# make install include_modules="db_mysql"
[root@my-dev opensips-1.8.2-tls]# vim /usr/local/etc/opensips/opensipsctlrc #把和mysql有关的注释去掉,其中DB_PATH和USERCOL保留注释
## database type: MYSQL, PGSQL, ORACLE, DB_BERKELEY, or DBTEXT,
## by default none is loaded
# If you want to setup a database with opensipsdbctl, you must at least specify
# this parameter.
DBENGINE=MYSQL
## database host
DBHOST=localhost
## database name (for ORACLE this is TNS name)
DBNAME=opensips
# database path used by dbtext or db_berkeley
# DB_PATH="/usr/local/etc/opensips/dbtext"
## database read/write user
DBRWUSER=opensips
## password for database read/write user
DBRWPW="opensipsrw"
## database super user (for ORACLE this is 'scheme-creator' user)
DBROOTUSER="root"
# user name column
#USERCOL="username"
[root@my-dev opensips]# /usr/local/sbin/opensipsdbctl create
MySQL password for root: <---- 输入mysql root用户的密码
INFO: test server charset
INFO: creating database opensips ...
INFO: Core OpenSIPS tables succesfully created.
Install presence related tables? (y/n): y
INFO: creating presence tables into opensips ...
INFO: Presence tables succesfully created.
Install tables for imc cpl siptrace domainpolicy carrierroute userblacklist? (y/n): y
INFO: creating extra tables into opensips ...
INFO: Extra tables succesfully created.
[root@my-dev opensips]# mysql -uopensips -popensipsrw -h 10.0.16.16
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 42
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use opensips;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [opensips]> show tables;
+---------------------+
| Tables_in_opensips |
+---------------------+
| acc |
| active_watchers |
| address |
| aliases |
| carrierfailureroute |
| carrierroute |
| cpl |
| dbaliases |
| dialog |
| dialplan |
| dispatcher |
| domain |
| domainpolicy |
| dr_carriers |
| dr_gateways |
| dr_groups |
| dr_rules |
| globalblacklist |
| grp |
| imc_members |
| imc_rooms |
| load_balancer |
| location |
| missed_calls |
| nh_sockets |
| pdt |
| presentity |
| pua |
| re_grp |
| rls_presentity |
| rls_watchers |
| route_tree |
| silo |
| sip_trace |
| speed_dial |
| subscriber |
| uri |
| userblacklist |
| usr_preferences |
| version |
| watchers |
| xcap |
+---------------------+
42 rows in set (0.00 sec)
opensips配置文件调整
- opensips配置文件
- 配置文件需要注意:mpath路径问题
- modparam("dispatcher", "db_url" 数据库配置链接
- route 匹配规则
[root@my-dev opensips]# vim /usr/local/etc/opensips/opensips.cfg
#G
#$Id: dispatcher.cfg 8602 2011-12-01 16:56:59Z bogdan_iancu $
# sample config file for dispatcher module
#
debug=3 # debug level (cmd line: -dddddddddd)
fork=yes
log_stderror=no
log_facility=LOG_LOCAL0
children=4
check_via=no # (cmd. line: -v)
dns=off # (cmd. line: -r)
rev_dns=off # (cmd. line: -R)
port=5060
listen=udp:0.0.0.0:5060 # CUSTOMIZE ME
# for more info: opensips -h
# ------------------ module loading ----------------------------------
mpath="/usr/local/lib64/opensips/modules/" #该路径需要find / -name maxfwd.so 看下真实路径
loadmodule "maxfwd.so"
loadmodule "signaling.so"
loadmodule "sl.so"
loadmodule "tm.so"
loadmodule "db_mysql.so"
loadmodule "dispatcher.so"
loadmodule "rr.so"
loadmodule "sipmsgops.so"
#loadmodule "uri.so"
loadmodule "path.so"
loadmodule "uac_auth.so"
loadmodule "dialog.so"
loadmodule "uac.so"
loadmodule "mi_fifo.so"
# ----------------- setting module-specific parameters ---------------
# -- dispatcher params --
modparam("dispatcher", "db_url", "mysql://opensips:opensipsrw@10.0.16.16/opensips")
modparam("dispatcher", "flags", 2)
modparam("dispatcher", "force_dst", 1)
#modparam("rr","append_fromtag",0)
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_fifo", "fifo_mode", 0666)
route{
if ( !mf_process_maxfwd_header("10") )
{
send_reply("483","To Many Hops");
xlog("rU is $rU aaaaaaaaa\n");
exit;
}
if(is_method("REGISTER"))
{
route(1); #如果是注册消息就走route[1]的规则
}
else #非注册消息就通过下面规则路由
{
xlog("rU is $rU bbbbbbb\n");
if(is_method("ACK"))
{
if($tU=~"^1")
{
if (!ds_select_domain("4", "8") )
{
send_reply("500","Unable to route");
exit;
}
forward();
}
else if($tU=~"^2")
{
if (!ds_select_domain("4", "8") )
{
send_reply("500","Unable to route");
exit;
}
forward();
}
}
else
{
if($tU=~"^1")
{
if (!ds_select_domain("4", "8") )
{
send_reply("500","Unable to route");
exit;
}
forward();
}
else if($tU=~"^88")
{
if (!ds_select_domain("1", "8") ) ##这是dispatcher模块的函数,第一个参数是路由到的setid,第二参数是路由模式,8为指定setid的第一个路由,也就是单数号码路由到setid为1的
{
send_reply("500","Unable to route");
exit;
}
forward();
}
else if($tU=~"^99")
{
if (!ds_select_domain("1", "8") )
{
send_reply("500","Unable to route");
exit;
}
forward();
}
else
{
if (!ds_select_domain("4","8"))
{
send_reply("500","Unable to route");
exit;
}
forward();
}
}
}
}
route[1] { #这就是上面注册消息要走的route[1]规则
# if (!add_path_received())
# {
# sl_send_reply("503", "Internal path befuddlement");
# exit;
# }
xlog("rU is $rU fu is $fu register\n");
if($fU=~"^88")
{
xlog("tn is $tn\n");
rewriteuri("sip:10.99.150.111:5060");
uac_replace_from("sip:$fU@10.99.150.111:5060");
uac_replace_to("sip:$tU@10.99.150.111:5060");
t_relay();
}
else if($fU=~"^99")
{
xlog("tn is $tn\n");
rewriteuri("sip:10.99.150.222:5060");
uac_replace_from("sip:$fU@10.99.150.222:5060");
uac_replace_to("sip:$tU@10.99.150.222:5060");
t_relay();
}
}
[root@my-dev opensips]# opensipsctl start
INFO: Starting OpenSIPS :
INFO: started (pid: 16500)
[root@my-dev opensips]# opensipsctl dispatcher addgw 1 sip:10.99.150.111:5060 1 'WGW-1'
[root@my-dev opensips]# opensipsctl dispatcher addgw 2 sip:10.99.150.222:5060 1 'WGW-2'
[root@my-dev opensips]# opensipsctl dispatcher show
dispatcher gateways #setid 也就是上面配置文件中指向的ds_select_domain。
+----+-------+------------------------+--------+-------+--------+-------+-------------+
| id | setid | destination | socket | flags | weight | attrs | description |
+----+-------+------------------------+--------+-------+--------+-------+-------------+
| 1 | 1 | sip:10.99.150.111:5060 | NULL | 1 | 1 | | WGW-1 |
| 2 | 2 | sip:10.99.150.222:5060 | NULL | 1 | 1 | | WGW-2 |
+----+-------+------------------------+--------+-------+--------+-------+-------------+
[root@my-dev opensips]# opensipsctl restart
验证opensips
网友评论