您好,登錄后才能下訂單哦!
源碼安裝bind
1.準備源碼包:
bind官網:http://www.isc.org/downloads/bind/
[root@dns1 ~]#ll -rw-r--r-- 1 root root 8356463 Dec 11 11:16 bind-9.10.1-P1.tar.gz
2.編譯環境正常,未安裝rpm的bind程序包
[root@dns1 ~]#yumgroupinstall Development tools [root@dns1 ~]#yumgroupinstall Server Platform Development [root@dns1 ~]# rpm-qa bind [root@dns1 ~]#
3.編譯安裝源碼包:
解壓源碼:
[root@dns1 ~]#tar jxf bind-9.10.1-P1.tar.gz [root@dns1 ~]#cd bind-9.10.1-P1 [root@dns1bind-9.10.1-P1]#
可以從中獲取幫助:
[root@dns1bind-9.10.1-P1]#./configure --help |less
編譯:設置安裝路徑,程序配置文件路徑,禁用Ipv6,禁用chroot,允許多線程
[root@dns1bind-9.10.1-P1]#./configure --prefix=/usr/local/bind --sysconfdir=/etc/named/ --disable-ipv6 --disable-chroot --enable-threads
我這里編譯出現了錯誤,依賴openssl-devel的包:
[root@dns1bind-9.10.1-P1]#yum install openssl-devel
重新編譯:
[root@dns1bind-9.10.1-P1]#./configure --prefix=/usr/local/bind --sysconfdir=/etc/named/ --disable-ipv6 --disable-chroot --enable-threads
安裝程序:
[root@dns1bind-9.10.1-P1]#make && make install
4.盡量加入系統用戶named來管理bind
[root@dns1 ~]#groupadd -r -g 53 named [root@dns1 ~]# useradd-r -g named -u 53 named
5.下面即將進行的步驟:
導出程序路徑至PATH中
導出幫助文件
導出庫文件和頭文件:
如果開發沒用使用其中的庫就不用導出
[root@dns1 ~]#ls /usr/local/bind/sbin/ arpaname dnssec-revoke lwresd named-rrchecker ddns-confgen dnssec-settime named nsec3hash dnssec-dsfromkey dnssec-signzone named-checkconf rndc dnssec-importkey dnssec-verify named-checkzone rndc-confgen dnssec-keyfromlabel genrandom named-compilezone tsig-keygen dnssec-keygen isc-hmac-fixup named-journalprint [root@dns1 ~]#ls /usr/local/bind/bin/ bind9-config delv dig host isc-config.sh nslookup nsupdate [root@dns1 ~]#vim .bash_profile PATH=$PATH:$HOME/bin:/usr/local/bind/bin:/usr/local/bind/sbin [root@dns1 ~]#source .bash_profile
6.源碼安裝是沒有任何配置文件和服務腳本的哦!
#ls/etc/named/ 主配置文件 #ls/var/named/ 區域解析庫文件 #ls/etc/rc.d/init.d 啟動腳本
我們自己來編寫配置文件和服務腳本哦!
[root@dns1 ~]#mkdir /var/named [root@dns1 ~]#cd /var/named
訪問一個能訪問的DNS獲取根區域文件:
[root@dns1named]# dig -t NS . @172.16.0.1 >/var/named/named.ca [root@dns1named]# ls named.ca
編輯好本地解析庫文件:
[root@dns1 named]# vim named.localhost $TTL 1D @ IN SOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H) ; minimum NS @ A 127.0.0.1
[root@dns1 named]#vi named.loopback $TTL 1D @ IN SOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H) ; minimum NS @ A 127.0.0.1 PTR localhost.
權限設置和設置屬組為named:
[root@dns1 named]# chmod 640 * [root@dns1 named]# chown :named * [root@dns1 named]# ll total 12 -rw-r----- 1 root named 2100 Dec 11 11:56named.ca -rw-r----- 1 root named 374 Dec 11 11:57 named.localhost -rw-r----- 1 root named 401 Dec 11 11:58 named.loopback
提供主配置文件:named.conf
先設置好rndc密鑰配置文件:
[root@dns1 named]# rndc-confgen -r /dev/urandom> /etc/named/rndc.conf
需要將rndc密鑰文件配置在named.conf文件中:
[root@dns1 named]# cat /etc/named/named.conf options { directory "/var/named"; }; zone "." IN { type hint; file "named.ca"; }; zone "localhost" IN { type master; file "named.localhost"; allow-update { none; }; }; zone "0.0.127.in-addr.arpa" IN { type master; file "named.loopback"; allow-update { none; }; }; # Use with the following in named.conf,adjusting the allow list as needed: key"rndc-key" { algorithm hmac-md5; secret "4a8/AsRRQ5OH5a0oRaBeAg=="; }; # controls{ inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; }; }; #End of named.conf
設置好文件的權限和屬組:
[root@dns1 named]# chmod 640 /etc/named/* [root@dns1 named]# chown :named /etc/named/* [root@dns1 named]# ll /etc/named/ total 12 -rw-r----- 1 root named 2389 Dec 11 11:29bind.keys -rw-r----- 1 root named 545 Dec 11 12:09 named.conf -rw-r----- 1 root named 479 Dec 11 12:01 rndc.conf
7.到這里我們其實可以啟動named服務了!
但是有些復雜,只說一些命令哦!
查看幫助文件
#ls /usr/local/bind9/share/man #man -M /usr/local/bind9/share/man named
前臺啟動,日志也在前臺記錄
[root@dns1 named]# named -u named –g
使其在后臺運行:
[root@dns1 named]# named -u named
查看啟動狀態:
[root@dns1 named]# ss -tunl |grep :53 udp UNCONN 0 0 172.16.31.100:53 *:* udp UNCONN 0 0 127.0.0.1:53 *:* tcp LISTEN 0 10 172.16.31.100:53 *:* tcp LISTEN 0 10 127.0.0.1:53 *:* tcp LISTEN 0 128 :::53887 :::* [root@dns1 named]# ps aux |grep named named 18870 0.0 1.1 13××× 11848 ? Ssl 12:23 0:00 named -u named root 18883 0.0 0.0 103252 824 pts/1 S+ 12:24 0:00 grep named
關閉named服務:
[root@dns1 named]# killall named [root@dns1 named]# ps aux |grep named root 18887 0.0 0.0 103252 824 pts/1 S+ 12:24 0:00 grep named
8.我們現在來實現加入區域:
[root@dns1 named]# vim /etc/named/named.conf zone "oracle.com" IN { type master; file "oracle.com.zone"; };
設置區域正向區域解析庫文件:
[root@dns1 named]#vim /var/named/oracle.com.zone $ORIGIN oracle.com. @ IN SOA ns.oracle.com. root.oracle.com. ( 2014121101 ;serial 1D ;refresh 5M ;retry 1W ;expiry 1H) ;minimum @ IN NS ns.oracle.com. IN MX 5 mail.oracle.com. ns IN A 172.16.31.100 www IN A 172.16.31.100 www IN A 172.16.31.101 mail IN A 172.16.31.100 pop3 IN CNAME mail iamp4 IN CNAME mail
設置好權限和屬組:
[root@dns1 named]# chmod 640 oracle.com.zone [root@dns1 named]# chown :named oracle.com.zone
啟動named服務:
[root@dns1 named]# named -u named
查看日志:
[root@dns1 named]# tail /var/log/messages Dec 11 12:33:41 dns1 named[18945]: automaticempty zone: 8.B.D.0.1.0.0.2.IP6.ARPA Dec 11 12:33:41 dns1 named[18945]: commandchannel listening on 127.0.0.1#953 Dec 11 12:33:41 dns1 named[18945]: the workingdirectory is not writable Dec 11 12:33:41 dns1 named[18945]:managed-keys-zone: loaded serial 0 Dec 11 12:33:41 dns1 named[18945]: zonelocalhost/IN: loaded serial 0 Dec 11 12:33:41 dns1 named[18945]:oracle.com.zone:2: no TTL specified; using SOA MINTTL instead Dec 11 12:33:41 dns1 named[18945]: zoneoracle.com/IN: loaded serial 2014121101 Dec 11 12:33:41 dns1 named[18945]: zone0.0.127.in-addr.arpa/IN: loaded serial 0 Dec 11 12:33:41 dns1 named[18945]: all zonesloaded Dec 11 12:33:41 dns1 named[18945]: running
可以查詢了:
[root@dns1 named]# dig -t A www.oracle.com@172.16.31.100 ; <<>> DiG9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6 <<>> -t A www.oracle.com@172.16.31.100 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY,status: NOERROR, id: 15903 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2,AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;www.oracle.com. IN A ;; ANSWER SECTION: www.oracle.com. 3600 IN A 172.16.31.101 www.oracle.com. 3600 IN A 172.16.31.100 ;; AUTHORITY SECTION: oracle.com. 3600 IN NS ns.oracle.com. ;; ADDITIONAL SECTION: ns.oracle.com. 3600 IN A 172.16.31.100 ;; Query time: 0 msec ;; SERVER: 172.16.31.100#53(172.16.31.100) ;; WHEN: Thu Dec 11 12:37:19 2014 ;; MSG SIZE rcvd: 97
成功了哦!
9.下面就可以進行服務啟動腳本的書寫了:
我們先將bind的幫助文件寫進/etc/man.config進行調用:
方便named服務啟動后生成pid文件:
[root@dns1 named]# chown named:named/usr/local/bind/var/run/ [root@dns1 named]# touch /var/lock/subsys/named [root@dns1 named]# touch /etc/rc.d/init.d/named [root@dns1 named]# chmod 755/etc/rc.d/init.d/named
[root@dns1 named]# vim /etc/rc.d/init.d/named #!/bin/bash # named a network name service. # chkconfig: 345 35 75 # description: a name server pidfile=/usr/local/bind/var/run/named/named.pid lockfile=/var/lock/subsys/named conffile=/etc/named/named.conf named=/usr/local/bind/sbin/named prog=named [ -r /etc/rc.d/init.d/functions ] && ./etc/rc.d/init.d/functions start() { if [ -e $lockfile ] ; then echo -n -e "$prog is already running.\n" warning echo -n -e \n exit 0 fi echo -n "Starting $prog:" daemon --pidfile $pidfile $named -u named -c $conffile tetval=$? echo if [[ $retval -eq 0 ]] ; then touch $lockfile return $retval else rm -f $lockfile $pidfile return 1 fi } stop() { if [ ! -e $lockfile ] ; then echo -n "$prog is stopped." warning echo exit 0 fi echo -n "Stopping $prog:" killproc $prog retval=$? echo if [[ $retval -eq 0 ]] ; then rm -f $lockfile $pidfile return 0 else echo "Can't stop $prog" return 1 fi } restart() { stop start } reload() { echo -n "Reload the $prog:" killproc -HUP $prog retval=$? echo return $retval } status() { if pidof $prog &>/dev/null; then echo -n "$prog is running." success echo else echo -n "$prog is stopped." success echo fi } usage() { echo "Usage:named {start|stop|status|reload|restart}" } case $1 in start) start;; stop) stop;; restart) restart;; status) status;; reload) reload;; *) usage exit 1 ;; esac
有個bug,warning函數會覆蓋前面的輸出
我懷疑是warning函數的問題!
就不管了o(∩_∩)o 哈哈
10.最后介紹一下DNS下面的壓力測試工具:queryperf
實際測試要考慮帶寬哦!
[root@dns1bind-9.10.1-P1]# ls contrib dane idn perftcpdns queryperf scripts zkt-1.1.2 dlz nslint-3.0a2 query-loc-0.4.0 README sdb [root@dns1bind-9.10.1-P1]# cd contrib/queryperf/ [root@dns1queryperf]# ls config.h.in configure.in Makefile.in queryperf.c utils configure input missing README
簡單編譯安裝:
[root@dns1 queryperf]# make root@dns1 queryperf]# ./configure
復制命令到bin下:
[root@dns1 queryperf]# cp queryperf /bin/
開始壓力測試:
queryperf [-d datafile] [-s server_addr] [-p port] [-qnum_queries] [-b bufsize] [-t timeout] [-n] [-l limit] [-f family] [-1] [-i interval] [-r arraysize] [-u unit] [-H histfile] [-T qps] [-e] [-D] [-R] [-c] [-v] [-h] 常用選項: -d datefile:選擇要解析域名集合的文件,對哪些區域進行測試 -s server_addr:指定壓力測試的服務器
我們需要建立一個解析域名集合的文件:
例如:
[root@dns1 ~]#vi test.txt www.oracle.com A mail.oarcle.com A oracle.com NS oracle.com MX pop3.oracle.com A iamp4.oracle.com A www.oracle.com A mail.oarcle.com A oracle.com NS oracle.com MX pop3.oracle.com A iamp4.oracle.com A
簡單測試一下哦!
[root@dns1 ~]# queryperf -d test.txt -s172.16.31.100 DNS Query Performance Testing Tool Version: $Id: queryperf.c,v 1.12 2007/09/0507:36:04 marka Exp $ [Status] Processing input data [Status] Sending queries (beginning with272.16.31.100) [Timeout] Query timed out: msg id 2 [Timeout] Query timed out: msg id 8 [Status] Testing complete Statistics: Parseinput file: once Endeddue to: reaching end of file Queriessent: 12 queries Queriescompleted: 12 queries Querieslost: 0 queries Queriesdelayed(?): 0 queries RTTmax: 0.004873 sec RTTmin: 0.000074 sec RTTaverage: 0.001751 sec RTT stddeviation: 0.001375 sec RTT outof range: 0 queries Percentage completed: 100.00% Percentage lost: 0.00% Startedat: Thu Dec 11 14:05:39 2014 Finished at: Thu Dec 1114:05:44 2014 Ranfor: 5.004047 seconds Queriesper second: 2.398059 qps
機器不咋的,處理的慢。
到這里源碼安裝Bind的介紹就結束了,shell腳本構建服務還是不熟練!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。