emcli command-line interface可以执行几乎所有EMCC控制台界面的操作。之前工作中,在目标端服务器部署agent时,通过控制台图形界面进行配置目标端自动搜索时,偶尔会遇见无法搜索发现某些目标类型的情况。例如目标服务器上面存在oracle instance以及listener,配置自动搜索后无法发现此类型的目标,并且排查失败原因比较耗时。此时就需要通过emcli命令行接口登录OMS去执行添加操作。这里介绍的是命令行模式下的emcli的一些操作,此外还有交互脚本模式这里不做介绍。
■ Workstation running Solaris, Linux, HPUX, Tru64, AIX, or Windows with NTFS
[oracle@rptdb ~]$ tar -xvf jdk-8u231-linux-x64.tar.gz [oracle@rptdb bin]$ /home/oracle/jdk1.8.0_231/bin/java -version java version "1.8.0_231" Java(TM) SE Runtime Environment (build 1.8.0_231-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode) [oracle@rptdb ~]$ export JAVA_HOME=/home/oracle/jdk1.8.0_231 [oracle@rptdb ~]$ env | grep JAVA_HOME JAVA_HOME=/home/oracle/jdk1.8.0_231
[oracle@rptdb ~]$ mkdir emcli [oracle@rptdb ~]$ $JAVA_HOME/bin/java -jar emclikit.jar -install_dir=/home/oracle/emcli Oracle Enterprise Manager 12c Release 5. Copyright (c) 2012, 2015 Oracle Corporation. All rights reserved. EM CLI client-side install completed successfully. Execute "emcli help setup" from the EM CLI home (the directory where you have installed EM CLI) for further instructions.
在非oms服务器本地上使用emcli登录oms,需要先进行setup配置。
--查看相关语法:
./emcli help sync
--执行初始化配置:
[oracle@rptdb emcli]$ ./emcli setup -url= Oracle Enterprise Manager 12c Release 5. Copyright (c) 1996, 2015 Oracle Corporation and/or its affiliates. All rights reserved. Enter password Emcli setup successful
注: -autologin参数的作用是,如果登录超时,emcli会自动进行登录。默认时 noautologin模式,emcli超过45min没用执行操作,会超时,需要重新登录。
--执行同步操作:
[oracle@rptdb emcli]$./emcli sync Synchronized successfully [oracle@rptdb emcli]$
--查看状态:
[oracle@rptdb emcli]$ ./emcli status Oracle Enterprise Manager 12c Release 5 EM CLI. Copyright (c) 1996, 2015 Oracle Corporation and/or its affiliates. All rights reserved. Instance Home : /home/oracle/emcli/.emcli Verb Jars Home : /home/oracle/emcli/.emcli Status : Configured EM CLI Home : /home/oracle/emcli/. EM CLI Version : 12.1.0.5.0 Java Home : /home/oracle/jdk1.8.0_231/jre Java Version : 1.8.0_231 Log file : /home/oracle/emcli/.emcli/.emcli.log EM URL : EM user : sysman Auto login : true Trust all certificates : true
--添加l类型为oracle数据库目标
[oracle@rptdb emcli]$ ./emcli add_target -name="ekpdev" -type="oracle_database" -host="ekptest" -prop="SID:ekpdev;MachineName:ekptest" -prop="OracleHome:/u01/app/oracle/product/11.2.0/db_1;Port:1521" -credentials="UserName:dbsnmp;password:oracle;Role:normal" Target "ekpdev:oracle_database" added successfully
--添加类型为listener的目标的方法:
[oracle@rptdb emcli]$ ./emcli add_target -name="LISTENER_ekpdev" -type="oracle_listener" -host="ekptest" -prop="Machine:ekptest;OracleHome:/u01/app/oracle/product/11.2.0/db_1;ListenerOraDir:/u01/app/oracle/product/11.2.0/db_1/network/admin;LsnrName:LISTENER;Port:1521" Target "LISTENER_ekpdev:oracle_listener" added successfully
[oracle@rptdb emcli]$ ./emcli get_targets -targets="ekpdev:oracle_database;" Status Status Target Type Target Name ID 1 Up oracle_database ekpdev [oracle@rptdb emcli]$ ./emcli get_targets -targets="LISTENER_ekpdev:oracle_listener;" Status Status Target Type Target Name ID 1 Up oracle_listener LISTENER_ekpdev
[oracle@rptdb emcli]$ ./emcli delete_target –type = "oracle_database" –name="ekpdev" Target " ekpdev:oracle_database" deleted successfully [oracle@rptdb emcli]$ ./emcli delete_target -name="LISTENER_ekpdev" -type="oracle_listener" Target "LISTENER_ekpdev:oracle_listener" deleted successfully
例如,我需要把 crmmysql01主机上 一个mysql迁移到一台新的服务器上,并进行监控。新的服务器 prdmysql01 安装好agent,mysql迁移完成后,就可以执行下面命令进行relocate target:
emcli relocate_targets -src_agent="crmmysql01:3872" -dest_agent=" prdmysql01 :3872" -target_name="crmmysql01" -target_type="mysql" -copy_from_src
[oracle@rptdb emcli]$ ./emcli get_targets -targets="oracle_emd" Status Status Target Type Target Name ID 1 Up oracle_emd crmmysql03:3872 1 Up oracle_emd ekptest:3872 1 Up oracle_emd EKPDB01:3872 1 Up oracle_emd zysf:3872 1 Up oracle_emd oms.oracle.com:3872 1 Up oracle_emd ngpdb02:3872 1 Up oracle_emd ngpdb01:3872 1 Up oracle_emd crmmysql02:3872 1 Up oracle_emd ngppdg:3872 1 Up oracle_emd rptdb:3872 1 Up oracle_emd crmmysql01:3872 1 Up oracle_emd crmngpstd:3872
[oracle@rptdb emcli]$ ./emcli stop_agent -agent=ekptest:3872 -host_username=oracle Host User password: The Shut Down operation is in progress for the Agent: ekptest:3872 The Agent "ekptest:3872" has been stopped successfully. --------------------- Operation Output --------------------- Oracle Enterprise Manager Cloud Control 12c Release 5 Copyright (c) 1996, 2015 Oracle Corporation. All rights reserved.Stopping agent ..... stopped.
[oracle@rptdb emcli]$ ./emcli start_agent -agent=ekptest:3872 -host_username=oracle Host User password: The Start Up operation is in progress for the Agent: ekptest:3872 The Agent "ekptest:3872" has been started successfully. --------------------- Operation Output --------------------- Oracle Enterprise Manager Cloud Control 12c Release 5 Copyright (c) 1996, 2015 Oracle Corporation. All rights reserved.Starting agent ................ started.
--启动后查看agent状态
[oracle@rptdb emcli]$ ./emcli get_targets -targets="ekptest:3872:oracle_emd" Status Status Target Type Target Name ID 1 Up oracle_emd ekptest:3872
[oracle@rptdb emcli]$ ./emcli restart_agent -agent=ekptest:3872 -host_username=oracle Host User password: The Restart operation is in progress for the Agent: ekptest:3872 The Agent "ekptest:3872" has been restarted successfully. --------------------- Operation Output --------------------- Oracle Enterprise Manager Cloud Control 12c Release 5 Copyright (c) 1996, 2015 Oracle Corporation. All rights reserved.Stopping agent ..... stopped.Oracle Enterprise Manager Cloud Control 12c Release 5 Copyright (c) 1996, 2015 Oracle Corporation. All rights reserved.Starting agent ................ started.
[oracle@rptdb emcli]$ ./emcli get_agent_properties -agent_name=ekptest:3872 Name Value agentVersion 12.1.0.5.0 agentTZRegion Asia/Shanghai emdRoot /home/oracle/agent/core/12.1.0.5.0 agentStateDir /home/oracle/agent/agent_inst perlBin /home/oracle/agent/core/12.1.0.5.0/perl/bin scriptsDir /home/oracle/agent/core/12.1.0.5.0/sysman/admin/sc ripts EMD_URL localListeningHost localListeningPort REPOSITORY_URL externalProxyPort EMAGENT_PERL_TRACE_LEVEL INFO UploadInterval 15 Total Properties : 13
[oracle@rptdb emcli]$ ./emcli stop_agent -agent=crmmysql01:3872 -host_username=crmuser Host User password: The Shut Down operation is in progress for the Agent: crmmysql01:3872 The Agent "crmmysql01:3872" has been stopped successfully. --------------------- Operation Output --------------------- Oracle Enterprise Manager Cloud Control 12c Release 5 Copyright (c) 1996, 2015 Oracle Corporation. All rights reserved.Stopping agent ..... stopped. [oracle@rptdb emcli]$ ./emcli stop_agent -agent=crmmysql02:3872 -host_username=crmuser Host User password: The Shut Down operation is in progress for the Agent: crmmysql02:3872 The Agent "crmmysql02:3872" has been stopped successfully. --------------------- Operation Output --------------------- Oracle Enterprise Manager Cloud Control 12c Release 5 Copyright (c) 1996, 2015 Oracle Corporation. All rights reserved.Stopping agent ..... stopped. [oracle@rptdb emcli]$ ./emcli stop_agent -agent=crmmysql03:3872 -host_username=crmuser Host User password: The Shut Down operation is in progress for the Agent: crmmysql03:3872 The Agent "crmmysql03:3872" has been stopped successfully. --------------------- Operation Output --------------------- Oracle Enterprise Manager Cloud Control 12c Release 5 Copyright (c) 1996, 2015 Oracle Corporation. All rights reserved.Stopping agent ..... stopped.
[oracle@rptdb emcli]$ ./emcli delete_target -type="oracle_emd" -name="crmmysql01:3872" -delete_monitored_targets -async; Target "crmmysql01:3872:oracle_emd" deleted successfully [oracle@rptdb emcli]$ ./emcli delete_target -type="oracle_emd" -name="crmmysql02:3872" -delete_monitored_targets -async; Target "crmmysql02:3872:oracle_emd" deleted successfully [oracle@rptdb emcli]$ ./emcli delete_target -type="oracle_emd" -name="crmmysql03:3872" -delete_monitored_targets -async; Target "crmmysql03:3872:oracle_emd" deleted successfully
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/69982136/viewspace-2718482/,如需转载,请注明出处,否则将追究法律责任。