学习资料之Kaimailio and rtpengine安装使用

Kaimailio and rtpengine安装使用

1.Kamailio编译安装使用

1.1kamailio安装前准备:git, gcc, g++

1.1.1可直接从镜像源安装:

   yum install pkg-config
   yum install nasm
   yum install libgnomeui-devel
   yum install openssl-devel
   yum install libevent2-devel
   yum install pcre-devel
   yum install xmlrpc-c-devel
   yum install iptables-devel
   yum install epel-release.noarch
   yum install json-glib-devel
   yum install libpcap-devel
   yum install flex
   yum install bison
   yum install libcurl-devel.x86_64
   yum install libxml2-devel.x86_64

1.1.2 安装hiredis

从网站https://pkgs.org/download/hiredis下载以下两个包并安装:
rpm -ivh hiredis-last-0.13.3-1.el7.remi.x86_64.rpm
rpm -ivh hiredis-last-devel-0.13.3-1.el7.remi.x86_64.rpm

1.1.3安装mysql5.7

1.1.3.1下载并添加存储库

	sudo yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

1.1.3.2安装MySQL 5.7包

若无法安装,参考1.1.4手动下载rpm包安装
	yum install mysql-community-server
	yum install mysql-community-devel.x86_64

1.1.3.3 启动mysql

1.1.3.4 修改mysql 配置文件

		在/etc/my.cnf 末尾
		default-storage-engine=MyISAM
	sudo systemctl enable mysqld
	sudo systemctl start mysqld

1.1.3.5 从文件中查找到mysql登录初始密码

	sudo grep 'temporary password' /var/log/mysqld.log

1.1.3.6 运行mysql_secure_installation安装

随后输入1.1.3.4步骤显示的密码,随后会要求重新输入新密码,必须按要求输入(大小写字母,特殊符号)

1.1.3.7 登录mysql

	mysql -u root -p

1.1.3.8将密码修改成简单密码

方便后面调试登录mysql后,输入:
	set global validate_password_policy=0;
	use mysql;
	update user set authentication_string=password(‘12345678’) where user='root';
	flush privileges;

1.1.4 手动下载rpm包安装mysql

1.1.4.1 卸载系统自带的 mariadb-lib

[root@centos-linux ~]# rpm -qa|grep mariadb
 mariadb-libs-5.5.44-2.el7.centos.x86_64 
[root@centos-linux ~]# rpm -e mariadb-libs-5.5.44-2.el7.centos.x86_64 --nodeps

1.1.4.2 下载mysql5.7.16 rpm安装包

官网最新的mysql安装包是mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar下载地址
[root@centos-linux ~]# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar
然后解压
 [root@linux_node_1 src]# tar -xvf mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar 

1.1.4.3 安装

依次执行(几个包有依赖关系,所以执行有先后)下面命令安装
rpm -ivh mysql-community-common-5.7.16-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.16-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.16-1.el7.x86_64.rpm

余下步骤与从1.1.3.3一致。

1.2获取kamailio源代码

mkdir -p /usr/local/src/kamailio-5.1
cd /usr/local/src/kamailio-5.1
git clone --depth 1 --no-single-branch https://github.com/kamailio/kamailio kamailio
cd kamailio
git checkout -b 5.1 origin/5.1

1.3编译

1.3.1 产生Makefile

	make cfg
	修改vim src/modules.lst:
		include_modules= db_mysql rtpproxy rtpengine
	若需要修改生成目录,使用:make PREFIX="/usr/local/kamailio-5.1" cfg

1.3.2 make && make install

1.3.3 安装在/usr/local/sbin有:

• kamailio - Kamailio SIP server
• kamdbctl - script to create and manage the Databases
• kamctl - script to manage and control Kamailio SIP server
• kamcmd - CLI - command line tool to interface with Kamailio SIP server
添加环境变量:
PATH=$PATH:/usr/local/sbin
export PATH
步骤1.3.2 编译生成的模块会安装在:
/usr/local/lib/kamailio/modules/

1.4生成数据库

1.4.1 修改文件:(可从配置文件夹直接拷贝)

	vim -w /usr/local/etc/kamailio/kamctlrc:

我列出我修改的部分,对应意思参照配置文件,还有部分列在附录“Kamailio配置文件修改部分”:
DBENGINE=MYSQL

DBHOST=localhost

DBPORT=5060

DBNAME=kamailio

DBRWUSER=“kamailio”

DBRWPW=“12345678”

DBROUSER=“kamailioro”

DBROPW=“12345678”

DBACCESSHOST=10.10.200.77
DBROOTUSER=“root”

DBROOTPW=“12345678”

CHARSET=“latin1”

RPCFIFOPATH="/var/run/kamailio/kamailio_rpc_fifo"

PID_FILE=/var/run/kamailio/kamailio.pid

1.4.2 生成数据库

	/usr/local/sbin/kamdbctl create
	按提示输入密码等即可

1.5修改启动kamailio服务的配置文件

可从配置文件夹直接拷贝

1.5.1 编辑配置文件

	 vi /usr/local/etc/kamailio/kamailio.cfg 

1.5.1.1 修改配置文件IP地址部分

		若从配置文件夹直接拷贝kamailio.cfg,在配置文件查找“10.10.200.77”和“192.168.200.77”,修改成主机上的两个网段的地址.可以忽略一下两个步骤
		若不拷贝文件,注意附录中“Kamailio配置文件修改部分”红色字体需要修改

