设为首页 收藏本站
查看: 480|回复: 0

[经验分享] 命令行界面下使用emca安装配置Oracle Database Control实战

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-7-11 08:51:36 | 显示全部楼层 |阅读模式
作为命令行忠实用户,服务器端软件的运维都倾向于使用命令或 脚本完成,非常讨厌资源占用很大的GUI。Oracle数据库作为重要的服务器端软件,其安装运维自然也完全支持纯命令行方式,尽管同时提供了OUI这个GUI安装程序。至于纯命令行下静默安装Oracle11g,本人之前写过详细的博文。按照这篇博文安装的数据库完全可用。本文算是对前面这篇博文的一个补充,就是在数据库安装完成的基础上安装配置Oracle Enterprise Manager,使得管理员在厌倦单纯sqlplus的情况下,可以使用浏览器来管理Oracle数据库。
1 Oracle Enterprise Manager与Oracle Database ControlOEM是一个统称,是Oracle提供的图形化企业级管理工具的统称。具体有三种可用的工具:
(1)Database Control
它用于管理一个数据库(可以是RAC集群数据库),具有实时管理和监视的功能,运行调度作业功能,告警功能。
(2)Application Server Control
用于管理一个或者多个应用服务器实例。
(3)Grid Control
Grid Control可以管理多个数据库和应用服务器,还可以管理计算机节点,支持通过第三方插件管理第三方产品。


在Oracle9i以及之前,OEM是以C/S架构出现的,从10g开始,使用B/S架构,使得管理员无需安装客户端即可直接通过浏览器进行管理。本文专注于Database Control这个工具,Database Control无需单独安装,在安装oracle的时候,它是自动一起安装的,但是必须经过仔细的配置才能使用。
2 Oracle Database Control 目录结构与工作原理分析任何软件都需要从静态和动态两个方面着手,静态对应的是软件安装后的物理目录和文件布局;动态对应的是软件运行时各个部分之间的交互过程和内存布局。
2.1 目录结构Database Control在10g和11g中的目录结构有细微差异,本文以11g为基础说明。
20140710173403342.jpg
在安装完oracle 11g之后,$ORACLE_HOME目录下会有专门为Database Control提供服务的目录,如上图所示。其中oc4j是oracle container for j2ee的缩写,是oracle专用的j2ee容器与tomcat类似。
2.2 工作原理从本质上说,Database Control本身就是一个j2EE应用,只是这个应用的功能很单一,就是管理Oracle数据库。它运行在oracle为其定制的j2EE容器中,使用其管理的oracle数据库来存放自身数据,使用代理进程来收集数据库之外的系统信息。


单纯从程序角度来说,Database Control其实本身与其管理的oracle数据库(称之为目标数据库)并无关联,完全可以使用单独的数据库(如单独的oracle数据库或者mysql数据库)来存放自身数据,也可以运行在单独机器的符合j2EE标准的容器中(如Tomcat)。但是Oracle公司考虑到效率和配置,为其定制了专门的容器,并且本身使用目标数据库来存放管理数据,而且运行在目标数据库实例所在的机器上。


Database Control的工作原理如下图所示。


20140710174039240.jpg


Database Control自身使用的管理数据都存放到SYSMAN这个模式下。
了解了工作原理,其配置就容易理解了。与部署其他的j2EE程序一样,需要从数据和程序文件两个方面进行。从本质上说,所有这些操作都可以通过手工来一一完成,但是无论是建立大量的配置文件还是创建大量的数据表,纯手工方式都会很低效,也容易出错。所以Oracle公司为部署Database Control提供了专门的工具软件。


如果使用OUI来安装Oracle可以在安装阶段配置Database Control,在安装完成后还可以通过DBCA来配置,这些都是好用的GUI工具,但是本文的目的是在纯命令行下进行配置,所以上述方式不可用。

为了应对命令行模式下的配置,ORACLE公司为Database Control专门提供了配置助手emca(Enterprise manager Configuration Assistant)。
3 使用EMCA配置Database Control3.1 配置数据使用的命令是: emca -repos create
它的作用是为Database Control在数据库中创建必要的用户(模式)(sysman, dbsnmp等)和模式对象(存储过程,表,索引等等)。emca本身是一个脚本文件,最终调用的是java程序来完成实际的工作。由于在创建对象的过程中,需要以sysman用户身份调用Oracle数据库提供的一些函数或过程,所以必须要确保sysman拥有相关的权限。这也是配置中通常会出问题的地方。


