首先安裝前,你已經對kamailio的基本用法了解。可根據情況選擇安裝方式,本次安裝基於Ubuntu18.04系統安裝,對於16.04及一下會遇到版本問題,請自己查閱文檔解決
安裝第三方庫
sudo apt-get install gcc flex bison libmysqlclient-dev make libcurl4-openssl-dev libxml2-dev libpcre3-dev libncurses5-dev libreadline6 libreadline-dev e2fsprogs-dev uuid-dev libuuid-dev
確保數據庫安裝成功
第一種
可直接通過sudo apt-get install kamailio安裝
配置
修改/etc/kamailio/kamctlrc,配置mysql kamdbctl create創建mysql數據庫
指定log
修改/etc/rsyslog.d/50-default.conf #*.*;auth,authpriv.none -/var/log/syslog #注釋掉這一行 *.*;auth,authpriv.none,local0.none -/var/log/syslog #新加行 if $syslogfacility-text=='local0' then -/var/log/kamailio.log #新加行 重啟 systemctl restart rsyslog
修改/etc/kamailio/kamailio.cfg 配置路由
啟動kamactl start
第二種下載源碼安裝
下載源碼包
http://www.kamailio.org/pub/kamailio/latest/src/
解壓
tar xvf kamailio-*_src.tar.gz
cd kamailio-*
執行下面指令生成modules.list文件
make FLAVOUR=kamailio cfg
進入modules.list找到"exclude_modules",將等號后面的db_mysql刪除(這里可以根據自己的需要調整編譯的模塊)。然后執行如下指令編譯
執行指令安裝
make all
sudo make install
執行過程中如果報錯根據提示慢慢解決
啟動文件在 /etc/local/sbin下 配置文件在 /usr/local/etc/kmailio下
配置
打開/usr/local/etc/kamailio/kamailio.cfg,添加下面幾行(添加在最頂端即可):
#!define WITH_MYSQL #!define WITH_AUTH #!define WITH_USRLOCDB #!define WITH_NAT #!define WITH_DEBUG
修改 /usr/local/etc/kamailio/kamctlrc
掉SIP_DOMAIN前的注釋,並且修改成自己的服務器地址192.168.1.111(根據自己服務器的實際情況來寫),我的是SIP_DOMAIN=192.168.1.111。然后去掉DBENGINE=MYSQL前的注釋語句,選定mysql數據庫,其他的按照如下內容來修改:
# cat /usr/local/etc/Kamailio/kamctlrc # $Id$ # 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.1.111 ## 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=
生成kamailio的mysql數據庫
# /usr/local/sbin/kamdbctl create
啟動kamilio服務
# /usr/local/sbin/kamctl start
可能會出現“ERROR:PID file /var/run/kamailio/kamaillio.pid does not exist---Kamailio start failed"
這種種錯誤出現的原因是/var/run/路徑下沒有kamailio目錄,手動創建一個即可,但不要生成kamailio.pid文件。
然后再開啟服務試一下能否成功,如果還是不行,請按順序檢查如下內容:
(1)kamdbctlrc這個配置文件中的DBHOST處是否是127.0.0.1或者localhost,如果不是請將其修改成127.0.0.1或者localhost試試。
(2)執行“kamailio -c”來檢測配置文件是否有錯誤,如果有報錯,請根據具體報錯信息解決問題。如果出現“config file ok,exiting......”,說明配置文件沒有問題了。
(3)執行“kamailio -dddd”,看是否有ERROR輸出,若有,請依據錯誤提示進行修改。
注冊sip賬號
#kamctl add user1 123456 #kamctl add user2 123456
測試kamailio服務
