首页 > 技术文章 > 企业安全建设第14课-实验ELK安装

miansj 2020-11-23 16:39 原文

实验声明:本实验教程仅供研究学习使用,请勿用于非法用途,违者一律自行承担所有风险!

ELK安装实验

实验环境

新安装的CENTOS7.5 一台 内存8G

一台windows,用于客户端浏览kibana

实验目标

安装ELK服务器,用于收集其它设备日志

实验步骤

一、准备环境

修改系统默认配置,以提高性能

vim /etc/security/limits.conf

加入以下四行,其中nofile指同时打开文件,nproc指同时的进程数

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

vim /etc/sysctl.conf,增大虚拟内存

vm.max_map_count=655300

执行以下命令生效

sysctl -p

安装JAVA环境

yum install -y java-1.8.0-openjdk-devel.x86_64

验证安装成功

java -version

安装elasticsearch

导入安装源

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

新建文件vim /etc/yum.repos.d/elasticsearch.repo

[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

安装 elasticsearch

yum install elasticsearch

启动服务,需要花费约30秒。

systemctl start elasticsearch

验证服务已启动,查看TCP 9200端口 开启

ss -lnt | grep 9200

curl验证,看到显示如下

curl 127.0.0.1:9200
[root@111]# curl 127.0.0.1:9200
{
  "name" : "ehcvjmC",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "9b75UiQTTvauX1ZjOB9Nvg",
  "version" : {
    "number" : "6.7.0",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "8453f77",
    "build_date" : "2019-03-21T15:32:29.844721Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

logstash

导入安装源

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

新建文件vim /etc/yum.repos.d/logstash.repo

[logstash-6.x]
name=Elastic repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

生成配置文件

cp /etc/logstash/logstash-sample.conf /etc/logstash/conf.d/logstash.conf

安装logstash

yum install -y logstash

启动服务

systemctl start logstash

检查服务

ss -lnt |grep 5044

kibana

新建文件

vi /etc/yum.repos.d/kibana.repo

[kibana-6.x]
name=Kibana repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

安装kibana

yum install kibana

配置外部端口,以供访问

vim /etc/kibana/kibana.yml

找到以下行,并修改 ,其中x.x.x.x 为本机IP地址。以供其它PC访问

server.host: "x.x.x.x"

启动kibana

systemctl start kibana

检查服务是否启动

ss -lnt | grep 5601

可以用其它同网段设备访问,会出现kibana界面 。

http://x.x.x.x:5601

完装成功

最后检查所有端口

ss -lnt 

应该会看到

elasticsearch 的9200 9300

logstash 的 5044

kibana的 5601

证明安装成功

推荐阅读