目录:
一、介绍
二、安装JDK
三、安装Elasticsearch
四、安装Kibana
五、安装Nginx
六、安装Logstash
七、安装Logstash-forwarder
八、测试
系统环境:CentOS Linux release 7.4.1708 (Core)
软件版本:
elasticsearch-5.6.10
kibana-5.6.10
logstash-5.6.10
当前问题状况
开发人员不能登录线上服务器查看详细日志。各个系统都有日志,日志数据分散难以查找。日志数据量大,查询速度慢,或者数据不够实时。1、组成
ELK由Elasticsearch、Logstash和Kibana三部分组件组成;Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。Logstash是一个完全开源的工具,它可以对你的日志进行收集、分析,并将其存储供以后使用kibana 是一个开源和免费的工具,它可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。
2、四大组件Logstash: logstash server端用来搜集日志;Elasticsearch: 存储各类日志;Kibana: web化接口用作查寻和可视化日志;Logstash Forwarder: logstash client端用来通过lumberjack 网络协议发送日志到logstash server;
3、工作流程
在需要收集日志的所有服务上部署logstash,作为logstash agent(logstash shipper)用于监控并过滤收集日志,将过滤后的内容发送到Redis,然后logstash indexer将日志收集在一起交给全文搜索服务ElasticSearch,可以用ElasticSearch进行自定义搜索通过Kibana 来结合自定义搜索进行页面展示。
官方下载地址:https://www.elastic.co/downloads/past-releases/elasticsearch-5-6-10
#创建用户elasticsearch-5.6.10 [root@elk-node1 local]# useradd elasticsearch #解压 [root@elk-node1 application]# tar -xf elasticsearch-5.6.10.tar.gz -C /usr/local/ #创建软链接 [root@elk-node1 local]# ln -s elasticsearch-5.6.10/ elasticsearch #授权 [root@elk-node1 local]# chown -R elasticsearch elasticsearch-5.6.10/ [root@elk-node1 local]# chown -R elasticsearch elasticsearch #修改配置文件 [root@elk-node1 local]# cd elasticsearch/config/ [root@elk-node1 config]# pwd /usr/local/elasticsearch/config [root@elk-node1 config]# grep -Ev "^#|^$" elasticsearch.yml cluster.name: pcidata-elk node.name: elk-node1 bootstrap.memory_lock: true network.host: 0.0.0.0 http.port: 9200 http.cors.enabled: true http.cors.allow-origin: "*" #修改打开文件句柄数,添加limits.conf内容 [root@elk-node1 config]# ulimit -SHn 65536 [root@elk-node1 config]# tail /etc/security/limits.conf elasticsearch hard nofile 131072 elasticsearch soft nproc 2048 elasticsearch hard nproc 4096 elasticsearch soft memlock unlimited elasticsearch hard memlock unlimited #切换到elasticsearch启动服务 [root@elk-node1 config]# su - elasticsearch Last login: Mon Aug 6 18:42:34 CST 2018 on pts/2 [elasticsearch@elk-node1 ~]$ ll total 0 [elasticsearch@elk-node1 ~]$ cd /usr/local/elasticsearch/bin/ [elasticsearch@elk-node1 bin]$ ./elasticsearch -d #报错则根据日志信息填坑 [elasticsearch@elk-node1 logs]$ pwd /usr/local/elasticsearch/logs [elasticsearch@elk-node1 logs]$ tail pcidata-elk.log [elasticsearch@elk-node1 logs]$ ss -lntp|grep 9200 LISTEN 0 128 :::9200 :::* users:(("java",pid=4189,fd=170)) #输出以下信息说明安装ok [elasticsearch@elk-node1 logs]$ curl 'http://localhost:9200/?pretty' { "name" : "elk-node1", "cluster_name" : "pcidata-elk", "cluster_uuid" : "GrfwFbeOQAmATCqZnvsq8Q", "version" : { "number" : "5.6.10", "build_hash" : "b727a60", "build_date" : "2018-06-06T15:48:34.860Z", "build_snapshot" : false, "lucene_version" : "6.6.1" }, "tagline" : "You Know, for Search" } 安装elasticsearch-head插件 1、安装git [root@elk-node1 config]# yum install -y git 2、下载elasticsearch-head插件源码 [root@elk-node1 config]# git clone git://github.com/mobz/elasticsearch-head.git Cloning into 'elasticsearch-head'... remote: Counting objects: 4224, done. remote: Total 4224 (delta 0), reused 0 (delta 0), pack-reused 4224 Receiving objects: 100% (4224/4224), 2.16 MiB | 542.00 KiB/s, done. Resolving deltas: 100% (2328/2328), done. 3.安装node 由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包,npm可以理解为maven [root@elk-node1 elasticsearch]# wget https://nodejs.org/dist/v8.11.3/node-v8.11.3-linux-x64.tar.xz 4.解压node [root@elk-node1 elasticsearch]# mv node-v8.11.3-linux-x64.tar.xz /usr/local/application/ [root@elk-node1 application]# tar -xf node-v8.11.3-linux-x64.tar.xz [root@elk-node1 application]# ln -s node-v8.11.3-linux-x64/ node 5.配置node环境变量 [root@elk-node1 application]# vim /etc/profile export NODE_HOME=/usr/local/application/node export PATH=$NODE_HOME/bin:$PATH [root@elk-node1 application]# source /etc/profile 6.测试node是否生效 [root@elk-node1 application]# node -v v8.11.3 [root@elk-node1 application]# npm -v 5.6.0 初始化 [root@elk-node1 application]# npm init This utility will walk you through creating a package.json file. It only covers the most common items, and tries to guess sensible defaults. See `npm help json` for definitive documentation on these fields and exactly what they do. Use `npm install <pkg>` afterwards to install a package and save it as a dependency in the package.json file. Press ^C at any time to quit. package name: (application) version: (1.0.0) description: entry point: (index.js) test command: git repository: keywords: author: license: (ISC) About to write to /usr/local/application/package.json: { "name": "application", "version": "1.0.0", "description": "", "main": "index.js", "dependencies": { "grunt-cli": "^1.2.0" }, "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" } Is this ok? (yes) yes 7.安装grunt grunt是一个很方便的构建工具,可以进行打包压缩、测试、执行等等的工作,5.6.10里的head插件就是通过grunt启动的。因此需要安装一下 [root@elk-node1 elasticsearch-head]# pwd /usr/local/elasticsearch/elasticsearch-head [root@elk-node1 elasticsearch-head]# npm install -g grunt-cli 8.检查安装是否成功 [root@elk-node1 elasticsearch-head]# grunt -version grunt-cli v1.2.0 9.修改服务器监听地址 vim elasticsearch-head/Gruntfile.js connect: { server: { options: { port: 9100, hostname: '*', base: '.', keepalive: true } } } 增加hostname属性设置为* 10.修改head的连接地址: vim elasticsearch-head/_site/app.js this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200"; 把localhost修改成你es的服务器地址,如: this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://172.20.10.198:9200"; 11.运行head, 在head目录中,执行npm install [root@elk-node1 elasticsearch-head]# npm install phantomjs-prebuilt@5.6.106 --ignore-scripts [root@elk-node1 elasticsearch-head]# npm install 12.启动nodejs grunt server & 13.访问target:9100 http://172.20.10.198:9100/官方下载地址:https://www.elastic.co/downloads/past-releases/kibana-5-6-10
#解压kibana-5.6.10 [root@elk-node1 local]# pwd /usr/local [root@elk-node1 local]# tar -xf kibana-5.6.10-linux-x86_64.tar.gz #创建软链接 [root@elk-node1 local]# ln -s kibana-5.6.10-linux-x86_64/ kibana #修改配置文件 [root@elk-node1 config]# pwd /usr/local/kibana/config [root@elk-node1 config]# grep -Ev "^#|^$" kibana.yml server.port: 5601 server.host: "0.0.0.0" elasticsearch.url: "http://172.20.10.198:9200" kibana.index: ".kibana" #启动 [root@elk-node1 config]# /usr/local/kibana/bin/kibana #输出以下信息说明安装ok [root@elk-node1 config]# curl localhost:5601 <script>var hashRoute = '/app/kibana'; var defaultRoute = '/app/kibana'; var hash = window.location.hash; if (hash.length) { window.location = hashRoute + hash; } else { window.location = defaultRoute; }</script>效果图:
转载于:https://www.cnblogs.com/Dev0ps/p/7852156.html