ELK

ELK下载地址:https://www.elastic.co/downloads

JDK下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Redis下载地址:http://download.redis.io/releases/redis-3.2.3.tar.gz

 

1、安装JDK(Logstash要求JDK版本不低于1.7,官方文档已写明)

  1. # tar zxf jdk-8u101-linux-x64.gz
  2. # mv jdk1.8.0_101 /usr/local/jdk_1.8.0
  3. # vim /etc/profile
  4. ---------------文件最后加入如下内容------------
  5. #JDK1.8
  6. export JAVA_HOME=/usr/local/jdk_1.8.0
  7. export PATH=$JAVA_HOME/bin:$PATH
  8. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tool.jar
  9. ------------------------------------------------------------
  10. # source /etc/profile        #使声明生效
  11. # java –version         #查看java jdk版本

blob.png

 

2、安装Redis agent端不用安装 

  1. # tar zxf redis-3.2.3.tar.gz
  2. # cd redis-3.2.3
  3. # yum install gcc -y        (一般情况下,所有安装包这个都是必安得!)
  4. # ./runtest         #检测下安装环境,看是否缺少支持包
  5. 提示: You need tcl 8.5 or newer in order to run the Redis test
  6. # yum install tcl -y     #安装tcl
  7. # make  MALLOC=libc (加上MALLOC=libc是因为在redis中的readme中有这么一段话:
  8. Allocator --------- Selecting a non-default memory allocator when building Redis is done by setting the `MALLOC` environment variable. Redis is compiled and linked against libc malloc by default, with the exception of jemalloc being the default on Linux systems. This default was picked because jemalloc has proven to have fewer fragmentation problems than libc malloc. To force compiling against libc malloc, use: % make MALLOC=libc To compile against jemalloc on Mac OS X systems, use: % make MALLOC=jemalloc)
  9. # make test     #make完成后测试下
  10. # cd src 
  11. # make install            #进入src目录并且进行编译
  12. # cd ../..    #回到redis安装目录
  13. # mv redis-3.2.3 /usr/local/redis
  14. # vim /usr/local/redis/redis.conf         #修改redis配置文件,以后台运行
  15. -------------------------修改redis.conf-----------------
  16. daemonize yes           #以守护进程运行(后台运行)
  17. ----------------------------------------------------------------
  18. # /usr/local/redis/src/redis-server /usr/local/redis/redis.conf  #启动redis
  19.  
  20.  
  21. 另一种安装方式(推荐使用):
  22. make install 之前都是一样的
  23.  
  24. cd ../utils/
  25. ./install_server.sh     #脚本执行后,同样可以安装redis的节点,这个脚本的好处就是路径之类的你可以自己设置,不用过多的修改配置文件.而且默认也是守护进程。
  26.  
  27. Welcome to the redis service installer
  28. This script will help you easily set up a running redis server
  29.  
  30. Please select the redis port for this instance: [6379] 
  31. Selecting default: 6379
  32. Please select the redis config file name [/etc/redis/6379.conf] 
  33. Selected default - /etc/redis/6379.conf
  34. Please select the redis log file name [/var/log/redis_6379.log] 
  35. Selected default - /var/log/redis_6379.log
  36. Please select the data directory for this instance [/var/lib/redis/6379] 
  37. Selected default - /var/lib/redis/6379
  38. Please select the redis executable path [/usr/local/bin/redis-server] 
  39. Selected config:
  40. Port           : 6379
  41. Config file    : /etc/redis/6379.conf
  42. Log file       : /var/log/redis_6379.log
  43. Data dir       : /var/lib/redis/6379
  44. Executable     : /usr/local/bin/redis-server
  45. Cli Executable : /usr/local/bin/redis-cli
  46. Is this ok? Then press ENTER to go on or Ctrl-C to abort.
  47. Copied /tmp/6379.conf => /etc/init.d/redis_6379
  48. Installing service...
  49. Successfully added to chkconfig!
  50. Successfully added to runlevels 345!
  51. Starting Redis server...
  52. Installation successful!
  53.  
  54.  
  55.  
  56. 注意:关于redis配置文件里面的bind这个参数。我本以为bind选项是允许那些ip访问redis。后来经过测试发现我理解错了。这个bind参数是你的服务器ip。也就是如果填写127.0.0.1则是本机访问,如果填写的是外网网卡ip。则是所有人都可以访问你的redis了。并非权限控制。(个人理解的,如有不对请包涵)

 

