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
tar -zxvpf opensips-2.2.0.tar.gz
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
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环境变量。保存即生效。
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=
cd /usr/local/opensips/sbin/
sudo osipsconfig
依次选择–> Generate OpenSIPS Script –> Residential Script–> Configure Residential Script
空格选中【USE_AUTH,USE_DBACC,USE_DBUSRLOC,USE_DIALOG】四项。然后左键返回,选中“Generate Residential Script”,回车,会生成新的cfg文件
进入cd /usr/local/opensips/etc/opensips/
sudo chmod 777 -R opensips_residential_2022-2-11_14:55:21.cfg
mv opensips.cfg opensips.cfg.old
mv opensips_residential_2022-2-11_14:55:21.cfg opensips.cfg
sudo vim opensips.cfg
如下所示修改: 你的ip:39.107.127.32
listen=udp:39.107.127.32:5060 # CUSTOMIZE ME
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
如果需要让opensips在前台运行,便于调试和查看日志,可以在opensips.cfg配置文件中设置:
debug_mode = yes
该选项默认为no。然后在安装根目录下直接执行sbin/opensips文件运行opensips/
将debug_mode配置项设置为no,或屏蔽掉该配置项,然后适用脚本进行启动和停止
启动:opensipsctl start
重启:opensipsctl restart
停止:opensipsctl stop
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