需要注意的是emca首先以sys身份创建sysman账户,然后以sysman账户进行后续对象的创建。然后这两者之间是连续的,没有给我们修改sysman权限的机会。所以我们要在运行emca之前把sysman需要的权限赋予public账户,这样当sysman账户被创建后自动就会有相应的权限了。

那么到底需要赋予sysman那些权限呢?答案是很多。我的方法是,首先运行emca,如果权限有问题emca就会爆粗,然后根据错误日志找到缺少的权限,之后把这个权限赋给public,然后emca -repos recreate。
下面给出一个排错的例子:

  • [oracle@db001 ~]$ emca -repos recreate;
  • STARTED EMCA at Jul 10, 2014 4:18:24 PM
  • EM Configuration Assistant, Version 11.2.0.0.2 Production
  • Copyright (c) 2003, 2005, Oracle.  All rights reserved.
  • Enter the following information:
  • Database SID: xgdb
  • Listener port number: 1521
  • Password for SYS user:
  • Password for SYSMAN user:
  • Password for SYSMAN user:
  • Do you wish to continue? [yes(Y)/no(N)]: y
  • Jul 10, 2014 4:18:37 PM oracle.sysman.emcp.EMConfig perform
  • INFO: This operation is being logged at /oracle/cfgtoollogs/emca/xgdb/emca_2014_07_10_16_18_24.log.
  • Jul 10, 2014 4:18:37 PM oracle.sysman.emcp.EMReposConfig invoke
  • INFO: Dropping the EM repository (this may take a while) ...
  • Jul 10, 2014 4:19:44 PM oracle.sysman.emcp.EMReposConfig invoke
  • INFO: Repository successfully dropped
  • Jul 10, 2014 4:19:44 PM oracle.sysman.emcp.EMReposConfig createRepository
  • INFO: Creating the EM repository (this may take a while) ...
  • Jul 10, 2014 4:21:53 PM oracle.sysman.emcp.EMReposConfig invoke
  • SEVERE: Error creating the repository
  • Jul 10, 2014 4:21:53 PM oracle.sysman.emcp.EMReposConfig invoke
  • INFO: Refer to the log file at /oracle/cfgtoollogs/emca/xgdb/emca_repos_create_<date>.log for more details.
  • Jul 10, 2014 4:21:53 PM oracle.sysman.emcp.EMConfig perform
  • SEVERE: Error creating the repository
  • Refer to the log file at /oracle/cfgtoollogs/emca/xgdb/emca_2014_07_10_16_18_24.log for more details.
  • Could not complete the configuration. Refer to the log file at /oracle/cfgtoollogs/emca/xgdb/emca_2014_07_10_16_18_24.log for more details.


上面是一个出错的例子,从红色部分看出,创建数据失败,根据提供的信息,查看日志文件:
  • 313 Jul 10, 2014 4:19:44 PM oracle.sysman.emcp.EMReposConfig createRepository
  • 314 CONFIG: Spooling to /oracle/cfgtoollogs/emca/xgdb/emca_repos_create_2014_07_10_16_19_44.log
  • 315 Jul 10, 2014 4:19:44 PM oracle.sysman.emcp.EMReposConfig createRepository
  • 316 INFO: Creating the EM repository (this may take a while) ...
  • 317 Jul 10, 2014 4:21:53 PM oracle.sysman.emcp.EMReposConfig createRepository
  • 318 CONFIG: ORA-04063: package body "SYSMAN.MGMT_LOGIN_ASSISTANT" has errors
  • 319 ORA-06508: PL/SQL: could not find program unit being called:

这里已经能看出大概的错误是SYSMAN.MGMT_LOGIN_ASSISTANT这个包编译有问题了,为了获取详细错误,继续查看提示的日志文件。
  • PL/SQL procedure successfully completed.
  • Commit complete.
  • BEGIN
  • *
  • ERROR at line 1:
  • ORA-04063: package body "SYSMAN.MGMT_LOGIN_ASSISTANT" has errors
  • ORA-06508: PL/SQL: could not find program unit being called:
  • "SYSMAN.MGMT_LOGIN_ASSISTANT"


