程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> 命令行界面下使用emca安裝配置OracleDatabaseControl實戰

命令行界面下使用emca安裝配置OracleDatabaseControl實戰

編輯:Oracle教程

命令行界面下使用emca安裝配置OracleDatabaseControl實戰


作為命令行忠實用戶,服務器端軟件的運維都傾向於使用命令或 腳本完成,非常討厭資源占用很大的GUI。Oracle數據庫作為重要的服務器端軟件,其安裝運維自然也完全支持純命令行方式,盡管同時提供了OUI這個GUI安裝程序。至於純命令行下靜默安裝Oracle11g,本人之前寫過詳細的博文,有需要的請參考之,博文地址http://blog.csdn.net/smstong/article/details/7352036。按照這篇博文安裝的數據庫完全可用。本文算是對前面這篇博文的一個補充,就是在數據庫安裝完成的基礎上安裝配置Oracle Enterprise Manager,使得管理員在厭倦單純sqlplus的情況下,可以使用浏覽器來管理Oracle數據庫。

1 Oracle Enterprise Manager與Oracle Database Control

OEM是一個統稱,是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為基礎說明。

\

在安裝完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自身使用的管理數據都存放到SYSMAN這個模式下。

了解了工作原理,其配置就容易理解了。與部署其他的j2EE程序一樣,需要從數據和程序文件兩個方面進行。從本質上說,所有這些操作都可以通過手工來一一完成,但是無論是建立大量的配置文件還是創建大量的數據表,純手工方式都會很低效,也容易出錯。所以Oracle公司為部署Database Control提供了專門的工具軟件。

如果使用OUI來安裝Oracle可以在安裝階段配置Database Control,在安裝完成後還可以通過DBCA來配置,這些都是好用的GUI工具,但是本文的目的是在純命令行下進行配置,所以上述方式不可用。

為了應對命令行模式下的配置,ORACLE公司為Database Control專門提供了配置助手emca(Enterprise manager Configuration Assistant)。

3 使用EMCA配置Database Control

3.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"

執行 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 

找到了錯誤根源,解決就容易多了,以sys賬戶登錄,然後賦予public角色執行SYS.UTL_I18N這個包的權限。

SQL>  grant execute on UTL_I18N to public;

Grant succeeded. 

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 ~]$

[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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved