电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 1544 人浏览分享

centos6.5下部署elk

[复制链接]
1544 0

1、介绍

   elk是实时日志分析平台,主要是为开发和运维人员提供实时的日志分析,方便人员更好的了解系统状态和代码问题。

2、elk中的e(elasticsearch):

(2.1)先安装依赖包,官方文档说明使用java1.8

yum -y install java-1.8.0-openjdk

安装elasticsearch:

  1. tar zvxf elasticsearch-1.7.0.tar.gz
  2. mv elasticsearch-1.7.0 /usr/local/elasticsearch
  3. vim /usr/local/elasticsearch/config
  4. cp elasticsearch.yml elasticsearch.yml.bak
  5. vim elasticsearch.yml(修改)
  6. cluster.name: elasticsearch
  7. node.name: syk
  8. node.master: true
  9. node.data: true
  10. index.number_of_shards: 5
  11. index.number_of_replicas: 1(分片副本)
  12. path.data: /usr/local/elasticsearch/data
  13. path.conf: /usr/local/elasticsearch/conf
  14. path.work: /usr/local/elasticsearch/work
  15. path.plugins: /usr/local/elasticsearch/plugins
  16. path.logs: /usr/local/elasticsearch/logs
  17. bootstrap.mlockall: true (内存)
  18. 启动:/usr/local/elasticsearch/bin/elasticsearch -d
  19. netstat -tlnp查看
  20. 会有9200与9300的java进程
  21. curl http://192.168.137.50:9200
复制代码


显示:

  1. {
  2.   "status" : 200,
  3.   "name" : "syk",
  4.   "cluster_name" : "elasticsearch",
  5.   "version" : {
  6.     "number" : "1.7.0",
  7.     "build_hash" : "929b9739cae115e73c346cb5f9a6f24ba735a743",
  8.     "build_timestamp" : "2015-07-16T14:31:07Z",
  9.     "build_snapshot" : false,
  10.     "lucene_version" : "4.10.4"
  11.   },
  12.   "tagline" : "You Know, for Search"

  13. }
复制代码

(2.2)使用官方给的启动脚本:

  1. https://codeload.github.com/elastic/elasticsearch-servicewrapper/zip/master
复制代码


用rz命令传到服务器上

  1. unzip elasticsearch-servicewrapper-master.zip
  2. mv elasticsearch-servicewrapper-master/service/ /usr/local/elasticsearch/bin/
  3. cd /usr/local/elasticsearch/bin/service
  4. ./elasticsearch install(在init.d下自动创建服务脚本)
  5. /etc/init.d/elasticsearch restart
复制代码


  1. curl -XGET 'http://192.168.137.50:9200/_count?pretty' -d '
  2. > {
  3. >      "query":{
  4. >         "match_all":{}
  5. >     }
  6. >  }
  7. > '
复制代码


会返回:

  1. {
  2.   "count" : 0,
  3.   "_shards" : {
  4.     "total" : 0,
  5.     "successful" : 0,
  6.     "failed" : 0
  7.   }
  8. }
复制代码

(2.3)基于rest api的界面(可以增删改差)

安装插件:/usr/local/elasticsearch/bin/plugin -i elasticsearch/marvel/latest (自动安装)
网页访问:http://192.168.137.50:9200/_plugin/marvel

安装集群管理插件

  1. /usr/local/elasticsearch/bin/plugin -i mobz/elasticsearch-head
  2. 或者:https://github.com/mobz/elasticsearch-head/archive/master.zip下载下来,rz传到服务器
  3. unzip elasticsearch-head-master.zip
  4. mv elasticsearch-head-master plugins/head
  5. 网页访问:http://192.168.137.50:9200/_plugin/head
  6. 可以以网页的方式显示你的分片已分片副本。
复制代码

3、elk中的l(logstash):

(3.1)安装logstash:
i)、官方提供了yum安装的安装方式:
  1.   1、rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
  2.    2、vim /etc/yum.repos.d/logstash.repo
  3.     添加:

  4.     [logstash-2.3]
  5.     name=Logstash repository for 2.3.x packages
  6.     baseurl=https://packages.elastic.co/logstash/2.3/centos
  7.     gpgcheck=1
  8.     gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch
  9.     enabled=1
  10.    3、yum --enablerepo=logstash-2.3 -y install logstash
