CentOS Oracle 报 Environment variable ORACLE

今天在 CentOS 上安装完 Oracle 后,通过命令 “emctl start dbconsole” 启动管理控制台时,报了 “Environment variable ORACLE_UNQNAME not defined” 的错误。问题原因是因为 Oracle 总是获取不到正确的 IP 地址(安装 Oracle 时获取的 IP 地址就是错误的),导致 em 出现问题,只需重新配置 emca 即可。折腾了好久,最后终于把问题给解决了。

环境描述

操作系统: CentOS 6.5IP: 192.168.132.41域: mycompany.com.cn主机名: hemw-pcOracle:11gR2,安装目录为/opt/oracle/11g

问题分析

刚开始按照网上的解决方案使用命令“emca -config dbcontrol db -repos create” 重新创建 em,输入完对应的信息时,到最后确认时获取到的 IP 地址总是不正确(Local hostname 应该是192.168.132.41 才对):

—————————————————————–You have specified the following settingsDatabase ORACLE_HOME ……………. /opt/oracle/11gLocal hostname ……………. 192.168.64.61Listener ORACLE_HOME ……………. /opt/oracle/11gListener port number ……………. 1521Database SID ……………. orclEmail address for notifications …………… Outgoing Mail (SMTP) server for notifications …………… —————————————————————–因为获取到的 hostname 值不正确,导致一直无法创建成功,提示如下错误Could not complete the configuration. Refer to the log file at /opt/oracle/cfgtoollogs/emca/orcl/emca_2015_03_10_17_19_30.log for more details.解决方案

经过各种尝试和折腾后,最终还是把问题给搞定了,,步骤如下:

1. 停止监听器

$ lsnrctl stop

2. 停止 oracle 数据库

$ sqlplus "sys / as sysdba"SQL*Plus: Release 11.2.0.1.0 Production on Tue Mar 10 17:16:45 2015Copyright (c) 1982, 2009, Oracle. All rights reserved.Enter 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

3. 修改 $ORACLE_HOME/network/admin/listener.ora,将文件内容中HOST 的值改为正确的 IP(192.168.132.41),如:

LISTENER = (DESCRIPTION_LIST =(DESCRIPTION =(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.132.41)(PORT = 1521))) )4.修改 $ORACLE_HOME/network/admin/tnsnames.ora,将文件内容中 HOST 的值改为正确的 IP(192.168.132.41),如:ORCL = (DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.132.41)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = orcl)) )5. 修改/etc/sysconfig/network,将文件内容改为:NETWORKING=yesNETWORKING_IPV6=noHOSTNAME=hemw-pc

因为修改完这个文件后需要重启操作系统才会生效,所以在不重启操作系统的情况下需要同时执行一下:#hostname hemw-pc

6. 修改/etc/hosts,在文件的最后新增如下内容:

192.168.132.41 hemw-pc hemw-pc.mycompany.com.cn

7. 启动数据库

SQL> startup

8. 启动监听

$ lsnrctl start9. 删除早期DBCONSOLE创建的用户:sql>drop role MGMT_USER;sql>drop user MGMT_VIEW cascade;sql>drop user sysman cascade;10. 删除早期DBCONSOLE创建的对象:sql>drop PUBLIC SYNONYM MGMT_TARGET_BLACKOUTS;sql>drop public synonym SETEMVIEWUSERCONTEXT;11. 重新创建DBCONSOLE:(如果是在windows下,要先到注册表删除DBCONSOLE的服务,重启电脑)$emca -config dbcontrol db -repos create 如果提示创建失败,输出类似 “Could not complete the configuration. Refer to the log file at /opt/oracle/cfgtoollogs/emca/orcl/emca_*.log for more details.” 的错误信息,请查看对应的日志文件, 日志文件的最后一行内容如果是 “ORA-00955: name is already used by an existing object”,如:CREATE PUBLIC SYNONYM MGMT_AVAILABILITY FOR MGMT_AVAILABILITY*ERROR at line 1:ORA-00955: name is already used by an existing object则需要执行一次重建的命令:$emca -config dbcontrol db -repos recreate 在执行上面命令的过程中需要根据提示输入对应的数据库信息及 SYS、DBSNMP 和SYSMAN 的登录密码,最后输入 Y 进行确认,如:STARTED EMCA at Mar 10, 2015 10:03:17 PMEM Configuration Assistant, Version 11.2.0.0.2 ProductionCopyright (c) 2003, 2005, Oracle. All rights reserved.Enter the following information:Database SID: orclListener port number: 1521Listener ORACLE_HOME [ /opt/oracle/11g ]: Password for SYS user: Password for DBSNMP user: Password for SYSMAN user: Email address for notifications (optional): Outgoing Mail (SMTP) server for notifications (optional):12. 检查 em 的状态$ emctl status dbconsoleOracle Enterprise Manager 11g Database Control Release 11.2.0.1.0 Copyright (c) 1996, 2009 Oracle Corporation. All rights reserved.https://hemw-pc:1158/em/console/aboutApplicationOracle Enterprise Manager 11g is running. ——————————————————————Logs are generated in directory /opt/oracle/11g/hemw-pc_orcl/sysman/log至此,问题已经解决完毕。附:emca 常用命令创建一个 em 资料库:emca -repos create重建一个 em 资料库:emca -repos recreate删除一个 em 资料库:emca -repos drop配置数据库的 Database Control:emca -config dbcontrol db删除数据库的 Database Control配置:emca -deconfig dbcontrol db重新配置db control的端口,默认端口在1158emca -reconfig portsemca -reconfig ports -dbcontrol_http_port 1160emca -reconfig ports -agent_port 3940先设置 ORACLE_SID 环境变量后,启动 em console服务:emctl start dbconsole先设置 ORACLE_SID 环境变量后,停止em console服务:emctl stop dbconsole先设置 ORACLE_SID 环境变量后,查看 em console服务的状态:emctl status dbconsole配置 dbconsole 的步骤emca -repos createemca -config dbcontrol dbemctl start dbconsole重新配置 dbconsole 的步骤emca -repos dropemca -repos createemca -config dbcontrol db

emctl start dbconsole

参考资料:

旅行,不要害怕错过什么,

CentOS Oracle 报 Environment variable ORACLE

相关文章:

你感兴趣的文章:

标签云: