ELK5.X搭建并收集Nginx日志

ELK5.X搭建并收集Nginx日志

ELK

 

  • ELK5.X搭建并收集Nginx日志
    • 一、基础环境配置及软件包下载
    • 二、安装Elasticsearch
    • 三、安装logstash
    • 四、安装Kibana
    • 五、安装并配置Nginx收集日志
    • 六、Elasticsearch Head插件安装

本文转载https://www.i4t.com

 


ELK Stack 是 Elasticsearch、Logstash、Kibana 三个开源软件的组合。在实时数据检索和分析场合,三者通常是配合共用,而且又都先后归于 Elastic.co 公司名下,故有此简称。

ELK Stack 在最近两年迅速崛起,成为机器数据分析,或者说实时日志处理领域,开源界的第一选择。和传统的日志处理方案相比,ELK Stack 具有如下几个优点:

• 处理方式灵活。Elasticsearch 是实时全文索引,不需要像 storm 那样预先编程才能使用;
• 配置简易上手。Elasticsearch 全部采用 JSON 接口,Logstash 是 Ruby DSL 设计,都是目前业界最通用的配置语法设计;
• 检索性能高效。虽然每次查询都是实时计算,但是优秀的设计和实现基本可以达到全天数据查询的秒级响应;
• 集群线性扩展。不管是 Elasticsearch 集群还是 Logstash 集群都是可以线性扩展的;
• 前端操作炫丽。Kibana 界面上,只需要点击鼠标,就可以完成搜索、聚合功能,生成炫丽的仪表板。

ELK地址:https://www.elastic.co/
Logstash 最佳实践:http://udn.yyuap.com/doc/logstash-best-practice-cn/index.html
Elasticsearch 权威指南:http://www.learnes.net/index.html
ELKStack中文社区:https://kibana.logstash.es/content/
更多ELK文章:https://www.i4t.com/category/elkstack/

 

  对于日志来说,最常见的需求就是收集、存储、查询、展示,开源社区正好有相对应的开源项目:logstash(收集)、elasticsearch(存储+搜索)、kibana(展示),我们将这三个组合起来的技术称之为ELKStack,所以说ELKStack指的是Elasticsearch(java)、Logstash(jruby)、Kibana技术栈的结合,一个通 用的架构如下图所示:
image_1d3o2hl6ltsp1gnk1p1c13nnvalm.png-136.7kB
图片解释:elk 前面主要靠logstash来进行收集日志,logstash将日志上传到broker上,后面还有一个logstash用来读取broker中的日志,在将日志存储到es里面,最后用kibana练到es上进行展示

提示:我们可以将Elasticsearch简称为es

1.Elasticsearch介绍
ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是第二流行的企业搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。

2.Logstash介绍

Logstash是一个完全开源的工具,他可以对你的日志进行收集、分析,并将其存储供以后使用(如,搜索),您可以使用它。说到搜索,logstash带有一个web界面,搜索和展示所有日志。
  kibana也是一个开源和免费的工具,他可以帮助您汇总、分析和搜索重要数据日志并提供友好的web界面。他可以为 Logstash 和 ElasticSearch 提供的日志分析的 Web 界面。

提示:logstash与es没有任何关系
image_1d3o2ia8t8m11sbn16ouotv11pc13.png-68.9kB

ELK几个概念

 
  1. INPUT 进
  2. FILTER (支持过滤的功能)
  3. OUTPUT 出

33333333.png-43.3kB
首先LogStash是收集日志,它收集完日志就需要把日志存储下来,所以我们可以用运输者的身份来表示LogStash(INPUT or OUTPUT)LogStash可以在日志发送之前做一个过滤(OUTPUT之前)

3.Kibana简介
Kibana是为 Elasticsearch 设计的开源分析和可视化平台。你可以使用 Kibana 来搜索,查看存储在 Elasticsearch 索引中的数据并与之交互。你可以很容易实现高级的数据分析和可视化,以图表的形式展现出来。

Kibana版本使用php、ruby、js、jruby、node.js等不同语言编写
Kibana 4使用nodejs进行编写(nodejs号称全栈,什么都可以干)

本段文章截取https://www.i4t.com/category/elkstack/


image_1d3o2gruh4h11npj9akfs0kq59.png-96.2kB

