当前位置:   article > 正文

elk系列之elk单机部署_elk单机完整部署

elk单机完整部署
`简介`
ELK是目前主流的一种日志系统,三个开源软件的缩写,分别表示:Elasticsearch , Logstash, Kibana , 它们都是开源软件。
Elasticsearch是一个分布式、RESTful 风格的搜索和数据分析引擎,能够解决不断涌现出的各种用例。
Logstash 是免费且开放的服务器端数据处理管道,能够从多个来源采集数据,转换数据,然后将数据发送到您最喜欢的“存储库”中。采用jruby语言开发。
Kibana 是一个免费且开放的用户界面,能够对 Elasticsearch 数据进行可视化,并让在 Elastic Stack 中进行导航。可以进行各种操作,从跟踪查询负载,到理解请求如何流经整个应用。
`工作原理`
收集日志->          存储分析->               界面展示->
        logstash->          elasticsearch->          kibana
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

1、环境描述

10.1.0.103          安装jdk,elasticsearch7.x,logstash7.x,kibana7.x
  • 1

2、安装jdk

下载地址:https://download.oracle.com
(1)解压安装包
tar xvf jdk-8u141-linux-x64.tar.gz
(2)配置环境变量(解压路径及下载版本跟需调整)
echo ' export JAVA_HOME=/usr/local/java/jdk1.8.0_141/' >> /etc/profile
echo ' export JAVA_BIN=/usr/local/java/jdk1.8.0_141/bin' >> /etc/profile
echo ' export PATH=$PATH:$JAVA_HOME/bin' >> /etc/profile
echo ' export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar' >> /etc/profile
echo ' export JAVA_HOME JAVA_BIN PATH CLASSPATH' >> /etc/profile
(3)刷新环境变量
source /etc/profile
(4)查看安装情况
java -version
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

3、安装elasticsearch

(1)配置elasticsearch源
 vim /etc/yum.repos.d/elasticsearch.repo
 [elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
(2)安装elasticsearch
yum install elasticsearch -y
(3)配置elasticsearch
vim /etc/elasticsearch/elasticsearch.yml
17 cluster.name: my-application
23 node.name: elk-1
56 network.host: 0.0.0.0
61 http.port: 9200
74 cluster.initial_master_nodes: ["elk-1"]
#head插件连接es
http.cors.enabled: true
http.cors.allow-origin: "*"
说明:启动内存和其他参数跟机器需求调整
(4)启动
/etc/init.d/elasticsearch start
(5)测试
curl 127.0.0.1:9200
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

elasticsearch启动
4、安装elasticsearch-head插件

(1)安装nodejs
curl -sL https://rpm.nodesource.com/setup_11.x | bash -
yum install nodejs -y
(2)使用git安装elasticsearch-head
yum install git -y
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
说明:安装报错,可参考https://blog.csdn.net/weixin_44320761/article/details/121291103?spm=1001.2014.3001.5501
(3)后台启动
nohup npm run start >/dev/null 2>&1 &
(4)浏览器访问测试
http://IP:9100
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

elasticsearch-head访问
5、安装logstash

(1)安装
yum install -y logstash
(2)创建一个软连接(默认安装在/usr/share下)
ln -s /usr/share/logstash/bin/logstash /bin/
(3)测试
logstash -e 'input { stdin { } } output { stdout {} }'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

logstash测试

(4)标准输出elasticsearch中
logstash -e 'input { stdin { } } output { elasticsearch { hosts => ["10.1.0.103:9200"] } stdout { codec => rubydebug }}'
  • 1
  • 2

logstash
elasticsearch-head查看logstash

(5)logstash使用配置文件配置系统日志
vim logstash.conf
input {
    file {
        path => "/var/log/messages"
        type => "system"
        start_position => "beginning"
    }
}

output {
    if [type] == "system" {
        elasticsearch {
            hosts => ["10.1.0.103:9200"]
            index => "test-system-%{+YYYY.MM.dd}"
        }
    }
}
(6)后台启动
nohup logstash -f logstash.conf >/dev/null 2>&1 &
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

logstash访问
6、安装kibana

(1)安装
yum install kibana -y
(2)配置kibana
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://10.1.0.103:9200"]
kibana.index: ".kibana"
(3)启动
/etc/init.d/kibana start
(4)浏览器访问
http://IP:5601
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

kibana
kibana

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/992940
推荐阅读
相关标签
  

闽ICP备14008679号