Linux下Sendmail慢卡问题的解决方法:dnscache配置使用全过程

来源:互联网 发布:淘宝开店要交多少钱 编辑:程序博客网 时间:2024/04/30 03:52

发大量的邮件的时候,DNS的解析速度将成为sendmail最大的瓶颈,尤其是在发一批DNS解析都非常慢的邮件服务器时。这种情况,可以通过安装DNS Cache来解决。下面记录一下自己根据网上搜出来的信息配置安装dnscache的过程。

 

Like any other piece of software (and information generally), djbdns comes with NO WARRANTY. Exception: See the djbdns security guarantee.

djbdns works only under UNIX. One UNIX flavor, SCO UnixWare, is not supported at this time.

Before installing djbdns, install daemontools 0.70 or above, and install ucspi-tcp.

------------------------------------------------------------------------------------------------

How to install daemontools

Like any other piece of software (and information generally), daemontools comes with NO WARRANTY.

System requirements

daemontools works only under UNIX.

Installation

Create a /package directory:

     mkdir -p /package     chmod 1755 /package     cd /package

Download daemontools-0.76.tar.gz into /package. Unpack the daemontools package:

     gunzip daemontools-0.76.tar     tar -xpf daemontools-0.76.tar     rm daemontools-0.76.tar     cd admin/daemontools-0.76

Compile and set up the daemontools programs:

 

(编译时会出现错误:cp: cannot stat `compile/svscan': No such file or directory

Although here is, as far as I know, no patches for daemontools and ucspi-tcp, the problem can be fixed by replacing
extern int errno;        with         #include <errno.h>     in the file error.h) 

     package/install

On BSD systems, reboot to start svscan.

To report success:

     mail djb-sysdeps@cr.yp.to < /package/admin/daemontools/compile/sysdeps

How to install ucspi-tcp

Like any other piece of software (and information generally), ucspi-tcp comes with NO WARRANTY. 

System requirements

ucspi-tcp works only under UNIX. 

Installation

Download the ucspi-tcp package. The latest published ucspi-tcp package is ucspi-tcp-0.88.tar.gz. 
Unpack the ucspi-tcp package: 
     gunzip ucspi-tcp-0.88.tar     tar -xf ucspi-tcp-0.88.tar     cd ucspi-tcp-0.88

Compile the ucspi-tcp programs:

 

(编译时会出现错误,同样replacing
extern int errno;        with         #include <errno.h>     in the file error.h) 

     make

As root, install the ucspi-tcp programs under /usr/local:

     make setup check

To report success:

     ( echo 'First M. Last'; cat `cat SYSDEPS` ) /     | mail djb-sysdeps@cr.yp.to

Replace First M. Last with your name.

-----------------------------------------------------------------------------------------

As you go through the installation and configuration process, please keep notes of exactly what you did and exactly what the computer did. Put the notes on your web pages, and include the URL with any questions that you send to the dns mailing list.

1. If you would like a local copy of these web pages, download the djbdns documentation package and unpack it under under /doc:

     gunzip < doc.tar.gz | (cd /; tar -xf -)

Then run slashdoc-merge to create indices such as /doc/commands.html.

2. Download the djbdns package. The latest published djbdns package is djbdns-1.05.tar.gz.

3. Unpack the djbdns package:

     gunzip djbdns-1.05.tar     tar -xf djbdns-1.05.tar     cd djbdns-1.05

4. Compile the djbdns programs:

     echo gcc -O2 -include /usr/include/errno.h > conf-cc     make

The first line, modifying conf-cc, is necessary for some Linux systems, to work around a Linux bug. It can be skipped under BSD, Solaris, and other systems that comply with IEEE Std 1003.1-1990.

5. As root, install the djbdns programs under /usr/local:

     make setup check

6. Report success:

     ( echo 'First M. Last'; cat `cat SYSDEPS` ) /     | mail djb-sysdeps@cr.yp.to

Replace First M. Last with your name.

-----------------------------------------------------------------------------------------

下面是使用root用户操作安装过程

#mkdir /var/service
#csh (或者exit退出再登陆,或者运行bash也可以)
#dnscache-conf nobody nobody /var/service/dnscache 127.0.0.1
#vi /etc/rc.conf 里加入 svscan_enable=”YES”

(reboot一下mail server?)
#/usr/local/etc/rc.d/svscan.sh start 启动服务,完成安装

 

下面检查服务启动情况
#netstat -anl |grep LISTEN
看看里面是否有53端口的监听服务,如果有就ok了
接着修改/etc/resolv.conf文件,把127.0.0.1加入到第一行,如下
nameserver 127.0.0.1
nameserver xx.xx.xx.xx (其他的公网的DNS)

 

这时测试一下效果
dig www.oklinux.cn

dig google.com mx (代表email?)

nslookup www.oklinux.cn
你会发现可能第一次稍微时间长一点,第二次反应时间都基本是0.001msec,这就是取到了本地的缓存,效果好的很!
接着测试了sendmail的大量并发发信,结果完全能满足中等网站的并发业务处理了!

 

-----------------------------------------------------------------------------------------

一般来说,DNS cache的值是以TTL来决定,
所以超过 TTL 还没更换 IP, 有可能是 nscd 这支程式有 cache IP

可重新启动 nscd 来达成清除 DNS cache 的效果 

# service nscd restart
Stopping nscd: [ OK ]
Starting nscd: [ OK ]
  
或是

# /etc/init.d/nscd restart
Stopping nscd: [ OK ]
Starting nscd: [ OK ]