1. 介绍
kamailio是一款强大的开源的SIP信令服务器。通过一些简单的配置和参数设置即可进行使用,这里介绍在unbuntu-20.04 server版上的安装步骤。
2 安装
2.1 安装依赖
sudo apt install libssl-dev libmysqlclient-dev autoconf libcurl4-openssl-dev libxml2-dev libpcre3-dev
2.2 安装mysql
sudo apt install mysql-server
安装完毕之后,使用如下命令登录mysql,
mysql -u root
如果出现如下错误,
mindlinker@mindlinker:~$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
那么使用如下命令重启mysql,
sudo service mysql stop
sudo service mysql start
再次进行登录,如果出现如下错误:
mindlinker@mindlinker:~$ mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
那么需要重新设置一下参数,首先打开mysql的配置文件:
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
然后再后面追加一条信息:
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
character-set-server=utf8
collation-server=utf8_general_ci
skip-grant-tables <-- add here
然后重启mysql服务
service mysql restart
现在可以使用如下命令登录到mysql中,
mysql -u root -p
然后执行如下命令:
use mysql;
update user set authentication_string=password("你的密码") where user="root";
如果上述指令执行失败,那么请使用,请退出mysql,然后重启mysql,进入mysql,然后使用如下指令:
use mysql;
update user set authentication_string=password("ln122920"),plugin='mysql_native_password' where user='root';
如果上述指令依旧报错,那么可能是mysql版本的问题,再mysql8中,需要使用如下指令(请在重启mysql指令之后,进入mysql执行)。
use mysql;
flush privileges;
update user set plugin='mysql_native_password' WHERE user='root' AND host='localhost';
ALTER user 'root'@'localhost' IDENTIFIED BY 'newpassward';
执行完下面的第三条数据之后,可以使用命令select user, plugin from user;
查看是否修改完成,如果结果和下面一致,即可
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| debian-sys-maint | caching_sha2_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session | caching_sha2_password |
| mysql.sys | caching_sha2_password |
| root | mysql_native_password |
+------------------+-----------------------+
5 rows in set (0.00 sec)
上述指令执行的过程,可能出现如下错误,那么如果出现请重启mysql后再次进入继续执行那条命令
ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded
2.3 安装kamailio
2.3.1 下载kamailio源码
git clone --depth 1 --no-single-branch https://github.com/kamailio/kamailio kamailio
cd kamailio
git checkout -b 5.5 origin/5.5
执行如下命令,将会完成kamailio的编译和安装:
make PREFIX="/usr/local/kamailio-5.5" include_modules="db_mysql dialplan tls" cfg
make all
sudo make install
2.3.1 运行配置
如果完整按照上述进行安装,那么kamailio的文件将会安装在/user/local/kamailio-5.5
。为了运行kamailio,还需要做一些简单的配置。
首先使用命令sudo vi /usr/local/kamailio-5.5/etc/kamailio/kamctlrc
修改kamailio的控制配置文件为如下所示:
## The Kamailio configuration file for the control tools.
##
## Here you can set variables used in the kamctl and kamdbctl setup
## scripts. Per default all variables here are commented out, the control tools
## will use their internal default values.
## the SIP domain
SIP_DOMAIN=192.168.110.236 #宿主机的IP
## 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 kamdbctl, you must at least specify
## this parameter.
DBENGINE=MYSQL
## database host
DBHOST=localhost
## database port
# DBPORT=3306
## database name (for ORACLE this is TNS name)
DBNAME=kamailio
## database path used by dbtext, db_berkeley or sqlite
# DB_PATH="/usr/local/etc/kamailio/dbtext"
## database read/write user
DBRWUSER="kamailio"
## password for database read/write user
DBRWPW="kamailiorw"
## database read only user
DBROUSER="kamailioro"
## password for database read only user
DBROPW="kamailioro"
## database access host (from where is kamctl used)
# DBACCESSHOST=192.168.0.1
## database super user (for ORACLE this is 'scheme-creator' user)
DBROOTUSER="root"
## password for database super user
## - important: this is insecure, targeting the use only for automatic testing
## - known to work for: mysql
# DBROOTPW="dbrootpw"
## option to ask confirmation for all database creation steps
# DBINITASK=yes
## database character set (used by MySQL when creating database)
#CHARSET="latin1"
## user name column
USERCOL="username"
## SQL definitions
## If you change this definitions here, then you must change them
## in db/schema/entities.xml too.
## FIXME
# FOREVER="2030-05-28 21:32:15"
# DEFAULT_Q="1.0"
## Program to calculate a message-digest fingerprint
# MD5="md5sum"
## awk tool
# AWK="awk"
## gdb tool
# GDB="gdb"
## If you use a system with a grep and egrep that is not 100% gnu grep compatible,
## e.g. solaris, install the gnu grep (ggrep) and specify this below.
##
## grep tool
# GREP="grep"
## egrep tool
# EGREP="egrep"
## sed tool
# SED="sed"
## tail tool
# LAST_LINE="tail -n 1"
## expr tool
# EXPR="expr"
## 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
## If to install uid modules related tables.
# INSTALL_DBUID_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
## kamdbctl.base script.
## Kamailio standard modules
# STANDARD_MODULES="standard acc lcr domain group permissions registrar usrloc msilo
# alias_db uri_db speeddial avpops auth_db pdt dialog dispatcher
# dialplan"
## Kamailio extra modules
# EXTRA_MODULES="imc cpl siptrace domainpolicy carrierroute userblocklist htable purple sca"
## type of aliases used: DB - database aliases; UL - usrloc aliases
## - default: none
# ALIASES_TYPE="DB"
## control engine: RPCFIFO
## - default RPCFIFO
# CTLENGINE="RPCFIFO"
## path to FIFO file for engine RPCFIFO
# RPCFIFOPATH="/run/kamailio/kamailio_rpc.fifo"
## 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"
## check if user exists (used by some commands such as acl);
## - default on (1); off (0)
# VERIFY_USER=1
## 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
## Kamailio START Options
## PID file path - default is: /run/kamailio/kamailio.pid
PID_FILE=/run/kamailio/kamailio.pid
## Extra start options - default is: not set
## example: start Kamailio with 64MB share memory: STARTOPTIONS="-m 64"
# STARTOPTIONS=
然后在使用命令sudo vi /usr/local/kamailio-5.5/etc/kamailio/kamailio.cfg
修改kamailio的运行配置文件,修改内容主要是在这个文件的顶部增加如下参数:
#!define WITH_MYSQL
#!define WITH_AUTH
#!define WITH_USRLOCDB
#!define WITH_NAT
#!define WITH_DEBUG
然后使用命令kamdbctl create
,创建kamailio的数据库,如果命令运行过程中遇到如下提示
mindlinker@mindlinker:~$ kamdbctl create
MySQL password for root:
-e database engine 'mysql' loaded
-e \E[37;33mINFO: test server charset
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
-e \E[37;32mWARNING: Your current default mysql characters set cannot be used to create DB. Please choice another one from the following list:
-e armscii8
ascii
big5
binary
cp1250
cp1251
cp1256
cp1257
cp850
cp852
cp866
cp932
dec8
eucjpms
euckr
gb18030
gb2312
gbk
geostd8
greek
hebrew
hp8
keybcs2
koi8r
koi8u
latin1
latin2
latin5
latin7
macce
macroman
sjis
swe7
tis620
ujis
utf16
utf16le
utf32
-e Enter character set name:
输入utf16即可,后续全部Y即可。
3 运行kamailio
使用命令kamctl start
,即可运行kamailio,如果需要关闭kamailio,那么使用命令kamctl stop
即可。
在运行kamctl start
命令时如果遇到如下错误:
mindlinker@mindlinker:~$ kamctl start
-e database engine 'MYSQL' loaded
-e Control engine 'RPCFIFO' loaded
-e \E[37;33mINFO: Starting Kamailio :
-e \E[37;31mERROR: PID file /run/kamailio/kamailio.pid does not exist -- Kamailio start failed
这个问题实际上是kamailio的pid文件没有权限创建导致的,可以现在/run
目录下使用命令sudo mkdir kamailio
创建一个文件夹,然后使用命令sudo chown 当前用户名 /run/kamailio
,将文件夹权限转移到当前用户,这样操作完毕之后,即可解决该问题。
3.1 kamailio增加账号
按照上面的步骤可以运行kamailio之后,需要给kamailio添加账号,这样终端就可以使用这个账号来向kamailio服务器进行SIP注册了。
增加账号的命令如下:
kamctl add username password
添加完毕账号之后,就可以启动kamailio服务器,来进行操作。
更多推荐