在本文中,我们将向您介绍如何在香港服务器www.a5idc.net的Debian 10系统上安装ELK Stack。ELK stack是一个流行的、开源的日志管理平台。它被用作集中管理,用于存储、分析和查看日志。集中管理使得研究日志和识别任何数量的服务器的问题变得更加容易。
步骤1.在安装任何软件之前,通过apt在终端中运行以下命令来确保系统是最新的很重要:
sudo apt update
sudo apt upgrade
步骤2.安装Java。
运行以下命令以在Debian系统上安装Java:
sudo apt install openjdk-11-jre
验证安装的Java版本:
java -version
步骤3.在Debian 10上安装Elasticsearch。
首先,添加Elasticsearch存储库:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
接下来,通过发出以下命令将Elasticsearch存储库添加到系统中:
echo “deb https://artifacts.elastic.co/packages/6.x/apt stable main” | tee -a /etc/apt/sources.list.d/elastic-6.x.list
现在运行apt update,然后在您的Debian系统上安装Elasticsearch软件包:
sudo apt update
sudo apt install elasticsearch
安装过程完成后,使用以下命令启动并启用该服务:
sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
您可以使用curl命令行实用工具对其进行测试。使用curl运行简单的GET命令以验证设置。您将在屏幕上看到带有版本的Elasticsearch集群详细信息:
curl -X GET “localhost:9200/”
您应该看到类似于以下内容:
{
"name" : "GoDeTz",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "B-5B34Meilana-MariaeIYkimpoiD3ww",
"version" : {
"number" : "6.6.1",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "1fd8f69",
"build_date" : "2020-12-08T17:15:36.160291Z",
"build_snapshot" : false,
"lucene_version" : "7.8.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.8.0"
},
"tagline" : "You Know, for Search"
}
步骤4.安装Logstash。
使用来自官方Elastic仓库的apt软件包管理器安装Logstash:
sudo apt install logstash-oss
安装Logstash软件包后,启动Logstash服务并将其设置为在启动时自动启动:
sudo systemctl restart logstash
sudo systemctl enable logstash
步骤5.安装Kibana。
Kibana提供了对Elasticsearch上存储的数据的可视化。现在,我们使用以下命令安装Kibana。
sudo apt install kibana-oss
安装完成后,打开kibana.yml文件并限制对Kibana实例的远程访问:
nano /etc/kibana/kibana.yml
# Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
# The default is 'localhost', which usually means remote machines will not be able to connect.
# To allow connections from remote users, set this parameter to a non-loopback address.
server.host: "localhost"
启动Kibana服务并将其设置为在启动时自动启动:
sudo systemctl start kibana
sudo systemctl enable kibana
步骤6.安装和配置Nginx。
要将Nginx配置为通过SSL到Kibana的代理连接,您需要生成SSL / TLS证书并创建一个Nginx配置文件以定义Kibana设置:
sudo apt install nginx
接下来,使用OpenSSL命令创建基本身份验证文件:
echo “admin:openssl passwd -apr1 YourPasswd
” | sudo tee -a /etc/nginx/htpasswd.kibana
然后,为Kibana实例创建一个虚拟主机配置文件:
rm -f /etc/nginx/sites-enabled/default
nano /etc/nginx/sites-available/kibana
添加以下行:
server {
listen 80 default_server;
server_name _;
return 301 https://$server_name$request_uri;
}
server {
listen 443 default_server ssl http2;
server_name _;
ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
ssl_session_cache shared:SSL:10m;
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/htpasswd.kibana;
location / {
proxy_pass http://localhost:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
然后,创建一个符号链接并测试Nginx配置:
ln -s /etc/nginx/sites-available/kibana /etc/nginx/sites-enabled/kibana
nginx -t
重新启动Nginx服务,并将其设置为在启动时自动启动:
sudo systemctl restart nginx
sudo systemctl enable nginx
如果UFW正在运行,则允许HTTP和HTTPS的Nginx连接:
sudo ufw allow ‘Nginx Full’
步骤7.访问Kibana Web界面。
您可以使用以下URL访问Kibana Web界面:
https://你的IP地址。
到这里,ELK Stack的安装就已经全部完成了。