今天在一台HPUX的机器上(以下称A机)无法连接另外一台机器(以下称B机)上的TimesTen服务,而原来是可以的。
先在B机上本地连接tt没有问题,再检查了A机tt的配置,也没有问题。但是运行ttisqlcs就是报错:
$ttisqlcs ds1
connect "DSN=ds1";
S1000: GetNodeName: nodename nor servname provided, or not known
The command failed.
又检查了一下A机tt的info目录下面的tterrors.log,里面有gethostbyname() failed字样,想想可能是主机名解析有问题,因此就检查/etc/hosts,还果真发现hosts里面有三个ip地址都对应到B机的主机名,因此就删掉了不对的两个,可惜,再试还是报同样的错。
无奈之下,重启A机上的TT服务(实际上我想这个没有关系,因为是连接远程的tt,只是死马当作活马医了),结果再ttstatus看的时候就无tt服务运行了:
No TimesTen server running
No TimesTen webserver running
检查tterrors.log,有如下内容:
11:35:43.02 Warn: : 27070: TimesTen Daemon Release 7.0.4.0.0.tt70 started.
2009-02-02 11:35:43.11 Err : SRV: 27075: EventID=33| Server is exiting. gethostbyname() failed. ListenAddr: test1; System error: 1
而执行ttisqlcs ds1还是和原来一样报错,并没有因为本机tt服务没起来而有所不同,这个也印证了上面本机服务和远程连接没有关系的想法。
为了验证是否gethostbyname有问题,写了如下一个小程序测试了一下:
#include <stdio.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <arpa/nameser.h>
#include <resolv.h>
main()
{
char sHostName[255];
memset(sHostName, 0x00, sizeof(sHostName));
if (gethostname(sHostName, sizeof(sHostName)) == -1)
{
printf("gethostname error/n");
return -1;
}
printf("hostname=%s/n",sHostName);
struct hostent *hp = gethostbyname(sHostName);
if (NULL == hp)
{
printf("herror=%d/n", h_errno);
herror("gethostbyname");
return -2;
}
}
保存为a.c
$cc -o a a.c
$./a
hostname=test1
herror=1
gethostbyname: Unknown host
确实和tterrors.log里面一样,系统错误号为1,主机名解析不到。但是hosts里面就几行,看来看去也看不出什么名堂。
google tt的报错信息"S1000: GetNodeName: nodename nor servname provided, or not known"根本没有结果。搜"S1000: GetNodeName"有两篇相关文章,不过都没有详细的解决的办法。
百思不得其解的时候,随便ping了一下本机主机名,晕,发现也不行:
$ping test1
ping: unknown host test1
$
再ping了一下hosts里面的其他主机,发现一个都不行。这说明域名解析根本就没用hosts里面的内容,由此想到可以在系统管理工具里面看看关于域名解析的系统配置。
运行sam(进去之后提示说sam已经过时了,现在用smh,真是很久没用hp的机器了)进入Networking and Communications,然后是Network Services Configuration,里面有很多东东,主要看了下面几个:
DNS (BIND)
Hosts
NIS
Name Service Switch
其中DNS里面配置了公司的dns服务器,应该没有问题。 Hosts里面就是/etc/hosts文件的内容,而NIS没启用。再看Name Service Switch下面,也是一堆:
Type of First Second Third Fourth
Information Source Source Source Source
aliases /etc/aliases NIS
automount Local Files NIS
group /etc/group NIS
hosts DNS NIS /etc/hosts
netgroup NIS /etc/netgroup
networks NIS /etc/networks
passwd /etc/passwd NIS
protocols NIS /etc/protocols
publickey NIS /etc/publickey
rpc NIS /etc/rpc
services NIS /etc/services
ipnodes DNS /etc/hosts
其中hosts那一行看起来和域名解析相关,进去瞧瞧,原来是搜索顺序的设置:
Search Order:
1. [ DNS ->]
If Information is Not Found: [ Stop Searching ->]
If Source is Not Configured: [ Try Next Source ->]
If Source is Not Responding: [ Stop Searching ->]
2. [ NIS ->]
If Information is Not Found: [ Stop Searching ->]
If Source is Not Configured: [ Try Next Source ->]
3. [ /etc/hosts ->]
4. [ none ->]
这样看来,/etc/hosts是排在第三,关键是那几个stop searching,看起来很有问题。全部改为Try Next Source,修改后还要重启机器,好在是测试机,重启就重启吧。
然后就是等,过了10几分钟才好,先ping了一下本机主机名test1,god,it's ok! 再ttisqlcs ds1,也连上了。哈哈,到此总算搞定了。
事后在/etc下面看了看,发现就是nsswitch.conf改变了:
nsswitch.conf内容:
hosts: dns [NOTFOUND=continue UNAVAIL=continue TRYAGAIN=continue] nis [NOTFOUND=continue UNAVAIL=continue TRYAGAIN=continue] files
nsswitch.conf.old内容:
hosts: dns [NOTFOUND=return UNAVAIL=continue TRYAGAIN=return] nis [NOTFOUND=return UNAVAIL=continue TRYAGAIN=continue] files
对HP机器配置熟悉的话,应该就可以直接修改此文件了。