背景

opensips版本在3.x的文章一方面比较少,另一方面相关的介绍部分过时。 最近在研究opensips,所以一并把相关的文章详细列出来,敬请期待,linux版本是centos7.9

1. opensips-cli 安装准备

1.1 python3.9.18 安装

opensips-cli 源码安装地址: https://github.com/OpenSIPS/opensips-cli/blob/master/docs/INSTALLATION.md
该模块是python写的,所以需要python3环境。*python 升级版本到3.9.18。 高版本python3.11.2也试过,但是版本太高有其他的错误。

python3.6版本报错:

File "/usr/lib64/python3.6/hashlib.py", line 120, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha512-256

python3.11.2版本报错:

File "/usr/local/python-3.11.2/lib/python3.11/site-packages/MySQLdb/cursors.py", line 252, in execute
    res = self._query(query)
          ^^^^^^^^^^^^^^^^^^
  File "/usr/local/python-3.11.2/lib/python3.11/site-packages/MySQLdb/cursors.py", line 378, in _query
    db.query(q)
  File "/usr/local/python-3.11.2/lib/python3.11/site-packages/MySQLdb/connections.py", line 280, in query
    _mysql.connection.query(self, query)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

1.1.1 openssl 1.1.1w版本安装
下载:

wget  https://www.openssl.org/source/openssl-1.1.1w.tar.gz 

安装:

./config --prefix=/usr/local/openssl
./config -t
make && make install 

1.1.2 python3.9.18版本安装
下载:

wget https://www.python.org/ftp/python/3.9.18/Python-3.9.18.tgz 

下载之后解压:
tar -zxvf Python-3.9.18.tgz
cd Python-3.9.18
安装:

./configure --prefix=/usr/local/python-3.9.18   --with-openssl=/usr/local/openssl  OPENSSL_LDFLAGS=-L/usr/local/openssl   OPENSSL_LIBS=-l/usr/local/openssl/lib OPENSSL_INCLUDES=-I/usr/local/openssl/include/openssl

然后:
make && make install 注意 make过程中如果有报错,需要openssl=1.1.1 那么就相应地安装openssl1.1.1版本,否则就算python安装成功,pip install 其他服务也会报错:HTTPSConnectionPool error

ERROR: Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/70/ca/20aee170afe6011e295e34b27ad7d7ccd795faba581dd3c6f7cec237f561/pyglet-1.5.0-py2.py3-none-any.whl (Caused by NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f776824ed30>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

python被安装到/usr/local/python-3.9.18 下,
之后修改默认的python版本为python3.9.18

ln -fs /usr/local/python-3.9.18/bin/python3.9 /usr/bin/python 

ln -fs /usr/local/python-3.9.18/bin/pip3.9 /usr/bin/pip 

python -V
Python 3.9.18

1.1.3 opensips-cli安装
安装方法:
https://github.com/OpenSIPS/opensips-cli/blob/master/docs/INSTALLATION.md

yum install python36 python36-pip python36-devel gcc mysql-devel python36-mysql python36-sqlalchemy python36-pyOpenSSL

此时会报错:

没有可用软件包 python36-mysql。
没有可用软件包 python36-sqlalchemy。
没有可用软件包 python36-pyOpenSSL。

解决方法:
pip install sqlalchemy-utils pyOpenSSL
到python第三方库里查找mysqlclient和SQLALchemy
https://pypi.org/simple/
分别找到对应的版本: mysqlclient-1.3.14.tar.gz 和SQLAlchemy-1.3.3.tar.gz 下载到本地,然后pip install mysqlclient-1.3.14.tar.gz SQLAlchemy-1.3.3.tar.gz
这样就解决了opensips-cli相关的依赖。

git clone https://github.com/opensips/opensips-cli ~/src/opensips-cli
cd ~/src/opensips-cli

# local install (only visible to your user)
python setup.py install --user clean

# system-wide install
python setup.py install clean

安装成功的日志:

opensipscli 0.2.0 is already the active version in easy-install.pth
Installing opensips-cli script to /usr/local/python-3.9.18/bin

Installed /usr/local/python-3.9.18/lib/python3.9/site-packages/opensipscli-0.2.0-py3.9.egg
Processing dependencies for opensipscli==0.2.0
Searching for SQLAlchemy-Utils==0.41.1
Best match: SQLAlchemy-Utils 0.41.1
Adding SQLAlchemy-Utils 0.41.1 to easy-install.pth file

Using /usr/local/python-3.9.18/lib/python3.9/site-packages
Searching for SQLAlchemy==1.3.3
Best match: SQLAlchemy 1.3.3
Adding SQLAlchemy 1.3.3 to easy-install.pth file

Using /usr/local/python-3.9.18/lib/python3.9/site-packages
Searching for mysqlclient==1.3.14
Best match: mysqlclient 1.3.14
Adding mysqlclient 1.3.14 to easy-install.pth file

Using /usr/local/python-3.9.18/lib/python3.9/site-packages
Finished processing dependencies for opensipscli==0.2.0

此时opensips-cli 二进制在/usr/local/python-3.9.18/bin/,

cp /usr/local/python-3.9.18/bin/opensips-cli 到 /usr/bin

opensips-cli安装完成。

2. opensips-cli 使用

在/root/下新增.opensips-cli.cfg

[default]
log_level: DEBUG
prompt_name: opensips-cli 
prompt_intro: Welcome to OpenSIPS Command Line Interface!
prompt_emptyline_repeat_cmd: False
history_file: ~/.opensips-cli.history
history_file_size: 1000
output_type: pretty-print
fifo_file: /tmp/opensips_fifo
communication_type: http 

database_modules: ALL 
database_admin_url: mysql://test:test123@192.168.40.143:3306
database_url: mysql://test:test123@192.168.40.143:3306 
databse_name: opensips 
database_schema_path: /home/opensips/opensips-3.2.13/scripts

database_schema_path: 指向opensips-3.2.13源码下的scripts脚本用来创建表。

2.1 创建库:(如果有opensips库,提前删除)
opensips-cli -x database create

2.2 创建用户
opensips-cli -x user add 1001 1234
成功添加用户。


白沙云影
1 声望2 粉丝

一个专注于voip的频道