千家信息网

修改hostname后导致oracle客户端无法连接怎么办

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,本篇内容介绍了"修改hostname后导致oracle客户端无法连接怎么办"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细
千家信息网最后更新 2026年11月02日修改hostname后导致oracle客户端无法连接怎么办

本篇内容介绍了"修改hostname后导致oracle客户端无法连接怎么办"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

虚拟机centos7中刚装了oracle11g,没重启前一切正常

重启后发现客户端无法连接到数据库了

SQL*Plus: Release 11.2.0.1.0 Production on 星期五 11月 16 15:05:18 2018Copyright (c) 1982, 2010, Oracle.  All rights reserved.请输入用户名:  system@orcl输入口令:ERROR:ORA-12541: TNS: 无监听程序

登陆服务器看一下监听状态

[root@lzr ~]# lsnrctl statusLSNRCTL for Linux: Version 11.2.0.1.0 - Production on 16-NOV-2018 15:07:55Copyright (c) 1991, 2009, Oracle.  All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))STATUS of the LISTENER------------------------Alias                     LISTENERVersion                   TNSLSNR for Linux: Version 11.2.0.1.0 - ProductionStart Date                16-NOV-2018 15:00:14Uptime                    0 days 0 hr. 7 min. 45 secTrace Level               offSecurity                  ON: Local OS AuthenticationSNMP                      OFFListener Parameter File   /data/oracle/product/11.2.0/db_1/network/admin/listener.oraListener Log File         /data/oracle/diag/tnslsnr/lzr/listener/alert/log.xmlListening Endpoints Summary...  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))Services Summary...Service "ORCL" has 1 instance(s).  Instance "ORCL", status UNKNOWN, has 1 handler(s) for this service...The command completed successfully

实例ORCL状态为UNKNOWN,有点不太懂了,百度了一下之后

解决办法

发现可能是hostname出现了问题

我在重启之前用命令

#hostnamectl set-hostname lzr

修改过hostname

先打开/etc/hosts检查一下

[root@lzr ~]# vi /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

host文件解释

添加新的一行

[root@lzr ~]# vi /etc/hosts127.0.0.1   lzr127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

然后wq保存退出

现在我将数据库重启

[root@lzr ~]# sqlplusSQL*Plus: Release 11.2.0.1.0 Production on Fri Nov 16 15:25:52 2018Copyright (c) 1982, 2009, Oracle.  All rights reserved.Enter user-name: sys as sysdbaEnter password: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> shutdown immediateDatabase closed.Database dismounted.ORACLE instance shut down.SQL> startupORACLE instance started.Total System Global Area 1185853440 bytesFixed Size                  2212776 bytesVariable Size             738200664 bytesDatabase Buffers          436207616 bytesRedo Buffers                9232384 bytesDatabase mounted.Database opened.

再将监听重启,查看状态

[root@lzr ~]# lsnrctlLSNRCTL for Linux: Version 11.2.0.1.0 - Production on 16-NOV-2018 15:31:17Copyright (c) 1991, 2009, Oracle.  All rights reserved.Welcome to LSNRCTL, type "help" for information.LSNRCTL> stopConnecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))The command completed successfullyLSNRCTL> startStarting /data/oracle/product/11.2.0/db_1/bin/tnslsnr: please wait...TNSLSNR for Linux: Version 11.2.0.1.0 - ProductionSystem parameter file is /data/oracle/product/11.2.0/db_1/network/admin/listener.oraLog messages written to /data/oracle/diag/tnslsnr/lzr/listener/alert/log.xmlListening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lzr)(PORT=1521)))Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))STATUS of the LISTENER------------------------Alias                     LISTENERVersion                   TNSLSNR for Linux: Version 11.2.0.1.0 - ProductionStart Date                16-NOV-2018 15:31:21Uptime                    0 days 0 hr. 0 min. 5 secTrace Level               offSecurity                  ON: Local OS AuthenticationSNMP                      OFFListener Parameter File   /data/oracle/product/11.2.0/db_1/network/admin/listener.oraListener Log File         /data/oracle/diag/tnslsnr/lzr/listener/alert/log.xmlListening Endpoints Summary...  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lzr)(PORT=1521)))Services Summary...Service "ORCL" has 1 instance(s).  Instance "ORCL", status UNKNOWN, has 1 handler(s) for this service...The command completed successfullyLSNRCTL> statusConnecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))STATUS of the LISTENER------------------------Alias                     LISTENERVersion                   TNSLSNR for Linux: Version 11.2.0.1.0 - ProductionStart Date                16-NOV-2018 15:31:21Uptime                    0 days 0 hr. 0 min. 8 secTrace Level               offSecurity                  ON: Local OS AuthenticationSNMP                      OFFListener Parameter File   /data/oracle/product/11.2.0/db_1/network/admin/listener.oraListener Log File         /data/oracle/diag/tnslsnr/lzr/listener/alert/log.xmlListening Endpoints Summary...  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lzr)(PORT=1521)))Services Summary...Service "ORCL" has 1 instance(s).  Instance "ORCL", status UNKNOWN, has 1 handler(s) for this service...The command completed successfully

好像和之前没有什么变化

去数据库中注册一下监听

[root@lzr ~]# sqlplusSQL*Plus: Release 11.2.0.1.0 Production on Fri Nov 16 15:32:54 2018Copyright (c) 1982, 2009, Oracle.  All rights reserved.Enter user-name: sys as sysdbaEnter password: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> alter system register  2  ;System altered.

再出来查看一下监听状态

[root@lzr ~]# lsnrctlLSNRCTL for Linux: Version 11.2.0.1.0 - Production on 16-NOV-2018 15:33:35Copyright (c) 1991, 2009, Oracle.  All rights reserved.Welcome to LSNRCTL, type "help" for information.LSNRCTL> statusConnecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))STATUS of the LISTENER------------------------Alias                     LISTENERVersion                   TNSLSNR for Linux: Version 11.2.0.1.0 - ProductionStart Date                16-NOV-2018 15:31:21Uptime                    0 days 0 hr. 2 min. 15 secTrace Level               offSecurity                  ON: Local OS AuthenticationSNMP                      OFFListener Parameter File   /data/oracle/product/11.2.0/db_1/network/admin/listener.oraListener Log File         /data/oracle/diag/tnslsnr/lzr/listener/alert/log.xmlListening Endpoints Summary...  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lzr)(PORT=1521)))Services Summary...Service "ORCL" has 2 instance(s).  Instance "ORCL", status UNKNOWN, has 1 handler(s) for this service...  Instance "orcl", status READY, has 1 handler(s) for this service...Service "orclXDB" has 1 instance(s).  Instance "orcl", status READY, has 1 handler(s) for this service...The command completed successfully

看上去正常了,status ready

现在回到客户端中测试一下连接

C:\Users\lzr>sqlplusSQL*Plus: Release 11.2.0.1.0 Production on 星期五 11月 16 15:34:10 2018Copyright (c) 1982, 2010, Oracle.  All rights reserved.请输入用户名:  system@orcl输入口令:连接到:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> show userUSER 为 "SYSTEM"

可以正常使用客户端连接了

"修改hostname后导致oracle客户端无法连接怎么办"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

0