rhces 发表于 2019-1-28 11:25:44

ELK安装实战

  ELK日志分析系统:
  ####################################################################################################
  一、修改主机名,配置本地解析
  hostname:linux-node1和linux-node2
  192.168.11.34 linux-node1.tangbo.com linux-node1
  192.168.11.35 linux-node2.tangbo.com linux-node2
  ####################################################################################################
  二、elk准备环境(两台完全一致)
  yum install yum-downloadonly -y
  ####################################################################################################
  三、下载并安装GPG key
  # rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
  # vim /etc/yum.repos.d/elasticsearch.repo
  
  name=Elasticsearch repository for 2.x packages
  baseurl=http://packages.elastic.co/elasticsearch/2.x/centos
  gpgcheck=1
  gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
  enabled=1
  安装elasticsearch
  yum install elasticsearch --downloadonly --downloaddir=/tmp/
  ####################################################################################################
  四、logstash安装
  # vim /etc/yum.repos.d/logstash.repo
  
  name=Logstash repository for 2.1.x packages
  baseurl=http://packages.elastic.co/logstash/2.1/centos
  gpgcheck=1
  gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
  enabled=1
  # yum install logstash --downloadonly --downloaddir=/tmp/
  # rpm -ivh logstash-2.1.3-1.noarch.rpm
  Preparing...                ###########################################
  1:logstash               ###########################################
  #
  

  安装kibana:
  #cd /usr/local/src
  #wget https://download.elastic.co/kibana/kibana/kibana-4.3.1-linux-x64.tar.gz
  tar zxf kibana-4.3.1-linux-x64.tar.gz
  # mv kibana-4.3.1-linux-x64 /usr/local/
  # ln -s /usr/local/kibana-4.3.1-linux-x64/ /usr/local/kibana
  ####################################################################################################
  五、安装java,可选安装redis,nginx
  # rpm -ivh jdk-7u80-linux-x64.rpm
  Preparing...                ###########################################
  1:jdk                  ###########################################
  Unpacking JAR files...
  rt.jar...
  jsse.jar...
  charsets.jar...
  tools.jar...
  localedata.jar...
  jfxrt.jar...
  #
  ####################################################################################################
  六、管理linux-node1的elasticsearch
  修改elasticsearch配置文件,并授权:
  # grep -n '^' /etc/elasticsearch/elasticsearch.yml
  17:cluster.name: chuck-cluster判别节点是否是统一集群
  23:node.name: linux-node1 节点的hostname
  33:path.data: /data/es-data 数据存放路径
  37:path.logs: /var/log/elasticsearch/ 日志路径
  43:bootstrap.mlockall: true锁住内存,使内存不会再swap中使用
  54:network.host: 0.0.0.0允许访问的ip
  58:http.port: 9200端口
  # mkdir -p /data/es-data
  # chownelasticsearch.elasticsearch /data/es-data/
  

  启动elasticsearch:
  # service elasticsearch start
  Starting elasticsearch:                                    
  #
  # netstat -lntup|grep 9200
  tcp      0      0 :::9200                     :::*                        LISTEN      1993/java
  #
  ####################################################################################################
  七、启动成功,访问9200端口,会把信息显示出来 。浏览器要用火狐、谷歌。
  {
  "name" : "linux-node1",
  "cluster_name" : "chuck-cluster",
  "version" : {
  "number" : "2.2.0",
  "build_hash" : "8ff36d139e16f8720f2947ef62c8167a888992fe",
  "build_timestamp" : "2016-01-27T13:32:39Z",
  "build_snapshot" : false,
  "lucene_version" : "5.4.1"
  },
  "tagline" : "You Know, for Search"
  }
  ####################################################################################################
  八、使用RESTful API进行交互
  (1)查看当前索引和分片情况,稍后会有插件展示:
  #   curl -i -XGET 'http://172.16.10.34:9200/_count?pretty' -d '{
  > "query" {
  >      "match_all": {}
  > }
  > }'
  HTTP/1.1 200 OK
  Content-Type: application/json; charset=UTF-8
  Content-Length: 95
  

  {
  "count" : 0,
  "_shards" : {
  "total" : 0,
  "successful" : 0,
  "failed" : 0
  }
  }
  #
  (2)使用head插件显示索引和分片情况(未成功就多安装几次)
  # /usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head
  -> Installing mobz/elasticsearch-head...
  Trying https://github.com/mobz/elasticsearch-head/archive/master.zip ...
  Downloading ................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................DONE
  Verifying https://github.com/mobz/elasticsearch-head/archive/master.zip checksums if available ...
  NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .md5 file to verify)
  Installed head into /usr/share/elasticsearch/plugins/head
  #
  

  访问:http://172.16.10.34:9200/_plugin/head/
  ####################################################################################################
  九、使用kopf插件监控elasticsearch
  # /usr/share/elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf
  -> Installing lmenezes/elasticsearch-kopf...
  Trying https://github.com/lmenezes/elasticsearch-kopf/archive/master.zip ...
  Downloading .............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................DONE
  Verifying https://github.com/lmenezes/elasticsearch-kopf/archive/master.zip checksums if available ...
  NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .md5 file to verify)
  Installed kopf into /usr/share/elasticsearch/plugins/kopf
  #
  打开看看:http://172.16.10.34:9200/_plugin/kopf/#!/cluster
  ####################################################################################################
  十、配置logstash
  (1)启动一个logstash,-e:在命令行执行;input输入,stdin标准输入,是一个插件;output输出,stdout:标准输出
  # /opt/logstash/bin/logstash -e 'input { stdin{} } output { stdout{} }'         Settings: Default filter workers: 1
  Logstash startup completed
  chuck==>输入
  2016-01-14T06:01:07.184Z linux-node1 chuck==>输出
  www.chuck-blog.com==>输入
  2016-01-14T06:01:18.581Z linux-node1 www.chuck-blog.com==>输出
  

  

  (2)使用rubudebug显示详细输出,codec为一种编解码器
  # /opt/logstash/bin/logstash -e 'input { stdin{} } output { stdout{ codec => rubydebug} }'
  Settings: Default filter workers: 1
  Logstash startup completed
  chuck   ==>输入
  {
  "message" => "chuck",
  "@version" => "1",
  "@timestamp" => "2016-01-14T06:07:50.117Z",
  "host" => "linux-node1"
  }   ==>使用rubydebug输出
  上述每一条输出的内容称为一个事件,多个相同的输出的内容合并到一起称为一个事件(举例:日志中连续相同的日志输出称为一个事件)!
  (3)使用logstash将信息写入到elasticsearch
  ####################################################################################################
  ####################################################################################################
  编辑kinaba配置文件使之生效:
  # grep '^' /usr/local/kibana/config/kibana.yml
  server.port: 5601 kibana端口
  server.host: "0.0.0.0"对外服务的主机
  elasticsearch.url:       "http://172.16.10.34:9200" 和elasticsearch联系
  kibana.index: ".kibana在elasticsearch中添加.kibana索引
  一个screen,并启动kibana:
  # yum -y install screen
  # screen
  # /usr/local/kibana/bin/kibana
  使用crtl +a+d退出screen
  




页: [1]
查看完整版本: ELK安装实战