TNS-12541 TNS-12560 TNS-00511 Linux Error: 111 解决方法

来源:互联网 发布:超极本推荐 知乎 编辑:程序博客网 时间:2024/04/27 20:40

今天在做ORACLE数据库和torquebox的连接

在配置好driver之后 rake的时候发现如下异常:

java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection>

数据库链接失败..

打开sqlplus 链接一切正常..

反复修改database.yaml后,仍然报错。

于是netstat查看端口

发现列表中并没有1521端口。

可能是防火墙把端口屏蔽掉了

于是

iptables -I INPUT -p tcp --dport 1521 -j ACCEPTiptables -I FORWARD -p tcp --dport 1521 -j ACCEPT 

开放1521端口,再试..

仍然不行...

查看下oracle监听服务:

lsnrctl status
结果如下:
LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 01-AUG-2012 16:07:46Copyright (c) 1991, 2011, Oracle.  All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))TNS-12541: TNS:no listener TNS-12560: TNS:protocol adapter error  TNS-00511: No listener   Linux Error: 111: Connection refusedConnecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=wodeoraclefuwuqi)(PORT=1521)))TNS-12541: TNS:no listener TNS-12560: TNS:protocol adapter error  TNS-00511: No listener   Linux Error: 111: Connection refused

找到问题原因了,上网google,发现这个问题和IP有关系,之前在调整apache虚拟服务器的时候,为了测试把/etc/hosts里的这一行:

127.0.0.1       localhost.localdomain   localhost

删掉了,重新加上, 然后

lsnrctl start

之后

lsnrctl status
结果如下:

LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 01-AUG-2012 16:11:35Copyright (c) 1991, 2011, Oracle.  All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))STATUS of the LISTENER------------------------Alias                     LISTENERVersion                   TNSLSNR for Linux: Version 11.2.0.2.0 - ProductionStart Date                01-AUG-2012 16:11:27Uptime                    0 days 0 hr. 0 min. 8 secTrace Level               offSecurity                  ON: Local OS AuthenticationSNMP                      OFFDefault Service           XEListener Parameter File   /u01/app/oracle/product/11.2.0/xe/network/admin/listener.oraListener Log File         /u01/app/oracle/diag/tnslsnr/sstdevel/listener/alert/log.xmlListening Endpoints Summary...  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=wodeoraclefuwuqi)(PORT=1521)))Services Summary...Service "PLSExtProc" has 1 instance(s).  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...The command completed successfully
重新进入rails目录 rake db:migrate 搞定!