Kamailio SIP Server + MySQL + Rocky Linux
MySQL 数据库
安装 mysql 模块
[root@netkiller ~]# dnf install -y kamailio-mysql
配置 kamailio
[root@netkiller ~]# cat /etc/kamailio/kamailio.cfg #!KAMAILIO # # Kamailio SIP Server v6.0 - default configuration script # - web: https://www.kamailio.org # - git: https://github.com/kamailio/kamailio # # Direct your questions about this file to: <sr-users@lists.kamailio.org> # # Refer to the Core CookBook at https://www.kamailio.org/wikidocs/ # for an explanation of possible statements, functions and parameters. # # Note: the comments can be: # - lines starting with #, but not the pre-processor directives, # which start with #!, like #!define, #!ifdef, #!endif, #!else, #!trydef, # #!subst, #!substdef, ... # - lines starting with // # - blocks enclosed in between /* */ # Note: the config performs symmetric SIP signaling # - it sends the reply to the source address of the request # - remove the use of force_rport() for asymmetric SIP signaling # # Several features can be enabled using '#!define WITH_FEATURE' directives: # # *** To run in debug mode: # - define WITH_DEBUG # - debug level increased to 3, logs still sent to syslog # - debugger module loaded with cfgtrace enabled # # *** To enable mysql: # - define WITH_MYSQL # # *** To enable authentication execute: # - enable mysql # - define WITH_AUTH # - add users using 'kamctl' or 'kamcli' # # *** To enable IP authentication execute: # - enable mysql # - enable authentication # - define WITH_IPAUTH # - add IP addresses with group id '1' to 'address' table # # *** To enable persistent user location execute: # - enable mysql # - define WITH_USRLOCDB # # *** To enable presence server execute: # - enable mysql # - define WITH_PRESENCE # - if modified headers or body in config must be used by presence handling: # - define WITH_MSGREBUILD # # *** To enable nat traversal execute: # - define WITH_NAT # - option for NAT SIP OPTIONS keepalives: WITH_NATSIPPING # - install RTPProxy: http://www.rtpproxy.org # - start RTPProxy: # rtpproxy -l _your_public_ip_ -s udp:localhost:7722 # # *** To use RTPEngine (instead of RTPProxy) for nat traversal execute: # - define WITH_RTPENGINE # - install RTPEngine: https://github.com/sipwise/rtpengine # - start RTPEngine: # rtpengine --listen-ng=127.0.0.1:2223 ... # # *** To enable PSTN gateway routing execute: # - define WITH_PSTN # - set the value of pstn.gw_ip # - check route[PSTN] for regexp routing condition # # *** To enable database aliases lookup execute: # - enable mysql # - define WITH_ALIASDB # # *** To enable speed dial lookup execute: # - enable mysql # - define WITH_SPEEDDIAL # # *** To enable multi-domain support execute: # - enable mysql # - define WITH_MULTIDOMAIN # # *** To enable TLS support execute: # - adjust CFGDIR/tls.cfg as needed # - define WITH_TLS # # *** To enable JSONRPC over HTTP(S) support execute: # - define WITH_JSONRPC # - adjust event_route[xhttp:request] for access policy # # *** To enable anti-flood detection execute: # - adjust pike and htable=>ipban settings as needed (default is # block if more than 16 requests in 2 seconds and ban for 300 seconds) # - define WITH_ANTIFLOOD # # *** To load htable module execute: # - define WITH_HTABLE # # *** To block 3XX redirect replies execute: # - define WITH_BLOCK3XX # # *** To block 401 and 407 authentication replies execute: # - define WITH_BLOCK401407 # # *** To enable VoiceMail routing execute: # - define WITH_VOICEMAIL # - set the value of voicemail.srv_ip # - adjust the value of voicemail.srv_port # # *** To enhance accounting execute: # - enable mysql # - define WITH_ACCDB # - add following columns to database #!ifdef ACCDB_COMMENT ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT ''; ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT ''; ALTER TABLE acc ADD COLUMN src_ip varchar(64) NOT NULL default ''; ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT ''; ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT ''; ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT ''; ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT ''; ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT ''; ALTER TABLE missed_calls ADD COLUMN src_ip varchar(64) NOT NULL default ''; ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT ''; ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT ''; ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT ''; #!endif ####### Include Local Config If Exists ######### import_file "kamailio-local.cfg" ####### Defined Values ######### # *** Value defines - IDs used later in config #!ifdef WITH_DEBUG #!define DBGLEVEL 3 #!else #!define DBGLEVEL 2 #!endif #!ifdef WITH_MYSQL # - database URL - used to connect to database server by modules such # as: auth_db, acc, usrloc, a.s.o. #!trydef DBURL "mysql://sip:13113668890@124.71.107.154/sip" #!endif #!ifdef WITH_MULTIDOMAIN # - the value for 'use_domain' parameters #!define MULTIDOMAIN 1 #!else #!define MULTIDOMAIN 0 #!endif #!ifdef WITH_ANTIFLOOD # - hash table 'ipban' used to store blocked IP addresses #!trydef WITH_HTABLE #!endif # - flags # FLT_ - per transaction (message) flags #!define FLT_ACC 1 #!define FLT_ACCMISSED 2 #!define FLT_ACCFAILED 3 #!define FLT_NATS 5 # FLB_ - per branch flags #!define FLB_NATB 6 #!define FLB_NATSIPPING 7 ####### Global Parameters ######### /* LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR, ... */ debug=DBGLEVEL /* set to 'yes' to print log messages to terminal or use '-E' cli option */ log_stderror=no memdbg=5 memlog=5 log_facility=LOG_LOCAL0 log_prefix="{$mt $hdr(CSeq) $ci} " /* number of SIP routing processes for each UDP socket * - value inherited by tcp_children and sctp_children when not set explicitely */ children=8 /* uncomment the next line to disable TCP (default on) */ # disable_tcp=yes /* number of SIP routing processes for all TCP/TLS sockets */ # tcp_children=8 /* UDP receiving mode: * - 0: multi-process (default) * - 1: multi-threaded with async worker group 'udp' * - 2: per socket configuration (see core cookbook) */ # async_workers_group="name=udp;workers=8" # udp_receiver_mode = 1 /* uncomment the next line to disable the auto discovery of local aliases * based on reverse DNS on IPs (default on) */ # auto_aliases=no /* add local domain aliases - it can be set many times */ alias="sip.netkiller.cn" /* listen sockets - if none set, Kamailio binds to all local IP addresses * - basic prototype (full prototype can be found in Wiki - Core Cookbook): * listen=[proto]:[localip]:[lport] advertise [publicip]:[pport] * - it can be set many times to add more sockets to listen to */ # listen=udp:10.0.0.10:5060 listen=udp:192.168.0.71:5060 advertise 139.19.54.21:5060 listen=tcp:192.168.0.71:5060 advertise 139.19.54.21:5060 /* life time of TCP connection when there is no traffic * - a bit higher than registration expires to cope with UA behind NAT */ tcp_connection_lifetime=3605 /* upper limit for TCP connections (it includes the TLS connections) */ tcp_max_connections=2048 /* upper limit for TCP connections for one ip address - default 1024 */ #tcp_accept_iplimit=1024 #!ifdef WITH_JSONRPC tcp_accept_no_cl=yes #!endif #!ifdef WITH_TLS enable_tls=yes /* upper limit for TLS connections */ tls_max_connections=2048 /* For OpenSSL 3 integration * functions calling libssl3 can be invoked in a transient thread * 0: disable threaded calls * 1: use thread executors for process #0 only * 2: no thread executors, but use atfork handler to reset thread-locals to NULL */ tls_threads_mode=2 #!endif /* set it to yes to enable sctp and load sctp.so module */ enable_sctp=no ####### Custom Parameters ######### /* These parameters can be modified at runtime via RPC interface * - see the documentation of 'cfg_rpc' module. * * Format: group.id = value 'desc' description * Access: $sel(cfg_get.group.id) or @cfg_get.group.id */ #!ifdef WITH_PSTN /* PSTN GW Routing * * - pstn.gw_ip: valid IP or hostname as string value, example: * pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address" * * - by default is empty to avoid misrouting */ pstn.gw_ip = "" desc "PSTN GW Address" pstn.gw_port = "" desc "PSTN GW Port" #!endif #!ifdef WITH_VOICEMAIL /* VoiceMail Routing on offline, busy or no answer * * - by default Voicemail server IP is empty to avoid misrouting */ voicemail.srv_ip = "" desc "VoiceMail IP Address" voicemail.srv_port = "5060" desc "VoiceMail Port" #!endif ####### Modules Section ######## /* set paths to location of modules */ # mpath="/usr/lib64/kamailio/modules/" # when using TLS with OpenSSL it is recomm