Linux DNS原始碼編譯安裝(五)

來源:互聯網
上載者:User

標籤:linux dns原始碼編譯安裝

DNS原始碼的編譯安裝、


官方bind:www.isc.org
這裡我們編譯的是bind-9.9.5.tar.gz版本


1、編譯環境
  Desktop Platform Development
  Development tools
  Server Platform Development


2、展開安裝包查看編譯命令
 首先我們應該先看下伺服器時間,
[[email protected] ~]# tar xf bind-9.9.5.tar.gz -----展開安裝包
[[email protected] ~]# cd bind-9.9.5
[[email protected] bind-9.9.5]# ls--------------進入解壓目錄查看檔案是否完全
acconfig.h    config.h.in        COPYRIGHT   isc-config.sh.1        make           version
aclocal.m4    config.h.win32     doc         isc-config.sh.docbook  Makefile.in    win32utils
Atffile       config.sub         docutil     isc-config.sh.html     mkinstalldirs
bin           config.threads.in  FAQ         isc-config.sh.in       README
bind.keys     configure          FAQ.xml     lib                    srcid
CHANGES       configure.in       HISTORY     libtool.m4             unit
config.guess  contrib            install-sh  ltmain.sh              util


[[email protected] bind-9.9.5]# ./configure --help--------------查看協助檔案
[[email protected] bind-9.9.5]# less README---------------bind的說明
因為DNS服務不是root使用者運行,我們要先建立使用者和組
[[email protected] bind-9.9.5]# groupadd -r -g 53 named
[[email protected] bind-9.9.5]# useradd -r -g named -u 53 named
[[email protected] bind-9.9.5]# id named
uid=53(named) gid=53(named) groups=53(named)


3、編譯
[[email protected] bind-9.9.5]# ./configure --prefix=/usr/local/bind9 --sysconfdir=/etc/named/ --enable-threads --disable-chroot --disable-ipv6
 命令解釋:
 --prefix=/usr/local/bind9 -------------指定安裝路徑
 --sysconfdir=/etc/named/---------------存放所有的設定檔
 --enable-threads----------啟用線程提高DNS運行效能
 --disable-chroot --disable-ipv6--------不啟用的一些應用根據自己的需要,自己在協助資訊中尋找
 
(1)修改PATH環境變數
 編譯使用新dig命令
  (1)
  [[email protected] bind9]# /usr/local/bind9/bin/dig -v-----------剛編譯的dig版本
  DiG 9.9.5
  [[email protected] bind9]# dig -v--------------原系統的dig版本
  DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6
  [[email protected] bind9]# vim /etc/profile.d/bind.sh------------在/etc/profile.d/建立bind.sh添加以下內容即可

  export PATH=/usr/local/bind9/bin:/usr/local/bind9/sbin:$PATH
  (2)
  測試:重新登入下查看
  [[email protected] ~]# echo $PATH
  /usr/lib64/qt-3.3/bin:/usr/local/bind9/bin:/usr/local/bind9/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/nginx/sbin:/root/bin
  [[email protected] ~]# dig -v
  DiG 9.9.5

 (2) 匯出協助手冊
  [[email protected] bind9]# man -M share/man/ named ------- -M指定路徑和要查看的named
  [[email protected] bind9]# man named----------------這樣是不能使用
  No manual entry for named
  [[email protected] bind9]# vim /etc/man.config -------在/etc/man.config添加找到
  MANPATH /usr/man
  MANPATH /usr/share/man
  MANPATH /usr/local/man
  MANPATH /usr/local/share/man
  MANPATH /usr/X11R6/man
  MANPATH /usr/local/bind9/share/man----------添加這一條即可:這裡的路徑是我們剛編譯儲存的路徑
  [[email protected] bind9]# man named------再次使用就能用了
  
 (3) 庫檔案和標頭檔的匯出-----編譯開放使用,匯出庫檔案
  [[email protected] bind9]# vim /etc/ld.so.conf.d/bind9.conf