复制代码

ii)、下载tar包安装:


  1. tar zvxf logstash-1.5.3.tar.gz
  2.    mv logstash-1.5.3 /usr/local/logstash
复制代码


(3.2)测试

  1. /usr/local/logstash/bin/logstash -e 'input { stdin{} } output { stdout{codec => rubydebug} }'
  2.   输入hehe
  3.   显示:  
  4.   Logstash startup completed
  5.   hehe
  6.   {
  7.        "message" => "hehe",
  8.       "@version" => "1",
  9.     "@timestamp" => "2016-08-07T17:46:10.836Z",
  10.           "host" => "web10.syk.com"
  11.    }
复制代码


这表示正常。

(3.3)写logstash配置文件
  注意:
   必须input{}与output{}
   写法:符号使用=>
  1. vim /etc/logstash.conf
  2.    input{
  3.      file {
  4.        path => "/var/log/syk.log"
  5.     }
  6.    }
  7.    output{
  8.      file {
  9.        path => "/tmp/%{+YYYY-MM-dd}.syk.gz"
  10.        gzip => true
  11.      }
  12.    }
复制代码


启动logstash:/usr/local/logstash/bin/logstash -f /etc/logstash.conf
cd /var/log

cat maillog >> syk.log(追加到syk.log里)
在/tmp下可以看到以日期命名的syk.gz压缩文件
(3.4)使用redis存储logstash:
  1. yum -y install redis(redis放在另外一台服务器上)
  2. vim /etc/redis.conf(修改)
  3.   bind 192.168.137.52
  4. 在192.168.137.52服务器上也安装logstash
复制代码


编写配置文件:

  1. vim /etc/logstash.conf  
  2.    input{
  3.      file {
  4.        path => "/var/log/syk.log"
  5.      }
  6.    }
  7.    output{
  8.      redis {
  9.      data_type => "list"
  10.      key => "system-messages"
  11.      host => "192.168.137.52"
  12.      port => "6379"
  13.      db => "1"
  14.      }
  15.    }
复制代码


启动52服务器的logstash:

  1. /usr/local/logstash/bin/logstash -f /etc/logstash.conf
  2. cd /var/log
  3. cat maillog >> syk.log(追加到syk.log里)
复制代码


进去redis里查看:

  1. redis-cli -h 192.168.137.52 -p 6379
  2. select 1
  3. keys *(可以看到system-messages这个key)
  4. llen system-messages(可以看大system-messages这个key的长度)
复制代码


(3.4)将logstash收集的日志信息传到es上
在192.168.137.50的服务器上写logstash配置文件:
  1. vim /etc/logstash.conf   
  2.    input {
  3.       redis {
  4.       data_type => "list"
  5.       key => "system-messages"
  6.       host => "192.168.137.52"
  7.       port => "6379"
  8.       db => "1"
  9.      }
  10.    }
  11.    output {
  12.      elasticsearch {
  13.      host => "192.168.137.50"
  14.      protocol => "http"
  15.      index => "system-messages-%{+YYYY.MM.dd}"
  16.       }
  17.    }
复制代码

启动logstash:

/usr/local/logstash/bin/logstash -f /etc/logstash.conf
这时我们去看redis的LLEN system-messages,会发现已经变成了0,这说明数据已经传输到es上了。
网页访问:http://192.168.137.50:9200/_plugin/head/
会多出来一个system-messages-2016.08.07的分片副本

4、elk中的k(kibana):
(4.1)安装:
  解压 mv就行
  1. cd /usr/local/kiabna/config/
  2.    vim kibana.yml修改:
  3.     elastcsearch: "http://192.168.137.50:9200"
复制代码


启动:

     
  1. nohup ./bin/kiban &
复制代码
(默认端口5601)
网页访问:

http://192.168.137.50:5601
相关操作需要配合图片说明,这里暂时不说了。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

0

粉丝

9021

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.