Follow these instructions to install agents on EC2 instances.

Conceptual Overview

AWS:
When launching a new EC2 instance, you can give it two kinds of data to run at startup: cloud-init directives, and shell scripts. This page has an example of a shell script that—when run as AWS user data—installs Cmd on an EC2 instance running Ubuntu 18.
 
Cmd:
The script in this guide implements the steps in Cmd's automated agent deployment guide.
 
Tested OS:
These instructions were tested on an EC2 instance running Ubuntu 18. You may need to adapt the script for other OSes.

 

Instructions

To install Cmd on a new EC2 instance, include the following script as user data.

Required script changes:
At the top of the script, you will need to choose values for several variables:

  • CMD_API_KEY — Your Cmd project key.

  • CMD_ARCH — Currently, the only valid value is amd64 (includes x86_64).

  • CMD_PKG_FORMAT — Either deb or rpm , depending on the target OS.

  • CMD_PKG_VERSION — The version of the agent you wish to download. Use a supported version number, or leave it blank for the latest version.

  • CMD_AGENT_TYPE — Choose whether to install the Cmd Control or Cmd Audit agent. Use ccf for the Cmd Control agent, or cmd for the Cmd Audit agent. (Make sure that the version number you specify matches the agent_type .)

  • CMD_SUB — Your Cmd instance's subdomain. For example if your Cmd web app is at sub1.app.cmd.com , use "sub1". If it's at sub2.app.cmd.com , use "sub2".

Optional changes:

  • HTTP_Proxy:
    If necessary, change the value of http_proxy as described in step 5 of the automated deployment guide.

  • Name:
    To associate a name with a server in the Cmd web app, simply name the EC2 instance within AWS.

  • Group:
    To add the server to one or more server groups, add a comma-separated list of group names after groups = (e.g., groups=groupA,groupB,groupC ). Valid characters for a server group are: 0-9 , a-z , A-Z , - , and _ .

#!/bin/bash
CMD_API_KEY="" # Your Cmd API key
CMD_ARCH="amd64" # Supported architecture: amd64
CMD_PKG_FORMAT="deb" # Supported formats: rpm, deb
CMD_PKG_VERSION="" # A supported version number, or "" for latest
CMD_AGENT_TYPE="ccf" # Supported values: cmd, ccf
CMD_SUB="sub2" # Your Cmd webapp subdomain(e.g. sub1, sub2, sub3)

mkdir -p /etc/cmd/
cat <<- EOF > /etc/cmd/config.ini
server_name=$(hostname)
groups=
http_proxy=
url=https://${CMD_SUB}.c-app.cmd.com/ws
sos_url=https://${CMD_SUB}.sos-app.cmd.com
EOF

echo "${CMD_API_KEY}" > /etc/cmd/cmd.prj
chown root:root /etc/cmd/cmd.prj /etc/cmd/config.ini
chmod 0644 /etc/cmd/cmd.prj /etc/cmd/config.ini

curl -L -o /tmp/${CMD_AGENT_TYPE}-${CMD_PKG_VERSION}.${CMD_PKG_FORMAT} -H "project-key: ${CMD_API_KEY}" "https://${CMD_SUB}.c-app.cmd.com/download/${CMD_AGENT_TYPE}?architecture=${CMD_ARCH}&format=${CMD_PKG_FORMAT}&version=${CMD_PKG_VERSION}"
dpkg -i /tmp/${CMD_AGENT_TYPE}-${CMD_PKG_VERSION}.${CMD_PKG_FORMAT}
rm /tmp/${CMD_AGENT_TYPE}-${CMD_PKG_VERSION}.${CMD_PKG_FORMAT}

systemctl restart cmd

Automating Cmd deployment

Adding a new server

Did this answer your question?