在CentOS 7上从源代码安装Kamailio SIP代理服务器
本文介绍如何在CentOS 7服务器上从源代码安装Kamailio SIP代理服务器。
使用repo进行安装的缺点是我们将永远无法获得最新版本的Kamailio SIP服务器。如果要在服务器上获取最新版本的Kamailio,请考虑从源文件构建Kamailio SIP服务器。
设置准备工作
运行CentOS 7服务器MariaDB数据库服务器
确保服务器已更新:
sudo yum -y update sudo reboot
然后安装MariaDB数据库服务器。
sudo yum install mariadb-server
现在启动并启用MariaDB数据库服务,并使其在启动时运行:
sudo systemctl enable --now mariadb
设置用于登录的MariaDB超级用户密码:
sudo mysql_secure_installation
它将要求我们设置root密码并禁用远程root登录:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
在CentOS 7中从源代码安装Kamailio SIP代理服务器
如果我们不使用SELinux,则可以考虑将其设置为"允许"模式:
sudo sed -i 's/(^SELINUX=).*/SELINUX=permissive/' /etc/selinux/config
如果我们事先安装了Kamailio,尤其是从存储库中安装了Kamailio,请彻底删除:
sudo su find/-name "kamai*" -print0 | xargs -0 /bin/rm -rf
然后删除旧数据库:
$mysql -u root -p MariaDB [(none)]> SHOW DATABASES; If there's a database called kamailio,drop it: MariaDB [(none)]> DROP DATABASE kamailio; MariaDB [(none)]> EXIT
安装以下必需的依赖项:
sudo yum -y install epel-release sudo yum groupinstall "Development Tools" sudo yum install bison pcre-devel libpcap-devel flex git libevent json* libunistring-devel webkitgtk3-devel perl librabbitmq mariadb-devel libevent-devel librabbitmq-devel perl-devel mod_perl-devel perl-Encode-devel perl-Qt-devel perl-Glib-devel perl-Tk-devel
从github下载最新版本的Kamailio并安装。
sudo su cd /usr/src/ git clone git://git.sip-router.org/kamailio kamailio cd kamailio/
在安装Kamailio时启用默认情况下未编译的模块,这些是我编译时使用的模块:
sudo make include_modules="db_mysql dialplan websocket debugger permissions usrloc dispatcher registrar uuid sdpops presence auth auth_db avp tm presence_mwi outbound sl maxfwd nat xhttp helper kazoo db_text textops siputils uac presence_dialoginfo kex uac_redirect xlog sanity htable rr pv app_perl path ctrl tls ctl mi_fifo dmq dialog avpops textopsx tmx presence_xml" cfg
输出:
make -C src/cfg target architecture <x86_64>, host architecture <x86_64> make[1]: Entering directory `/usr/src/kamailio/src' making config... rm -f modules.lst make --no-print-directory modules.lst saving modules list... make[1]: Leaving directory `/usr/src/kamailio/src'
编译Kamailio:
sudo make all
安装Kamailio:
sudo make install
与kamailio相关的所有二进制文件和可执行脚本都安装在:
$ls /usr/local/sbin/kam*
每个的解释:kamdbctl数据库命令行控制和管理实用程序。kamailio Kamailio SIP服务器守护程序application.kamctl用于管理Kamailio SIP服务器的命令行实用程序kamcmd调用Kamailio RPC函数的Unix工具
安装的Kamailio模块位于:/usr/local/lib64/kamailio/modules /
$ls /usr/local/lib64/kamailio/modules/
查看我所有模块的屏幕截图。
打开Kamailio配置文件:
sudo vi /usr/local/etc/kamailio/kamailio.cfg
在#!KAMAILIO行之后添加以下行。
#!define WITH_MYSQL #!define WITH_AUTH #!define WITH_USRLOCDB #!define WITH_NAT #!define WITH_PRESENCE #!define WITH_ACCDB #!define WITH_VOICEMAIL #!define WITH_PSTN
在/etc/default /目录中创建默认的kamailio文件。
sudo tee /etc/default/kamailio<<EOF RUN_KAMAILIO=yes USER=kamailio GROUP=kamailio SHM_MEMORY=64 PKG_MEMORY=8 PIDFILE=/var/run/kamailio/kamailio.pid CFGFILE=/usr/local/etc/kamailio/kamailio.cfg #DUMP_CORE=yes EOF
添加Kamailio用户和组:
sudo groupadd -g 5000 kamailio sudo useradd -u 5000 -g 5000 -d /var/run/kamailio -M -s /bin/false kamailio
创建pid文件目录
sudo mkdir -p /var/run/kamailio sudo chown kamailio:kamailio -R /var/run/kamailio
创建Kamailio Systemd文件以启动和停止kamailio服务。
sudo tee /etc/systemd/system/kamailio.service<<EOF [Unit] Description=Kamailio SIP Proxy Server After=syslog.target network.target mariadb.service [Service] Type=forking EnvironmentFile=-/etc/default/kamailio PIDFile=$PIDFILE # ExecStart requires a full absolute path ExecStart=/usr/local/sbin/kamailio -P $PIDFILE -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY -u $USER -g $GROUP ExecStopPost=/bin/rm -f $PIDFILE Restart=on-abort [Install] WantedBy=multi-user.target EOF
编辑文件kamctlrc以设置数据库引擎
$sudo vi /usr/local/etc/kamailio/kamctlrc DBENGINE=MYSQL
创建kamailio使用的数据库:
sudo /usr/local/sbin/kamdbctl create
我们已完成安装Kamailio SIP代理服务。通过以下方式启动:
sudo systemctl daemon-reload sudo systemctl start kamailio sudo systemctl enable kamailio
确认服务状态:
$sudo systemctl status kamailio ● kamailio.service - Kamailio SIP Proxy Server Loaded: loaded (/etc/systemd/system/kamailio.service; disabled; vendor preset: disabled) Active: active (running) since Sun 2017-05-03 16:31:49 UTC; 10s ago Process: 18887 ExecStopPost=/bin/rm -f (code=exited, status=0/SUCCESS) Process: 18907 ExecStart=/usr/local/sbin/kamailio -P $PIDFILE -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY -u $USER -g $GROUP (code=exited, status=0/SUCCESS) Main PID: 18909 (kamailio) CGroup: /system.slice/kamailio.service ├─18909 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai... ├─18913 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai... ├─18914 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai... ├─18915 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai... ├─18916 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai... ├─18917 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai... ├─18918 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai... ├─18919 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai... ├─18920 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai... ├─18921 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai... ├─18922 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai... ├─18923 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai... ├─18924 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai... ├─18925 /usr/local/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f /usr/local/etc/kamailio/kamailio.cfg -m 64 -M 8 -u kamailio -g kamai... ....