【本文谢绝转载原文来自】
报错的现象:
[oracle@oracle11 ~]$ lsnrctl startLSNRCTL for Linux: Version 11.2.0.1.0 - Production on 29-AUG-2016 10:38:59Copyright (c) 1991, 2009, Oracle. All rights reserved.Starting /opt/oracle/app/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...TNSLSNR for Linux: Version 11.2.0.1.0 - ProductionSystem parameter file is /opt/oracle/app/product/11.2.0/dbhome_1/network/admin/listener.oraLog messages written to /opt/oracle/app/diag/tnslsnr/oracle11/listener/alert/log.xmlListening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle11)(PORT=1521)))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 existListener failed to start. See the error message(s) above...
以上是报错信息.
开始查错,
查到了TNS-12545: Connect failed because target host or object does not exist
[oracle@oracle11 ~]$ > /opt/oracle/app/diag/tnslsnr/oracle11/listener/alert/log.xml[oracle@oracle11 ~]$ lsnrctl start[oracle@oracle11 ~]$ grep txt /opt/oracle/app/diag/tnslsnr/oracle11/listener/alert/log.xmlSystem parameter file is /opt/oracle/app/product/11.2.0/dbhome_1/network/admin/listener.ora Log messages written to /opt/oracle/app/diag/tnslsnr/oracle11/listener/alert/log.xml Trace information written to /opt/oracle/app/diag/tnslsnr/oracle11/listener/trace/ora_3706_140351658579712.trc Trace level is currently 0 Started with pid=3706 Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle11)(PORT=1521))) TNS-12545: Connect failed because target host or object does not exist No longer listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))[oracle@oracle11 ~]$
网上查[TNS-12545: Connect failed] 找到tnsnames.ora文件
cat /opt/oracle/app/product/11.2.0/dbhome_1/network/admin/tnsnames.ora# tnsnames.ora Network Configuration File: /opt/oracle/app/product/11.2.0/dbhome_1/network/admin/tnsnames.ora# Generated by Oracle configuration tools.ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oracle11)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) )
看到:HOST = oracle11
查看我的hosts文件,真的没有这个:
[oracle@oracle11 ~]$ cat /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6[oracle@oracle11 ~]$
添加一条:
[oracle@oracle11 ~]$ su rootPassword: [root@oracle11 oracle]# echo "127.0.0.1 oracle11 " >> /etc/hosts[root@oracle11 oracle]# cat /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6127.0.0.1 oracle11 [root@oracle11 oracle]#
访问测试:,启动监听:
[oracle@oracle11 ~]$ ping oracle11PING oracle11 (127.0.0.1) 56(84) bytes of data.64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.090 ms64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.048 ms64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.046 ms[oracle@oracle11 ~]$ lsnrctl startLSNRCTL for Linux: Version 11.2.0.1.0 - Production on 29-AUG-2016 10:47:44Copyright (c) 1991, 2009, Oracle. All rights reserved.Starting /opt/oracle/app/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...TNSLSNR for Linux: Version 11.2.0.1.0 - ProductionSystem parameter file is /opt/oracle/app/product/11.2.0/dbhome_1/network/admin/listener.oraLog messages written to /opt/oracle/app/diag/tnslsnr/oracle11/listener/alert/log.xmlListening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle11)(PORT=1521)))Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))STATUS of the LISTENER------------------------Alias LISTENERVersion TNSLSNR for Linux: Version 11.2.0.1.0 - ProductionStart Date 29-AUG-2016 10:47:44Uptime 0 days 0 hr. 0 min. 0 secTrace Level offSecurity ON: Local OS AuthenticationSNMP OFFListener Parameter File /opt/oracle/app/product/11.2.0/dbhome_1/network/admin/listener.oraListener Log File /opt/oracle/app/diag/tnslsnr/oracle11/listener/alert/log.xmlListening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle11)(PORT=1521)))The listener supports no servicesThe command completed successfully[oracle@oracle11 ~]$
scott登陆上去试一试:
我的数据库服务已经启动
[oracle@oracle11 ~]$ sqlplus scott/11SQL*Plus: Release 11.2.0.1.0 Production on Mon Aug 29 10:48:36 2016Copyright (c) 1982, 2009, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> select * from dept; DEPTNO DNAME LOC---------- -------------- ------------- 50 oracle England 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTONSQL> SQL> exit;Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options[oracle@oracle11 ~]$
搞定!