3、安装elasticsearch

 

  1. # tar zxf elasticsearch-2.3.5.tar.gz
  2. # mv elasticsearch-2.3.5 /usr/local/elasticsearch
  3. # vim /usr/local/elasticsearch/config/elasticsearch.yml          #修改配置文件
  4. --------------------------
  5. network.host: 192.168.1.104    #指定主机地址,其实是可选的,但是最好指定因为后面跟kibana集成的时候会报http连接出错(直观体现好像是监听了:::9200 而不是0.0.0.0:9200!暂时不知道这个地址需不需要和kibana的server host一致)
  6. http.cors.allow-origin: "/.*/"
  7. http.cors.enabled: true        #这2项都是解决跟kibana集成的问题,错误体现是 你的 elasticsearch 版本过低,其实不是
  8. http.port: 9200                   #端口9200
  9. -------------------------
  10. # useradd guoxin    #创建一个用户guoxin,elasticsearch禁止root用户启动服务
  11. # chown -R guoxin.guoxin /usr/local/elasticsearch    #将属主属组修改为guoxin
  12. # su guoxin
  13. /usr/local/elasticsearch/bin/elasticsearch d       (启动服务)
  14. $ curl 'http://10.10.16.21:9200'    #验证是否成功
  15. exit    #退出guoxin用户
  16.  
  17.  
  18.  
  19. 注意:在5.0版本中head插件的安装方式变了。请自行研究,因为我也没搞懂呢
  20. 另外有几个系统参数需要修改!否则在5.X版本下,es是会报错的
  21.  
  22. 1、使用说明!由于elasticsearch需要大量的现成,请确保系统允许至少2048个线程处理能力。
  23. 解决方法:编辑/etc/security/limits.d/90-nproc.conf  * soft nproc 后面的1024个线程改为2048
  24.  
  25. 2es要求文件描述符至少要65536个,请确保文件描述符配置正确
  26. 解决方法:/etc/security/limts.conf中最后添加如下两行。这里的guoxin是启动es的用户。知道要保证65535才可以,添加内容如下 
  27. guoxin soft nofile 65536
  28. guoxin hard nofile 65536
  29.  
  30. 3es要求虚拟内存至少要262144,请确保虚拟内存大小
  31. 解决方法:vim /etc/sysctl..conf
  32. 增加vm.max_map_count = 655350
  33. 使用sysctl -使配置生效
  34.  
  35. 4、另外在配置es时候,我们需要限制内存大小,这里最大和最小内存要一致。默认是2G,由于我是虚拟机所以改>为最小启动512m
  36. 解决方法:vim /usr/local/elasticsearch/config/jvm.options
  37.  
  38.     -Xms2g 
  39.     -Xmx2g
  40. 修改为 
  41.     -Xms512m 
  42.     -Xmx512m

blob.png

  1. 安装Head插件(Optional)
  2. # cd /usr/local/elaticsearch    进入Elasticsearch目录
  3. # ls plugins/            安装Head插件前,此目录为空
  4. # ./bin/plugin install mobz/elasticsearch-head    安装head插件
  5. # ls plugins/        安装完成后此目录下多了个head目录
  6. head
  7.  
  8. 杀掉进程重启Elasticsearch服务

Head插件访问地址    http://10.10.16.21:9200/_plugin/head/

 