温馨提示:本次搭建属于单点,不算是集群。集群搭建只需要改相关的配置文件重启即可

环境 CentOS Linux release 7.4.1708 (Core)
版本 
elasticsearch-5.5.0.tar.gz
kibana-5.5.0-linux-x86_64.tar.gz
logstash-5.5.0.tar.gz

主机
10.4.11.11   Elasticsearch  Kibana
10.4.11.12   logstash nginx
如果Nginx和elk都在一台,可以都安装在一台服务器上!


环境配置
#时间同步
#关闭selinux 及防火墙
#内核优化

一、基础环境配置及软件包下载

 
  1. 1.设置yum源
  2. curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  3. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  4. yum makecache
  5. yum install wget vim lsof net-tools lrzsz -y
  6.  
  7.  
  8. 2.时间同步
  9. yum -y install ntp
  10. systemctl enable ntpd
  11. systemctl start ntpd
  12. ntpdate -u cn.pool.ntp.org
  13. hwclock --systohc
  14. timedatectl set-timezone Asia/Shanghai
  15.  
  16. 3.关闭Selinux && 防火墙
  17. systemctl stop firewalld
  18. systemctl disable firewalld
  19. setenforce 0
  20. sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
  21.  
  22. 4.内核优化
  23. echo '
  24. * hard nofile 65536
  25. * soft nofile 65536
  26. * soft nproc 65536
  27. * hard nproc 65536
  28. '>>/etc/security/limit.conf
  29. echo '
  30. vm.max_map_count = 262144
  31. net.core.somaxconn=65535
  32. net.ipv4.ip_forward = 1
  33. '>>/etc/sysctl.conf
  34. sysctl -p

下载软件包

 
  1. mkdir /root/elk
  2.  
  3. Elasticsearch:
  4. wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.tar.gz
  5. Kibana:
  6. wget https://artifacts.elastic.co/downloads/kibana/kibana-5.5.0-linux-x86_64.tar.gz
  7. Logstash:
  8. wget https://artifacts.elastic.co/downloads/logstash/logstash-5.5.0.tar.gz

安装Jdk环境

 
  1. 1.源码安装
  2.  
  3. 下载安装http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  4. 配置Java环境
  5. tar zxf jdk-8u91-linux-x64.tar.gz -C /usr/local/
  6. ln –s /usr/local/jdk1.8.0_91 /usr/local/jdk
  7.  
  8. vim /etc/profile
  9. export JAVA_HOME=/usr/local/jdk
  10. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  11. export PATH=$JAVA_HOME/bin:$PATH
  12.  
  13. source /etc/profile
  14.  
  15. 看到如下信息,java环境配置成功
  16. # java -version
  17. java version "1.8.0_91"
  18. Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
  19. Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
  20.  
  21. 2.yum安装
  22. yum install -y java
  23.  
  24. [root@i4t.com ~]# java -version
  25. openjdk version "1.8.0_65"
  26. OpenJDK Runtime Environment (build 1.8.0_65-b17)
  27. OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)

二、安装Elasticsearch

我们elk都使用普通用户进行启动管理

 
  1. 新建持久化目录及logo目录
  2. mkdir /data1/{es-data,es-logs} -p
  3. tar xf elasticsearch-5.5.0.tar.gz -C /usr/local/
  4. ln -s /usr/local/elasticsearch-5.5.0 /usr/local/elasticsearch
  5.  
  6. 修改配置文件,修改后如下
  7. grep -Ev "^$|#" /usr/local/elasticsearch-5.5.0/config/elasticsearch.yml
  8. node.name: my-es
  9. path.data: /data1/es-data
  10. path.logs: /data1/es-logs
  11. config.reload.automatic: true
  12. config.reload.interval: 10
  13. http.host: "10.4.82.217"
  14. http.cors.enabled: true
  15. http.cors.allow-origin: "*"
  16.  
  17.  
  18. 配置说明
  19. node.name: my-es #设置节点名称,一般写主机名
  20. path.data: /data1/es-data #创建logstash 和插件使用的持久化目录
  21. path.logs: /data1/es-logs #创建es日志路径
  22. config.reload.automatic: true #开启配置文件自动加载
  23. config.reload.interval: 10 #定义配置文件重载时间周期
  24. http.host: "10.4.82.217" #定义访问主机名,一般为域名或IP
  25. http.cors.enabled: true #使用head插件需要开启
  26. http.cors.allow-origin: "*"
  27.  
  28. 更多配置说明:https://blog.csdn.net/ma_shou_feng/article/details/83783213

在运行es之前,我们需要创建用户,设置属主属组

 
  1. useradd elk
  2. chown -R elk /data1/es-*
  3.  
  4. [root@i4t.com ~]# ll /data1/
  5. 总用量 32
  6. drwxr-xr-x 2 elk root 4096 1月 25 04:48 es-data
  7. drwxr-xr-x 2 elk root 4096 1月 25 04:48 es-logs
  8. drwxr-xr-x 3 root root 4096 8月 24 20:17 etcd
  9. drwxr-xr-x 2 root root 4096 8月 16 11:41 kubelet
  10. drwx------. 2 root root 16384 7月 13 2018 lost+found
  11.  
  12. 设置es服务
  13. chown -R elk /usr/local/elasticsearch-5.5.0/
  14. [root@i4t.com local]# ll /usr/local/elasticsearch-5.5.0/
  15. 总用量 236
  16. drwxr-xr-x 2 elk root 4096 1月 25 04:49 bin
  17. drwxr-xr-x 2 elk root 4096 1月 25 04:54 config
  18. drwxr-xr-x 2 elk root 4096 7月 1 2017 lib
  19. -rw-r--r-- 1 elk root 11358 7月 1 2017 LICENSE.txt
  20. drwxr-xr-x 13 elk root 4096 7月 1 2017 modules
  21. -rw-r--r-- 1 elk root 194187 7月 1 2017 NOTICE.txt
  22. drwxr-xr-x 2 elk root 4096 7月 1 2017 plugins
  23. -rw-r--r-- 1 elk root 9548 7月 1 2017 README.textile

启动es服务

 
  1. 启动之前需要su到普通用户上
  2. [root@i4t.com ~]# su - elk
  3. [elk@i4t.com ~]$ /usr/local/elasticsearch/bin/elasticsearch -d
  4.  
  5. # -d 参数为后台启动,第一次安装好可以不加-d先启动测试,查看是否有error或者报错

前台查看启动成功,我们就可以加上-d参数让它后台运行
image_1d20s2rd61q2545o1fnn175r1bn39.png-827.5kB

检查是否启动成功

 
  1. [elk@i4t ~]$ /usr/local/elasticsearch/bin/elasticsearch -d
  2. [elk@i4t~]$ lsof -i:9200
  3. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  4. java 7157 elk 312u IPv6 391237534 0t0 TCP node1:wap-wsp (LISTEN)
  5.  
  6. [elk@i4t ~]$ curl 10.4.82.217:9200
  7. {
  8. "name" : "my-es",
  9. "cluster_name" : "elasticsearch",
  10. "cluster_uuid" : "tXBJMwRhQUyPNrwKETCWgg",
  11. "version" : {
  12. "number" : "5.5.0",
  13. "build_hash" : "260387d",
  14. "build_date" : "2017-06-30T23:16:05.735Z",
  15. "build_snapshot" : false,
  16. "lucene_version" : "6.6.0"
  17. },
  18. "tagline" : "You Know, for Search"
  19. }

Elasticsearch常用命令

 
  1. curl -XDELETE 'http://host.IP.address:9200/logstash-*' 删除索引(后面为索引名称)
  2. curl -XGET 'host.IP.address:9200/_cat/health?v&pretty' 查看集群状态
  3. curl -XGET 'host.IP.address:9200/_cat/indices?v&pretty' 查看索引

三、安装logstash

