CentOS7 环境下搭建OpenSIPS服务器

3,094 阅读2分钟

OpenSIPS is an Open Source SIP proxy/server for voice, video, IM, presence and any other SIP extensions.

安装mysql

操作系统版本:我在CentOS8上试过,限于mysql版本,每次yum安装都会直接装成mysql8.0,也没有拿tar包直接装mysql,所以直接用了CentOS7

mysql版本:需要安装mysql5.6,尝试过mysql8.0,由于给用户修改密码的语法不一样,会导致opensips用户建库失败,在此一定要注意mysql版本

环境预安装软件,几条命令就可以搞定:

yum install mysql
yum install mysql-server
yum install mysql-devel
yum install gcc gcc-c++
yum install ncurses-devel
yum install flex
yum install bison

如果找不到mysql的安装包,可用以下方法安装mysql:

  1. 检查是否已经有mysql:rpm -qa | grep mysql
  2. 版本不符合要求就卸载掉,卸载命令:rpm -qa|grep mysql|xargs rpm -e --nodeps

mysql 设置密码并打开远程访问权限

  1. 装好的mysql启动默认是没有密码的,进入mysql后进去运行下面的代码
// 设置密码
set password for 'root'@'localhost' =password('123456');
// 设置远程访问及全表权限
grant all privileges on *.* to root@'%'identified by '123456';
// 更新权限
flush privileges;
  1. 开启防火墙5060端口
firewall-cmd --zone=public --add-port=5060/udp --permanent
firewall-cmd --reload

OpenSIPs安装与使用

  1. 下载源码包(下2.4版本的,3.0版本我编译后发现少一些二进制文件)
git clone https://github.com/OpenSIPS/opensips.git -b 2.4 opensips-2.4
  1. 解压、编译、安装
tar -zxvf opensips-2.4.7.tar.gz
cd opensips-2.4.7
make menuconfig

注意:进入这个菜单后(左右键进入返回,空格键选中,回车键确定),进入Configure Compile Options,再进入Configure Excluded Modules,按空格键选中db_mysql保存,返回主菜单选择Compile And Install OpenSIPS编译安装即可。完成后会回到这个界面,保存退出。

  1. 配置文件及二进制文件目录
  2. 修改配置文件
    • opensips.cfg
      • listen=udp:192.168.190.142:5060 # CUSTOMIZE ME
    • opensipsctlrc
# 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=192.168.190.142

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

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

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

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

## database super user (for ORACLE this is 'scheme-creator' user)
DBROOTUSER="root"
  1. 创建opensips库,傻瓜式操作
opensipsdbctl create
  1. 启动opensips server
opensipsctl start

7. 添加用户

# 注册用户格式 opensipsctl 用户名 密码
opensipsctl add 1001 1001
opensipsctl add 1002 1002
  1. 测试
  • 找了两个免费软件电话:MicroSIP、Zoiper5,配置下用户
  • MicroSIP
  • Zoiper5

  • 打电话测试:

后续

再发掘下OpenSIPS的更多玩法~