目前最新版是2.7.1 ,可去其FTP下載:http://www.thekelleys.org.uk/dnsmasq/
安裝過程比較簡單
yum -y install dnsmasq* wget http://www.keepalived.org/software/keepalived-1.2.9.tar.gztar zxvf keepalived-1.2.9.tar.gzcd keepalived-1.2.9./configure --prefix=/usr/local/keepalivedmake && make installmkdir /etc/keepalivedcp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/chkconfig --add keepalivedchkconfig --level 35 keepalived on
keepalived的配置很簡單,只需要配置一個VIP可以在兩台Server之間飄來飄去就可以實現主備了
! Configuration File for keepalived global_defs { notification_email { xxx@xxx.com } notification_email_from xxx@xxx.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL} vrrp_instance dnscache { state MASTER // 另一台配置BACKUP interface eth1 // 在哪個介面上進行伺服器狀態檢測 virtual_router_id 51 priority 180 // BACKUP機器上配置100 advert_int 1 // 檢查間隔,單位為秒 authentication { auth_type PASS auth_pass 1234 } virtual_ipaddress { // VIP設定,指定到內網網卡 192.168.100.99/24 dev eth1 }}
dnsmasq的配置也很簡單
resolv-file=/etc/resolv.dnsmasq.confcache-size=1000conf-dir=/etc/dnsmasq.d
將dns地址寫入到/etc/resolv.dnsmasq.conf檔案中
echo "nameserver 8.8.8.8" > /etc/resolv.dnsmasq.conf
本機和區域網路其它全部的伺服器dns解析都用它
echo "nameserver 192.168.100.99" > /etc/resolv.conf
最後找一台區域網路Server驗證一下,如果能解析就說明正常了.
nslookup www.google.cn 192.168.100.99
此方案只適合小型企業,規模少的情況下使用,解析量大的時候還是用bind最好。
下面是其它網友的補充:
複製代碼 代碼如下:
sudo pacman -S --needed dnsmasq
cd /etc
[admin@huangye etc]$ sudo cp -v dnsmasq.conf{,.orig}
`dnsmasq.conf' -> `dnsmasq.conf.orig'
[admin@huangye etc]$ sudo vim dnsmasq.conf
相比來說,dnsmasq的配置簡單多了:
複製代碼 代碼如下:
resolv-file=/etc/dnsmasq.resolv.conf
addn-hosts=/etc/dnsmasq.hosts
local=/localnet/
no-dhcp-interface=eth0
conf-dir=/etc/dnsmasq.d
複製代碼 代碼如下:
[admin@huangye etc]$ sudo cp -v resolv.conf dnsmasq.resolv.conf
Password:
`resolv.conf' -> `dnsmasq.resolv.conf'
sudo mkdir /etc/dnsmasq.d
sudo touch /etc/dnsmasq.hosts
sudo /etc/rc.d/dnsmasq start
最後,別忘記加入rc.conf DAEMONS,注意要在network後面。
dnsmasq 可從額外的hosts檔案讀取條目,如可以這樣添加正向解析:
echo "IP地址 網域名稱" > /etc/dnsmasq.hosts
另外,重啟dnsmasq可以用SIGHUP(可以在修改hosts檔案後,讓配置生效)
killall -s SIGHUP dnsmasq
查看服務狀態:
netstat -tunl
tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN
udp 0 0 0.0.0.0:53 0.0.0.0:*
再dig 一下,發現穩定在4ms ,我暈,同樣的配置,我在一台ubuntu server 10.04 上面dig 是1ms ,在我本地居然在4ms ,囧