当前位置: 首页 > 工具软件 > OpenSIPS > 使用案例 >

opensips安装及配置

易衡
2023-12-01

0 环境

Debian v10 (Buster) x64 minimal install (netinst),腾讯云
OpenSips v3.1
OpenSips GUI v8.3.0
Apache v2.4
PHP v7.3
MariaDB v10

1 安装依赖

sudo apt update && sudo apt upgrade -y && sudo apt -y install m4 git nano sudo curl dbus apache2 lsb-release

2 安装PHP

添加php依赖

sudo apt -y install curl apt-transport-https ca-certificates

设置php仓库

 wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/php.list 

更新源并安装php

sudo apt update && sudo apt -y install php7.3 php7.3-gd php7.3-mysql php7.3-xmlrpc php-pear php7.3-cli php-apcu php7.3-curl php7.3-xml libapache2-mod-php7.3

安装MDB2库和pear

sudo pear install MDB2#mysql

修改php.ini中的 short_open_tag为On

sed -i "s#short_open_tag = Off#short_open_tag = On#g" /etc/php/7.3/apache2/php.ini

3 安装MariaDB

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo apt update && sudo apt -y install mariadb-server 

打开vim /etc/mysql/my.cnf文件 增加

[mysqld]
sql_mode='' 
character-set-server = latin1

启动MariaDB

sudo systemctl restart mariadb

执行mysql_secure_installation脚本

sudo mysql_secure_installation

根据提示设置root账号密码及相关配置,重启mariadb

4 安装opensips

添加gpgkey

sudo apt -y install dirmngr && sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 049AD65B

添加opensips repos

echo "deb https://apt.opensips.org $(lsb_release -sc) 3.1-releases" | sudo tee -a /etc/apt/sources.list.d/opensips.list 
echo "deb https://apt.opensips.org $(lsb_release -sc) cli-nightly" | sudo tee -a /etc/apt/sources.list.d/opensips-cli.list 

/etc/apt/sources.list.d/opensips.list内容为:

deb https://apt.opensips.org buster 3.1-releases

/etc/apt/sources.list.d/opensips-cli.list的内容为:

deb https://apt.opensips.org buster cli-nightly

$(lsb_release -sc) 得到系统名字 debian 10的名字为 buster
3.1-release 需要到 https://www.opensips.org/Documentation/Manuals 看看当前有没有对应的版本

更新并安装opensips

sudo apt update && sudo apt -y install opensips opensips-cli opensips-*-module opensips-*-modules python3-mysqldb python3-sqlalchemy python3-sqlalchemy-utils 

给opensips-cli创建配置文件 /etc/opensips/opensips-cli.cfg,内容为:

[default]
#database_modules: acc clusterer dialog dialplan dispatcher domain rtpproxy usrloc
database_modules: ALL

#database_admin_url: postgres://root@localhost
database_admin_url: mysql://root@localhost

5 创建数据库

mysql -p
>
CREATE USER 'opensips'@'localhost' IDENTIFIED BY 'opensipsrw'; 
GRANT ALL PRIVILEGES ON opensips.* TO 'opensips'@'localhost'; 
FLUSH PRIVILEGES; 
exit 
sudo opensips-cli -x database create 

6 生成配置文件

sudo /usr/sbin/osipsconfig

依次进入 GenerateOpenSIPS Script > Residential Script > Configure Residential Script. 
使用空格选择所有项目

按Q键返回,然后选择 Generate Residential Script.

默认会在/etc/opensips/下生成用时间命名的cfg文件(例如 opensips—2023:0203xxx.cfg),用这个替换默认的opensips.cfg

sudo mv /etc/opensips/opensips.cfg /etc/opensips/opensips.cfg.orig 
sudo cp /etc/opensips/opensips—2023:0203xxx.cfg /etc/opensips/opensips.cfg 
chmod 644 /etc/opensips/opensips.cfg 

注意:chmod 很重要,否则 opensips无法加载

7 修改ip

sudo vim /etc/opensips/opensips.cfg
listen=udp:192.168.0.1:5060
listen=tcp:192.168.0.1:5060

修改log_stderror=yes这样可以在用 sudo tail -f /var/log/syslog 查看报错信息

sudo systemctl restart opensips

如果遇到报

ERROR:  SSL_CTX_use_certificate_file: error:140AB18E:SSL routines:SSL_CTX_use_certificate:ca md too weak

解决方法:

打开/etc/ssl/openssl.cnf,修改

[system_default_sect]
CipherString = DEFAULT@SECLEVEL=1

9 安装GUI

下载opensips GUI

git clone -b 8.3.0 https://github.com/OpenSIPS/opensips-cp.git /var/www/opensips-cp

数据库中创建相关表

cd /var/www/opensips-cp/config 
mysql -p opensips < db_schema.mysql 

10 配置cron

cd /var/www/opensips-cp/config
sudo cp tools/system/smonitor/opensips_stats_cron /etc/cron.d/
sudo systemctl restart cron

11 全局配置

编辑 /var/www/opensips-cp/config/boxes.global.inc.php 修改为如下:

// monit host:port 
$boxes[$box_id]['monit']['conn']="127.0.0.1:2812"; 
$boxes[$box_id]['monit']['user']="admin"; 
$boxes[$box_id]['monit']['pass']="admin"; 
$boxes[$box_id]['monit']['has_ssl']=0;

12 配置apache

创建 /etc/apache2/sites-available/opensips.conf,内容为

<VirtualHost *:80> 

DocumentRoot /var/www/opensips-cp 

<Directory /var/www/opensips-cp/web>
     Options Indexes FollowSymLinks MultiViews
     AllowOverride None
     Require all granted 
</Directory> 

<Directory /var/www/opensips-cp>
     Options Indexes FollowSymLinks MultiViews
     AllowOverride None
     Require all denied 
</Directory> 
Alias /cp /var/www/opensips-cp/web 

<DirectoryMatch "/var/www/opensips-cp/web/tools/.*/.*/(template|custom_actions|lib)/">
      Require all denied 
</DirectoryMatch> 

</VirtualHost> 

保存后 执行如下命令

sudo a2dissite 000-default 
sudo a2ensite opensips 
sudo chown -R www-data. /var/www/opensips-cp 
sudo systemctl restart apache2 

如果提示如下错误

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "UTF-8",
    LANG = "en_US.UTF-8"

解决方法:

$ export LC_ALL=C
$ perl -e 'print "hello world"'

13 远程通过浏览器访问

输入 http://serverip/cp 后会出现登录界面
账号 admin
密码 opensips
即可

参考
https://fatiherikci.com/en/opensips-installation/
https://gpu.xuandashi.com/11897.html
https://zhuanlan.zhihu.com/p/524189331
https://zhuanlan.zhihu.com/p/367752158?utm_id=0

 类似资料: