首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> Oracle 資料庫 >> Oracle 教學

Oracle 監聽器 lsnrctl 啟動報錯 TNS-12537/TNS-12560/TNS-00507 根因與解決

     編輯:Oracle 教學

Oracle 監聽器 lsnrctl 啟動報錯 TNS-12537/TNS-12560/TNS-00507 根因與解決

錯誤現場重現

[oracle@localhost ~]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 29-APR-2015 07:38:11
Starting /home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...
TNS-12537: TNS:connection closed
TNS-12560: TNS:protocol adapter error
Linux Error: 29: Illegal seek

根因分析

/etc/hosts 檔案中存在兩個 localhost 主機名條目,導致監聽器解析衝突。

典型錯誤配置:

127.0.0.1 localhost
::1 localhost          <-- IPv6 也指向 localhost,造成衝突

解決步驟

1. 修改主機名(臨時生效)

hostname oracle

2. 修改 /etc/hosts 映射

[root@oracle etc]# cat /etc/hosts
127.0.0.1 localhost
::1 oracle             <-- 將 IPv6 映射到新主機名

3. 修改 /etc/sysconfig/network 永久生效

[root@oracle etc]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=oracle

4. 重啟作業系統並驗證

[oracle@oracle ~]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 29-APR-2015 07:46:27
Starting /home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
The command completed successfully

深度解析:為什麼會發生這個錯誤?

  1. 雙重解析衝突:監聽器啟動時需綁定主機名/IP,/etc/hosts 中 IPv4 和 IPv6 同時指向 localhost,導致 getaddrinfo() 返回多個地址
  2. 協議適配器失敗:監聽器嘗試在衝突的地址上建立 socket,導致 TNS-12560: protocol adapter error
  3. Illegal seek (Errno 29):底層系統調用在非預期的文件描述符上操作,反映網絡堆疊初始化異常

最佳實踐:/etc/hosts 標準配置範本

# IPv4 本地回環
127.0.0.1   localhost.localdomain localhost

# IPv6 本地回環
::1         localhost6.localdomain6 localhost6

# 實際主機名映射(需與 /etc/sysconfig/network 一致)
192.168.1.100  oracle-db01.oracle.com oracle-db01

# IPv6 實際地址(如有)
fe80::1%eth0  oracle-db01-v6

驗證清單

  • [ ] hostname 輸出與 /etc/sysconfig/network 中 HOSTNAME 一致
  • [ ] ping $(hostname) 解析到正確 IP
  • [ ] /etc/hosts 無重複主機名映射
  • [ ] lsnrctl status 顯示正確的 HOST/IP/PORT
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved