在Linux平臺中,對hostname的修改,是否對ORACLE資料庫實例或監聽進程有影響呢?如果有影響,又要如何解決問題呢?另外/etc/hosts下相關內容的修改,是否也會影響實例或監聽呢?這裡涉及的場景非常多,當然關係也非常複雜,我們下麵通過幾個例子來測試驗證一下。 如下所示,伺服器/etc/... ...
在Linux平臺中,對hostname的修改,是否對ORACLE資料庫實例或監聽進程有影響呢?如果有影響,又要如何解決問題呢?另外/etc/hosts下相關內容的修改,是否也會影響實例或監聽呢?這裡涉及的場景非常多,當然關係也非常複雜,我們下麵通過幾個例子來測試驗證一下。
如下所示,伺服器/etc/hosts 與/etc/sysconfig/network的原始配置信息如下
[root@test ~]# more /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
#::1 localhost6.localdomain6 localhost6
127.0.0.1 localhost.localdomain localhost
192.168.27.134 test test
[root@test ~]#
[root@test ~]# more /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=test
GATEWAY=192.168.27.1
[root@test ~]#
1: 首先假設有個需求,需要修改hostname,使之變成test.edution.com(加上功能變數名稱部分), 那麼此時是否有問題呢?我們先修改/etc/sysconfig/network下的HOSTNAME,然後重啟伺服器
[root@test ~]# more /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=test.eduction.com
GATEWAY=192.168.27.1
[root@test ~]# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
#::1 localhost6.localdomain6 localhost6
127.0.0.1 localhost.localdomain localhost
192.168.27.134 test test
然後我們重啟資料庫實例後,並沒有任何問題,但是重啟監聽的時候遇到下麵錯誤:
[oracle@test ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Sat Jun 18 16:42:21 2016
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 1509949440 bytes
Fixed Size 2096472 bytes
Variable Size 1392509608 bytes
Database Buffers 67108864 bytes
Redo Buffers 48234496 bytes
Database mounted.
Database opened.
SQL> exit
Disconnected from Oracle Database 10g Release 10.2.0.5.0 - 64bit Production
[oracle@test ~]$ lsnrctl start
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 18-JUN-2016 16:42:47
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Log messages written to /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=test.eduction.com)(PORT=1521)))
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
TNS-12535: TNS:operation timed out
TNS-12560: TNS:protocol adapter error
TNS-00505: Operation timed out
Linux Error: 110: Connection timed out
[oracle@test ~]$
出現這個問題時,必須修改/etc/hosts下主機名的部分,使之與/etc/sysconfig/network下的HOSTNAME一致,上面錯誤就能解決。如下紅色部分所示:
[root@test ~]# more /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=test.eduction.com
GATEWAY=192.168.27.1
[root@test ~]# more /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
#::1 localhost6.localdomain6 localhost6
127.0.0.1 localhost.localdomain localhost
192.168.27.134 test.eduction.com test
[root@test ~]#
由於這裡測試,我修改了功能變數名稱,如果伺服器真實功能變數名稱部分跟/etc/resolv.conf一致,那麼資料庫實例啟動過程中,監控告警日誌,就會發現告警日誌裡面會出現大量ORA-07445 & ORA-00108錯誤
2:修改/etc/sysconfig/network下的hostname並使之生效,如下所示
[oracle@kerry ~]$ more /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
#::1 localhost6.localdomain6 localhost6
127.0.0.1 localhost.localdomain localhost
192.168.27.134 test.eduction.com test
[oracle@kerry ~]$ more /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=kerry.eduction.com
GATEWAY=192.168.27.1
資料庫實例啟動並沒有任何問題,但是監聽啟動出現上面一樣的錯誤。 如果功能變數名稱使用真實的功能變數名稱,則會遇到另外一種情況,告警日誌裡面也會出現下麵錯誤
Errors in file /u01/app/oracle/admin/SCM2/bdump/scm2_ora_4494.trc:
ORA-07445: exception encountered: core dump [kslgetl()+120] [SIGSEGV] [Address not mapped to object] [0x000000210] [] []
ORA-00108: failed to set up dispatcher to accept connection asynchronously
關於這個,可以參考官方文檔ORA-07445: [kslgetl()+80] Followed by ORA-108: failed to set up dispatcher to accept connection asynchronously (文檔 ID 1298804.1)
3: 如果屏蔽/etc/hosts下的localhost部分,如下所示,此時有可能會影響監聽
[root@kerry ~]# more /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
#::1 localhost6.localdomain6 localhost6
#127.0.0.1 localhost.localdomain localhost
192.168.27.134 kerry.eduction.com kerry
[root@kerry ~]#
[oracle@kerry ~]$ lsnrctl start
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 18-JUN-2016 17:45:37
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Log messages written to /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=kerry.eduction.com)(PORT=1521)))
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
TNS-12547: TNS:lost contact
TNS-12560: TNS:protocol adapter error
TNS-00517: Lost contact
Linux Error: 104: Connection reset by peer
這是因為我沒有在$ORACLE_HOME/network/admin下配置listener.ora,所以在註釋或刪除了/etc/hosts下localhost部分後就會出現這個錯誤,因為在沒有listener.ora下的情況下,都會使用預設值(如下官方文檔描述),監聽進程會使用本機配置127.0.0.1註冊監聽服務,所以會出現上面錯誤信息,官方文檔關於這方面的描述如下所示:
Oracle Net Listener Configuration Overview
Note:
Oracle Database 10g and later databases require a version 10 or later listener. Earlier versions of the listener are not supported for use with Oracle Database 10g and later databases. However, you can use a version 10 listener with previous versions of Oracle Database.
A listener is configured with one or more listening protocol addresses, information about supported services, and parameters that control its runtime behavior. The listener configuration is stored in a configuration file named listener.ora.
Because all of the configuration parameters have default values, it is possible to start and use a listener with no configuration. This default listener has a name of LISTENER, supports no services on startup, and listens on the following TCP/IP protocol address:
(ADDRESS=(PROTOCOL=tcp)(HOST=host_name)(PORT=1521))
Supported services, that is, the services to which the listener forwards client requests, can be configured in the listener.ora file or this information can be dynamically registered with the listener. This dynamic registration feature is called service registration. The registration is performed by the PMON process—an instance background process—of each database instance that has the necessary configuration in the database initialization parameter file. Dynamic service registration does not require any configuration in the listener.ora file.
解決方案兩種:
1:在$ORACLE_HOME/network/admin/下配置listener.ora文件。則屏蔽或刪除/etc/hosts下127.0.0.1後,監聽不會有任何問題。
2:在配置文件/etc/hosts下增加localhost(紅色部分所示)也能解決這個問題。
[root@kerry ~]# more /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
#::1 localhost6.localdomain6 localhost6
#127.0.0.1 localhost.localdomain localhost
192.168.27.134 kerry.eduction.com kerry localhost
[root@kerry ~]#
具體可以參考官方文檔Starting TNS Listener or LSNRCTL Start Yields TNS-12541, Linux Error: 111: Connection Refused (文檔 ID 343295.1)
另外,我們這裡也忽略了lisnter.ora裡面的配置,如果該配置文件使用的是hostname而不是IP,那麼也會遇到一些問題。