1.5.1.2添加:(注意 “#” 不能少)

		#!define WITH_MYSQL
		#!define WITH_USRLOCDB
		#!define WITH_NAT
		因为1.4.1步骤修改了配置文件kamctlrc中的密码(DBRWPW、 DBROPW、DBROOTPW),所以对应修改kamailio配置文件的:(红色字体)
		#!ifndef DBURL
		#!define DBURL "mysql://kamailio:12345678@localhost/kamailio"
		#!endif

1.5.1.3:将该配置文件替换为

 注释#loadmodule “rtpproxy.so” ,添加loadmodule “rtpengine.so”
 注释modparam(“rtpproxy”, “rtpproxy_sock”, “udp:127.0.0.1:7722”)
添加modparam (“rtpengine”, “rtpengine_sock”, “udp:127.0.0.1:7722”)
 注释rtpproxy_manage(“co”);
添加rtpengine_manage(“codec-strip-all codec-transcode-PCMA codec-transcode-PCMU codec-transcode-G729”);
 注释rtpproxy_manage(“cor”);
添加rtpengine_manage(“codec-strip-all codec-transcode-PCMA codec-transcode-PCMU codec-transcode-G729”);

1.5.2 添加inid.d脚本

1.5.2.1 编辑kamailio.init

	将kamailio.init复制到/etc/init.d/,并重命名kamailioc
	p /usr/local/src/kamailio-5.1/kamailio/pkg/kamailio/centos/7/kamailio.init /etc/init.d/kamailio
	chmod 755 /etc/init.d/kamailio
	修改内容:
		KAM=/usr/local/sbin/kamailio
		KAMCFG=/usr/local/etc/kamailio/kamailio.cfg
		PROG=kamailio
		HOMEDIR=/var/run/$PROG
		PID_FILE=/var/run/$PROG/kamailio.pid
		LOCK_FILE=/var/lock/subsys/kamailio
		DEFAULTS=/etc/default/kamailio

1.5.2.4 编辑kamailio.sysconfig

复制kamailio.sysconfig 复制到 /etc/default/
cp /usr/local/src/kamailio-5.1/kamailio/pkg/kamailio/centos/7/kamailio.sysconfig  /etc/default/kamailio
修改RUN_KAMAILIO=yes,DUMP_CORE=yes

1.5.3 添加用户权限

添加pid文件:mkdir -p /var/run/kamailio
添加用户kamailio和用户组kamailio
groupadd kamailio  
adduser --system --gid kamailio --shell /bin/false --home-dir /var/run/kamailio kamailio 
set ownership to /var/run/kamailio
chown kamailio:kamailio /var/run/kamailio

2.编译安装rtpengine

2.1 所需的库

2.1.2 安装ffmpeg codec libraries

2.1.2.1准备文件

		    从https://www.ffmpeg.org获取源码
            从官网或者git clone git://git.videolan.org/x264.git获取x264源码
		    从 http://www.tortall.net/projects/yasm/releases/ 获取yasm

2.1.2.2:安装yasm

			./configure 
			make
			make install

2.1.2.3编译安装x264

			./configure --enable-shared  --enable-pic
			make
			make install

2.1.2.4 编译安装bcg729

		  从git clone https://github.com/BelledonneCommunications/bcg729.git 源码
		  	cmake3 . -DCMAKE_INSTALL_PREFIX=/usr/local/
		  	make && make install 
			export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH

2.1.2.5 编译安装libilbc

			从git clone https://github.com/TimothyGu/libilbc.git 获取源码
			执行安装
		  	cmake3 . -DCMAKE_INSTALL_PREFIX=/usr/local/
		  	make && make install 
			export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH

2.1.2.6 编译安装 amr (两个库)

			http://sourceforge.net/projects/opencore-amr/下载源码:
				opencore-amr-0.1.5.tar.gz,
				vo-amrwbenc-0.1.3.tar.gz

2.1.2.7 编译安装libgsm:

			http://www.quut.com/gsm/下载gsm源码
			编译前需要修改makefile,在第47行加上- fPIC,然后执行编译即可
			cp ../gsm-1.0-pl18/lib/libgsm.a /usr/local/lib64/
			cp inc/* /usr/local/include/

2.1.2.9编译ffmpeg

./configure --enable-libx264 --disable-yasm --enable-shared --enable-gpl --enable-nonfree --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-libvo-amrwbenc --enable-version3 --extra-libs=-ldl
Make
make install
修改文件:/etc/ld.so.conf,在文件尾添加一行:/usr/local/lib,执行ldconfig
修改环境变量:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

2.2 编译rtpengine

2.2.1 获取源码

	git clone https://github.com/sipwise/rtpengine.git 

2.2.2 修改Makefile

	进入rtpengine/daemon目录,修改Makefile 
		在第47行添加:
			have_bcg729 := yes
			bcg729_inc := -I /usr/local/include/bcg729/
			bcg729_lib := -L /usr/local/lib64/ -lbcg729

2.2.3 编译rtpengine

			直接make 就可以生成可执行文件rtpengine

2.2.4 编译模块文件

			进入rtpengine/kernel-module目录,make编译.ko文件

2.2.5 编译依赖库文件

			进入rtpengine/ iptables-extension 目录,make编译libxt_RTPENGINE.so,拷贝到/usr/lib64/xtables/ 

2.3 运行rtpengine:

2.3.1 用户态运行

	在UDP	端口127.0.0.1:7722监听,执行ng协议,使用接口10.10.200.77,两个网卡的地址分别为10.10.28.131、192.168.28.131,线程数目为32个
	在rtpengine/daemon目录下
	./rtpengine -n 127.0.0.1:7722 --interface=pub/10.10.28.131 --interface=priv/192.168.28.131 --log-facility=local3 --num-threads=32 --tos=184

2.3.2 内核态运行

	在UDP	端口127.0.0.1:7722监听,执行ng协议,使用接口10.10.200.77
	在iptables/kernel-module加载模块:insmod xt_RTPENGINE.ko 
	使用iptables建立规则:(确保iptables下,表filter只有这两条)
		service iptables stop
		iptables -I INPUT -d 10.10.200.55 -p udp -j RTPENGINE --id 0
		iptables -I INPUT -d 192.168.200.55 -p udp -j RTPENGINE --id 0
	在rtpengine/daemon目录下运行rtpengine:
	./rtpengine -n 127.0.0.1:7722 --interface=pub/10.10.200.55 --interface=priv/192.168.200.55 --num-threads=32 --no-fallback --table=0 --tos=184

3.运行kamailio服务

3.1 kamctl start 启动服务

	没有错误信息,且查看端口5060有在监听,即使正常启动,若无启动,查看对应/var/log/messages的日志输出错误信息。

3.2 使用rtpengine模块工作

通过kamcmd使能rtpnegine模块:
Enables a RTPengine:
	kamcmd rtpengine.enable all 1 
Displays all the RTP proxies and their information:
	kamcmd rtpengine.show all
添加用户测试:
		现在就可以使用softphone注册用户,测试呼叫

4.附录

 安装kamailio http://kamailio.org/docs/tutorials/5.1.x/kamailio-install-guide-git/
 Rtpengine模块指南https://www.kamailio.org/docs/modules/stable/modules/rtpengine.html#idm1020019220
 https://github.com/sipwise/rtpengine github源码地址和相关介绍
 手动安装mysql :https://www.cnblogs.com/pythonal/p/6141516.html
 Opensips安装:https://www.jianshu.com/p/4f17429cfdcd
 Kamailio配置文件修改部分:


 RTPProxy control and signaling updates for NAT traversal
route[NATMANAGE] {
#!ifdef WITH_NAT
        if (is_request()) {
                if(has_totag()) {
                        if(check_route_param("nat=yes")) {
                                xinfo("setflag flb_natb");
                                setbflag(FLB_NATB);
                        }
                }
        }
        if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB))) return;

        if(nat_uac_test("8")) {
                xinfo("nat_uac_test true");
               rtpengine_manage("replace-origin replace-session-connection ICE=force");
                if (is_method("INVITE")) {
                        xinfo("is_method INVITE");
                        if (has_body("application/sdp")) {
                                xinfo("has_body application/sdp");
                                if($fd=="10.10.200.77"){
                                       if (rtpengine_offer("codec-strip-all codec-transcode-PCMA codec-transcode-PCMU codec-transcode-G729 replace-origin replace-session-connection direction=pub direction=priv ICE=force "))
                                                t_on_reply("1");
                                }
                                else if($fd=="192.168.200.77"){
                                        if (rtpengine_offer("codec-strip-all codec-transcode-PCMA codec-transcode-PCMU codec-transcode-G729 replace-origin replace-session-connection direction=priv direction=pub ICE=force "))
                                                t_on_reply("1");
                                }
                        } else {
                                xinfo("doesn't has_body application/sdp");
                                t_on_reply("2");
                        }
                }

                if (is_method("ACK") && has_body("application/sdp")){
                        xinfo("is_method ACK");
                        rtpengine_answer();
                }
        } else {
                xinfo("nat_uac_test false");
                rtpengine_manage();
        }

        if (is_request()) {
                if (!has_totag()) {
                        if(t_is_branch_route()) {
                                add_rr_param(";nat=yes");
                        }
                }
        }
        if (is_reply()) {
                if(isbflagset(FLB_NATB)) {
                        if(is_first_hop())
                                set_contact_alias();
                }
        }
#!endif
        return;
}

onreply_route[1]
{
    if (has_body("application/sdp"))
        rtpengine_answer();
}

onreply_route[2]
{
    if (has_body("application/sdp"))
        rtpengine_offer("codec-strip-all codec-transcode-PCMA codec-transcode-PCMU codec-transcode-G729 replace-origin replace-session-connection direction=priv direction=pub ICE=force ");
 }

总结: 这是本人工作时总结的,希望能帮到各位。
店铺地址:https://shop66907778.taobao.com/

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 1024 设计师: 上身试试
应支付0元
点击重新获取
扫码支付

支付成功即可阅读