opensips服务端搭建

opensips服务端搭建 (亲测可用)

1. 下载压缩包

git clone https://github.com/OpenSIPS/opensips.git -b2.2 opensips-2.2
官网:https://www.opensips.org/Downloads/Downloads
百度网盘(以下为不同版本,按需下载):
https://pan.baidu.com/s/1z9359ztgJfM9-wZ6-o4ZRA?pwd=u614
https://pan.baidu.com/s/1RUkvSkXs4g7CL5YenXHL1w?pwd=eumk

2. 解压

tar -zxvpf opensips-2.2.0.tar.gz

3. 进入opensips目录

make menuconfig 执行此命令直接退出,会在源码根目录下生成Makefile.conf文件(手动修改Makefile.conf文件)

修改Makefile.conf文件:
在exclude_modules中删掉db_mysql,
在include_modules中添加db_mysql,
修改安装目录为PREFIX=/usr/local/opensips/

make all include_modules="db_mysql"
make include_modules="db_mysql" prefix="/usr/local/opensips" install

4.配置opensips

cd /usr/local/opensips/

sudo chmod 777 -R /usr/local/opensips/
注意:这里需要给以上目录添加sudo权限,编辑/etc/sudoers文件,更改secure_path配置如下:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local:/usr/local/opensips:/usr/local/opensips/sbin:/usr/local/opensips/bin:usr/local/opensips/lib64

这里是为sudo命令定义PATH环境变量。保存即生效。

5.配置数据库信息

cd /usr/local/opensips/etc/opensips/
sudo vim 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=39.107.127.32

## 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=39.107.127.32

## 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=root

## password for database read/write user
DBRWPW="root"

## engine type for the MySQL/MariaDB tabels (default InnoDB)
MYSQL_ENGINE="MyISAM"

## database super user (for ORACLE this is 'scheme-creator' user)
DBROOTUSER="root"

# user name column
# USERCOL="username"

## for testing / development
#ETCDIR=etc/

# SQL definitions
# If you change this definitions here, then you must change them 
# in db/schema/entities.xml too.
# FIXME

# FOREVER="2020-05-28 21:32:15"
# DEFAULT_ALIASES_EXPIRES=$FOREVER
# DEFAULT_Q="1.0"
# DEFAULT_CALLID="Default-Call-ID"
# DEFAULT_CSEQ="13"
# DEFAULT_LOCATION_EXPIRES=$FOREVER


# Program to calculate a message-digest fingerprint 
# MD5="md5sum"

# awk tool
# AWK="awk"

# gdb tool
# GDB="gdb"

# grep tool
# GREP="grep"

# sed tool
# SED="sed"


# Describe what additional tables to install. Valid values for the variables
# below are yes/no/ask. With ask (default) it will interactively ask the user
# for an answer, while yes/no allow for automated, unassisted installs.
#

# If to install tables for the modules in the EXTRA_MODULES variable.
# INSTALL_EXTRA_TABLES=ask

# If to install presence related tables.
# INSTALL_PRESENCE_TABLES=ask

# Define what module tables should be installed.
# If you use the postgres database and want to change the installed tables,
# then you must also adjust the STANDARD_TABLES or EXTRA_TABLES variable 
# accordingly in the opensipsdbctl.base script.

# opensips standard modules
# STANDARD_MODULES="standard acc domain group permissions registrar usrloc 
#                   msilo alias_db uri_db speeddial avpops auth_db dialog 
#                   dispatcher dialplan drouting nathelper load_balancer"

# opensips extra modules
# EXTRA_MODULES="imc cpl siptrace domainpolicy carrierroute userblacklist 
#                 b2b registrant call_center fraud_detection cachedb_sql"


## type of aliases used: DB - database aliases; UL - usrloc aliases
## - default: none
# ALIASES_TYPE="DB"

## control engine: FIFO or UNIXSOCK
## - default FIFO
# CTLENGINE=xmlrpc

## path to FIFO file
# OSIPS_FIFO="/tmp/opensips_fifo"

## MI_CONNECTOR control engine: FIFO, UNIXSOCK, UDP, XMLRPC
# MI_CONNECTOR=FIFO:/tmp/opensips_fifo
# MI_CONNECTOR=UNIXSOCK:/tmp/opensips.sock
# MI_CONNECTOR=UDP:192.168.2.133:8000
# MI_CONNECTOR=XMLRPC:192.168.2.133:8000

## check ACL names; default on (1); off (0)
# VERIFY_ACL=1

## ACL names - if VERIFY_ACL is set, only the ACL names from below list
## are accepted
# ACL_GROUPS="local ld int voicemail free-pstn"

## verbose - debug purposes - default '0'
# VERBOSE=1

## do (1) or don't (0) store plaintext passwords
## in the subscriber table - default '1'
# STORE_PLAINTEXT_PW=0

## do not display the output highlighted
# NOHLPRINT=1

## OPENSIPS START Options
## PID file path - default is: /var/run/opensips.pid
# PID_FILE=/var/run/opensips.pid

## Extra start options - default is: not set
# example: start opensips with 64MB share memory: STARTOPTIONS="-m 64"
# STARTOPTIONS=

6.配置opensips

cd /usr/local/opensips/sbin/
sudo osipsconfig

1)弹框配置