4、安装logstash(Logstash的话,他的配置文件以及正则正在研究中,关于配置的话就不贴了,这个服务现在不需要开启,当日志收集的时候,根据自己写的正则作为配置文件开启服务)

  1. # tar zxf logstash-2.3.4.tar.gz
  2. # mv logstash-2.3.4 /usr/local/logstash
  3. # /usr/local/logstash/bin/logstash -f /usr/local/logstash/logstash_redis.conf(配置文件是需要自己写的)
  4.  
  5.  
  6. #测试redis是否能够保存logstash的输入数据
  7. # vim /usr/local/logstash/logstash_redis.conf    编写配置文件
  8. ###########内容如下#################
  9. input { stdin { } }            #这行是通过终端输入
  10. output {
  11.     stdout { codec => rubydebug }    #以debug模式输出到终端
  12.     
  13.     redis {                            配置redis
  14.         host => '127.0.0.1'            redis服务器IP
  15.         data_type => 'list'            数据类型是列表
  16.         key => 'logstash:redis'        
  17.     }
  18. }
  19. ##############保存####################################
  20.  
  21. #/usr/local/redis/src/redis-cli monitor    开启redis的动态监控(由于是实时监控,所以需要另外再开一个终端)
  22.  
  23. # /usr/local/logstash/bin/logstash -f /usr/local/logstash/logstash_redis.conf     启动logstashh,并且加载/usr/local/logstash/logstash_redis.conf配置文件(这里我们没有后台运行,如果需要后台运行在最后加上 &即可)
  24.  
  25. 启动后输入---->My name is guo_xin!
  26.  
  27. ##############以下是logstash的返回结果#############
  28. {
  29.     "@timestamp" => 2016-12-29T09:41:17.319Z,
  30.       "@version" => "1",
  31.           "host" => "0.0.0.0",
  32.        "message" => "My name is !"
  33. }
  34.  
  35.  
  36. ###########redis实时监控输出(这里我们可以看到redis监控已经将数据存进去了)#######################
  37. 1483004478.127705 [0 127.0.0.1:38750] "rpush" "logstash:redis" "{\"@timestamp\":\"2016-12-29T09:41:17.319Z\",\"@version\":\"1\",\"host\":\"0.0.0.0\",\"message\":\"My name is!\"}"
  38.  

5、安装kibana

 

  1. # tar zxf kibana-4.5.4-linux-x64.tar.gz      
  2. # mv kibana-4.5.4-linux-x64 /usr/local/kibana
  3. # mkdir -pv /usr/local/kibana/logs 创建日志目录
  4. # vim /usr/local/kibana/config/kibana.yml
  5. -----------------------------------------
  6. server.host: "10.10.16.21"   #输入服务器IP
  7. kibana.index: ".kibana"
  8. elasticsearch.url: http://10.10.16.21:9200”  #elasticsearch的URL
  9. ----------------------------------------
  10. # cd /usr/local/kibana/logs/ && nohup /usr/local/kibana/bin/kibana &
  11. (#nohup: 忽略输入并把输出追加到"nohup.out")
  12. #启动命令的意思是进入kibana的目录并且忽略输入并把输出追加到nohup.out中,然后后台方式启动kibana
  13. # ll /usr/local/kibana/logs/        查看日志文件是否生成

blob.png

环境构建完成

kibana访问地址    http://ip:5601

 

 

 

 

6、遇到的问题

blob.png

解决办法:

修改属主属组为非root用户,然后重启服务

# chown -R guoxin.guoxin /usr/local/elasticsearch/

# su guoxin

$ /usr/local/elasticsearch/bin/elasticsearch –d

 

 

blob.png

解决方法:

出现这个问题是因为在elasticsearch配置文件中添加了http.cors.enabled:true。

在kibana4.x版本中,这个参数已经被废除了,kibana4.x不在兼容elasticsearch中的这个参数,所以需要删除elasticsearch配置文件中的这个参数,然后杀掉elasticsearch服务进程,重新启动elasticsearch服务即可

X-Pack在线安装方法

  1. # /usr/local/elasticsearch/bin/elasticsearch-plugin install x-pack    #使用Elasticsearch的plugin命令来安装X-Pack插件
    虽然Elasticsearch默认不允许root用户启动,但是安装X-pack插件时候,请使用root用户。否则会报如下错误↓↓

{W54GLN0NTI7)E_L00XYO51.png

  1. 使用root用户执行在线安装正确提示如下:↓↓

blob.png

  1. 上图选项填写yX-Pack插件需要额外权限

    # /usr/local/kibana/bin/kibana-plugin install x-pack    #使用kibana的plugin命令来安装X-Pack插件


    kibana.yml文件中配置:
    elasticsearch.username: "elastic"
    elasticsearch.password: "guoxin0521"


    启动Elasticsearchkibana服务

    注意:
    如果你的elasticsearch.yml配置文件使用了action.auto_create_index(禁止自动创建索引)参数。
    请将以下内容添加到action.auto_create_index后↓
    .security,.monitoring*,.watches,.triggered_watches,.watcher-history*

    例如:
    action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*

 

在启动kibana时候会有个警告:

blob.png

以后会去解决!不影响使用!

 

 

X-Pack离线安装方法

  1. # wget https://artifacts.elastic.co/downloads/kibana-plugins/x-pack/x-pack-5.0.0.zip    #下载X-Pack安装包
    # /usr/local/elasticsearch/bin/elasticsearch-plugin install file:///usr/local/src/x-pack-5.0.0.zip #使用Elasticsearch的plugin命令来安装本地X-Pack插件zip包,这里file:///后面跟着的是下载的安装包路径
    # /usr/local/kibana/bin/kibana-plugin install file:///usr/local/src/x-pack-5.0.0.zip    #使用kibana的plugin同样装一下X-Pack包,这里file:///后面跟着的是下载的安装包路径

    下面是kibana离线安装成功的样子↓↓

blob.png

 

离线安装方式启动和禁用X-Pack方法(官方文档说需要添加这些,不过我添加后发现服务起不来了。报错,不加任何参数反而能起来。不明白为什么。没深研究。不过我是在线安装的,不知道是不是离线安装特殊的需求。有空大家可以自己玩玩试试!)

  1. 1、编辑elasticsearch.ymlkibana.yml
    xpack.security.enabled        
    开启X-Pack插件,关闭的话是将enabled改为false(elasticsearch.yml  kibana.yml都需要添加)

    xpack.monitoring.enabled      
    开启X-Pack监控功能,关闭的话是将enabled改为falseelasticsearch.yml  kibana.yml都需要添加)

    xpack.graph.enabled           
    开启X-Pack图功能,关闭的话是将enable改为false elasticsearch.yml  kibana.yml都需要添加)

    xpack.watcher.enabled         
    开启X-Pack游客功能,关闭的话是将enable改为false(仅elasticsearch.yml需要添加)

    xpack.reporting.enabled       
    开启X-Pack报告功能,关闭的话是将enbale改为false(仅kibana.yml都需要添加)

    2、启动Elasticsearchkibana服务 (略...)

 

