Contents
This document guides you through installing the Wazuh server and the Elastic Stack components in an all-in-one configuration. This guide provides instructions for configuring the official repositories to perform the installations; alternatively, all available packages can be found here .
Root user privileges are required to execute all the commands described below.
Prerequisites
The installation requires some extra packages, such as curl or unzip, that will be used in the following steps
Install all the necessary packages:
apt-get install apt-transport-https zip unzip lsb-release curl gnupg
Installing Elasticsearch
Elasticsearch is a highly scalable full-text search and analytics engine.
Adding the Elastic Stack repository
Install the GPG key:
curl -s https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
Add the repository:
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee /etc/apt/sources.list.d/elastic-7.x.list
Update the package information:
apt-get update
Elasticsearch installation and configuration
Install the Elasticsearch package:
apt-get install elasticsearch=7.14.2
Download the configuration file /etc/elasticsearch/elasticsearch.yml as follows:
curl -so /etc/elasticsearch/elasticsearch.yml https://packages.wazuh.com/resources/4.2/elastic-stack/elasticsearch/7.x/elasticsearch_all_in_one.yml
Certificates creation and deployment
Download the configuration file to create the certificates:
curl -so /usr/share/elasticsearch/instances.yml https://packages.wazuh.com/resources/4.2/elastic-stack/instances_aio.yml
In the following steps, a file will be created that contains a folder named after the instance defined here. This folder will contain the certificates and keys necessary to communicate with the Elasticsearch node using SSL.
The certificates can be created using the elasticsearch-certutil tool:
/usr/share/elasticsearch/bin/elasticsearch-certutil cert ca --pem --in instances.yml --keep-ca-key --out ~/certs.zip
Extract the /usr/share/elasticsearch/certs.zip file created in the previous step.
unzip ~/certs.zip -d ~/certs
The next step is to create the /etc/elasticsearch/certs directory and then copy the CA file, the certificate and the key there:
mkdir /etc/elasticsearch/certs/ca -p
cp -R ~/certs/ca/ ~/certs/elasticsearch/* /etc/elasticsearch/certs/
chown -R elasticsearch: /etc/elasticsearch/certs
chmod -R 500 /etc/elasticsearch/certs
chmod 400 /etc/elasticsearch/certs/ca/ca.* /etc/elasticsearch/certs/elasticsearch.*
rm -rf ~/certs/ ~/certs.zip
Enable and start the Elasticsearch service:
To mitigate the Apache Log4j2 Remote Code Execution (RCE) vulnerability, add the following configuration – CVE-2021-44228 – ESA-2021-31.
mkdir -p /etc/elasticsearch/jvm.options.d
echo '-Dlog4j2.formatMsgNoLookups=true' > /etc/elasticsearch/jvm.options.d/disabledlog4j.options
chmod 2750 /etc/elasticsearch/jvm.options.d/disabledlog4j.options
chown root:elasticsearch /etc/elasticsearch/jvm.options.d/disabledlog4j.options
systemctl daemon-reload
systemctl enable elasticsearch
systemctl start elasticsearch
Generate credentials for all the Elastic Stack pre-built roles and users:
/usr/share/elasticsearch/bin/elasticsearch-setup-passwords auto
The command above will prompt for output like the following. Save the password of the elastic user for the next steps:
Output
Changed password for user apm_system
PASSWORD apm_system = lLPZhZkB6oUOzzCrkLSF
Changed password for user kibana_system
PASSWORD kibana_system = TaLqVOnSoqKTYLIU0vDn
Changed password for user kibana
PASSWORD kibana = TaLqVOvXoqKTYLIU0vDn
Changed password for user logstash_system
PASSWORD logstash_system = UtuDv2tWkXGYL83v9kWA
Changed password for user beats_system
PASSWORD beats_system = qZcbvCslafMpoEOrE9Ob
Changed password for user remote_monitoring_user
PASSWORD remote_monitoring_user = LzJpQiSylncmCU2GLBTS
Changed password for user elastic
PASSWORD elastic = AN4UeQGA7HGl5iHpMla7
To check that the installation was successful, run the following command, replacing <elastic_password> with the password generated in the previous step for the elastic user:
curl -XGET https://localhost:9200 -u elastic:<elastic_password> -k
The output of this command should look like this:
Output
{
"name" : "elasticsearch",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "upF9h1afQN2TfHtt0h3Kuw",
"version" : {
"number" : "7.14.2",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "6bc13727ce758c0e943c3c21653b3da82f627f75",
"build_date" : "2021-09-15T10:18:09.722761972Z",
"build_snapshot" : false,
"lucene_version" : "8.9.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
The Wazuh server collects and analyzes data from deployed agents. It runs the Wazuh manager, the Wazuh API and Filebeat. The first step in setting up Wazuh is to add the Wazuh repository to the server. Alternatively, the Wazuh manager package can be downloaded directly, and compatible versions can be checked here .
Adding the Wazuh repository
Install the GPG key:
curl -s https://packages.wazuh.com/key/GPG-KEY-WAZUH | apt-key add -
Add the repository:
echo "deb https://packages.wazuh.com/4.x/apt/ stable main" | tee -a /etc/apt/sources.list.d/wazuh.list
Update the package information:
apt-get update
Installing the Wazuh manager
Install the Wazuh manager package:
systemctl daemon-reload
systemctl enable wazuh-manager
systemctl start wazuh-manager
Run the following command to check whether the Wazuh manager is active:
systemctl status wazuh-manager
Installing Filebeat
Filebeat is the tool on the Wazuh server that securely forwards alerts and archived events to Elasticsearch.
Filebeat installation and configuration
Install the Filebeat package:
apt-get install filebeat=7.14.2
Download the pre-configured Filebeat configuration file used to forward Wazuh alerts to Elasticsearch:
curl -so /etc/filebeat/filebeat.yml https://packages.wazuh.com/resources/4.2/elastic-stack/filebeat/7.x/filebeat_all_in_one.yml
Download the alerts template for Elasticsearch:
curl -so /etc/filebeat/wazuh-template.json https://raw.githubusercontent.com/wazuh/wazuh/4.2/extensions/elasticsearch/7.x/wazuh-template.json
chmod go+r /etc/filebeat/wazuh-template.json
Download the Wazuh module for Filebeat:
curl -s https://packages.wazuh.com/4.x/filebeat/wazuh-filebeat-0.1.tar.gz | tar -xvz -C /usr/share/filebeat/module
Edit the /etc/filebeat/filebeat.yml file:
output.elasticsearch.password: <elasticsearch_password>
Replace elasticsearch_password with the password previously generated for the elastic user.
Copy the certificates into /etc/filebeat/certs/
cp -r /etc/elasticsearch/certs/ca/ /etc/filebeat/certs/
cp /etc/elasticsearch/certs/elasticsearch.crt /etc/filebeat/certs/filebeat.crt
cp /etc/elasticsearch/certs/elasticsearch.key /etc/filebeat/certs/filebeat.key
Enable and start the Filebeat service:
systemctl daemon-reload
systemctl enable filebeat
systemctl start filebeat
To make sure that Filebeat has been successfully installed, run the following command:
filebeat test output
Kibana installation and configuration
Kibana is a flexible and intuitive web interface for exploring and visualizing the events and archives stored in Elasticsearch.
Install the Kibana package:
apt-get install kibana=7.14.2
Copy the Elasticsearch certificates into the Kibana configuration folder:
mkdir /etc/kibana/certs/ca -p
cp -R /etc/elasticsearch/certs/ca/ /etc/kibana/certs/
cp /etc/elasticsearch/certs/elasticsearch.key /etc/kibana/certs/kibana.key
cp /etc/elasticsearch/certs/elasticsearch.crt /etc/kibana/certs/kibana.crt
chown -R kibana:kibana /etc/kibana/
chmod -R 500 /etc/kibana/certs
chmod 440 /etc/kibana/certs/ca/ca.* /etc/kibana/certs/kibana.*
Download the Kibana configuration file:
curl -so /etc/kibana/kibana.yml https://packages.wazuh.com/resources/4.2/elastic-stack/kibana/7.x/kibana_all_in_one.yml
Edit the /etc/kibana/kibana.yml file:
elasticsearch.password: <elasticsearch_password>
Values to be replaced:
<elasticsearch_password>: The password generated during the Elasticsearch installation and configuration for theelasticuser.
Create the /usr/share/kibana/data directory:
mkdir /usr/share/kibana/data
chown -R kibana:kibana /usr/share/kibana
Install the Wazuh Kibana plugin. The plugin must be installed from the Kibana home directory as follows:
cd /usr/share/kibana
sudo -u kibana /usr/share/kibana/bin/kibana-plugin install https://packages.wazuh.com/4.x/ui/kibana/wazuh_kibana-4.2.5_7.14.2-1.zip
Bind Kibana's socket to the privileged port 443:
setcap 'cap_net_bind_service=+ep' /usr/share/kibana/node/bin/node
Enable and start the Kibana service:
systemctl daemon-reload
systemctl enable kibana
systemctl start kibana
Access the web interface using the password generated during the Elasticsearch installation process:
URL: https://<wazuh_server_ip>
user: elastic
password: <PASSWORD_elastic>
On the first access to Kibana, the browser shows a warning message stating that the certificate was not issued by a trusted authority. An exception can be added in the advanced options of the web browser or, for more security, the previously generated ca.crt file can be imported into the browser's certificate manager. Alternatively, a certificate obtained from a trusted authority can be configured.
Disabling repositories
This installation guide explains how to install and configure Wazuh and the Elastic Stack by configuring their repositories first.
With each new version of Wazuh or the Elastic Stack, the development team at Wazuh thoroughly tests the compatibility of each component and makes the necessary adjustments before releasing a new Wazuh Kibana plugin.
We recommend disabling the repositories so that individual packages are not updated unintentionally, which could potentially leave you with an Elastic Stack version for which the Wazuh integration has not yet been released.
sed -i "s/^deb/#deb/" /etc/apt/sources.list.d/wazuh.list
sed -i "s/^deb/#deb/" /etc/apt/sources.list.d/elastic-7.x.list
apt-get update
