大型网站集群构建之:DNS配置篇

来源:互联网 发布:中国的战争潜力 知乎 编辑:程序博客网 时间:2024/06/05 00:29
看了前面的应该知道,由于访问量大,地域分布广,这里假设使用了3加运营商介入,分别是网通,电信,还有一个其他接入方式。先分析一下网络情况,现在我们是3根线路接入,网络用户分别来自不同的地方,不同地方的线路速度是不同的,如果电信的用户一定要从网通的线路来访问我的站点那就会变得非常缓慢,所以第一个目的就是让电信的用户通过电信线路,网通的用户通过网通线路来访问,用户访问只是通过在浏览器中输入域名来访问,没有办法处理线路上的问题,而数据发出后经过N多路由到达我们的网站,路由会自动选择最经济路由,我们也没办法处理,那我们只有在域名上想想办法了。这里使用bind的view功能,配置也不复杂,作用就是根据ip的来源不同解析到不同的ip上去。
1、named.conf文件的配置
  配置named.conf,因为涉及到隐私问题,这里就不写实际地址了,用伪地址代替,下面涉及到的一些查询权限,zone传输,slave服务器配置等大家使用的时候根据实际情况修改。
  named.conf

  //
  //Samplenamed.confBINDDNSserver'named'configurationfile
  //fortheRedHatBINDdistribution.
  //
  //SeetheBINDAdministrator'sReferenceManual(ARM)fordetails,in:
  //file:///usr/share/doc/bind-*/arm/Bv9ARM.html
  //AlsoseetheBINDConfigurationGUI:/usr/bin/system-config-bindand
  //itsmanual.
  //
  options
  {
  /*makenameduseport53forthesourceofallqueries,toallow
  *firewallstoblockallportsexcept53:
  */
  query-sourceaddress*port53;
  //query-source-v6port53;
  //Putfilesthatnamedisallowedtowriteinthedata/directory:
  directory"/var/named";//thedefault
  dump-file"data/cache_dump.db";
  statistics-file"data/named_stats.txt";
  memstatistics-file"data/named_mem_stats.txt";
  datasize100M;
  allow-query{192.168.0.0/24;2xx.1xx.2xx.0/24;1xx.1xx.1xx.192/24;};
  };
  logging
  {
  /*Ifyouwanttoenabledebugging,eg.usingthe'rndctrace'command,
  *namedwilltrytowritethe'named.run'fileinthe$directory(/var/named).
  *Bydefault,SELinuxpolicydoesnotallownamedtomodifythe/var/nameddirectory,
  *soputthedefaultdebuglogfileindata/:
  */
  channeldefault_debug{
  file"data/named.run";
  severitydynamic;
  };
  };
  //
  //AllBIND9zonesareina"view",whichallowdifferentzonestobeserved
  //todifferenttypesofclientaddresses,andforoptionstobesetforgroups
  //ofzones.
  //
  //Bydefault,ifnamed.confcontainsno"view"clauses,allzonesareinthe
  //"default"view,whichmatchesallclients.
  //
  //Ifnamed.confcontainsany"view"clause,thenallzonesMUSTbeinaview;
  //soitisrecommendedtostartoffusingviewstoavoidhavingtorestructure
  //yourconfigurationfilesinthefuture.
  //
  acl"zero-transfer"{192.168.0.0/24;2xx.1xx.2xx.0/24;1xx.1xx.1xx.192/24;};
  acl"slave-updata"{192.168.0.0/24;2xx.1xx.2xx.0/24;1xx.1xx.1xx.192/24;};
  include"/etc/zone.conf";
  #-----------------------------------------#
  view"internal"{
  match-clients{127.0.0.1;};
  recursionno;
  zone"localhost"{
  typemaster;
  file"localhost.zone";
  };
  zone"0.0.127.IN-ADDR.ARPA"{
  typemaster;
  file"named.local";
  };
  };
  #-----------------------------------------#
  view"cnc"{
  match-clients{CNC;};
  match-destinations{any;};
  recursionyes;
  include"/etc/cnc.zones";
  include"/etc/cnc.local";
  };
  view"telecom"{
  match-clients{CHINANET;};
  match-destinations{any;};
  recursionyes;
  include"/etc/telecom.zones";
  include"/etc/telecom.local";
  };
  view"other"{
  match-clients{any;};
  match-destinations{any;};
  recursionyes;
  include"/etc/other.zones";
  include"/etc/other.local";
  };
  #-----------------------------------------#
  include"/etc/rndc.key";
  zone.conf:
  acl"CNC"{
  117.8.0.0/13;
  ……
  123.112.0.0/12;
  };
  acl"CHINANET"{
  222.222.0.0/15
  ……
  222.86.0.0/15
  };
  *.zones为正向解析配置文件,*.local为反向解析文件,同dns的标准配置。
  #-------------------------------------------#
  zone"."{
  typehint;
  file"/var/named/named.root";
  };
  #------------------------------------------#
  zone"56hr.com"IN{
  typemaster;
  file"cnc/xinyv.com.ndb";
  allow-query{any;};
  allow-transfer{zero-transfer;};
  allow-update{slave-updata;};
  };
  #-----------------------------------------#
  然后分别在不同的文件夹建立相应的ndb数据文件即可。
2、slavedns配置
  在配置dnsview的时候slavedns的配置要有一些小小的改动。named.conf除了allow-query一般设置any以外没有什么变化。主要是在*.zones中要制定同步用的源地址。
  cnc.zones
  #---------------------------------------#
  zone"."{
  typehint;
  file"/var/named/named.root";
  };
  #---------------------------------------#
  zone"56hr.com"IN{
  typeslave;
  file"cnc/xinyv.com.ndb";
  allow-query{any;};
  allow-transfer{zero-transfer;};
  transfer-source192.168.0.205;
  masters{192.168.0.204;};
  };
  #---------------------------------------#
  cnc.local
  #------------------------------------------#
  zone"58.112.202.in-addr.arpa"IN{
  typemaster;
  file"cnc/xinyv.com.local";
  allow-query{any;};
  allow-update{slave-updata;};
  allow-transfer{zero-transfer;};
  };
  大家可能发现我多了一个zone.conf文件,这个文件是那里来的呢?这个是用一个脚本产生出啦的。
  #!/bin/bash
  #Sourcefunctionlibrary.
  ./etc/init.d/functions
  [!-f/etc/sysconfig/network]&&exit1
  ./etc/sysconfig/network
  ["${NETWORKING}"="no"]&&exit0
  [-z$1]&&{echo"$0cnc$0chinanet";exit1;}
  FILE="/dev/shm/ip_apnic"
  rm-f$FILE
  echo"acl$1{">>_zone.conf
  wgethttp://ftp.apnic.net/apnic/stats ... latest-o/dev/null-O$FILE
  grep'apnic|CN|ipv4|'$FILE|awk-F'|''{print$4""$5}'|whileread_IP_MASK
  do
  MASK=$(cat<<EOF|bc|tail-1
  pow=32;
  definelog2(x){
  if(x<=1)return(pow);
  pow--;
  return(log2(x/2));
  }
  log2($_MASK)
  EOF)
  [email=whois$_IP@whois.apnic.net|grep^netname|uniq|sed-e]whois$_IP@whois.apnic.net|grep^netname|uniq|sed-e's/^netname://g'|grep-qi$1&&echo$_IP/$MASK\;>>/dev/shm/_zone.conf[/email]
  done
  echo"};">>_zone.conf
  这样dns服务器就算配置完了.

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hw_cncn/archive/2009/03/02/3949830.aspx
原创粉丝点击