logstash安装的Nginx服务器上,并非es服务器

 
  1. 1.解压安装logstash
  2. tar xf logstash-5.5.0.tar.gz -C /usr/local/
  3. ln -s /usr/local/logstash-5.5.0 /usr/local/logstash
  4.  
  5. 2.创建配置文件
  6. mkdir /usr/local/logstash/conf/
  7. vim /usr/local/logstash/conf/nginx.conf
  8. input {
  9. file {
  10. path => "/usr/local/nginx/logs/access.log"
  11. start_position => "beginning"
  12. }
  13. }
  14. filter {
  15. }
  16. output {
  17. #stdout { codec=> rubydebug }
  18. elasticsearch {
  19. hosts => ["10.4.82.118:9200"]
  20. index => "static_nginx_access-%{+YYYY.MM.dd}"
  21. }
  22. }
  23.  
  24. #这里面实际只是定义了一个nginx log路径
  25. #stdout { codec=> rubydebug } 将内容打印出来,方便测试
  26. #host 填写es主机
  27. index 索引名称

四、安装Kibana

 
  1. wget https://artifacts.elastic.co/downloads/kibana/kibana-5.5.0-linux-x86_64.tar.gz
  2. tar xf kibana-5.5.0-linux-x86_64.tar.gz -C /usr/local/
  3. chown -R elk.elk kibana-5.5.0-linux-x86_64
  4.  
  5. kibana配置文件修改
  6. [root@YZSJHL82-217 ~]# vim /usr/local/kibana-5.5.0-linux-x86_64/config/kibana.yml
  7. server.port: 5601
  8. server.host: "10.4.82.217"
  9. elasticsearch.url: "http://127.0.0.1:9200"
  10.  
  11.  
  12.  
  13. [root@YZSJHL82-217 ~]# grep -Ev "^$|#" /usr/local/kibana-5.5.0-linux-x86_64/config/kibana.yml
  14. server.port: 5601 #kibana端口
  15. server.host: "10.4.82.217" #kibana主机
  16. elasticsearch.url: "http://127.0.0.1:9200" #ES服务器端口
  17.  
  18. 启动
  19. [root@YZSJHL82-217 ~]# su - elk
  20. 前台启动
  21. [elk@i4t kibana-5.5.0-linux-x86_64]$ /usr/local/kibana-5.5.0-linux-x86_64/bin/kibana
  22. 后台启动
  23. [elk@i4t kibana-5.5.0-linux-x86_64]$ /usr/local/kibana-5.5.0-linux-x86_64/bin/kibana &
  24.  
  25. 温馨提示:可以先前台启动查看日志,正常之后在后台启动
  26.  
  27.  
  28. 查看端口
  29. [root@i4t ~]# lsof -i:5601
  30. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  31. node 30297 elk 12u IPv4 420317733 0t0 TCP node1:esmagent (LISTEN)
  32. [root@i4t ~]# netstat -lntup|grep 5601
  33. tcp 0 0 10.4.82.217:5601 0.0.0.0:* LISTEN 30297/node

访问kibana
http://ip:5601
123.png-492kB

因为现在没有数据,我们现在配置Nginx进行Nginx的日志收集

五、安装并配置Nginx收集日志

安装Nginx

 
  1. wget http://nginx.org/download/nginx-1.10.3.tar.gz
  2.  
  3. yum install -y gcc glibc gcc-c++ prce-devel openssl-devel pcre-devel
  4. useradd -s /sbin/nologin www -M
  5. tar xf nginx-1.10.3.tar.gz && cd nginx-1.10.3
  6.  
  7. ./configure --prefix=/usr/local/nginx-1.10.3 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
  8. make && make install
  9. ln -s /usr/local/nginx-1.10.3 /usr/local/nginx
  10.  
  11.  
  12.  
  13.  
  14. 手动启动
  15. /usr/local/nginx/sbin/nginx
  16.  
  17. 设置开机启动
  18. echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local
  19.  
  20.  
  21. 查看服务器是否启动
  22. netstat -lntp|grep nginx
  23. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7058/nginx: master

