Introduction
This article explains how to work with localhost if you are using Linux or Docker. It shows you how to:
- Route an Elasticsearch cluster URL to localhost
- Configure localhost
- Check localhost connectivity.
Let’s start by looking at Linux.
Linux
If you’re using Linux OS, you can simplify the process by modifying the /etc/hosts file to route the Elasticsearch/OpenSearch cluster URL to localhost.
The first step is to check the Elasticsearch/OpenSearch cluster URL reachability. You can do so by opening a terminal on your Linux machine and using the curl command to check if the cluster URL is reachable. The command that you should run is as follows:
curl http://<ES_CLUSTER_URL>
You need to replace <ES_CLUSTER_URL> with the actual URL or IP address of your cluster.
In case you are using basicauth, please add -u user:pass to the command.
If the connection is successful, you should see a response from the Elasticsearch/OpenSearch cluster in the terminal. This indicates that the cluster is reachable from your Linux machine. If you do not get an answer here, it means that you are not able to reach the cluster from that machine. If that is the case, you should fix it and try again.
Configuring localhost on a Linux machine
Here’s a step-by-step guide to configuring localhost:
- First, open a terminal on your Linux machine.
- Then, run the following command to open the /etc/hosts file using a text editor with administrative privileges:
vim /etc/hosts
- Next, locate an empty line or create a new line at the end of the file.
- On that new line, add an entry that maps the Elasticsearch/OpenSearch cluster URL to the IP address 127.0.0.1, which represents localhost. The format is as follows:
127.0.0.1 <ES_CLUSTER_URL>
- Again, you should replace <ES_CLUSTER_URL> with the actual URL or hostname of your Elasticsearch/OpenSearch cluster. In case you are using basicauth, please add -u user:pass to the command.
- Reload the hostname service with /bin/systemctl restart systemd-hostnamed command
- Finally, save the changes.
Checking localhost connectivity
After modifying the /etc/hosts file to route the Elasticsearch/OpenSearch cluster URL to localhost, you can verify the connectivity by running the following curl command:
curl http://localhost
This time, you are accessing the cluster using the modified URL that points to localhost.
If the connection is successful, you should receive a response from the cluster, similar to the previous check. This confirms that the cluster is now accessible via localhost, and you can proceed and run the Opster installation command.
Docker
Configuring localhost on a Docker container
Here’s a step-by-step guide to configuring localhost on your Docker container:
- First, open a terminal on your Linux machine where your docker app is installed so you can install Opster’s Metricbeat agent container.
- Second, run the following command to open the /etc/hosts file using a text editor with administrative privileges:
vim /etc/hosts
- Then, locate an empty line or create a new line at the end of the file.
- On that new line, add an entry that maps the Elasticsearch/OpenSearch cluster URL to the IP address 127.0.0.1, which represents localhost. The format to use is as follows:
127.0.0.1 <ES_CLUSTER_URL>
- Again, you have to replace <ES_CLUSTER_URL> with the actual URL or hostname of your cluster.
- Then, save the changes
- Reload the hostname service with:
- For linux – /bin/systemctl restart systemd-hostnamed
- For mac – sudo dscacheutil -flushcache
Finally, go to AutoOps installation wizard and add to the command with the ‘–network=host’ option to use the host’s network stack. You can proceed and run the Opster installation command.
In this doc we covered how to work with localhost when using Linux or Docker, including steps to route an Elasticsearch/OpenSearch cluster URL to localhost, configure localhost, and check localhost connectivity, essential for deploying Opster’s Metricbeat agent container.