Oracle LISTENER 主机名修改为IP地址后LISTENER无法监听到实例 oracle监听错误与hosts文件配置

时间:2022-04-30 23:20:21

  为什么listener.ora文件里面HOST后面到底应该输入IP地址还是主机名。我的经验告诉我,这边最好使用主机名。很多的时候,一个机器绑定的不只一个IP地址,如HOST后面是IP地址,那么ORACLE的listener只会监听指定的IP地址的访问请求,本机其它IP地址的连接都会拒绝的。另外,创建监听的时候,listener.ora文件默认创建的就是主机名。那么,如果没有特别的需要,就不要再去画蛇添足的修改host_name为IP地址了。

.oratnsnames.ora文件中的HOST信息从原来的主机名字修改为IP地址后,监听可以启动,但是无论如何也监听不到数据库实例的信息(即使反复重启数据库)。

修改后重新启动监听,但是监听一直保持在如下的状态
LSNRCTL> status
Connecting 

to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=144.194.192.183)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date                21-JUL-2009 14:34:20
Uptime                    0 days 0 hr. 0 min. 36 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /oracle/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File         /oracle/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=144.194.192.183)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

.【问题原因】
罪魁祸首在/etc/hosts文件!!
先看一下在我处理之前该文件的内容:
[root@testdb ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1   testdb  localhost.localdomain   localhost
::1     localhost6.localdomain6 localhost6

在这种默认配置下(操作系统后的状态),主机名字和本机的IP地址没有对应起来.

.【问题解决】
1)将/etc/hosts内容修改为:
[root@testdb ~]# cat /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
144.194.192.183   testdb

比较一下与之前文件的不同,这里修改的内容如下:
1)将127.0.0.1后面的testdb主机名删除
2)添加IP地址和主机名对应关系144.194.192.183   testdb

通过ping主机名testdb的方式验证一下修改后的效果:
ora10g@testdb /home/oracle$ ping testdb
PING testdb (144.194.192.183) 56(84) bytes of data.
64 bytes from testdb (144.194.192.183): icmp_seq=1 ttl=64 time=0.082 ms
64 bytes from testdb (144.194.192.183): icmp_seq=2 ttl=64 time=0.047 ms
64 bytes from testdb (144.194.192.183): icmp_seq=3 ttl=64 time=0.050 ms
到此,主机名testdbIP地址144.194.192.183建立起了对应关系。

2)重新启动监听

oracle监听器启动错误-TNS-12546: TNS:permission denied

看下监听器状态

    oracle@linux-34:~> lsnrctl status  
      
    LSNRCTL for Linux: Version 11.1.0.6.0 - Production on 14-OCT-2011 09:12:37  
      
    Copyright (c) 1991, 2007, Oracle.  All rights reserved.  
      
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=linux-34.site)(PORT=1521)))  
    TNS-12541: TNS:no listener  
     TNS-12560: TNS:protocol adapter error  
      TNS-00511: No listener  
       Linux Error: 111: Connection refused  
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))  
    TNS-12541: TNS:no listener  
     TNS-12560: TNS:protocol adapter error  
      TNS-00511: No listener  
       Linux Error: 111: Connection refused  

启动下试试

    oracle@linux-34:~> lsnrctl start  
      
    LSNRCTL for Linux: Version 11.1.0.6.0 - Production on 14-OCT-2011 09:12:45  
      
    Copyright (c) 1991, 2007, Oracle.  All rights reserved.  
      
    Starting /home/oracle/product/11.1.0/db_1/bin/tnslsnr: please wait...  
      
    TNSLSNR for Linux: Version 11.1.0.6.0 - Production  
    System parameter file is /home/oracle/product/11.1.0/db_1/network/admin/listener.ora  
    Log messages written to /home/oracle/diag/tnslsnr/linux-34/listener/alert/log.xml  
    Error listening on: (ADDRESS=(PROTOCOL=ipc)(PARTIAL=yes)(QUEUESIZE=1))  
    No longer listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=linux-34.site)(PORT=1521)))  
    TNS-12546: TNS:permission denied  
     TNS-12560: TNS:protocol adapter error  
      TNS-00516: Permission denied  
       Linux Error: 13: Permission denied  
      
    Listener failed to start. See the error message(s) above...  

竟然报TNS-12546: TNS:permission denied
查看下 /var/tmp/.oracle/tmp/.oracle 这两个目录的权限访问。

    linux-34:~ # ls -lrtd /tmp/.oracle  
    drwxrwxrwx 2 root root 4096 May  9 16:01 /tmp/.oracle  
      
    linux-34:~ # ls -lrtd /var/tmp/.oracle  
    drwxr-xr-x 2 root root 4096 Oct 14 09:45 /var/tmp/.oracle  

原因应该就在这了,/var/tmp/.oracle755权限,把它修改为777
view plainprint?

    linux-34:~ # chmod -R 777 /var/tmp/.oracle 

================================================================

oracle监听错误与hosts文件配置

 ORACLE数据库的监听起不来报错,很快解决了。在这里记录一下遇到的问题,方便备查。在数据库listener.ora文件里面HOST后面到底应该输入IP地址还是主机名?很多人可能有不同的做法。我的经验是最好使用主机名。比如说,一个机器绑定的不只一个IP地址,你在HOST后面写的是IP地址,那么ORACLElistener只会监听指定IP地址的访问请求,本机其它IP地址的连接都会拒绝的。而且创建监听的时候,listener.ora文件默认创建的就是主机名。在listener.ora文件里HOST后面如果是主机名,那么就会与/etc/hosts这个文件扯上关系了。

这次出现的问题,就是因为研发人员不小心修改了主机名,而在/etc/hosts文件里又没有修改主机名和IP的对应造成的。
 我们看报错截图:

当你查找1521端口时发现PMON(缺省情况下,PMON TCP/IP 的缺省本地地址端口1521- 处的本地监听程序注册服务信息)
# netstat -antp | grep 1521
 tcp      0   1    192.168.1.252:36842         202.106.0.20:1521     SYN_SENT 28794/ora_pmon_orcl
检查202.106.0.20这个ip到底哪来的?
 在 /etc/hosts 里居然多了这条记录
202.106.0.20         wxtest
不知道是谁加上的,从来没有这个部署需求。先不管了,直接把这条语句注释掉
 重新启动数据库,重新启动监听,一切正常了!
 附图:
 

 

补充:/etc/hosts文件相关的几个错误。
1/etc/hosts文件oracle没有权限访问
 这时候oracle用户去启动监听会报如下错误
TNS-12545: Connect failed because target host or object does not exist
 TNS-12560: TNS:protocol adapter error
 TNS-00515: Connect failed because target host or object does not exist
Linux Error: 13: Permission denied

2/etc/hosts文件里面的主机名对应的IP地址没有正确在本机绑定
 这时候oracle用户去启动监听会报如下错误
TNS-12535: TNS:operation timed out
 TNS-12560: TNS:protocol adapter error
 TNS-00505: Operation timed out
 Linux Error: 110: Connection timed out