方法一:修改 /etc/hosts

在虚拟机上装了 CentOS5.5 服务器启动速度慢,特别是 sendmail,sendmail启动时,会进行DNS正向或反向查询,导致漫长等待,启动时要等很久。
经检查,其 hostname=LinuxName,IP地址为xxx.xxx.xxx.xxx。
再检查 /etc/hosts、/etc/resolv.conf 等,发现/etc/hosts中内容如下:

[root@linux1 ~]# vi /etc/hosts

 # Do not remove the following line, or various programs
 # that require network functionality will fail.
 127.0.0.1               localhost.localdomain localhost
 ::1             localhost6.localdomain6 localhost6
 xxx.xxx.xxx.xxx  LinuxName




将/etc/hosts内容改为:

127.0.0.1    loclahost.localdomain    localhost  LinuxName



然后重启 sendmail 或重启计算机。

sendmail启动时,绕过DNS查询,启动速度有了提升。




方法二:(同方法一,呵呵……)

在大部分Linux发行版本中,sendmail这个古老的邮件系统包是默认安装的,装完系统后,重启时,不少兄弟遇到在启动过程中,到了启动sendmail服务的时候就停止了,没有耐性和经验的朋友这时候可能会以为系统出故障或者系统没有装好,其实既不是系统出故障,一般也不是系统没有安装好,而是系统sendmail的时候在查询你设置的主机名的A记录或反向域名记录,由于全球9台DNS根系统都在美国,这个时候会去查询本机主机名对应的dns A记录,特别时你安装系统时设置的一些“奇怪”的主机名的时候,比如webserver等等之类的,这个时候sendmail会去做这个操作过程。

Apr 28 13:41:36 webserver sendmail[3494]: gethostby*.getanswer: asked for "webserver IN AAAA", got type "A"
 Apr 28 13:42:36 webserversendmail[3499]: gethostby*.getanswer: asked for "webserver IN AAAA", got type "A"
 Apr 28 13:43:37 webserver sendmail: sendmail startup succeeded
 Apr 28 13:43:37 webserver sm-msp-queue[3509]: gethostby*.getanswer: asked for "webserver IN AAAA", got type "A"



运气好,我的意思是你的“RP”好,呵呵,查询比较快,你感觉不到异样,“RP”不好,少则一到两分钟,多则四到五分钟,而且要命的是不报任何错误信息,这个时间大大超过了我们能忍受的“8s”时间了,心里承受力差的兄弟就要受煎熬了。
知道了问题的症结,就可以对症下药了,比如我们可以修改系统配置文件/etc/hosts 和/etc/resolv.conf
让sendmial绕过查询远程主机,这里给出一种最简单的方法,给主机设置一个别名

修改/etc/hosts

[root@linux1 ~]# vi /etc/hosts

 # Do not remove the following line, or various programs
 # that require network functionality will fail.
 127.0.0.1               localhost.localdomain localhost
 ::1             localhost6.localdomain6 localhost6
 xxx.xxx.xxx.xxx  LinuxName



将/etc/hosts内容改为:

127.0.0.1    loclahost.localdomain    localhost  LinuxName



再次重新启动sendmail看看

[root@linux1 ~]# service sendmail restart

 Shutting down sm-client: [ OK ]
 Shutting down sendmail: [ OK ]
 Starting sendmail: [ OK ]
 Starting sm-client: [ OK ]



启动时间已经变短了。



方法三:(与方法一和方法二略有不同)

Starting sendmail:
 Starting sm-client:



原因就是sendmail和sm-client都是MTA,只认网络主机名,如admin.slyar.com这样的,解决办法如下:

1.修改 /etc/sysconfig/network 下的主机名为网络主机名 Slyar.localdomain

[root@linux1 ~]# vi /etc/sysconfig/network


centos6 dnf centos6 dnf启动慢_主机名


2.修改 /etc/hosts 下的主机名为网络主机名 Slyar.localdomain


[root@linux1 ~]# vi /etc/hosts


centos6 dnf centos6 dnf启动慢_主机名_02



3.重新启动系统,以后就不会出现速度慢的情况了。



[root@linux1 ~]# reboot