1. 程式人生 > >[oralce拾遺]oracle修改監聽IP地址

[oralce拾遺]oracle修改監聽IP地址

在區域網中遠端連線oracle時,一直提示拒絕連線,在確定防火牆關閉,oracle伺服器監聽埠開啟的情況下,可能的錯誤就是oracle的監聽IP地址不是預設的那樣,而是本地的127.0.0.1。

排錯過程不再細說,這裡只分享由於主機名不正確而導致oracle拒絕連線的解決辦法。

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

修改hosts檔案

  1. 開啟cmd,輸入hostname,記下主機名
  2. 用記事本開啟c:\windows\system32\drivers\etc\hosts 檔案,新增主機名
# Copyright (c) 1993-2009 Microsoft Corp.
# # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one
# space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host # localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost # ::1 localhost [主機IP] [主機名]

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

修改oracle監聽檔案

1、開啟listener.ora,檔案在F:\app\young\product\11.2.0\dbhome_1\NETWORK\ADMIN 目錄下,將裡面的localhost換為自己的主機名。

# listener.ora Network Configuration File: F:\app\young\product\11.2.0\dbhome_1\network\admin\listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = F:\app\young\product\11.2.0\dbhome_1)
      (PROGRAM = extproc)
      (ENVS = "EXTPROC_DLLS=ONLY:F:\app\young\product\11.2.0\dbhome_1\bin\oraclr11.dll")
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = Young-PC)(PORT = 1521))//Young-PC原為localhost
) ) ADR_BASE_LISTENER = F:\app\young

2、修改tnsnames.ora,目錄同上,也將localhost更改為主機名。

# tnsnames.ora Network Configuration File: F:\app\young\product\11.2.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

LISTENER_ORCL =
  (ADDRESS = (PROTOCOL = TCP)(HOST = Young-PC)(PORT = 1521))//Young-PC原為localhost


ORACLR_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
    (CONNECT_DATA =
      (SID = CLRExtProc)
      (PRESENTATION = RO)
    )
  )

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = Young-PC)(PORT = 1521))//Young-PC原為localhost
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

3、重啟tnslsnr。

開啟cmd,輸入以下命令。

lsnrctl stop
lsnrctl start
lsnrctl stat

這裡寫圖片描述

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

再次遠端連線,已經可以連上了,成功。