问题描述:

虚拟机win7上Oracle11g安装完成后,修改虚拟机系统和宿主机之间的网络连接为NAT类型,两边ip均可相互ping通,并且虚拟机上Oracle的139端口也可以telnet通过,但宿主机访问虚拟机telnet 虚拟机IP 1521无法连接。

image.png

环境说明:

宿主机环境:win10_64bit专业版 虚拟机安装环境:VMware11虚拟机上的Win7-32bit旗舰版环境,核心1核,内存3G,硬盘空间35G 安装版本:Oracle Database 11g Release 2 (11.2.0.1.0) for Microsoft Windows (x86) 安装文件为:win32_11gR2_database_1of2.zip和win32_11gR2_database_2of2.zip 宿主机与虚拟机网络连接类型:NAT连接

现象分析:

需要修改oracle监听文件

解决方案:

  1. 打开防火墙,看1521端口是否在inboundoutbound中。如果不在,加入1521端口。(最简单的方法就是关闭宿主机和虚拟机内系统的防火墙)
  2. 运行cmd,进入控制台,netstat -a -n 看一下1521端口的ip是 0.0.0.0 还是127.0.0.1,如果是后者,就需要修改listener.oratnsnames.ora文件,
  3. 修改监听文件:将两个文件里的localhost替换为自己的主机名
  • 文件位置:D:\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN目录下

listener.ora(共一处)

  1. # listener.ora Network Configuration File: F:\oracle\product\11.2.0\dbhome_1\network\admin\listener.ora
  2. # Generated by Oracle configuration tools.
  3. SID_LIST_LISTENER =
  4. (SID_LIST =
  5. (SID_DESC =
  6. (SID_NAME = CLRExtProc)
  7. (ORACLE_HOME = F:\oracle\product\11.2.0\dbhome_1)
  8. (PROGRAM = extproc)
  9. (ENVS = "EXTPROC_DLLS=ONLY:F:\oracle\product\11.2.0\dbhome_1\bin\oraclr11.dll")
  10. )
  11. )
  12. LISTENER =
  13. (DESCRIPTION_LIST =
  14. (DESCRIPTION =
  15. (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
  16. (ADDRESS = (PROTOCOL = TCP)(HOST = Young-PC)(PORT = 1521))//Young-PC原为localhost
  17. ) ) ADR_BASE_LISTENER = F:\oracle

tnsnames.ora(共两处)

# tnsnames.ora Network Configuration File: F:\oracle\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)
    )
  )