2、提供設定檔/etc/named/named.conf
 
 (1)[[email protected] ~]# ls /etc/named-----我們查看named目錄下什麼都沒有,需要我們手動建立設定檔
  bind.keys
   [[email protected] ~]# vim /etc/named.conf
  options {
     directory "/var/named";
     recursion yes;
    };

   zone "." IN {-----------------必鬚根解析
     type hint;
     file "named.ca";
   };

   zone "localhost" IN {-------------本地解析
     type master;
     file "localhost.zone";
     allow-update { none; };
   };

   zone "0.0.127.in-addr.arpa"  IN {---------本地反向解析
     type master;
     file "127.0.0.zone";
     allow-update { none; };
   };
   zone "ning.com" IN {---------------添加自己想建立的域
                        type master;
                        file "ning.com.zone";
                        allow-transfer { 172.16.0.0/16; 127.0.0.1; };
      allow-update { none; };

   };
 (2)設定檔的許可權
  [[email protected] named]# chown root:named named.conf------主設定檔屬主組
  [[email protected] named]# chmod 640 named.conf--------主配置許可權
  [[email protected] named]# ll
  total 8
  -rw-r--r-- 1 root root  2389 Aug  3 11:57 bind.keys
  -rw-r----- 1 root named  326 Aug  3 12:25 named.conf
 (3)建立目錄檔案
  [[email protected] named]# mkdir /var/named/slaves -pv-----建立var/named/的目錄
  mkdir: created directory `/var/named/slaves‘
  [[email protected] var]# chown root:named /var/named----------屬主組
  [[email protected] var]# chown named:named /var/named/slaves/----------屬主組
  [[email protected] var]# chmod 750 /var/named------目錄許可權(為了安全只有root使用者有修改許可權)
  [[email protected] var]# chmod 770 /var/named/slaves/------目錄許可權(存放從庫設定檔必須給寫入權限)


3、建立name.ca、建立域庫設定檔localhost.zone、127.0.0.zone、ning.com.zone
 (1)建立name.ca、
 [[email protected] var]# dig -t NS . @a.root-servers.net > named.ca---找個可以上外網的伺服器,產生一個,輔助過來即可
 [[email protected] named]# ls /var/named-------放到這個目錄下即可
  named.ca  slaves
(2)建立域庫設定檔localhost.zone
  [[email protected] named]# vim localhost.zone
  $TTL 86400
  @       IN      SOA     localhost. admin.localhost. (
      2014080701
      3H
      15M
      7D
      1D )
    IN      NS      localhost.
    IN      A       127.0.0.1
 (3)建立域庫設定檔127.0.0.zone
   [[email protected] named]# vim 127.0.0.zone
  $TTL 86400
  @       IN      SOA     localhost. admin.localhost. (
      2014080701
      3H
      15M
      7D
      1D )
    IN      NS      localhost.
  1       IN      PTR     localhost.
 (4)建立域庫設定檔ning.com.zone
   [[email protected] named]# vim ning.com.zone
  $TTL 3600
  @       IN      SOA     ns.ning.com.    ning.qq.com. (
        2014080701
        1H
        10M
        7D
        1D )
    IN      NS      ns
  ns      IN      A       172.16.3.20
  www     IN      A       172.16.3.30
 (5)修改庫設定檔的許可權及屬主屬組
  [[email protected] named]# chown :named 127.0.0.zone localhost.zone named.ca ning.com.zone
  [[email protected] named]# chmod 640 127.0.0.zone localhost.zone named.ca ning.com.zone
  (6)檢查設定檔和庫檔案
  [[email protected] named]# named-checkconf  /etc/named/named.conf
  [[email protected] named]# named-checkzone "localhost" /var/named/localhost.zone
  zone localhost/IN: loaded serial 2014080701
  OK
  [[email protected] named]# named-checkzone "0.0.127.in-addr.arpa" /var/named/127.0.0.zone
  zone 0.0.127.in-addr.arpa/IN: loaded serial 2014080701
  OK
  [[email protected] named]# named-checkzone "ning.com" ning.com.zone
  zone ning.com/IN: loaded serial 2014080701
  OK


4、嘗試啟動緩衝名稱伺服器
 [[email protected] named]# named -u named -c /etc/named/nmaed.conf-------我們可以直接回合組態檔案(在後台運行)
 [[email protected] named]# named -g -u named -c /etc/named/named.conf ----- -g是運行在前台。
 [[email protected] named]# named -u named------直接啟動也可以

5、提供rndc
(1)產生並啟用
 [[email protected] named]# rndc-confgen -r /dev/urandom > /etc/named/rndc.conf------產生rndc.conf(-r 指定產生器,是為了避免熵池中沒有隨機數)
 [[email protected] named]# cat /etc/named/rndc.conf 把產生的檔案的下面指定的檔案複製到,named.conf中並去掉注釋即可。
  # Start of rndc.conf
  key "rndc-key" {
   algorithm hmac-md5;
   secret "lkMCAFCZUSJ1k4mM1cmrXg==";
  };

  options {
   default-key "rndc-key";
   default-server 127.0.0.1;
   default-port 953;
  };
  # End of rndc.conf

  # Use with the following in named.conf, adjusting the allow list as needed:
  # key "rndc-key" {------------------從這裡到下面標記的地方
  #  algorithm hmac-md5;
  #  algorithm hmac-md5;
  #  secret "+8TPqh0+bGqDH7JVk2w3+w==";
  # };
  #
  # controls {
  #  inet 127.0.0.1 port 953
  #
  # };------------------------到這裡你懂得,把這中間的內容複寫到named.conf並去掉注釋啟用起來
  # End of named.conf
  
 (2)修改rndc.conf檔案的許可權和屬主,並重讀named測試rndc命令
   [[email protected] named]#chmod 440 rndc.conf ---------修改許可權
   [[email protected] named]#chown :named rndc.conf -----------修改屬主
   [[email protected] named]# killall -HUP named------------重讀設定檔
   [[email protected] named]# rndc reload-----------測試重新載入設定檔和域庫資訊
   server reload successful
   [[email protected] named]# rndc stautes------------測試查看狀態


 6、提供一個需要的域
  我們上面已經添加了,網域名稱為ning.com,,這個大家應該都懂,,呵呵,我只是在上面就添加了,,
  你可以不在上面添加,,測試完緩衝網域名稱伺服器後,在這裡在添加測試就行了。


 7、提供啟動指令碼: 
  [[email protected] named]# service named start-----------但是還不能用service正常啟動服務
  named: unrecognized service
  
 啟動指令碼:
  
  #!/bin/bash
  #
  # description: named daemon
  # chkconfig: - 25 80
  #
  pidFile=/usr/local/bind9/var/run/named.pid
  lockFile=/var/lock/subsys/named
  confFile=/etc/named/named.conf

  [ -r /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions

  start() {
   if [ -e $lockFile ]; then
    echo "named is already running..."
    exit 0
   fi

   echo -n "Starting named:"
   daemon --pidfile "$pidFile" /usr/local/bind9/sbin/named -u named -c "$confFile"
   RETVAL=$?
   echo

   if [ $RETVAL -eq 0 ]; then
    touch $lockFile
    return $RETVAL
   else
    rm -f $lockFile $pidFile
    return 1
   fi
  }

  stop() {
   if [ ! -e $lockFile ]; then
    echo "named is stopped."
   # exit 0
   fi

   echo -n "Stopping named:"
   killproc named
   RETVAL=$?
   echo

   if [ $RETVAL -eq 0 ];then
    rm -f $lockFile $pidFile
    return 0
   else
    echo "Cannot stop named."
    failure
    return 1
   fi
  }

  restart() {
   stop
   sleep 2
   start
  }

  reload() {
   echo -n "Reloading named: "
   killproc named -HUP
   #killall -HUP named
   RETVAL=$?
   echo
   return $RETVAL
  }

  status() {
   if pidof named &> /dev/null; then
    echo -n "named is running..."
    success
    echo
   else
    echo -n "named is stopped..."
    success
    echo
   fi
  }

  usage() {
   echo "Usage: named {start|stop|restart|status|reload}"
  }

  case $1 in
  start)
   start ;;
  stop)
   stop ;;
  restart)
   restart ;;
  status)
   status ;;
  reload)
   reload ;;
  *)
   usage
   exit 4
   ;; 
  esac 
  #chmod +x /etc/rc.d/init.d/named-----給指令碼執行許可權。
  #chkconfig --add named-----添加named到啟動守護chkconfig中
  #chkconfig --list named-----查看狀態
  # chkconfig named on------------開機自動啟動
  #service named start------這裡就可以使用了
 [[email protected] named]# service named restart
 Stopping named:                                            [  OK  ]
 Starting named:                                            [  OK  ]
 

 
 
 
 庫配置還沒有完善,後續會跟上
 

本文出自 “奮鬥的人” 部落格,請務必保留此出處http://wodemeng.blog.51cto.com/1384120/1537227

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.