使用OpenSips1.9搭建Sip服务器

Sip有很多服务端可以用,miniSipServer ,sipServer等等。如果只是做简单的测试用,可以直接下载minisipserver

1、安装好Mysql数据库

2、在opensips官方网站(http://opensips.org/)下载OpenSips1.9的源码

3、解压编译安装(安装过程中有很多命令需要用root权限。所以建议使用root角色进行操作。sudo -i)

$ make menuconfig

使用OpenSips1.9搭建Sip服务器_第1张图片

进入configure compile Options选择 Configure Install Prefix设置路径。


使用OpenSips1.9搭建Sip服务器_第2张图片

返回,选择编译并安装OpenSips,耐心等待2分钟,编译完成后会在设置的目录下生成一个opensips_proxy目录。这是OpenSips的安装目录。

 

4、修改/usr/local/opensips_proxy/etc/opensips/opensipsctlrc配置如下(只是打开了一些注释,其他的都不改变):

## your SIP domain 
SIP_DOMAIN=192.168.1.43 
#服务器的ip地址,使用ifconfig命令查看
## chrooted directory 
# $CHROOT_DIR="/path/to/chrooted/directory" 

## 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" 

5、修改/usr/local/opensips_proxy/etc/opensips/opensips.cfg配置文件,部分修改的配置项,其他的不动

####### Global Parameters ######### 
 
debug=3 
log_stderror=no 
#设置日志打印到单独的文件中 
#	root@ubuntu:vim /etc/rsylog.conf 
#	在最后面添加代码 
#	local1.*   -/var/log/opensips.log 
#	最后重启日志 
#	root@ubuntu:/etc/init.d/rsyslog restart 
#	日志即配置完成。 
log_facility=LOG_LOCAL1 
fork=yes 
children=4 
 
/* uncomment the following lines to enable debugging */ 
#debug=6 
#fork=no 
#log_stderror=yes 
 
/* uncomment the next line to enable the auto temporary blacklisting of 
   not available destinations (default disabled) */ 
#disable_dns_blacklist=no 
 
/* uncomment the next line to enable IPv6 lookup after IPv4 dns 
   lookup failures (default disabled) */ 
#dns_try_ipv6=yes 
 
/* comment the next line to enable the auto discovery of local aliases 
   based on revers DNS on IPs */ 
auto_aliases=no 
 
#添加TCP/UDP监听配置 
listen=udp:192.168.1.43:5060   # CUSTOMIZE ME 
 
disable_tcp=no 
listen=tcp:192.168.1.43:5060   # CUSTOMIZE ME 
 
disable_tls=yes 
 
 
####### Modules Section ######## 
 
#set module path  设置模块路径,这里一定是绝对路径。 
mpath="/usr/local/opensips_proxy/lib64/opensips/modules/" 
 
#### SIGNALING module 
loadmodule "signaling.so" 
 
#### StateLess module 
loadmodule "sl.so" 
 
#### Transaction Module 
loadmodule "tm.so" 
modparam("tm", "fr_timer", 5) 
modparam("tm", "fr_inv_timer", 30) 
modparam("tm", "restart_fr_on_each_reply", 0) 
modparam("tm", "onreply_avp_mode", 1) 
 
#### Record Route Module 
loadmodule "rr.so" 
/* do not append from tag to the RR (no need for this script) */ 
modparam("rr", "append_fromtag", 0) 
 
#### MAX ForWarD module 
loadmodule "maxfwd.so" 
 
#### SIP MSG OPerationS module 
loadmodule "sipmsgops.so" 
 
#### FIFO Management Interface 
loadmodule "mi_fifo.so" 
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo") 
modparam("mi_fifo", "fifo_mode", 0666) 
 
#### URI module 
loadmodule "uri.so" 
modparam("uri", "use_uri_table", 0) 
#必须添加 
modparam("uri", "db_url", "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME 
 
#### MYSQL module 添加Mysql模块支持 
loadmodule "db_mysql.so" 
 
 
 
#### USeR LOCation module 
loadmodule "usrloc.so" 
modparam("usrloc", "nat_bflag", "NAT") 
modparam("usrloc", "db_mode",   2) 
modparam("usrloc", "db_url", 
"mysql://opensips:opensipsrw@localhost/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", "failed_transaction_flag", "ACC_FAILED") 
/* account triggers (flags) */ 
modparam("acc", "log_flag", "ACC_DO") 
modparam("acc", "log_missed_flag", "ACC_MISSED") 

6、设置启动项

#cp /home/tang/sip/opensips-1.9/packaging/debian/opensips.init /etc/init.d/opensips 

#chmod +x /etc/init.d/opensips

修改/etc/init.d/opensips如下(部分):

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/opensips_proxy/sbin/opensips
NAME=opensips
DESC=opensips
HOMEDIR=/var/run/opensips
PIDFILE=$HOMEDIR/$NAME.pid
DEFAULTS=/etc/default/opensips
RUN_OPENSIPS=no

# Do not start opensips if fork=no is set in the config file
# otherwise the boot process will just stop
check_fork ()
{
    if grep -q "^[[:space:]]*fork[[:space:]]*=[[:space:]]*no.*" /usr/local/opensips_proxy/etc/opensips/opensips.cfg; then
	echo "Not starting $DESC: fork=no specified in config file; run /etc/init.d/opensips debug instead"
	exit 1
    fi
}

7、设置默认项opensips.default

# cp /home/tang/sip/opensips-1.9/packaging/debian/opensips.default /etc/default/opensips

修改/etc/default/opensips如下(部分修改的地方)

# Set to yes to enable opensips, once configured properly.
RUN_OPENSIPS=yes
 
# User to run as
USER=opensips
 
# Group to run as
GROUP=opensips
 
# Amount of shared memory to allocate for the running OpenSIPS server (in Mb)
S_MEMORY=128
 
# Amount of pkg memory to allocate for the running OpenSIPS server (in Mb)
P_MEMORY=4

8、创建数据库

root@pc:/usr/local/opensips_proxy/sbin# ./opensipsdbctl create 

MySQL password for root: 

INFO: test server charset 

INFO: creating database opensips ... 

INFO: Core OpenSIPS tables succesfully created. 

Install presence related tables? (y/n): n 

Install tables for imc cpl siptrace domainpolicy carrierroute userblacklist registrant? (y/n): n 

9、添加用户

root@pc:/usr/local/opensips_proxy/sbin# ./opensipsctl add 1001 1001 

new user '1001' added

用户将添加到subscriber表中

10、操作过程中的其他命令

root@ubuntu:/etc/init.d/opensips restart(重启)

root@ubuntu:/etc/init.d/opensips start(启动)

root@ubuntu:ps aux | grep opensips(查看进程)

root@ubuntu:netstat -ulpn|grep opensips(查看UDP链接状态)

root@ubuntu:netstat -utpn|grep opensips(查看TCP链接状态)

检查配置是否正确:opensips -c

 

如果在这个过程中出现其他错误,可以开启两个终端,通过命令:tail -f /var/log/syslog进行查看。

 

服务器的所有配置完成,可以自己下载一些sip源码或者直接下载现有的sip软件进行测试了。

具体的操作请查看官方文档

原创文章,转载请注明出处:http://blog.csdn.net/tangcheng_ok




你可能感兴趣的:(使用OpenSips1.9搭建Sip服务器)