Install EM13c agent and add targets using the Linux command line only

A few days ago, I was asked to find a way to automate the addition of newly created Linux virtual machines and databases in our EM13c console. Of course, no action should be performed via the EM web interface!

For the first part (installing the EM13c agent on newly created virtual machines), it’s quite simple, because Oracle gives you many methods (for example, “agent pull” method), in order to carry out this task. But the second part seemed more delicate according to the documentation and my constraints: everything must be done on the virtual machine. I am not allowed to connect to the EM server using SSH.

Fortunately, there is a simple solution that only requires a few extra lines in your shell script!

I will not give you my entire script because it is very specific to the environment, but I will give you the main steps and the code you need to know.

Context

Here’s a list of what you need to know before going any further. I give you the values ​​for my environment because I will use them in the next chapters.

OMS

  • OMS host: oem13c.local
  • EM Upload Port: 4903
  • EM Console Port: 7803
  • EM User: SYSMAN
  • EM User password & Agent Registration Password: welcome1

Agent

  • Agent host (hostname of my newly created virtual machine): linuxlab01.local
  • Agent owner: oracle
  • Agent version: 13.2.0.0.0
  • Agent platform: Linux x86-64
  • Agent port: 3872
  • Agent base directory: /app/oracle/product/agent13c
  • Agent instance home: /app/oracle/product/agent13c/agent_inst

Oracle installation

  • ORACLE_HOME: /app/oracle/product/12.1.0
  • ORACLE_SID: ORCL
  • Listener name: LISTENER
  • Listener port: 1521
  • EM User: DBSNMP
  • EM User password: welcome1

That’s a lot of information, but you will need each of them.

Agent installation

For an overview of all available possibilities, please read the Oracle documentation about installing Oracle Management Agent in silent mode.

In my case, I opted for the “AgentPull Script” method.

The EM agent will be installed into “/app/oracle/product/agent13c”. The directory must exist and be empty. Be careful: oracle (or the account you will use to own the agent installation) must have all privileges on this directory!

Unless mentioned, each step is performed with the owner of the agent installation.

Response file creation

First, you must create a response file that will be passed as a parameter to the “AgentPull” script. You need to replace the values according to your environment.

[oracle@linuxlab01]# cat /tmp/em_agent.rsp
LOGIN_USER=SYSMAN
LOGIN_PASSWORD=welcome1
PLATFORM="Linux x86-64"
VERSION=13.2.0.0.0
AGENT_REGISTRATION_PASSWORD=welcome1
AGENT_BASE_DIR=/app/oracle/product/agent13c
AGENT_INSTANCE_HOME=/app/oracle/product/agent13c/agent_inst
AGENT_PORT=3872
EM_UPLOAD_PORT=4903
OMS_HOST=oem13c.local
ORACLE_HOSTNAME=linuxlab01.local

Download the “AgentPull.sh” script from OMS

The script is available and directly downloadable from your OMS server.

[oracle@linuxlab01]# curl -sk https://oem13c.local:7803/em/install/getAgentImage > /tmp/AgentPull.sh
[oracle@linuxlab01]# chmod 755 /tmp/AgentPull.sh

EM agent installation

You just have to execute one command:

[oracle@linuxlab01]# /tmp/AgentPull.sh -ignorePrereqs RSPFILE_LOC=/tmp/em_agent.rsp

If everything worked fine, you will see the following line at the end of the script execution:

Successfully Promoted agent and its related targets to Management Agent

You can also test the return code as usual with the special variable “$?” .

root.sh execution

To complete the installation, you must run the “root.sh” script as “root” user, as indicated in the installation log:

[root@linuxlab01]# /app/oracle/product/agent13c/agent_13.2.0.0.0/root.sh

At this point, you server is visible in your EM13c console but you need additional steps to add your database(s) and your listener(s).

Resources addition

The easiest and fastest way I found to add resources to EM13c from a server is to deploy a temporary emcli client, add the targets, and delete it.

The Emcli client is quite lightweight(5MB) and only needs less than 2 minutes to be operational, so it does not represent a significant overhead in your shell script. Like the “AgentPull.sh” script, it can be downloaded directly from your OMS server.

Download and install emcli

Nothing complicated here: the emcli client is downloaded from the OMS server and then, installed in “/tmp/emcli”.

[oracle@linuxlab01]# export JAVA_HOME=/app/oracle/product/agent13c/agent_13.2.0.0.0/oracle_common/jdk/jre/
[oracle@linuxlab01]# mkdir -p /tmp/emcli/conf
[oracle@linuxlab01]# wget -P /tmp/emcli --quiet --no-check-certificate https://oem13c.local:7803/em/public_lib_download/emcli/kit/emclikit.jar
[oracle@linuxlab01]# ${JAVA_HOME}/bin/java -jar /tmp/emcli/emclikit.jar -install_dir=/tmp/emcli

Configure emcli client

Once downloaded and installed, you need to configure emcli in order to connect it with your OMS server. A lot of options are available, you can find an entire list on Oracle documentation.

In my case, the only important option is “noregister“. Since I will delete the emcli client after adding the resources, I do not want my OMS server to keep track about its installation.

[oracle@linuxlab01]# /tmp/emcli/emcli setup -url=https://oem13c.local:7803/em -username="sysman" -password="welcome1" -dir="/tmp/emcli/conf" -trustall -noregister -noautologin

Create a “commands file” for emcli

Because I want to keep track of the generated commands in case of a problem, I chose to put the addition commands in a text file and then pass the file as an argument to emcli.

Listener:
[oracle@linuxlab01]# echo "add_target -name=\"linuxlab01.local_listener\" -type=\"oracle_listener\" -host=\"linuxlab01.local\" -properties=\"LsnrName:LISTENER;ListenerOraDir:/app/oracle/product/12.1.0/network/admin;Port:1521;OracleHome:/app/oracle/product/12.1.0;Machine:linuxlab01.local;\"" >> "/tmp/emcli/emclicommands.txt"

Instance:
[oracle@linuxlab01]# echo "add_target -name=\"linuxlab01.local_ORCL\" -type=\"oracle_database\" -host=\"linuxlab01.local\" -credentials=\"UserName:dbsnmp;password:welcome1;Role:Normal\" -properties=\"SID:ORCL;Port:1521;OracleHome:/app/oracle/product/12.1.0;MachineName:linuxlab01.local;\"" >> "/tmp/emcli/emclicommands.txt"

The “-name” parameter is the name under which the resource will appear in EM13c. It must be unique, that’s why I’m adding the hostname in it.

Execute the command file

The last step is to run the generated command file via emcli and remove the emcli directory.

[oracle@linuxlab01]# /tmp/emcli/emcli sync
[oracle@linuxlab01]# /tmp/emcli/emcli argfile /tmp/emcli/emclicommands.txt
[oracle@linuxlab01]# rm -rf /tmp/emcli/

After a while (15 minutes on my installation), the targets will be visible from your EM13c web console or via emcli queries 🙂

I hope you find this articled useful. Stay tuned for more DBA stuff!

2 thoughts on “Install EM13c agent and add targets using the Linux command line only

  1. Hi !
    is it possible to install the agent with this method without the SYSMAN Password ?
    For autoation i found it very dangerous to put the sysman into such config-file.
    regards Tobi

    1. Hi Tobi,

      I don’t have access to an OEM console at the moment for testing, but I think you can try to create a new user in OEM with the “Add any target” and “View any target” privilege and use it instead of SYSMAN.

      It’s still not ideal, but it limits the risks by limiting the privileges of the user.

      Regards,
      Antoine

Leave a Reply

Your email address will not be published. Required fields are marked *