Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1150536
  • 博文数量: 188
  • 博客积分: 2267
  • 博客等级: 大尉
  • 技术积分: 1907
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-01 11:17
文章分类

全部博文(188)

文章存档

2016年(16)

2015年(16)

2014年(12)

2013年(32)

2012年(45)

2011年(67)

分类: LINUX

2016-02-25 09:09:38

系统环境:

Vmware Workstation 11

CentOS 6.5 x64

网络环境:

192.168.234.133

软件环境

Opensips 2.1.2



安装mysql

# yum -y install mysql-server mysql mysql-devel

# /etc/init.d/mysqld start

# mysql_secure_installation


安装编译

# yum -y install gcc gcc-c++ glibc bison flex zlib-devel ncurses ncurses-devel

# tar xf opensips-2.1.2.tar.gz

# make menuconfig 执行此命令直接退出,会在源码根目录下生成Makefile.cfg文件或者直接复制Makefile.cfg.temple(使用左右键进入/返回菜单;opensis中默认是不支持mysql的,需要手动修改Makefile.cfg文件)



exclude_modules中删掉db_mysql,include_modules中添加db_mysql,修改安装目录为PREFIX=/usr/local/opensips/


# make all

# make install

# cd /usr/local/opensips/

目录结构如下

# cd /usr/local/opensips/etc/opensips

修改opensipsctlrc文件

修改opensips.cfg文件(ps:此处有大坑,请注意;网上的教程千篇一律的说在此文件中打开mysql的注释项,然而此文件中并没有任何与mysql相关的配置项;虽然我们在开始编译安装的时候已经includemysql模块,我们自己生成一个cfg文件吧!










# mv opensips_residential_2016-2-24_4\:57\:26.cfg opensips.cfg

现在开始真正的修改opensips.cfg

listen=udp:192.168.234.133:5060   # CUSTOMIZE ME

listen=tcp:192.168.234.133:5060   # CUSTOMIZE ME

loadmodule "db_mysql.so"

mysql://opensips:opensipsrw@localhost/opensips    #这个应该有四处,注意mysql服务器的连接地址
以下是我的配置文件

点击(此处)折叠或打开

  1. #
  2. # $Id$
  3. #
  4. # OpenSIPS residential configuration script
  5. # by OpenSIPS Solutions
  6. #
  7. # This script was generated via "make menuconfig", from
  8. # the "Residential" scenario.
  9. # You can enable / disable more features / functionalities by
  10. # re-generating the scenario with different options.#
  11. #
  12. # Please refer to the Core CookBook at:
  13. #
  14. # for a explanation of possible statements, functions and parameters.
  15. #
  16. ####### Global Parameters #########
  17. debug=3
  18. log_stderror=no
  19. log_facility=LOG_LOCAL0
  20. fork=yes
  21. children=4
  22. /* uncomment the following lines to enable debugging */
  23. #debug=6
  24. #fork=no
  25. #log_stderror=yes
  26. /* uncomment the next line to enable the auto temporary blacklisting of
  27. not available destinations (default disabled) */
  28. #disable_dns_blacklist=no
  29. /* uncomment the next line to enable IPv6 lookup after IPv4 dns
  30. lookup failures (default disabled) */
  31. #dns_try_ipv6=yes
  32. /* comment the next line to enable the auto discovery of local aliases
  33. based on revers DNS on IPs */
  34. auto_aliases=no
  35. listen=udp:192.168.234.133:5060 # CUSTOMIZE ME
  36. listen=tcp:192.168.234.133:5060 # CUSTOMIZE ME
  37. ####### Modules Section ########
  38. #set module path
  39. mpath="/usr/local/opensips/lib64/opensips/modules/"
  40. #### SIGNALING module
  41. loadmodule "signaling.so"
  42. #### StateLess module
  43. loadmodule "sl.so"
  44. #### Transaction Module
  45. loadmodule "tm.so"
  46. modparam("tm", "fr_timeout", 5)
  47. modparam("tm", "fr_inv_timeout", 30)
  48. modparam("tm", "restart_fr_on_each_reply", 0)
  49. modparam("tm", "onreply_avp_mode", 1)
  50. #### Record Route Module
  51. loadmodule "rr.so"
  52. /* do not append from tag to the RR (no need for this script) */
  53. modparam("rr", "append_fromtag", 0)
  54. #### MAX ForWarD module
  55. loadmodule "maxfwd.so"
  56. #### SIP MSG OPerationS module
  57. loadmodule "sipmsgops.so"
  58. #### FIFO Management Interface
  59. loadmodule "mi_fifo.so"
  60. modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
  61. modparam("mi_fifo", "fifo_mode", 0666)
  62. #### URI module
  63. loadmodule "uri.so"
  64. modparam("uri", "use_uri_table", 0)
  65. #### MYSQL module
  66. loadmodule "db_mysql.so"
  67. #### USeR LOCation module
  68. loadmodule "usrloc.so"
  69. modparam("usrloc", "nat_bflag", "NAT")
  70. modparam("usrloc", "db_mode", 2)
  71. modparam("usrloc", "db_url",
  72. "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME
  73. #### REGISTRAR module
  74. loadmodule "registrar.so"
  75. modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")
  76. /* uncomment the next line not to allow more than 10 contacts per AOR */
  77. #modparam("registrar", "max_contacts", 10)
  78. #### ACCounting module
  79. loadmodule "acc.so"
  80. /* what special events should be accounted ? */
  81. modparam("acc", "early_media", 0)
  82. modparam("acc", "report_cancels", 0)
  83. /* by default we do not adjust the direct of the sequential requests.
  84. if you enable this parameter, be sure the enable "append_fromtag"
  85. in "rr" module */
  86. modparam("acc", "detect_direction", 0)
  87. modparam("acc", "failed_transaction_flag", "ACC_FAILED")
  88. /* account triggers (flags) */
  89. modparam("acc", "db_flag", "ACC_DO")
  90. modparam("acc", "db_missed_flag", "ACC_MISSED")
  91. modparam("acc", "db_url",
  92. "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME
  93. #### AUTHentication modules
  94. loadmodule "auth.so"
  95. loadmodule "auth_db.so"
  96. modparam("auth_db", "calculate_ha1", yes)
  97. modparam("auth_db", "password_column", "password")
  98. modparam("auth_db|uri", "db_url",
  99. "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME
  100. modparam("auth_db", "load_credentials", "")
  101. #### DIALOG module
  102. loadmodule "dialog.so"
  103. modparam("dialog", "dlg_match_mode", 1)
  104. modparam("dialog", "default_timeout", 21600) # 6 hours timeout
  105. modparam("dialog", "db_mode", 2)
  106. modparam("dialog", "db_url",
  107. "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME
  108. loadmodule "proto_udp.so"
  109. loadmodule "proto_tcp.so"
  110. ####### Routing Logic ########
  111. # main request routing logic
  112. route{
  113. if (!mf_process_maxfwd_header("10")) {
  114. sl_send_reply("483","Too Many Hops");
  115. exit;
  116. }
  117. if (has_totag()) {
  118. # sequential request withing a dialog should
  119. # take the path determined by record-routing
  120. if (loose_route()) {
  121. # validate the sequential request against dialog
  122. if ( $DLG_status!=NULL && !validate_dialog() ) {
  123. xlog("In-Dialog $rm from $si (callid=$ci) is not valid according to dialog\n");
  124. ## exit;
  125. }
  126. if (is_method("BYE")) {
  127. setflag(ACC_DO); # do accounting ...
  128. setflag(ACC_FAILED); # ... even if the transaction fails
  129. } else if (is_method("INVITE")) {
  130. # even if in most of the cases is useless, do RR for
  131. # re-INVITEs alos, as some buggy clients do change route set
  132. # during the dialog.
  133. record_route();
  134. }
  135. # route it out to whatever destination was set by loose_route()
  136. # in $du (destination URI).
  137. route(relay);
  138. } else {
  139. if ( is_method("ACK") ) {
  140. if ( t_check_trans() ) {
  141. # non loose-route, but stateful ACK; must be an ACK after
  142. # a 487 or e.g. 404 from upstream server
  143. t_relay();
  144. exit;
  145. } else {
  146. # ACK without matching transaction ->
  147. # ignore and discard
  148. exit;
  149. }
  150. }
  151. sl_send_reply("404","Not here");
  152. }
  153. exit;
  154. }
  155. # CANCEL processing
  156. if (is_method("CANCEL"))
  157. {
  158. if (t_check_trans())
  159. t_relay();
  160. exit;
  161. }
  162. t_check_trans();
  163. if ( !(is_method("REGISTER") ) ) {
  164. if (from_uri==myself)
  165. {
  166. # authenticate if from local subscriber
  167. # authenticate all initial non-REGISTER request that pretend to be
  168. # generated by local subscriber (domain from FROM URI is local)
  169. if (!proxy_authorize("", "subscriber")) {
  170. proxy_challenge("", "0");
  171. exit;
  172. }
  173. if (!db_check_from()) {
  174. sl_send_reply("403","Forbidden auth ID");
  175. exit;
  176. }
  177. consume_credentials();
  178. # caller authenticated
  179. } else {
  180. # if caller is not local, then called number must be local
  181. if (!uri==myself) {
  182. send_reply("403","Rely forbidden");
  183. exit;
  184. }
  185. }
  186. }
  187. # preloaded route checking
  188. if (loose_route()) {
  189. xlog("L_ERR",
  190. "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
  191. if (!is_method("ACK"))
  192. sl_send_reply("403","Preload Route denied");
  193. exit;
  194. }
  195. # record routing
  196. if (!is_method("REGISTER|MESSAGE"))
  197. record_route();
  198. # account only INVITEs
  199. if (is_method("INVITE")) {
  200. # create dialog with timeout
  201. if ( !create_dialog("B") ) {
  202. send_reply("500","Internal Server Error");
  203. exit;
  204. }
  205. setflag(ACC_DO); # do accounting
  206. }
  207. if (!uri==myself) {
  208. append_hf("P-hint: outbound\r\n");
  209. route(relay);
  210. }
  211. # requests for my domain
  212. if (is_method("PUBLISH|SUBSCRIBE"))
  213. {
  214. sl_send_reply("503", "Service Unavailable");
  215. exit;
  216. }
  217. if (is_method("REGISTER"))
  218. {
  219. # authenticate the REGISTER requests
  220. if (!www_authorize("", "subscriber"))
  221. {
  222. www_challenge("", "0");
  223. exit;
  224. }
  225. if (!db_check_to())
  226. {
  227. sl_send_reply("403","Forbidden auth ID");
  228. exit;
  229. }
  230. if ( proto==TCP || 0 ) setflag(TCP_PERSISTENT);
  231. if (!save("location"))
  232. sl_reply_error();
  233. exit;
  234. }
  235. if ($rU==NULL) {
  236. # request with no Username in RURI
  237. sl_send_reply("484","Address Incomplete");
  238. exit;
  239. }
  240. # do lookup with method filtering
  241. if (!lookup("location","m")) {
  242. if (!db_does_uri_exist()) {
  243. send_reply("420","Bad Extension");
  244. exit;
  245. }
  246. t_newtran();
  247. t_reply("404", "Not Found");
  248. exit;
  249. }
  250. # when routing via usrloc, log the missed calls also
  251. setflag(ACC_MISSED);
  252. route(relay);
  253. }
  254. route[relay] {
  255. # for INVITEs enable some additional helper routes
  256. if (is_method("INVITE")) {
  257. t_on_branch("per_branch_ops");
  258. t_on_reply("handle_nat");
  259. t_on_failure("missed_call");
  260. }
  261. if (!t_relay()) {
  262. send_reply("500","Internal Error");
  263. };
  264. exit;
  265. }
  266. branch_route[per_branch_ops] {
  267. xlog("new branch at $ru\n");
  268. }
  269. onreply_route[handle_nat] {
  270. xlog("incoming reply\n");
  271. }
  272. failure_route[missed_call] {
  273. if (t_was_cancelled()) {
  274. exit;
  275. }
  276. # uncomment the following lines if you want to block client
  277. # redirect based on 3xx replies.
  278. ##if (t_check_status("3[0-9][0-9]")) {
  279. ##t_reply("404","Not found");
  280. ## exit;
  281. ##}
  282. }
  283. local_route {
  284. if (is_method("BYE") && $DLG_dir=="UPSTREAM") {
  285. acc_db_request("200 Dialog Timeout", "acc");
  286. }
  287. }



检测配置文件语法

# ./opensips -C

创建数据库

# cd /usr/local/opensips/sbin

# ./opensipsdbctl create


# ./opensipsctl start 

如果有报错,可以查看/var/log/messages 查看



添加账号
# ./opensipsctl add 1000 1000
# ./opensipsctl add 2000 2000
添加的账号在数据库subscriber表中
查看在线用户
# ./opensipsctl ul show
# ./opensipsctl online


可以使用X-lite相互拨号测试



阅读(8854) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~