Elastic search Kibana
Installation and Configuration of ElasticSearch
Pre-requisites
sudo apt-get update
sudo apt-get install openjdk-8-jdk
Manual ElK Stack Installation steps
-
Download and install public signing key wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
-
Install apt-transport-https package sudo apt-get install apt-transport-https -y
-
Save directory definitions echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
-
Update and Install elasticsearch sudo apt-get update && sudo apt-get install elasticsearch && sudo apt-get install logstash && sudo apt-get install kibana
-
Configure elasticsearch sudo su nano /etc/elasticsearch/elasticsearch.yml
change cluster name cluster.name: demo-elk
give the cluster a descriptive name node.name: elk-1
change network binding network.host: 0.0.0.0
setup discovery.type as single node discovery.type: single-node
-
Enable elasticsearch service sudo systemctl enable elasticsearch
-
Start Elasticsearch service sudo systemctl start elasticsearch
-
Validate Elasticsearch cluster health curl -XGET http://localhost:9200/_cluster/health?pretty
Expected Result:
{ "cluster_name" : "moc-uat-applications", "status" : "green", "timed_out" : false, "number_of_nodes" : 1, "number_of_data_nodes" : 1, "active_primary_shards" : 0, "active_shards" : 0, "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 0, "delayed_unassigned_shards" : 0, "number_of_pending_tasks" : 0, "number_of_in_flight_fetch" : 0, "task_max_waiting_in_queue_millis" : 0, "active_shards_percent_as_number" : 100.0 }
- Configure kibana nano /etc/kibana/kibana.yml
uncomment server.port and server.port: 5601
change server.host in server.host: "0.0.0.0" or your private ip of server
change server.name server.name: "demo-kibana"
uncomment elasticsearch.host elasticsearch.hosts: ["http://localhost:9200"] or your private ip of server
-
Enable kibana service sudo systemctl enable kibana
-
Start Kibana service sudo systemctl start kibana
About "Filebeat"
-
File beat is a lightweight shipper for forwarding and centralizing log data.
-
Installed as an agent on your servers, File beat monitors the log files or locations that you specify, collects log events, and forwards them either to Elasticsearch or log stash for indexing.
-
It has TWO components
- Harvester - It's responsible for reading the content of a single file. The harvester reads each file, line by line, and sends the content to the output.
- Input - An input is responsible for managing the harvesters and finding all sources to read from.
Configure Kibana logging
-
Edit, sudo nano /etc/kibana/kibana.yml
Installation and configuration of Filebeat
-
Download and install public signing key wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
-
Install apt-transport-https package sudo apt-get install apt-transport-https -y
-
Save directory definitions echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
-
Update sudo apt-get update
-
Install filebeat sudo apt-get install filebeat
-
Configure filebeat (Navigate and open the file /etc/filebeat/filebeat.yml) i. Live reloading reload.enabled: true reload.period: 10s
ii. Setup dashboards setup.dashboards.enabled: true
iii. Kibana setup host: "<server_IP>:5601" // By default kibana will run under 5601 port
In the set iv, we can configure output to either logstash or elasticsearch. As of now configuring filebeat with Elasticsearch
iv. elasticsearch output hosts: "<server_IP>:9200" protocol: "http" username: "elastic" password: "<generated password, or we can change the password from the kibana UI>"
v. Set the path to send the logs and save
inset these lines in the .yml file at the last
logging.to_files: true
logging.files: path: /var/log/filebeat
name: filebeat
keepfiles: 7
permissions: 0644
Configure X-Pack Security
-
Stop kibana sudo systemctl stop kibana
-
Stop elasticsearch sudo systemctl stop elasticsearch
-
Enable xpack in elasticsearch.yml sudo nano /etc/elasticsearch/elasticsearch.yml xpack.security.enabled: true
Note: After doing above configuration, we need to start both kibana and elasticsearch services.
- Setup default user passwords cd /usr/share/elasticsearch/bin
sudo ./elasticsearch-setup-passwords --help
sudo ./elasticsearch-setup-passwords auto
- Check healthy check curl -XGET http://localhost:9200/_cluster/health?pretty
We will get the output as,
{ "error" : { "root_cause" : [ { "type" : "security_exception", "reason" : "missing authentication credentials for REST request [/_cluster/health?pretty]", "header" : { "WWW-Authenticate" : "Basic realm="security" charset="UTF-8"" } } ], "type" : "security_exception", "reason" : "missing authentication credentials for REST request [/_cluster/health?pretty]", "header" : { "WWW-Authenticate" : "Basic realm="security" charset="UTF-8"" } }, "status" : 401 }
Pass credentials from curl, curl -XGET -u elastic:password http://localhost:9200/_cluster/health?pretty
{ "cluster_name" : "moc-cam-production-applications", "status" : "green", "timed_out" : false, "number_of_nodes" : 1, "number_of_data_nodes" : 1, "active_primary_shards" : 11, "active_shards" : 11, "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 1, "delayed_unassigned_shards" : 0, "number_of_pending_tasks" : 0, "number_of_in_flight_fetch" : 0, "task_max_waiting_in_queue_millis" : 0, "active_shards_percent_as_number" : 91.66666666666666 }
- Add the default username in kibana sudo nano /etc/kibana/kibana.yml
elasticsearch.username: "kibana" elasticsearch.password: "new_password"
Login to kibana portal using elastic user
It is required if you use in the organization
About "metricbeat"
-
It's a lightweight shipper that you can install on your servers to periodically collect metrics from the operating system and from services running on the server.
-
Modules are standard configurations that can be enabled to monitor following ---> Apache HTTPD servers ---> System(CPU Load, memory), etc
METRIC BEAT - MODULES AND METRICSET
- A Metricbeat module defines the basic logic for collecting data from a specific service, such as apache http webserver and so on.
- A metric set is the part of the module that fetches and structures the data for example system module collects
Installation and configuration of Metricbeat on ELK Server
- Enable Monitoring on Elasticsearch Cluster
cd /etc/elasticsearch
sudo nano /etc/elasticsearch/elasticsearch.yml
xpack.monitoring.collection.enabled: true
xpack.monitoring.elasticsearch.collection.enabled: true
- Restart elasticsearch service
sudo systemctl restart elasticsearch
- Install Metricbeat
sudo apt-get install metricbeat
- Configure Metribeat
sudo su cd /etc/metricbeat
nano metricbeat.yml
i. Live reloading reload.enabled: true reload.period: 10s
ii. Name and tag name: <"Some Name"> tags: <"Some Name">
iii. Setup dashboards setup.dashboards.enabled: true
In the set iv, we can configure output to either logstash or elasticsearch. As of now configuring filebeat with Elasticsearch
iv. elasticsearch output hosts: "<server_IP>:9200" protocol: "http" username: "elastic" password: "<generated password, or we can change the password from the kibana UI>"
v. Set the path to send the
logging.to_files: true
logging.files:
path: /var/log/metricbeat
name: metricbeat
keepfiles: 7
permissions: 0644
vi. enable interal collection of metricbeat monitoring.enabled: true monitoring.elasticsearch
-
Start Metricbeat sudo systemctl start metricbeat
-
enable elasticsearch-xpack sudo metricbeat modules enable elasticsearch-xpack
nano elasticsearch-xpack.yml username: remote_monitoring_user password: remote_monitoring_user_password
- enable kibana-xpack sudo metricbeat modules enable kibana-xpack
nano kibana-xpack.yml
username: remote_monitoring_user password: remote_monitoring_user_password
-
enable beat-xpack sudo metricbeat modules enable beat-xpack
-
disable system module sudo metricbeat modules disable system
Instllation and configuration of Metricbeat on WebServer
-
Download and install public signing key wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
-
Install apt-transport-https package sudo apt-get install apt-transport-https -y
-
Save directory definitions echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
-
Update and Install metricbeat sudo apt-get update sudo apt-get install metricbeat
Configure Metribeat
sudo su cd /etc/metricbeat
nano metricbeat.yml
### live monitoring section
reload.enabled: true
reload.period: 10s
### name and tag
name: webserver
Tags: demo-web
### enable kibana dashboards
Setup.dashboards.enabled: true
host: <<ip_address_of_Kibana_server>>:5601
### output configuration
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["<<ip_address_of_elastic_server>>:9200"]
# Protocol - either `http` (default) or `https`.
protocol: "https"
#api_key: "id:api_key"
username: "elastic" #### elasticsuperuser
password: "password". #### elastic users password
logging
logging.level: debug
logging.selectors: ["*"]
logging.to_files: true
logging.files:
path: /var/log/metricbeat
name: metricbeat
keepfiles: 7
permissions: 0644
## enable interal collection of metricbeat
monitoring.enabled: true
monitoring.elasticsearch
Comments