依次选择–> Generate OpenSIPS Script –> Residential Script–> Configure Residential Script
空格选中【USE_AUTH,USE_DBACC,USE_DBUSRLOC,USE_DIALOG】四项。然后左键返回,选中“Generate Residential Script”,回车,会生成新的cfg文件

2)更改文件权限

进入cd /usr/local/opensips/etc/opensips/
sudo chmod 777 -R opensips_residential_2022-2-11_14:55:21.cfg

3)拷贝和替换原有配置文件

mv opensips.cfg opensips.cfg.old
mv opensips_residential_2022-2-11_14:55:21.cfg opensips.cfg

4)修改opensips.cfg

sudo vim opensips.cfg
如下所示修改: 你的ip:39.107.127.32

listen=udp:39.107.127.32:5060   # CUSTOMIZE ME

7.使用opensipsdbctl新建数据库

cd /usr/local/sbin/
sudo opensipsdbctl create

报错解决:
1)Access denied for user ‘root’@‘39.107.127.32’ (using password: YES)

//新增39.107.127.32连接形式;
use mysql;
create user 'root'@'39.107.127.32' identified by 'root';
flush privileges;

2)ERROR 1044 (42000) at line 1: Access denied for user ‘root’@‘39.107.127.32’ to database ‘opensips’

//mysql虽然拥有了账号和对应的密码。但是,由于存在空密码的情况,会默认登录到空密码中。 需要把空密码的账号删除
select host,user,password from user;
delete from user where USER=''; 
flush privileges;

grant all on opensips.* to 'root'@'%' identified by 'root' with grant option;
service mysqld restart

show variables like "%sql_mode%"
set @@GLOBAL.sql_mode='';
set sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

进入/etc/my.cnf
注释sql-mode=”STRICT_TRANS_TABLES, NO_AUTO_CREATE_USER,”
service mysqld restart //刷新mysql

8.启动与停止

1)前台运行

如果需要让opensips在前台运行,便于调试和查看日志,可以在opensips.cfg配置文件中设置:
debug_mode = yes
该选项默认为no。然后在安装根目录下直接执行sbin/opensips文件运行opensips/

2)后台运行

将debug_mode配置项设置为no,或屏蔽掉该配置项,然后适用脚本进行启动和停止
启动:opensipsctl start
重启:opensipsctl restart
停止:opensipsctl stop

3)启动失败

1)ERROR: PID file /var/run/opensips.pid does not exist – OpenSIPS start failed

a.查询密码设置表 (如果查询为空,先安装的插件)

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_check_user_name    | OFF    |
| validate_password_dictionary_file    |        |
| validate_password_length             | 8      |
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 1      |
| validate_password_policy             | MEDIUM |
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.02 sec)

安装的插件:

1.登录mysql后,查询插件
show plugins;
2.查询mysql插件目录位置:
show variables like "%plugin_dir%";
可以看到mysql自带validate_password插件只是没有安装
3.安装插件
install plugin validate_password soname 'validate_password.so';
4.配置插件
set global validate_password_policy=2

b.修改表中的配置,降低对密码的校验

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_mixed_case_count=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_number_count=3;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_special_char_count=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=3;
Query OK, 0 rows affected (0.00 sec)

c.修改之后显示的样子

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password_check_user_name    | OFF   |
| validate_password_dictionary_file    |       |
| validate_password_length             | 3     |
| validate_password_mixed_case_count   | 0     |
| validate_password_number_count       | 3     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 0     |
+--------------------------------------+-------+
7 rows in set (0.00 sec)

d.添加opensips用户对数据库opensips操作权限,最后的’opensipsrw’是固定值,无需改动

mysql> grant all privileges on opensips.* to opensips@localhost identified by 'opensipsrw';
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> grant all privileges on opensips.* to root@localhost identified by 'opensipsrw';
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

e.之后在执行,显示成功

[root@localhost sbin]# opensipsctl start

INFO: Starting OpenSIPS : 
INFO: started (pid: 14899)

2)ERROR:core:udp_init: bind(5, 0x7f5522350c74, 16) on 192.168.0.117: Cannot assign requested address

//进入到/etc/sysctl.conf 添加如下代码在最下面
net.ipv4.ip_nonlocal_bind = 1

//再执行
sysctl -p
  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Docker是一种开源的容器化平台,可以用于快速构建、打包和部署应用程序。OpenSIPS是一个开源的SIP服务器,用于实现语音和视频通信。在使用Docker搭建OpenSIPS时,你可以按照以下步骤进行操作。 首先,克隆我fork的docker-opensips仓库,并进入仓库目录: ``` git clone https://github.com/daxiondi/docker-opensips.git cd docker-opensips ``` 然后,使用make命令构建OpenSIPS的镜像(这个过程可能需要一些时间,请耐心等待): ``` make build-3.1 ``` 构建完成后,可以使用docker命令查看镜像是否成功启动: ``` docker ps ``` 如果看到opensips/opensips:latest的镜像运行成功,则说明Docker搭建OpenSIPS成功。你可以通过访问5060端口来使用OpenSIPS进行音视频通信。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [[sip]搭建opensips:ubuntu+x86+docker](https://blog.csdn.net/lvwx369/article/details/120739692)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [使用docker搭建 opensips3.1](https://blog.csdn.net/qq_28880087/article/details/109270108)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值