因为在网上我一直找不到完整的在centos7下安装opensips和rtpenginer的文档,因为它们一般都是的Debian 下进行安装的,而centos的安装依赖与Debian 有所不同,经过一段时间的折腾,我好不容易完成,故而小记一下:
需提醒一下,opensips的3和2在管理工具上有很大不同,下面安装的是2.4.8版本
yum install gcc gcc-c++ git flex bison ncurses ncurses-devel openssl-devel
yum provides ‘*/applydeltarpm’
yum install deltarpm wget unzip
在直接centos7默认带的mariadb版本下,opensips会找不到libmysqlclient!(编译时报错,ld找不到mariadb),鉴于默认带的版本也太老,干脆换新版本:
vi /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.5 CentOS repository list
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
yum -y install MariaDB MariaDB-server MariaDB-devel MariaDB-shared
systemctl start mariadb
systemctl enable mariadb.service
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server mysql mysql-server mysql-libs mysql-devel
systemctl start mysqld
systemctl enable mysqld
mysql_secure_installation
添加新用户:mysql -u root -p
create user ‘limx’@’%’ identified by ‘11223344’;
grant all privileges on . to ‘limx’@’%’ WITH GRANT OPTION ;
flush privileges;
firewall-cmd --zone=public --query-port=3306/tcp
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=5060/tcp --permanent
firewall-cmd --zone=public --add-port=5060/udp --permanent
firewall-cmd --permanent --zone=public --add-port=16384-32768/udp
firewall-cmd --permanent --zone=public --add-port=50000-61000/udp
firewall-cmd --reload
cd /usr/local/src
wget https://opensips.org/pub/opensips/2.4.8/opensips-2.4.8.tar.gz
tar -zxvf opensips-2.4.8.tar.gz
cd opensips-2.4.8
make menuconfig
进入到菜单选取模块(右左键进入返回,空格键选中,回车键确定),选择步骤:
Configure Compile Options => Configure Excluded Modules => db_mysql,然后 save。
最后选择Compile And Install Opensips等待安装完毕。
make install
完成安装后:
cd /usr/local/etc/opensips/
vi opensipsctlrc
编辑配置数据库信息:
SIP_DOMAIN=192.168.25.130 //centos7本机ip
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"
配置 opensips:
cd /usr/local/sbin/
osipsconfig
依次选择 => Generate OpenSIPS Script => Residential Script => Configure Residential Script 选中
[*] USE_AUTH
[*] USE_DBACC
[*] USE_DBUSERLOC
[*] USE_DIALOG
返回后选择 Generate Residential Script 回车,生成新的配置文件(路径:/usr/local/etc/opensips)。
拷贝和替换原有配置文件:
cd /usr/local/etc/opensips/
mv opensips.cfg opensips.cfg.backup
mv opensips_residential_2020-8-4_19:23:5.cfg opensips.cfg
注意:上面这个文件是按照生成配置时的时间动态命名的,可以手工输入命令,按下tab键去自动填充文件名!
修改opensips.cfg:
vi opensips.cfg
// 修改配置项
listen=udp:192.168.25.130:5060
修改完相关配置后使用opensipsdbctl新建数据库:
cd /usr/local/sbin
opensipsdbctl create
启动 opensips
/usr/local/sbin/opensipsctl start
添加用户
[root@localhost sbin]# opensipsctl add 1001 1001
new user ‘1001’ added
[root@localhost sbin]# opensipsctl add 1002 1002
new user ‘1002’ added
查看注册查看在线:
opensipsctl ul show
opensipsctl online
rtpengine没有找到相关的说明,我是一步步安装而后一步步根据错误信息补充安装相应环境完成的(基于Centos7最小安装,完成opensips编译后安装rtpengine):
需要 epel 支持:
yum install epel-release
需要ffmpeg开发库里面的av模块:
rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
yum install -y ffmpeg-devel
需要libtiff开发库:
yum install libtiff-devel
需要spandsp 支持:
cd /usr/local/src
wget https://www.soft-switch.org/downloads/spandsp/spandsp-0.0.6.tar.gz
tar -zxvf spandsp-0.0.6.tar.gz
cd spandsp-0.0.6
./configure
make
make install
cp /usr/local/lib/pkgconfig/spandsp.pc /usr/lib64/pkgconfig
echo “/usr/local/lib” >> /etc/ld.so.conf
ldconfig
需要libpcap、glib、json、event、zlib、pcre、perl、hiredis等:
yum install perl-IPC-Cmd.noarch gperf libpcap-devel glib2-devel pkgconfig hiredis-devel libcurl-devel openssl-devel pcre-devel xmlrpc-c-devel zlib-devel libevent-devel json-glib-devel psmisc
安装(代码包含3个部分,有内核的模块、iptables的模块、服务端程序,因为内核模块编译是基于linux内核的,对云服务器而言内核都是定制过的,用这个编译或许会导致服务器无法开机,建议谨慎!):
cd /usr/local/src
wget https://github.com/sipwise/rtpengine/archive/master.zip
unzip master.zip
cd rtpengine-master/daemon
TPENGINE_VERSION="“9.0.0.0"”
make
cd ../iptables-extension/
make
*注:编译成功前需要安装好iptables-devel
*编译后将libxt_RTPENGINE.so,复制到xtables模块目录中。可以 pkg-config xtables --variable=xtlibdir 命令确定此目录的位置 ,通常为 /lib/xtables/或/usr/lib/x86_64-linux-gnu/xtables/
cp *.so /usr/lib64/xtables
内核模块的编译需要安装内核开发头文件 /lib/modules/$VERSION/build/,其中$ VERSION是 uname -r 命令的输出。例如,如果命令uname -r产生输出3.9-1-amd64,则必须存在/lib/modules/3.9-1-amd64/build/,否则需要安装内核开发模块:
yum install kernel-devel kernel-headers
如果发现内核版本不对,需更新内核或指定安装统一的版本!
成功编译模块将产生文件xt_RTPENGINE.ko。可以通过以下方式手动将模块插入正在运行的内核中insmod xt_RTPENGINE.ko(如果未加载依赖的模块,例如x_tables模块,则会导致错误),但是建议将模块复制到/lib/modules/$VERSION/updates/,然后再运行depmod -a。之后,可以通过发出加载模块modprobe xt_RTPENGINE。
cd ../kernel-module/
make
cp *.ko /lib/modules/$VERSION/updates/
depmod -a
modprobe xt_RTPENGINE
/usr/local/src/rtpengine-master/daemon/rtpengine -p /var/run/rtpengine.pid -i priv/192.168.1.197 -i pub/121.52.224.150 -n 192.168.1.197:60000 -c 192.168.1.197:60001 -m 16000 -M 40000 -f -E -L 3
命令参数:-p 写pid文件 -i 命名名称/监听网络界面 -n ng监听地址 -c 客户端监听地址 -m 最小端口 -M 最大端口 -f 前端输出,不进入后台运行 -E 错误信息直接打印不写日志 -L log等级