Docker is an open platform for developing, shipping, and running applications. It provides the ability to package and run an application in a loosely isolated environment called a container. A container is lightweight and portable, which make it easy to dynamically manage workloads, scaling up or tearing down applications and services as business needs dictate.
In a Foglight monitoring environment, there is always a need to deploy/configure/run multiple agent manager instances, which requires much effort to set it up. By utilizing the docker technique, it can speed up the setup process, and should also have better workloads than using virtual machines.
Below are some scenarios we tested to see how to make agent manager run in the docker environment. You can get reference from these test cases and build your own agent manager images for setting up your monitoring environment.
Install and run agent manager in an existing running container
This testing is to verify if an agent manager can be installed and run in an existing running docker.
Preconditions:
-
Ubuntu 16.04
-
FMS server available for connection
-
FglAM installation file
FglAM-5_9_2-linux-x86_64.bin
-
FglAM silent install properties file
installer.properties
Steps:
-
Install docker in Ubuntu16.04.
sudo apt-get update curl -fsSL https://get.docker.com/ | sh # If the download speed is slow, the acceleration address
curl -sSL https://get.daocloud.io/docker | sh
is preferred. sudo systemctl start docker sudo systemctl enable dockerThe commands above are to install and enable docker in the host.
-
Instantiate a ubuntu container for FglAM installation.
docker run -it --rm --name fglam --entrypoint bash ubuntu
This command downloads the latest ubuntu docker image, then open a terminal for you input.
-
Open another terminal, and input below commands:
-
This command lists all the running containers. Please check if the container named fglam created at last step is listed.docker ps
-
Copy the prepared installer file to the fglam container.docker cp FglAM-5_9_2-linux-x86_64.bin fglam:/FglAM-5_9_2-linux-x86_64.bin
-
Copy the installer properties file to the fglam container.docker cp installer.properties fglam:/installer.properties
-
-
Configure the installer.properties file:
installer.installdir=/FglAM592 # Specify the installation directory installer.fms=url=https://10.154.14.90:8443,ssl-allow-self-signed=true,ssl-cert-common-name=quest.com # Specify the FMS address to which this agent manager connect. installer.noservice installer.silent installer.host-display-name=docktest # Specify the host display name. If it's not set here, container id will be the host-display-name.
-
Switch to the first terminal, run below commands:
-
To list all files which have copied from above step for validation.ls -l /
. -
and thenchmod +x FglAM-5_9_2-linux-x86_64.bin
It will install and start the agent manager./FglAM-5_9_2-linux-x86_64.bin
-
-
Go to FMS server, you will see the new agent manager named dockertest is shown in the Agent Manger dashboard. After that, you can deploy agent package and create agent in this new agent manager instance as what you would do on other agent managers.
- Restarting the docker container or docker host won't impact this installed agent manager as well as the agents deployed in it.
Build the agent manager installer into an image
This testing is first to create a docker image which contains the Agent Manager installer files. And then instantiate this image which will automatically install and run the agent manager.
With this way, we can run the agent manager docker image anywhere to get fresh agent manager instances with all default configurations. Below are the steps for this testing.
- Create a Dockerfile with below instructions to create the image.
FROM ubuntu RUN apt-get update \ && apt-get -y install gettext-base \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* WORKDIR /FglAM592 COPY FglAM-5_9_2-linux-x86_64.bin /FglAM592/ COPY installer.properties /FglAM592/ RUN chmod + x FglAM-5_9_2-linux-x86_64.bin COPY entrypoint.sh / RUN chmod + x /entrypoint.sh ENTRYPOINT /entrypoint.sh
-
Configure the entrypoint.sh file which will be executed when the image is instantiated. It will read the parameters specified in the docker run command line such as the <fms address> and <fglam display name>, and then replace the corresponding value in the installer.properties.
#! /bin/bash # Determine whether the log file exists,if exist, start fglam directly, if not, install fglam. PREFIX=/opt/fglam/state/default/logs if [ -d $PREFIX ]; then /opt/fglam/bin/fglam -d else # replace var defined in installer.properties with real value. [ -z "$display_name" ] && export display_name=$HOSTNAME envsubst < "installer.properties" > "installer.properties" ./FglAM-5_9_2-linux-x86_64.bin fi # Always output the latest log while true do
LATEST_LOG=$(ls $PREFIX|egrep FglAM.*\\.log|sort -r|head -n1)
if [ "$LOG_FILE" == "$LATEST_LOG" ]; then sleep 5 else LOG_FILE=$LATEST_LOG pkill tail (tail -f $PREFIX/$LOG_FILE &) fi done
-
Configure the installer.properties file:
installer.installdir=/opt/fglam # Specify the installation directory installer.fms=url=https://${fms},ssl-allow-self-signed=true,ssl-cert-common-name=quest.com installer.noservice installer.silent installer.host-display-name=${display_name}
-
Build an agent manager image by running
docker build -t fglamImg
-
After the image is built, we can run
docker run -d --name fglamtest -e fms=<fms address> -e display_name=<fglam display name> fglamImg
Remember to specify the <fms address> to which FMS this agent manager connect. And you can optionally specify the <fglam display name> if you want, otherwise display name will be the container id. Below is an example of customzing the the FMS address and FglAM display name:
docker run -d --name fglamtest -e fms=10.154.14.90:8443 -e display_name=fglam1 fglamImg.
After the command is executed, the new agent manager will be installed and run in the container.
- Go to FMS server, you will see the new agent manager is shown in the Agent Manger dashboard. After that, you can deploy agent packages and create agents in this new agent manager instance as what you would do on other agent managers.
-
Restarting the fglamtest container or docker host won't impact this agent manager as well as the agents deployed in it.
Build the agent manager installation into an image
This testing creates a docker image which contains an installed agent manager installation(instead of the installer). When the image is instantiated, it starts the FglAM instance without the need to install it. After the agent manager started, it preserves all the customized configurations preset in the image. Below are the steps for this testing.
Note: The difference between this test scenario and the next scenario(Build the existing agent manager installation into an image) is that this test installs the agent manager and customizes the agent manager configurations via the Dockerfile, while the next scenario embeds a pre-installed agent manager(with customzied configurations in it) in the image.
- Below is the Dockerfile used to build the image. In this Dockerfile, it installs the agent manager, modifies the agent manager configurations and then build the image. Once the image is built, it contains an installed agent manager with the customzied agent manager configurations set in the Dockerfile.
FROM ubuntu RUN apt-get update \ && apt-get -y install gettext-base xmlstarlet \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* WORKDIR /FglAM592 COPY FglAM-5_9_2-linux-x86_64.bin /FglAM592/ COPY installer.properties /FglAM592/ COPY wait-for-pid-file-existing.sh / COPY wait-for-pid-file-non-existing.sh / RUN chmod +x FglAM-5_9_2-linux-x86_64.bin RUN chmod +x /wait-for-pid-file-existing.sh RUN chmod +x /wait-for-pid-file-non-existing.sh RUN ./FglAM-5_9_2-linux-x86_64.bin && /wait-for-pid-file-existing.sh && ./bin/fglam -q && /wait-for-pid-file-non-existing.sh RUN rm -f /wait-for-pid-file-existing.sh RUN rm -f /wait-for-pid-file-non-existing.sh RUN rm -f FglAM-5_9_2-linux-x86_64.bin RUN xmlstarlet ed --inplace -d "/config:glue-configuration/config:host-id/config:id" state/default/config/fglam.config.xml RUN xmlstarlet ed --inplace -u "/config:glue-configuration/config:host-display-name/config:name" -v '${display_name}' state/default/config/fglam.config.xml RUN xmlstarlet ed --inplace -u "/config:glue-configuration/config:http-upstreams/config:http-upstream/@url" -v '${fms}' state/default/config/fglam.config.xml RUN touch
/FglAM592/init
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT /entrypoint.sh -
Configure the installer.properties file:
installer.installdir=/FglAM592 # Specify the installation directory installer.fms=url=https://10.154.14.90:8443,ssl-allow-self-signed=true,ssl-cert-common-name=quest.com # Specify the FMS address to which this agent manager connect. installer.noservice installer.silent
-
Configure the entrypoint.sh file:
#! /bin/bash VAR=/FglAM592/init if [ -f $VAR ]; then [ -z "$display_name" ] && export display_name=$HOSTNAME envsubst < "state/default/config/fglam.config.xml" > "state/default/config/fglam.config.xml" rm -f $VAR fi ./bin/fglam -d while true do LATEST_LOG=$(ls $PREFIX|egrep FglAM.*\\.log|sort -r|head -n1) if [ "$LOG_FILE" == "$LATEST_LOG" ]; then sleep 5 else LOG_FILE=$LATEST_LOG pkill tail (tail -f $PREFIX/$LOG_FILE &) fi done
-
Execute the command to build the image:
docker build -t fglamImg
-
Execute the command to run the container:
docker run -d --name fglaminstallation -e fms=<fms address> -e display_name=<fglam display name> fglamImg
Remember to specify the <fms address> and <fglam display name> if you want to customize them, otherwise the values in the installer.properties will be used. After the command is executed, the new agent manager will run in the container.
-
Go to FMS server, you will see the new agent manager is shown in the Agent Manger dashboard. After that, you can deploy agent packages and create agents in this new agent manager instance as what you would do on other agent managers.
- Restarting the fglaminstallation container or docker host won't impact this agent manager as well as the agents deployed in it.
Build the existing agent manager installation into an image
This testing creates a docker image which contains an installed agent manager installation(instead of the installer). When the image is instantiated, it starts the FglAM instance without the need to install it. After the agent manager started, it preserves all the customized configurations preset in the agent manager installation. Below are the steps for this testing.
Note: The difference between this test scenario and the above scenario(Build the agent manager installation into an image) is that this test embeds a pre-installed agent manager(with customzied configurations in it) in the image, while the above scenario installs the agent manager and customizes the agent manager configurations via the Dockerfile.
- First, install an agent manager, change some of its configurations such as the vms, maxActiveConnectionsCap and then run it.
-
Stop the agent manager instance, this agent manager is ready to be embeded in the image.
-
Configure the Dockerfile with below instructions to create the image which embeds above installed agent manager installation files.
FROM ubuntu RUN apt-get update \ && apt-get -y install gettext-base xmlstarlet\ && apt-get clean \ && rm -rf /var/lib/apt/lists/* WORKDIR /FglAM592 COPY myfglam /FglAM592 RUN xmlstarlet ed --inplace -d "/config:glue-configuration/config:host-id/config:id" state/default/config/fglam.config.xml RUN xmlstarlet ed --inplace -u "/config:glue-configuration/config:host-display-name/config:name" -v '${display_name}' state/default/config/fglam.config.xml RUN xmlstarlet ed --inplace -u "/config:glue-configuration/config:http-upstreams/config:http-upstream/@url" -v '${fms}' state/default/config/fglam.config.xml RUN touch /FglAM592/init COPY entrypoint.sh / RUN chmod +x /entrypoint.sh ENTRYPOINT /entrypoint.sh
-
Configure the entrypoint.sh file
#! /bin/bash VAR=/FglAM592/init if [ -f $VAR ]; then envsubst < "state/default/config/fglam.config.xml" > "state/default/config/fglam.config.xml" rm -f $VAR fi /FglAM592/bin/fglam -d PREFIX=/FglAM592/state/default/logs while true do LATEST_LOG=$(ls $PREFIX|egrep FglAM.*\\.log|sort -r|head -n1) if [ "$LOG_FILE" == "$LATEST_LOG" ]; then sleep 5 else LOG_FILE=$LATEST_LOG pkill tail (tail -f $PREFIX/$LOG_FILE &) fi done
-
Execute the command to build the image
docker build -t fglamImg
-
Execute the command to run the container
docker run -d --name fglaminstallation -e fms=<fms address> -e display_name=<fglam display name> fglamImg
Remember to specify the <fms address> and <fglam display name> if you want to customize them, otherwise the values of fglam display name will be container id. After the command is executed, the new agent manager will run in the container.
- Go to FMS server, you will see the new agent manager is shown in the Agent Manger dashboard. After that, you can deploy agent packages and create agents in this new agent manager instance as what you would do on other agent managers.
- Restarting the fglaminstallation container or docker host won't impact this agent manager as well as the agents deployed in it.
Persist agent manager status
Above test scenarios all work well not matter how you restart the docker container or docker host. The agent manager can persist its staus and agents after the restarts.
However, in the case that the constainer is removed, the agent manager running in it will be totally removed as well. In such case, if you want to persist the status of the Agent Manger, you can use command docker run -v to map a host directory. For example, run below command
docker run -d -v $PWD/myfglam:/opt/fglam --name newfglam -e fms=10.154.14.90:8443 -e display_name=fglam2 fglamImg
will create a new folder called myfglam with all fglam folders in it.
Go to the FMS, you can see the new agent manager fglam2 connects to it. Now you can deploy/create agents to this agent manger as what you would do on other agent managers.
If then this container is removed at sometime, you can use below command
docker run -d -v $PWD/myfglam:/opt/fglam --name newfglam -e fms=10.154.14.90:8443 -e display_name=fglam2 fglamImg
to start the agent manager which will preserve the status of fglam2 as well as all the agents run in it.