Kamailio Sip 会议服务搭建
在搭建Kamailio服务之前,请确保你已经安装了必要的依赖,如SIP proxy库(libkamailio)、数据库(如MySQL)、以及必要的编译工具(如make和gcc)。以下是一个简化的Kamailio服务器搭建流程:
- 安装数据库(如MySQL)和数据库驱动(如mysqlclient)。
- 安装Kamailio SIP代理软件。
- 配置Kamailio以连接数据库。
- 启动Kamailio服务。
以下是在基于UbuntuServer系统上的示例安装过程:
安装UbuntuServer
配置 SSH(非必要)
注:使用root登录后不用输入 sudo
sudo passwd root #配置root密码
Enter new UNIX password: #输入密码
Retype new UNIX password: #再次输入密码
passwd: password updated successfully #完成设置
编辑 /etc/ssh/sshd_config (非必要)
sudo nano /etc/ssh/sshd_config
找到 改成 PermitRootLogin yes (非必要)
ctrl+o 保存 回车
ctrl+x退出
reboot #重启一下服务器
给Server换源
注:使用root登录后不用输入 sudo
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup #备份源地址
sudo nano /etc/apt/sources.list #编辑sources.list文件
替换文件中的源地址为新的源。例如,使用阿里云的源:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
...
sudo apt update #更新软件列表
sudo apt upgrade #升级所有包
安装MySQL和数据库驱动
sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysqlclient-dev
安装Kamailio SIP代理软件
sudo apt-get update
sudo apt-get install kamailio kamailio-mysql-modules
mysql 5.7 设置root远程访问
登录mysql root用户
mysql -u root -p
输入root密码登录
执行以下语句:
mysql> use mysql;
mysql> GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'Zt33133...' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> exit;
以上步骤可能在mysql低版本上可行,如果还不能连接,继续下面操作
退出mysql,执行以下命令
vim /etc/mysql/mysql.conf.d/mysqld.cnf
找到bind-address=127.0.0.1,这一行,将其注释掉,即可
reboot #重启一下服务器
配置Kamailio以连接MySQL数据库
打开 /etc/kamailio/kamailio.cfg,添加下面几行(添加在最顶端即可)
#!define WITH_MYSQL
#!define WITH_AUTH
#!define WITH_USRLOCDB
打开 /etc/kamailio/kamctlrc,去掉SIP_DOMAIN前的注释,并且修改成自己的服务器地址192.168.15.16(根据自己服务器的实际情况来写),我的是SIP_DOMAIN=192.168.15.16。然后去掉DBENGINE=MYSQL前的注释语句,选定mysql数据库,其他的按照如下内容来修改:
# 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.
## your SIP domain
SIP_DOMAIN=192.168.15.16
## chrooted directory
# $CHROOT_DIR="/path/to/chrooted/directory"
## database type: MYSQL, PGSQL, ORACLE, DB_BERKELEY, or DBTEXT, 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 name (for ORACLE this is TNS name)
DBNAME=kamailio
# database path used by dbtext or db_berkeley
# 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
DBROUSER=kamailioro
## password for database read only user
DBROPW=kamailioro
## database super user (for ORACLE this is 'scheme-creator' user)
DBROOTUSER="root"
# 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="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"
# 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
# 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 userblacklist htable purple"
## type of aliases used: DB - database aliases; UL - usrloc aliases
## - default: none
# ALIASES_TYPE="DB"
## control engine: FIFO or UNIXSOCK
## - default FIFO
# CTLENGINE="FIFO"
## path to FIFO file
# OSER_FIFO="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"
## 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
## OPENSER START Options
## PID file path - default is: /var/run/Kamailio.pid
# PID_FILE=/var/run/kamailio/kamailio.pid
PID_FILE=/var/run/kamailio/kamailio.pid
## Extra start options - default is: not set
# example: start kamailio with 64MB share memory: STARTOPTIONS="-m 64"
# STARTOPTIONS=
建立MySQL数据库
sudo kamdbctl create
添加用户
sudo kamctl add 10001 123456
sudo kamctl add 10002 123456
重新启动kamctl
sudo kamctl stop
sudo kamctl start
确保替换user
, password
, host
, port
, 和 database
为你的数据库实际的连接信息。
使Kamailio服务开机自启
## 此方法应该是正确的,但是不知为何UbuntuServer下失效了
# 启动Kamailio服务
sudo systemctl start kamailio
# (可选)使Kamailio服务开机自启
sudo systemctl enable kamailio
创建一个sip.sh启动脚本赋予权限并且编辑sip.sh内容加入启动服务
sudo touch /sip.sh #创建脚本
sudo chmod 777 /sip.sh #赋予权限
sudo nano /sip.sh #编辑脚本
systemctl start kamailio #编辑sip.sh填入这行
#然后ctrl+o保存
#然后ctrl+x退出
输入 crontab -e
命令编辑crontab文件。添加这一行内容
@reboot sleep 50 && /sip.sh #在系统重启后,等待50秒后执行.
#然后ctrl+o保存
#然后ctrl+x退出
reboot #重启测试
注:使用root登录后不用输入 sudo