After hours of trying, here is what I figured out. I have tried to install OneAgent using two approaches.
The following relates to a Docker Swarm on AWS cluster that was created using the CloudFormation template
supplied by Docker. EC2 instances in such a deployment are based on the AMI Moby Linux 17.10.0-ce-aws1 edge (ami-b20bb2dd) for the latest version.
1. Install OneAgent on the “real” Docker Host
I first attempted to manage to build a SSH connection to a swarm EC2 instance in order to try the installation. I managed to do that by inserting the following instructions into the User Data section before the rc-service docker restart instruction.
echo "http://dl-2.alpinelinux.org/alpine/edge/community/" >> /etc/apk/repositories<br>apk add --no-cache openssh sudo shadow sed<br>echo "docker ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers# start sshd<br>sed -i 's/#Port 22/Port 2222/g' /etc/ssh/sshd_config<br>mkdir -p ~/.ssh && docker cp shell-aws:/home/docker/.ssh/authorized_keys ~/.ssh/authorized_keys<br>/etc/init.d/sshd start<br>
This allowed me to SSH into the Swarm EC2 instance at docker@{ec2-public-dns}:2222. The next issue was that the provided AMI is based on Alpine Linux but OneAgent requires glibc. I worked around this by installing glibc compatibility using the following commands:
# install alpine-glibc<br>wget -q -O /etc/apk/keys/sgerrand.rsa.pub "https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub"<br>wget "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.27-r0/glibc-2.27-r0.apk"<br>apk add --force glibc-2.27-r0.apk<br>
I then tried to reuse the OneAgent installation instructions provided during the Dynatrace SaaS setup. Before that, I had to install OpenSSL support as well as the trusted root CAs:
apk update && apk upgrade wget && apk add openssl coreutils && apk --no-cache add ca-certificates<br>
The installation commands provided by Dynatrace are as follows:
wget -O Dynatrace-OneAgent-Linux.sh "https://{ACCOUNT-ID}.live.dynatrace.com/api/v1/deployment/installer/agent/unix/default/latest?Api-Token={API-TOKEN}&arch=x86&flavor=default"<br># wget "https://ca.dynatrace.com/dt-root.cert.pem" ; ( echo 'Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg="sha-256"; boundary="--SIGNED-INSTALLER"'; echo ; echo ; echo '----SIGNED-INSTALLER' ; cat Dynatrace-OneAgent-Linux.sh ) | openssl cms -verify -CAfile dt-root.cert.pem > /dev/null<br>/bin/sh Dynatrace-OneAgent-Linux.sh APP_LOG_CONTENT_ACCESS=1<br>
I needed to deactivate the signature verification because the root ca could not be downloaded:
Connecting to ca.dynatrace.com (52.85.184.247:443)<br>wget: error getting response: Connection reset by peer<br>
Next, the GLIBC version check carried out by the OneAgent install script fails because it uses ldd --version and ldd in the AMI still targets the musl libc despite the prior installation of glibc compatibility. I manually deactivated the check in the script as a workaround.
After that, the invocation of base64 failed - it seems that Alpine comes with an uncommon version:
/bin/base64: unrecognized option: i<br>BusyBox v1.25.1 (2017-11-23 08:48:46 GMT) multi-call binary.<br>Usage: base64 [-d] [FILE]<br>Base64 encode or decode FILE to standard output<br> -d Decode data<br>tar: short read<br>
I solved this by simply removing the -i option from the base64 invocation (readonly UNPACK_BINARY_ARGS=“-d”).
The next problem was that the AMI’s root device is not mounted at / and the filesystem mounted as / is a tmpfs with only ~500MB in size. Thus, the installer script terminates because not enough space is available in the default insall path /opt/dynatrace.
I thought of 2 possible workarounds for this problem:
- Specify a different install path (e.g. to /var which is mounted on the root device with sufficient memory)
- Mount the root device in /opt via sudo mount /dev/xvdb1 /opt
I first tried option nr 2 and observed that the agent installation was working, although autostart could not be registered:
15:11:18 Error: Couldn't add oneagent to autostart. Please adjust and add it manually.<br>Dynatrace-OneAgent-Linux.sh: line 3305: ex: not found<br>
After option nr 2 worked, I did not try option nr 1.
Here are the final instructions - leaving out the ssh stuff - that need to be inserted into the user data section of the Swarm CloudFormation template right before the rc-service docker restart (you may need to adapt the OneAgent download URL):
"\n",<br>"# install openssl & ca certs\n",<br>"apk update && apk upgrade wget && apk add openssl coressl && apk --no-cache add ca-certificates\n",<br>"# install alpine-glibc\n",<br>"wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub\n",<br>"wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.27-r0/glibc-2.27-r0.apk\n",<br>"apk add --force glibc-2.27-r0.apk\n",<br>"# install Dynatrace OneAgent\n",<br>"mkdir -p /opt/dynatrace\n",<br>"mount /dev/xvdb1 /opt/dynatrace\n",<br>"if [ -d /opt/dynatrace/oneagent ]; then\n",<br>" /opt/dynatrace/oneagent/agent/initscripts/oneagent start\n",<br>"else\n",<br>" wget -O Dynatrace-OneAgent-Linux.sh \"https://{ACCOUNT-ID}.live.dynatrace.com/api/v1/deployment/installer/agent/unix/default/latest?Api-Token={API-TOKEN}&arch=x86&flavor=default\"\n",<br>" sed -i 's/arch_checkGlibc$/: #arch_checkGlibc/;s/readonly UNPACK_BINARY_ARGS=\\\"-di\\\"/readonly UNPACK_BINARY_ARGS=\\\"-d\\\"/' Dynatrace-OneAgent-Linux.sh\n",<br>" /bin/sh Dynatrace-OneAgent-Linux.sh APP_LOG_CONTENT_ACCESS=1\n",<br>"fi\n",<br>"\n",<br>
I noticed that there is also a docker image for running the OneAgent and tried that as well.
The docker image relies on a volume mount -v /:/mnt/root - this path is hard coded in the entrypoint.sh script. Again, the problem is that / is not mounted in the root device but in a tmpfs device with limited space. Hence, the installation fails due to insufficient space. The only way I was able to get it to work was by removing the volume mount and by adapting the entrypoint.sh script by:
readonly DOCKER_HOST_ROOT_PREFIX=/<br>
Conclusion
Installing OneAgent on a Swarm EC2 instance works but it would be very nice if Dynatrace could modify their install procedures to make this work out-of-the-box.