这就能确定确实是这个包的问题了,那么究竟为什么这个包编译失败呢?此时,sysman账户已经建立,我们以sysman账户登入sqlplus,然后手动编译这个包,看看错误究竟在哪里。执行 SQL> alter package mgmt_login_assistant compile body;
此时会报错,继续查看出错原因:
SQL> show errors;
显示 函数ENCRYPT invalid。
这说明magmt_login_assistant这个包依赖ENCRYPT函数,而ENCRYPT函数自身有问题。那么继续看看ENCRYPT函数究竟


  • SQL> alter function encrypt compile;
  • Warning: Function altered with compilation errors.
  • SQL> show errors;
  • Errors for FUNCTION ENCRYPT:
  • 9/5      PL/SQL: Statement ignored
  • 10/22    PLS-00201: identifier 'SYS.UTL_I18N' must be declared


可见错误在于ENCRYPT函数依赖于SYS.UTL_I18N这个包,而这个包没有声明,其实是sysman用户没有执行权限。找到了错误根源,解决就容易多了,以sys账户登录,然后赋予public角色执行SYS.UTL_I18N这个包的权限。

  • SQL>  grant execute on UTL_I18N to public;
  • Grant succeeded.


然后重新以sysman登录,并编译ENCRYPT函数成功,继续编译MGMT_LOGIN_ASSISTANT也成功了,这说明找到了问题所在。总结一下上面的依赖情况:SYSMAN.MGMT_LOGIN_ASSISTANT包 < SYSMAN.ENCRYPT函数 < SYS.UTL_I18N包。

然后退出sql,重新执行 emca -repos recreate。如果还是报错,请按照上面查找问题的思路解决问题,直到成功。
  • [oracle@db001 ~]$ emca -repos recreate;
  • STARTED EMCA at Jul 10, 2014 4:37:11 PM
  • EM Configuration Assistant, Version 11.2.0.0.2 Production
  • Copyright (c) 2003, 2005, Oracle.  All rights reserved.
  • Enter the following information:
  • Database SID: xgdb
  • Listener port number: 1521
  • Password for SYS user:
  • Password for SYSMAN user:
  • Do you wish to continue? [yes(Y)/no(N)]: y
  • Jul 10, 2014 4:37:24 PM oracle.sysman.emcp.EMConfig perform
  • INFO: This operation is being logged at /oracle/cfgtoollogs/emca/xgdb/emca_2014_07_10_16_37_11.log.
  • Jul 10, 2014 4:37:25 PM oracle.sysman.emcp.EMReposConfig invoke
  • INFO: Dropping the EM repository (this may take a while) ...
  • Jul 10, 2014 4:38:28 PM oracle.sysman.emcp.EMReposConfig invoke
  • INFO: Repository successfully dropped
  • Jul 10, 2014 4:38:29 PM oracle.sysman.emcp.EMReposConfig createRepository
  • INFO: Creating the EM repository (this may take a while) ...
  • Jul 10, 2014 4:42:47 PM oracle.sysman.emcp.EMReposConfig invoke
  • INFO: Repository successfully created
  • Enterprise Manager configuration completed successfully
  • FINISHED EMCA at Jul 10, 2014 4:42:47 PM


