{"id":11138,"date":"2021-12-13T20:10:02","date_gmt":"2021-12-13T17:10:02","guid":{"rendered":"https:\/\/kifarunix.com\/?p=11138"},"modified":"2024-03-18T07:44:30","modified_gmt":"2024-03-18T04:44:30","slug":"install-and-enroll-elastic-agents-to-fleet-manager-in-linux","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-and-enroll-elastic-agents-to-fleet-manager-in-linux\/","title":{"rendered":"Install and Enroll Elastic Agents to Fleet Manager in Linux"},"content":{"rendered":"\n
This tutorial will take you through how you can install and enroll Elastic agents to Fleet manager in Linux. According to Elastic Fleet and Elastic Agent overview page<\/a>;<\/p>\n\n\n\n In our previous tutorial, we learned how to ship logs to ELK stack using Elastic agents. The guide focused on setting up Fleet Server and installing Elastic agent on the Fleet server.<\/p>\n\n\n\n Ship System Logs to ELK Stack using Elastic Agents<\/a><\/p>\n\n\n\n In this example setup, we have two remote hosts to monitor; Debian 11 and Rocky Linux systems.<\/p>\n\n\n\n There are various ways in which you can install Elastic agents;<\/p>\n\n\n\n In Linux systems, it is recommended to install Elastic agent using the TAR archive over system packages (RPM\/DEB) as it makes it easy to upgrade the agent in Fleet.<\/p>\n\n\n\n Thus, we will be installing our Elastic agents in Linux using this method.<\/p>\n\n\n\n Navigate to Elastic Agents downloads<\/a> page and grab the installer for your respective system architecture.<\/p>\n\n\n\n The command below downloads Elastic Agent v7.16.0 for x86_64 systems;<\/p>\n\n\n\n Once download is complete, extract the installer;<\/p>\n\n\n\n Next, login back to Kibana and head over to Fleet > Agents > Add agent<\/strong>.<\/p>\n\n\n\n Copy the enrollment command and run on the remote host where you are installing the agent.<\/p>\n\n\n\n The command for my case looks like;<\/p>\n\n\n\n On the remote host where you downloaded the Elastic agent installer, navigate to agent installer directory;<\/p>\n\n\n\n Paste the copied agent installation and enrollment command from the Fleet server and execute it within the agent archive directory.<\/p>\n\n\n\n NOTE<\/strong>: if your Fleet server is using TLS certificates, you need to copy the Fleet server CA to some directory on the agent host.<\/p>\n\n\n\n In our agent host, we used Sample installation output;<\/p>\n\n\n\n You can reuse the same installation command across multiple hosts.<\/p>\n\n\n\n The agent will be installed at Checking the status of the Elastic agent;<\/p>\n\n\n\n Stop the agent;<\/p>\n\n\n\n If Elasticsearch is running on HTTP, the command above should just work and the agent should start sending logs immediately to the server.<\/p>\n\n\n\n However, if you setup Elasticsearch with TLS as we did in our guide above while setting up Fleet server, then you need to configure Elastic agent Filebeat and Metricbeat to connect to Elasticsearch via an encrypted and authenticated channel.<\/p>\n\n\n\n Therefore, copy the Elasticsearch CA to the agent host.<\/p>\n\n\n\n In our Fleet server setup, the cert is Hence, we copied and placed it on the agent host under, Edit both Elastic agent Filebeat and Metricbeat configuration files and;<\/p>\n\n\n\n Update Filebeat configs;<\/p>\n\n\n\n Update Elasticsearch output configs;<\/p>\n\n\n\n Similarly, update the Metricbeat configs just like above;<\/p>\n\n\n\n The Elastic agents have now been installed and enrolled to the Fleet Server. Check on the Fleet UI;<\/p>\n\n\n\n Agent status should at least be Healthy<\/strong>.<\/p>\n\n\n\n Click on the agent to view details.<\/p>\n\n\n\n Sample dashboards.<\/p>\n\n\n\n You can filter for specific host using the respective filters on the search bar.<\/p>\n\n\n\n And that concludes our guide.<\/p>\n\n\n\n Also see how you can enroll and monitor Windows systems using Elastic Osquery Manager;<\/p>\n\n\n\n Monitor Windows Systems using Elastic Osquery Manager<\/a><\/p>\n\n\n\n Install Elastic Agent<\/a><\/p>\n\n\n\n Integrate Wazuh Manager with ELK Stack<\/a><\/p>\n\n\n\n Configure ELK Stack Alerting with ElastAlert<\/a><\/p>\n\n\n\n\n
Installing Elastic Agents to Fleet Manager in Linux<\/h2>\n\n\n\n
Setup Elastic Fleet Server<\/h3>\n\n\n\n
Install Elastic Agent on Remote Hosts to Monitor<\/h3>\n\n\n\n
\n
Download Elastic Agent Tar Archive<\/h4>\n\n\n\n
wget https:\/\/artifacts.elastic.co\/downloads\/beats\/elastic-agent\/elastic-agent-7.16.0-linux-x86_64.tar.gz<\/code><\/pre>\n\n\n\n
Extract the installer<\/h4>\n\n\n\n
tar xzf elastic-agent-7.16.0-linux-x86_64.tar.gz<\/code><\/pre>\n\n\n\n
Add Elastic Agent to Fleet<\/h4>\n\n\n\n
\n
<\/figure>\n\n\n\n
Enroll Elastic Agent into Fleet Server<\/h4>\n\n\n\n
sudo .\/elastic-agent install --url=https:\/\/192.168.58.22:8220 --enrollment-token=RWlxd3FIMEI5V1c4cGdBQ3dPdks6ZFpNTmp3d1BSWUtER0RJYjlwSzQtdw==<\/code><\/pre>\n\n\n\n
cd elastic-agent-7.16.0-linux-x86_64\/<\/code><\/pre>\n\n\n\n
\/etc\/elasticsearch\/ca\/ca.crt<\/code><\/strong> from our Fleet server setup and placed it in the file
\/etc\/ssl\/certs\/ca.crt<\/code><\/strong>.<\/p>\n\n\n\n
sudo .\/elastic-agent install -f \\\n--url=https:\/\/192.168.58.22:8220 \\\n--certificate-authorities=\/etc\/ssl\/certs\/ca.crt \\\n--enrollment-token=RWlxd3FIMEI5V1c4cGdBQ3dPdks6ZFpNTmp3d1BSWUtER0RJYjlwSzQtdw==\n<\/code><\/pre>\n\n\n\n
2021-12-12T20:07:06.564+0300\tINFO\tcmd\/enroll_cmd.go:442\tStarting enrollment to URL: https:\/\/192.168.58.22:8220\/\n2021-12-12T20:07:11.089+0300\tINFO\tcmd\/enroll_cmd.go:250\tSuccessfully triggered restart on running Elastic Agent.\nSuccessfully enrolled the Elastic Agent.\nElastic Agent has been successfully installed.\n<\/code><\/pre>\n\n\n\n
\/opt\/Elastic\/Agent<\/code><\/strong> and will run as a service.<\/p>\n\n\n\n
ls -1 \/opt\/Elastic\/Agent\/<\/code><\/pre>\n\n\n\n
data\nelastic-agent\nelastic-agent-20211212203445\nelastic-agent.reference.yml\nelastic-agent.yml\nelastic-agent.yml.2021-12-12T20-34-44.0411.bak\nfleet.yml\nfleet.yml.lock\nLICENSE.txt\nNOTICE.txt\nREADME.md\n<\/code><\/pre>\n\n\n\n
systemctl status elastic-agent<\/code><\/pre>\n\n\n\n
\u25cf elastic-agent.service - Elastic Agent is a unified agent to observe, monitor and protect your system.\n Loaded: loaded (\/etc\/systemd\/system\/elastic-agent.service; enabled; vendor preset: disabled)\n Active: active (running) since Sun 2021-12-12 20:34:39 EAT; 1min 55s ago\n Main PID: 5825 (elastic-agent)\n Tasks: 10 (limit: 11388)\n Memory: 43.8M\n CGroup: \/system.slice\/elastic-agent.service\n \u2514\u25005825 elastic-agent\n\nDec 12 20:34:40 rocky8 elastic-agent[5825]: 2021-12-12T20:34:40.974+0300 INFO [api] api\/server.go:64 Metrics endpoint listening on: \/opt\/Elasti>\nDec 12 20:34:40 rocky8 elastic-agent[5825]: 2021-12-12T20:34:40.975+0300 INFO application\/local_mode.go:178 Agent is stopped\nDec 12 20:34:40 rocky8 elastic-agent[5825]: 2021-12-12T20:34:40.975+0300 INFO application\/periodic.go:79 Configuration changes detected\nDec 12 20:34:40 rocky8 elastic-agent[5825]: 2021-12-12T20:34:40.980+0300 INFO stateresolver\/stateresolver.go:48 New State ID is aqYAlQPW\nDec 12 20:34:40 rocky8 elastic-agent[5825]: 2021-12-12T20:34:40.981+0300 INFO stateresolver\/stateresolver.go:49 Converging state requires execution of>\nDec 12 20:34:45 rocky8 elastic-agent[5825]: 2021-12-12T20:34:45.091+0300 INFO operation\/operator.go:216 waiting for installer of pipeline 'default' to>\nDec 12 20:34:45 rocky8 elastic-agent[5825]: 2021-12-12T20:34:45.350+0300 INFO application\/periodic.go:101 No configuration change\nDec 12 20:34:45 rocky8 elastic-agent[5825]: 2021-12-12T20:34:45.350+0300 INFO process\/app.go:176 Signaling application to stop because of shutdown: me>\nDec 12 20:34:45 rocky8 elastic-agent[5825]: 2021-12-12T20:34:45.357+0300 INFO stateresolver\/stateresolver.go:48 New State ID is aqYAlQPW\nDec 12 20:34:45 rocky8 elastic-agent[5825]: 2021-12-12T20:34:45.695+0300 INFO stateresolver\/stateresolver.go:49 Converging state requires execution \n<\/code><\/pre>\n\n\n\n
systemctl stop elastic-agent<\/code><\/pre>\n\n\n\n
Configure Elasticsearch – Elastic Agent TLS connection<\/h4>\n\n\n\n
\/etc\/elasticsearch\/kifarunix-demo-fleet-server\/kifarunix-demo-fleet-server.crt<\/code><\/strong>.<\/p>\n\n\n\n
\/etc\/ssl\/certs\/kifarunix-demo-fleet-server.crt<\/strong><\/code>.<\/p>\n\n\n\n
\n
vim \/opt\/Elastic\/Agent\/data\/elastic-agent-4bcd95\/install\/filebeat-7.16.0-linux-x86_64\/filebeat.yml<\/code><\/pre>\n\n\n\n
# ---------------------------- Elasticsearch Output ----------------------------\noutput.elasticsearch:\n # Array of hosts to connect to.\n hosts: [\"192.168.58.22:9200\"]\n\n # Protocol - either `http` (default) or `https`.\n protocol: \"https\"\n ssl.certificate_authorities: [\"\/etc\/ssl\/certs\/kifarunix-demo-fleet-server.crt\"]\n\n # Authentication credentials - either API key or username\/password.\n #api_key: \"id:api_key\"\n username: \"elastic\"\n password: \"WSZdCjtgn9c8Pphd4St4\"\n<\/code><\/pre>\n\n\n\n
vim \/opt\/Elastic\/Agent\/data\/elastic-agent-4bcd95\/install\/metricbeat-7.16.0-linux-x86_64\/metricbeat.yml<\/code><\/pre>\n\n\n\n
# ---------------------------- Elasticsearch Output ----------------------------\noutput.elasticsearch:\n # Array of hosts to connect to.\n hosts: [\"192.168.58.22:9200\"]\n\n # Protocol - either `http` (default) or `https`.\n protocol: \"https\"\n ssl.certificate_authorities: [\"\/etc\/ssl\/certs\/kifarunix-demo-fleet-server.crt\"]\n\n # Authentication credentials - either API key or username\/password.\n #api_key: \"id:api_key\"\n username: \"elastic\"\n password: \"WSZdCjtgn9c8Pphd4St4\"\n<\/code><\/pre>\n\n\n\n
Start Elastic Agent<\/h4>\n\n\n\n
systemctl start elastic-agent<\/code><\/pre>\n\n\n\n
Verify Elastic Agent Enrollment<\/h3>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
Reference<\/h3>\n\n\n\n
Other Tutorials<\/h3>\n\n\n\n