ImageVerifierCode 换一换
格式:DOCX , 页数:15 ,大小:21.34KB ,
资源ID:10580780      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10580780.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(使用数据库保存Asterisk配置.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

使用数据库保存Asterisk配置.docx

1、使用数据库保存Asterisk配置在默认情况下,Asterisk的配置文件都保存在/etc/asterisk目录中,以ini文件的格式保存。我们也可以使用数据库来保存大多数Asterisk配置信息。Asterisk使用数据库保存配置信息有两种方法:静态和动态,对于不经常修改的配置数据,可以使用静态的方式保存,这些数据都是在Asterisk对应的模块加载时获取配置信息。动态方式适合那些经常变化的数据,例如SIP帐号信息。使用数据库来保存SIP帐号信息还有一个好处:Asterisk会自动把SIP帐号登录Asterisk的相关资料保存到表中,这样大大的方便了管理员检查当前SIP帐号的使用情况和状态。

2、下面开始介绍Asterisk的数据库获取配置的方法。我使用的是Asterisk版本是 11.0.0。在这里,我只对Asterisk的基本配置和SIP相关的配置感兴趣,AIX帐号的配置和SIP的配置应该类似,不想多作分析。1. 基本介绍1.1. 获取数据的方法配置信息可以保存在多种数据库中,下面是Asterisk支持的数据库的列表和对应的模块: odbc res_config_odbc sqlite res_config_sqlite pgsql res_config_pgsql curl res_config_curl ldap res_config_ldap为了通用性,我选择了ODBC作为获

3、得和修改Asterisk配置信息的方式,数据库使用mysql。在这里我不介绍如何安装unixODBC和mysql,只对相关的表和配置文件做介绍。1.2. 使用到的表结构1.2.1. 静态配置表CREATE TABLE ast_config ( id int(11) NOT NULL auto_increment, cat_metric int(11) NOT NULL default 0, var_metric int(11) NOT NULL default 0, commented int(11) NOT NULL default 0, filename varchar(128) NOT

4、NULL default , category varchar(128) NOT NULL default default, var_name varchar(128) NOT NULL default , var_val varchar(128) NOT NULL default , PRIMARY KEY (id), KEY filename_comment (filename,commented)这个表结构是一个通用的保存各种.conf文件信息的表结构。Asterisk可以让模块的配置信息保存在一个表中,或者分别保存在不同的表中。下面是表的说明Column nameColumn type

5、DescriptionidSerial, auto-incrementingAn auto-incrementing unique value for each row in the table.cat_metricIntegerThe weight of the category within the file. A lower metric means it appears higher in the file (see the sidebar ).context类型的权重var_metricIntegerThe weight of an item within a category. A

6、 lower metric means it appears higher in the list (see the sidebar ). This is useful for things like codec order in sip.conf, or iax.conf where you want disallow=all to appear first (metric of 0), followed by allow=ulaw (metric of 1), then allow=gsm (metric of 2).变量的权重filenameVarchar 128The filename

7、 the module would normally read from the hard drive of your system (e.g., musiconhold.conf, sip.conf, iax.conf, etc.).文件名categoryVarchar 128The section name within the file, such as general. Do not include the square brackets around the name when saving to the database.类型var_nameVarchar 128The optio

8、n on the left side of the equals sign (e.g., disallow is the var_name in disallow=all).名字var_valVarchar 128The value of an option on the right side of the equals sign (e.g., all is the var_val in disallow=all).值commentedIntegerAny value other than 0 will evaluate as if it were prefixed with a semico

9、lon in the flat file (commented out).注解1.2.2. SIP用户表SIP用户的存储方式在不同的Asterisk版本中差异很大,当看网上的文档的时候很容易犯迷糊,正确的表结构是在Asterisk源码包的下面目录中:rootkernel asterisk-11.0.0# ls contrib/realtime/mysql/sippeers.sql contrib/realtime/mysql/sippeers.sql具体的表结构是:# Table structure for table sippeers#CREATE TABLE IF NOT EXISTS s

10、ippeers ( id int(11) NOT NULL AUTO_INCREMENT, name varchar(10) NOT NULL, ipaddr varchar(15) DEFAULT NULL, port int(5) DEFAULT NULL, regseconds int(11) DEFAULT NULL, defaultuser varchar(10) DEFAULT NULL, fullcontact varchar(35) DEFAULT NULL, regserver varchar(20) DEFAULT NULL, useragent varchar(20) D

11、EFAULT NULL, lastms int(11) DEFAULT NULL, host varchar(40) DEFAULT NULL, type enum(friend,user,peer) DEFAULT NULL, context varchar(40) DEFAULT NULL, permit varchar(40) DEFAULT NULL, deny varchar(40) DEFAULT NULL, secret varchar(40) DEFAULT NULL, md5secret varchar(40) DEFAULT NULL, remotesecret varch

12、ar(40) DEFAULT NULL, transport enum(udp,tcp,udp,tcp,tcp,udp) DEFAULT NULL, dtmfmode enum(rfc2833,info,shortinfo,inband,auto) DEFAULT NULL, directmedia enum(yes,no,nonat,update) DEFAULT NULL, nat enum(yes,no,never,route) DEFAULT NULL, callgroup varchar(40) DEFAULT NULL, pickupgroup varchar(40) DEFAUL

13、T NULL, language varchar(40) DEFAULT NULL, allow varchar(40) DEFAULT NULL, disallow varchar(40) DEFAULT NULL, insecure varchar(40) DEFAULT NULL, trustrpid enum(yes,no) DEFAULT NULL, progressinband enum(yes,no,never) DEFAULT NULL, promiscredir enum(yes,no) DEFAULT NULL, useclientcode enum(yes,no) DEF

14、AULT NULL, accountcode varchar(40) DEFAULT NULL, setvar varchar(40) DEFAULT NULL, callerid varchar(40) DEFAULT NULL, amaflags varchar(40) DEFAULT NULL, callcounter enum(yes,no) DEFAULT NULL, busylevel int(11) DEFAULT NULL, allowoverlap enum(yes,no) DEFAULT NULL, allowsubscribe enum(yes,no) DEFAULT N

15、ULL, videosupport enum(yes,no) DEFAULT NULL, maxcallbitrate int(11) DEFAULT NULL, rfc2833compensate enum(yes,no) DEFAULT NULL, mailbox varchar(40) DEFAULT NULL, session-timers enum(accept,refuse,originate) DEFAULT NULL, session-expires int(11) DEFAULT NULL, session-minse int(11) DEFAULT NULL, sessio

16、n-refresher enum(uac,uas) DEFAULT NULL, t38pt_usertpsource varchar(40) DEFAULT NULL, regexten varchar(40) DEFAULT NULL, fromdomain varchar(40) DEFAULT NULL, fromuser varchar(40) DEFAULT NULL, qualify varchar(40) DEFAULT NULL, defaultip varchar(40) DEFAULT NULL, rtptimeout int(11) DEFAULT NULL, rtpho

17、ldtimeout int(11) DEFAULT NULL, sendrpid enum(yes,no) DEFAULT NULL, outboundproxy varchar(40) DEFAULT NULL, callbackextension varchar(40) DEFAULT NULL, timert1 int(11) DEFAULT NULL, timerb int(11) DEFAULT NULL, qualifyfreq int(11) DEFAULT NULL, constantssrc enum(yes,no) DEFAULT NULL, contactpermit v

18、archar(40) DEFAULT NULL, contactdeny varchar(40) DEFAULT NULL, usereqphone enum(yes,no) DEFAULT NULL, textsupport enum(yes,no) DEFAULT NULL, faxdetect enum(yes,no) DEFAULT NULL, buggymwi enum(yes,no) DEFAULT NULL, auth varchar(40) DEFAULT NULL, fullname varchar(40) DEFAULT NULL, trunkname varchar(40

19、) DEFAULT NULL, cid_number varchar(40) DEFAULT NULL, callingpres enum(allowed_not_screened,allowed_passed_screen,allowed_failed_screen,allowed,prohib_not_screened,prohib_passed_screen,prohib_failed_screen,prohib) DEFAULT NULL, mohinterpret varchar(40) DEFAULT NULL, mohsuggest varchar(40) DEFAULT NUL

20、L, parkinglot varchar(40) DEFAULT NULL, hasvoicemail enum(yes,no) DEFAULT NULL, subscribemwi enum(yes,no) DEFAULT NULL, vmexten varchar(40) DEFAULT NULL, autoframing enum(yes,no) DEFAULT NULL, rtpkeepalive int(11) DEFAULT NULL, call-limit int(11) DEFAULT NULL, g726nonstandard enum(yes,no) DEFAULT NU

21、LL, ignoresdpversion enum(yes,no) DEFAULT NULL, allowtransfer enum(yes,no) DEFAULT NULL, dynamic enum(yes,no) DEFAULT NULL, PRIMARY KEY (id), UNIQUE KEY name (name), KEY ipaddr (ipaddr,port), KEY host (host,port)看起来这个表字段很多很吓人,其实最近本的配置就下面几项: Name 帐号名字 Host 设置成dynamic Context 设置对应的context Type 选择frien

22、d Secret 帐号密码明文其他很多字段都是SIP帐号登录时的数据字段。1.3. 使用到的配置文件1.3.1. extconfig.conf最基本的配置文件是extconfig.conf,这个配置文件定义了哪些模块使用数据库的配置,确定了SIP帐号对应的表格。这个配置文件的注释已经基本介绍了它的使用方法,不过没有具体的表的结构。本文上面已经介绍了两个相关的表结构。其他表结构可以在Asterisk源码包的contrib/realtime/目录下找找。1.3.2. res_odbc.conf由于我选择了ODBC的数据库连接方式,所以必然的需要ODBC的资源配置。这个配置文件中,我使用了原来的配置

23、参数:asteriskenabled = yesdsn = asterisk如果是使用yum安装的unixODBC,Asterisk这个数据源在/etc/odbc.ini中定义。感觉就是:asteriskDriver = MySQLDatabase = asteriskServername = localhostUserName = rootPassword = xxxxx相关的设备在/etc/odbcinst.ini中定义:MySQLDescription = ODBC for MySQLDriver = /usr/local/lib/libmyodbc5.soSetup = /usr/lo

24、cal/lib/libmyodbc5w.soFileUsage = 11.3.3. Sip.conf在sip.conf中有一些和动态实时数据库配置相关的项,这些想对整个配置的实现影响不大,但是涉及是否建立内存缓存,影响性能。1.3.4. modules.conf这个文件是Asterisk加载模块的配置文件。要实现配置数据保存到数据库中,必须修改一下加载方法。下面是modules.conf中相应的注意事项:; Any modules that need to be loaded before the Asterisk core has been; initialized (just after

25、the logger has been initialized) can be loaded; using preload. This will frequently be needed if you wish to map all; module configuration files into Realtime storage, since the Realtime; driver will need to be loaded before the modules using those configuration; files are initialized.; An example o

26、f loading ODBC support would be:preload = res_odbc.sopreload = res_config_odbc.so任何模块想在Asterisk核心模块初始化之前加载,可以使用preload方式加载。实时驱动相关的模块需要在其他模块加载前加载,这样才能让其他模块使用数据库的配置信息。2. 静态配置在这里稍微介绍一个简单的静态配置例子,选择的模块是:musiconhold.conf。在配置静态配置文件之前,建议先看看extconfig.conf文件的下面内容:; The following files CANNOT be loaded from Re

27、altime storage:; asterisk.conf; extconfig.conf (this file); logger.conf; ; Additionally, the following files cannot be loaded from ; Realtime storage unless the storage driver is loaded ; early using preload statements in modules.conf:; manager.conf ; cdr.conf; rtp.conf; ; Named ACLs specified in re

28、altime also can not be used; from manager.conf unless the storage driver is preloaded.; Attempting to use a realtime stored named ACL before the; driver is loaded will result in an invalid ACL which; rejects all addresses.2.1. 删除配置文件$ cd /etc/asterisk$ mv musiconhold.conf musiconhold.conf.old2.2. 检查

29、模块加载情况*CLI core restart now*CLI moh show classes*CLI2.3. 插入数据记录INSERT INTO ast_config (filename,category,var_name,var_val) VALUES (musiconhold.conf,default,mode,files);INSERT INTO ast_config (filename,category,var_name,var_val) VALUES (musiconhold.conf,default,directory,/var/lib/asterisk/moh);asterisk=# SELECT filename,category,var_name,var_val FROM ast_config; filename | category | var_name | var_val-+-+-+- musiconhold.conf | default | mode | files musiconhold.conf | default | directory | /var/lib/asterisk/moh(2 rows)2.4. 设置extconfig.conf在extconfig.

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1