3.2 配置文件布局使用emca -config dbcontrol db命令来创建必要的配置文件。这个操作一般不会出错,注意填正确各个账户的密码就可以了。
  • [oracle@db001 ~]$ emca -config dbcontrol db
  • STARTED EMCA at Jul 10, 2014 4:47:43 PM
  • EM Configuration Assistant, Version 11.2.0.0.2 Production
  • Copyright (c) 2003, 2005, Oracle.  All rights reserved.
  • Enter the following information:
  • Database SID: xgdb
  • Listener port number: 1521
  • Listener ORACLE_HOME [ /oracle/11.2.0 ]:
  • Password for SYS user:
  • Password for DBSNMP user:
  • Password for SYSMAN user:
  • Email address for notifications (optional):
  • Outgoing Mail (SMTP) server for notifications (optional):
  • -----------------------------------------------------------------
  • You have specified the following settings
  • Database ORACLE_HOME ................ /oracle/11.2.0
  • Local hostname ................ localhost
  • Listener ORACLE_HOME ................ /oracle/11.2.0
  • Listener port number ................ 1521
  • Database SID ................ xgdb
  • Email address for notifications ...............
  • Outgoing Mail (SMTP) server for notifications ...............
  • -----------------------------------------------------------------
  • Do you wish to continue? [yes(Y)/no(N)]: y
  • Jul 10, 2014 4:48:05 PM oracle.sysman.emcp.EMConfig perform
  • INFO: This operation is being logged at /oracle/cfgtoollogs/emca/xgdb/emca_2014_07_10_16_47_43.log.
  • Jul 10, 2014 4:48:08 PM oracle.sysman.emcp.EMReposConfig uploadConfigDataToRepository
  • INFO: Uploading configuration data to EM repository (this may take a while) ...
  • Jul 10, 2014 4:49:06 PM oracle.sysman.emcp.EMReposConfig invoke
  • INFO: Uploaded configuration data successfully
  • Jul 10, 2014 4:49:08 PM oracle.sysman.emcp.util.DBControlUtil configureSoftwareLib
  • INFO: Software library configured successfully.
  • Jul 10, 2014 4:49:08 PM oracle.sysman.emcp.EMDBPostConfig configureSoftwareLibrary
  • INFO: Deploying Provisioning archives ...
  • Jul 10, 2014 4:49:34 PM oracle.sysman.emcp.EMDBPostConfig configureSoftwareLibrary
  • INFO: Provisioning archives deployed successfully.
  • Jul 10, 2014 4:49:34 PM oracle.sysman.emcp.util.DBControlUtil secureDBConsole
  • INFO: Securing Database Control (this may take a while) ...
  • Jul 10, 2014 4:50:11 PM oracle.sysman.emcp.util.DBControlUtil secureDBConsole
  • INFO: Database Control secured successfully.
  • Jul 10, 2014 4:50:11 PM oracle.sysman.emcp.util.DBControlUtil startOMS
  • INFO: Starting Database Control (this may take a while) ...
  • Jul 10, 2014 4:50:29 PM oracle.sysman.emcp.EMDBPostConfig performConfiguration
  • INFO: Database Control started successfully
  • Jul 10, 2014 4:50:29 PM oracle.sysman.emcp.EMDBPostConfig performConfiguration
  • INFO: >>>>>>>>>>> The Database Control URL is https://localhost:1158/em <<<<<<<<<<<
  • Jul 10, 2014 4:50:34 PM oracle.sysman.emcp.EMDBPostConfig invoke
  • WARNING:
  • ************************  WARNING  ************************
  • Management Repository has been placed in secure mode wherein Enterprise Manager data will be encrypted.  The encryption key has been placed in the file:
  • /oracle/11.2.0/localhost_xgdb/sysman/config/emkey.ora.   Please ensure this file is backed up as the encrypted data will become unusable if this file is lost.
  • ***********************************************************
  • Enterprise Manager configuration completed successfully
  • FINISHED EMCA at Jul 10, 2014 4:50:34 PM


4 浏览器访问Database Control
上面配置以后,Database Control已经自动启动了。可以使用emctl status dbconsole查看状态。
  • [oracle@db001 ~]$ emctl status dbconsole;
  • Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
  • Copyright (c) 1996, 2009 Oracle Corporation.  All rights reserved.
  • https://localhost:1158/em/console/aboutApplication
  • Oracle Enterprise Manager 11g is running.
  • ------------------------------------------------------------------
  • Logs are generated in directory /oracle/11.2.0/localhost_xgdb/sysman/log
  • [oracle@db001 ~]$



可以使用emctl stop dbconsole 停止Database Control。
可以使用emctl start dbconsole 启动Database Control。


  • [oracle@db001 ~]$ emctl stop dbconsole
  • Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
  • Copyright (c) 1996, 2009 Oracle Corporation.  All rights reserved.
  • https://localhost:1158/em/console/aboutApplication
  • Stopping Oracle Enterprise Manager 11g Database Control ...
  • ...  Stopped.
  • [oracle@db001 ~]$ emctl start dbconsole
  • Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
  • Copyright (c) 1996, 2009 Oracle Corporation.  All rights reserved.
  • https://localhost:1158/em/console/aboutApplication
  • Starting Oracle Enterprise Manager 11g Database Control ........ started.
  • ------------------------------------------------------------------
  • Logs are generated in directory /oracle/11.2.0/localhost_xgdb/sysman/log


确保Database Conrol启动后,使用浏览器访问:https://IP:1158/em即可。


20140710191431125.jpg
20140710191545796.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-21983-1-1.html 上篇帖子: oracle instant client,tnsping,tnsnames.ora和ORACLE_HOME 下篇帖子: ORA-14450 attempt to access a transactional temp table already in use Oracle
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表