下图是安装成功x-pack插件后的样子

blob.png

 

升级或删除X-Pack插件

  1. 1、关闭Elasticsearchkibana服务
    2、删除ElasticsearchkibanaX-Pack模块
    # /usr/local/elasticsearch/bin/elasticsearch-plugin remove x-pack    
    # /usr/local/kibana/bin/kibana-plugin remove x-pack
    3、如果想升级X-Pack插件则重新安装新插件即可,官方文档是这么写的不知道是否有update这种命令,以前没使用过ELK

 

官方文档地址:

  1. https://www.elastic.co/guide/en/x-pack/5.0/installing-xpack.html#xpack-enabling

 

 

用户管理

  1. X-Pack插件安装完成后会有个超级用户。
  2. 用户名:elastic
  3. 默认密码:changeme
  4. 这个用户拥有最高权限。包括对所有索引和数据的控制权,我们可以使用elastic用户在图形界面进行添加或删除用户并为其分配权限。
  5.  
  6. 操作:
  7. 1、使用elastic用户进入kibana界面
  8. 2、点击左侧management
  9. 3、选择users
  10. 4、选择New user创建用户
  11. 如下图↓↓

4`CRSQP8`ZK3HR%`D}8DEBO.png

 

***使用注意事项:***

1、你的logstash里面如果直接输出到es中,我们需要在logstash的output中添加用户名和密码

blob.png

 

2、在kibana.yml中要添加访问Elasticsearch的用户名和密码

  1. kibana.yml文件中配置:
  2. elasticsearch.username: "elastic"
  3. elasticsearch.password: "guoxin0521"

 

 

    1. 参考资料:
    2. http://www.2cto.com/os/201611/561466.html 
    3. http://www.guoxin-linux.com/?id=40
    4. http://yanliu.org/2015/08/19/ELK-redis%E6%90%AD%E5%BB%BAnginx%E6%97%A5%E5%BF%97%E5%88%86%E6%9E%90%E5%B9%B3%E5%8F%B0/#more
    5. 官方文档地址:
    6. https://www.elastic.co/guide/en/x-pack/5.0/installing-xpack.html#xpack-enabling

 

posted @ 2017-04-27 10:04  邓某某i  阅读(252)  评论(0编辑  收藏  举报