需要配置在我们要收集的服务器上

 
  1. vim /usr/local/nginx/conf/nginx.conf
  2. worker_processes 1;
  3.  
  4. events {
  5. worker_connections 1024;
  6. }
  7.  
  8.  
  9. http {
  10. include mime.types;
  11. default_type application/octet-stream;
  12. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  13. # '$status $body_bytes_sent "$http_referer" '
  14. # '"$http_user_agent" "$http_x_forwarded_for"';
  15.  
  16. log_format json '{"@timestamp":"$time_iso8601",'
  17. '"host":"$server_addr",'
  18. '"clientip":"$remote_addr",'
  19. '"remote_user":"$remote_user",'
  20. '"request":"$request",'
  21. '"http_user_agent":"$http_user_agent",'
  22. '"size":$body_bytes_sent,'
  23. '"responsetime":$request_time,'
  24. '"upstreamtime":"$upstream_response_time",'
  25. '"upstreamhost":"$upstream_addr",'
  26. '"http_host":"$host",'
  27. '"requesturi":"$request_uri",'
  28. '"url":"$uri",'
  29. '"domain":"$host",'
  30. '"xff":"$http_x_forwarded_for",'
  31. '"referer":"$http_referer",'
  32. '"status":"$status"}';
  33. access_log logs/access.log json;
  34.  
  35.  
  36. sendfile on;
  37. keepalive_timeout 65;
  38.  
  39.  
  40. server {
  41. listen 80;
  42. server_name localhost;
  43. location / {
  44. root html;
  45. index index.html index.htm;
  46. }
  47.  
  48. }
  49.  
  50. }
  51.  
  52. ###########################
  53. 实际上就是添加了json格式的日志
  54. log_format json '{"@timestamp":"$time_iso8601",'
  55. '"host":"$server_addr",'
  56. '"clientip":"$remote_addr",'
  57. '"remote_user":"$remote_user",'
  58. '"request":"$request",'
  59. '"http_user_agent":"$http_user_agent",'
  60. '"size":$body_bytes_sent,'
  61. '"responsetime":$request_time,'
  62. '"upstreamtime":"$upstream_response_time",'
  63. '"upstreamhost":"$upstream_addr",'
  64. '"http_host":"$host",'
  65. '"requesturi":"$request_uri",'
  66. '"url":"$uri",'
  67. '"domain":"$host",'
  68. '"xff":"$http_x_forwarded_for",'
  69. '"referer":"$http_referer",'
  70. '"status":"$status"}';
  71. access_log logs/access.log json;
  72. 日志保存在/usr/local/nginx/logs/下

