ELK

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

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

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

 

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

  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

 

二、安装Redis agent端不用安装 redis

  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了。并不是权限控制。(我的理解的,若有不对请包涵)

 

三、安装elasticsearchvim

 

  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/ruby

 

四、安装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.  

五、安装kibanaoracle

 

  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

环境构建完成cors

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

 

 

 

 

六、遇到的问题

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

 

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

一、你的logstash里面若是直接输出到es中,咱们须要在logstash的output中添加用户名和密码

blob.png

 

二、在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
相关文章
相关标签/搜索
本站公众号
   欢迎关注本站公众号,获取更多信息