ubuntu下安装opensips 最终总给版

来源:互联网 发布:淘客联盟有淘宝客程序 编辑:程序博客网 时间:2024/05/13 14:55

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

1、安装好Mysql数据库

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

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

  1.进入opensips目录

        root@ubuntu:cd /home/amaryllis/work/project/opensips/
        root@ubuntu:make menuconfig
        输入上述命令进入选择框模式如图:
        Opensips
        如图:往下执行
        环境
        
        选择mysql数据库模块
        安装
    
        制定安装目录
        Opensips
        如上图:红色部分为指针选择,蓝色部分为指定程序安装目录
        提示:程序安装目录最好指定到公共文件目录中,据测试放到用户目录中,启动会出问题,个人出现过BUG,故作此提示
        
        配置完成之后需要对配置进行保存,如下图
        环境
        下面会提示“db_mysql”模块存在问题,表示您需要安装apt-get install libmysqlclient-dev
这里可以使用make install 直接安装   使用menuconfig安装可能会报权限错误



在上面的配置完成后        安装步骤为   make  all      然后   make  install就可以了


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

 

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

  1. <span style="font-family:Microsoft YaHei;font-size:14px;">## your SIP domain   
  2. SIP_DOMAIN=192.168.1.43   
  3. #服务器的ip地址,使用ifconfig命令查看  
  4. ## chrooted directory   
  5. # $CHROOT_DIR="/path/to/chrooted/directory"   
  6.   
  7. ## database type: MYSQL, PGSQL, ORACLE, DB_BERKELEY, or DBTEXT,   
  8. ## by default none is loaded   
  9. # If you want to setup a database with opensipsdbctl, you must at least specify   
  10. # this parameter.   
  11. DBENGINE=MYSQL   
  12.   
  13. ## database host   
  14. DBHOST=localhost   
  15.   
  16. ## database name (for ORACLE this is TNS name)   
  17. DBNAME=opensips   
  18.   
  19. # database path used by dbtext or db_berkeley   
  20. # DB_PATH="/usr/local/etc/opensips/dbtext"   
  21.   
  22. ## database read/write user   
  23. DBRWUSER=opensips   
  24.   
  25. ## password for database read/write user   
  26. DBRWPW="opensipsrw"   
  27.   
  28. ## database super user (for ORACLE this is 'scheme-creator' user)   
  29. DBROOTUSER="root" </span>  

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

  1. <span style="font-family:Microsoft YaHei;font-size:14px;">####### Global Parameters #########   
  2.    
  3. debug=3   
  4. log_stderror=no   
  5. #设置日志打印到单独的文件中   
  6. #   root@ubuntu:vim /etc/rsylog.conf   
  7. #   在最后面添加代码   
  8. #   local1.*   -/var/log/opensips.log   
  9. #   最后重启日志   
  10. #   root@ubuntu:/etc/init.d/rsyslog restart   
  11. #   日志即配置完成。   
  12. log_facility=LOG_LOCAL1   
  13. fork=yes   
  14. children=4   
  15.    
  16. /* uncomment the following lines to enable debugging */   
  17. #debug=6   
  18. #fork=no   
  19. #log_stderror=yes   
  20.    
  21. /* uncomment the next line to enable the auto temporary blacklisting of   
  22.    not available destinations (default disabled) */   
  23. #disable_dns_blacklist=no   
  24.    
  25. /* uncomment the next line to enable IPv6 lookup after IPv4 dns   
  26.    lookup failures (default disabled) */   
  27. #dns_try_ipv6=yes   
  28.    
  29. /* comment the next line to enable the auto discovery of local aliases   
  30.    based on revers DNS on IPs */   
  31. auto_aliases=no   
  32.    
  33. #添加TCP/UDP监听配置   
  34. listen=udp:192.168.1.43:5060   # CUSTOMIZE ME   
  35.    
  36. disable_tcp=no   
  37. listen=tcp:192.168.1.43:5060   # CUSTOMIZE ME   
  38.    
  39. disable_tls=yes   
  40.    
  41.    
  42. ####### Modules Section ########   
  43.    
  44. #set module path  设置模块路径,这里一定是绝对路径。   
  45. mpath="/usr/local/opensips_proxy/lib64/opensips/modules/"   
  46.    
  47. #### SIGNALING module   
  48. loadmodule "signaling.so"   
  49.    
  50. #### StateLess module   
  51. loadmodule "sl.so"   
  52.    
  53. #### Transaction Module   
  54. loadmodule "tm.so"   
  55. modparam("tm", "fr_timer", 5)   
  56. modparam("tm", "fr_inv_timer", 30)   
  57. modparam("tm", "restart_fr_on_each_reply", 0)   
  58. modparam("tm", "onreply_avp_mode", 1)   
  59.    
  60. #### Record Route Module   
  61. loadmodule "rr.so"   
  62. /* do not append from tag to the RR (no need for this script) */   
  63. modparam("rr", "append_fromtag", 0)   
  64.    
  65. #### MAX ForWarD module   
  66. loadmodule "maxfwd.so"   
  67.    
  68. #### SIP MSG OPerationS module   
  69. loadmodule "sipmsgops.so"   
  70.    
  71. #### FIFO Management Interface   
  72. loadmodule "mi_fifo.so"   
  73. modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")   
  74. modparam("mi_fifo", "fifo_mode", 0666)   
  75.    
  76. #### URI module   
  77. loadmodule "uri.so"   
  78. modparam("uri", "use_uri_table", 0)   
  79. #必须添加   
  80. modparam("uri", "db_url", "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME   
  81.    
  82. #### MYSQL module 添加Mysql模块支持   
  83. loadmodule "db_mysql.so"   
  84.    
  85.    
  86.    
  87. #### USeR LOCation module   
  88. loadmodule "usrloc.so"   
  89. modparam("usrloc", "nat_bflag", "NAT")   
  90. modparam("usrloc", "db_mode",   2)   
  91. modparam("usrloc", "db_url",   
  92. "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME   
  93.    
  94. #### REGISTRAR module   
  95. loadmodule "registrar.so"   
  96. modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")   
  97.    
  98. /* uncomment the next line not to allow more than 10 contacts per AOR */   
  99. #modparam("registrar", "max_contacts", 10)   
  100.    
  101. #### ACCounting module   
  102. loadmodule "acc.so"   
  103. /* what special events should be accounted ? */   
  104. modparam("acc", "early_media", 0)   
  105. modparam("acc", "report_cancels", 0)   
  106. /* by default we do not adjust the direct of the sequential requests.   
  107.    if you enable this parameter, be sure the enable "append_fromtag"   
  108.    in "rr" module */   
  109. modparam("acc", "detect_direction", 0)   
  110. modparam("acc", "failed_transaction_flag", "ACC_FAILED")   
  111. /* account triggers (flags) */   
  112. modparam("acc", "log_flag", "ACC_DO")   
  113. modparam("acc", "log_missed_flag", "ACC_MISSED") </span>  

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如下(部分):

  1. <span style="font-family:Microsoft YaHei;font-size:14px;">PATH=/sbin:/bin:/usr/sbin:/usr/bin  
  2. DAEMON=/usr/local/opensips_proxy/sbin/opensips  
  3. NAME=opensips  
  4. DESC=opensips  
  5. HOMEDIR=/var/run/opensips  
  6. PIDFILE=$HOMEDIR/$NAME.pid  
  7. DEFAULTS=/etc/default/opensips  
  8. RUN_OPENSIPS=no  
  9.   
  10. # Do not start opensips if fork=no is set in the config file  
  11. # otherwise the boot process will just stop  
  12. check_fork ()  
  13. {  
  14.     if grep -q "^[[:space:]]*fork[[:space:]]*=[[:space:]]*no.*" /usr/local/opensips_proxy/etc/opensips/opensips.cfg; then  
  15.     echo "Not starting $DESC: fork=no specified in config file; run /etc/init.d/opensips debug instead"  
  16.     exit 1  
  17.     fi  
  18. }</span>  

7、设置默认项opensips.default

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

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

  1. <span style="font-family:Microsoft YaHei;font-size:14px;"># Set to yes to enable opensips, once configured properly.  
  2. RUN_OPENSIPS=yes  
  3.    
  4. # User to run as  
  5. USER=root  
  6.    
  7. # Group to run as  
  8. GROUP=root  
  9.    
  10. # Amount of shared memory to allocate for the running OpenSIPS server (in Mb)  
  11. S_MEMORY=128  
  12.    
  13. # Amount of pkg memory to allocate for the running OpenSIPS server (in Mb)  
  14. P_MEMORY=4</span>  

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软件进行测试了。

3 测试

  添加SIP用户:

  语法:opensipsctl add <username> <password>

  opensipsctl add alice@192.168.139.121 123456

  opensipsctl add bob@192.168.139.121 123456

  然后下载SIP客户端进行测试!

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

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

0 0
原创粉丝点击