配置完成后,访问nginx。查看日志是否修改为json

 
  1. [root@i4tnginx]# tail -f logs/access.log
  2. {"@timestamp""host":"10.4.82.203","clientip":"10.2.52.15","remote_user":"-","request":"GET / HTTP/1.1","http_user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"10.4.82.203","requesturi":"/","url":"/index.html","domain":"10.4.82.203","xff":"-","referer":"-","status":"304"}
  3. {"@timestamp""host":"10.4.82.203","clientip":"10.2.52.15","remote_user":"-","request":"GET / HTTP/1.1","http_user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"10.4.82.203","requesturi":"/","url":"/index.html","domain":"10.4.82.203","xff":"-","referer":"-","status":"304"}

测试logstash配置文件是否正常

 
  1. 我们尽量都是用elk用户,所以需要提前将logstash设置为elk的属主属组
  2. chown -R elk.elk /usr/local/logstash
  3.  
  4. /usr/local/logstash/bin/logstash -f /usr/local/logstash/conf/nginx.conf -t
  5. ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
  6. Sending Logstash's logs to /usr/local/logstash/logs which is now configured via log4j2.properties
  7. Configuration OK
  8. [2019-01-28T11:54:38,481][INFO ][logstash.runner ] Using config.test_and_exit mode. Config Validation Result: OK. Exiting Logstash

image_1d299p9iidpp1d5n1i119t5roc9.png-380.7kB

在Nginx服务器上启动logstash

 
  1. [root@abcdocker logstash]# su - elk
  2. [elk@abcdocker ~]$ /usr/local/logstash/bin/logstash -f /usr/local/logstash/conf/nginx.conf
  3.  
  4.  
  5. 温馨提示,一定要确保logs目录elk有权限写入,建议我们在启动elk之前在执行一次chown -R elk.elk /usr/local/logstash

image_1d3njupoc52v1tdv7gqjm814ho1j.png-760.4kB

请确保logstash中的file文件有读取权限,否则无法在ES中创建索引!

image_1d3nk3m8rjcn1ics196emvql9h2d.png-956.6kB
我们可以查一下索引

 
  1. [root@YZSJHL82-203 local]# curl -XGET '10.4.82.217:9200/_cat/indices?v&pretty'
  2. health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
  3. yellow open .kibana 9l1XmifhTd2187a9Zpkqsw 1 1 1 0 3.2kb 3.2kb
  4. yellow open pro_nginx_access-2019.02.15 Guze8x5hTymSzqzQKu5PTQ 5 1 1315 0 1.3mb 1.3mb

Kibana 配置
目前logstash已经将收集的日志存储在es里面,我们需要用kibana进行展示
image_1d3ntkdt115ht19u47fr1cg248r2q.png-250kB
查看索引命令

 
  1. [root@YZSJHL82-203 local]# curl -XGET '10.4.82.217:9200/_cat/indices?v&pretty'
  2. health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
  3. yellow open .kibana 9l1XmifhTd2187a9Zpkqsw 1 1 1 0 3.2kb 3.2kb
  4. yellow open pro_nginx_access-2019.02.15 Guze8x5hTymSzqzQKu5PTQ 5 1 1315 0 1.3mb 1.3mb

33333.png-134.6kB

Kibana创建索引
image_1d3ntnbmef52v4c1n6l12hm1aj337.png-220.8kB

创建完毕后查看索引
image_1d3nttiqk1bma1oqdbsq1jlkn6t49.png-103.7kB

 

六、Elasticsearch Head插件安装

image_1d3nvibr01v1v1p4j1t7s1ccn8lm4m.png-54.6kB

elasticsearch-head是一个界面化的集群操作和管理工具,可以对集群进行傻瓜式操作。你可以通过插件把它集成到es(首选方式),也可以安装成一个独立webapp。

  • 显示集群的拓扑,并且能够执行索引和节点级别操作
  • 搜索接口能够查询集群中原始json或表格格式的检索数据
  • 能够快速访问并显示集群的状态
  • 有一个输入窗口,允许任意调用RESTful API。这个接口包含几个选项,可以组合在一起以产生有趣的结果;
    1. 请求方法(get、put、post、delete),查询json数据,节点和路径
    2. 支持JSON验证器
    3. 支持重复请求计时器
    4. 支持使用javascript表达式变换结果
    5. 收集结果的能力随着时间的推移(使用定时器),或比较的结果
    6. 能力图表转换后的结果在一个简单的条形图(包括时间序列)

官方的文档:
https://github.com/mobz/elasticsearch-head

关于Head插件安装有2中,如果使用的yum安装es可以直接用es中的plugin install mobz/elasticsearch-head另一种就是需要安装Node环境
ELKStack 实战之 Elasticsearch [一]


安装插件时使用到了npm,所以我们需要安装npm
二进制安装npm https://www.i4t.com/2840.html

 
  1. [root@i4t ~]# yum install git npm #安装git和npm
  2. [root@i4t ~]# cd /usr/local/
  3. [root@i4t elasticsearch-head]# git clone https://github.com/mobz/elasticsearch-head.git #克隆代码
  4. [root@i4t local]# cd elasticsearch-head/
  5.  
  6. #需要注意的是执行以下命令需要在elasticsearch-head目录下执行
  7. npm install
  8. npm run start ##这是在前台运行,如果想让它在后台运行npm run start &
  9.  
  10.  
  11.  
  12. 需要提前在elasticsearch.yml配置如下,如果安装我的文档安装都是已经配置好了
  13. vim /usr/local/elasticsearch/elasticsearch.yml
  14. http.cors.enabled: true # elasticsearch中启用CORS
  15. http.cors.allow-origin: "*" #允许访问的IP地址段,* 为所有IP都可以访问

默认端口是9100,默认监控的主机也是localhost

请目录结构和我保持一致

image_1d3o1rt0j1lv1ord1ghpr251ns27f.png-143kB
111.png-138.1kB

修改默认端口以及默认连接ES地址
vim elasticsearch-head/Gruntfile.js
修改默认的端口
image_1d3o1gvalajsg2abfa1i1rvj86l.png-28.4kB

因为head插件默认打开是连接localhost的,我们需要将localhost修改为我们的ip
vim elasticsearch-head/_site/app.js
将localhost换成es的ip即可
image_1d3o1p7f71hukbn016pq16ugh4272.png-82.5kB
修改完成后直接要npm run start &即可,不需要build
321.png-229.2kB

因为是单点,所以是Yellow状态

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值