-★出爺;3 发表于 2019-1-28 09:17:54

ELK平台搭建 ES

  系统环境:
  System: Centos 6.5
  ElasticSearch: 2.3.3
  Logstash: 2.3.3
  Kibana: 4.5.1
  Java: jdk_1.8.0_71
  

  新建用户:
  ELK不允许root用户启动
#useradd elk  JDK或JRE下载安装:
  java也可到这个地址下载https://www.reucon.com/cdn/java/
# mkdir /usr/java/
# cd /usr/java
# tar -zxvf jdk-8u71-linux-x64.tar.gz  
# 修改文件夹名,防止异常,养成好习惯
# mv jdk1.8.0_71 jdk18071
# 配置环境变量
# vi /etc/profile
    export JAVA_HOME=/usr/java/jdk18071
    export JAVA_BIN=$JAVA_HOME/bin
    export JRE_HOME=$JAVA_HOME/jre
    export JRE_bin=$JRE_HOME/bin
    export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
    export PATH=$JAVA_BIN:$PATH
# 配置生效
# source /etc/profile
  Redis安装
# yum install epel-release –y
# yum install redis –y  修改redis配置文件使redis监听所有ip,默认情况下只监听127.0.0.01
# vi /etc/redis.conf
   bind 0.0.0.0  启动Redis
  CentOS 6
# service redis start  CentOS 7
# systemctl restart redis.service  

  下载:
  ELK下载:https://www.elastic.co/downloads/
http://s2.运维网.com/wyfs02/M02/83/31/wKiom1dsz-CieVOVAAEYEzx-v0s956.png-wh_500x0-wm_3-wmp_4-s_3067730089.png
  

  ElasticSearch安装:
  建立存放目录:
  切记:涉及ElasticSearch的目录和文件,一定要全修改权限,否则启动会报错。
# mkdir -p /elk/{data,logs,work,plugins,scripts}
# chown -R elk:elk /elk  配置ElasticSearch:
# tar -zxvf elasticsearch-2.3.3.tar.gz
#chown -R elk:elk elasticsearch-2.3.3
# cd elasticsearch-2.3.3  安装Head插件(Optional):
# ./bin/plugin install mobz/elasticsearch-headhttp://s1.运维网.com/wyfs02/M00/83/31/wKioL1ds0I_Dfs0YAACTX2xuGnc271.png
  然后编辑ES的配置文件:
# vi config/elasticsearch.yml  修改以下配置项:
cluster.name:cluster(集群名称)
node.name:"test-node1"(集群结点名称)
path.data:/elk/data(数据)
path.logs:/elk/logs(日志路径)
node.master: true(是否可被选为主结点,默认true)
node.data: true(结点是否存储数据,默认true)
index.number_of_shards:5(索引分片数)
index.number_of_replicas:1(索引副本数)
transport.tcp.port:9300(数据传输IP)
network.host:192.168.1.100(当前hostname或IP,我这里是IP)
http.port: 9200(对外访问监听IP)  启动ES:

  使用ctrl+C停止,参数-d 或& 为后台启动
$ ./bin/elasticsearch -d  
$ ./bin/elasticsearch &  测试:
curl -X GET http://IP:9200返回展示了配置的cluster_name和name,以及安装的ES的版本等信息。
  刚刚安装的head插件,它是一个用浏览器跟ES集群交互的插件,可以查看集群状态、集群的doc内容、执行搜索和普通的Rest请求等。
  现在也可以使用它打开http://IP:9200/_plugin/head页面来查看ES集群状态。
http://s5.运维网.com/wyfs02/M00/83/3B/wKioL1ds-ZHgWnCNAACfMEgaqm4147.png可以看到,现在,ES集群中没有index,也没有type,因此这两条是空的。
  

  Logstash安装:
  

  配置Logstash:
tar -zxvf logstash-2.1.1.tar.gz
cd logstash-2.1.1  

  编写配置文件(名字和位置可以随意,这里我放在config目录下,取名为log4j_to_es.conf):
mkdir config
vi config/log4j_to_es.conf  输入以下内容:
# For detail structure of this file
# Set: https://www.elastic.co/guide/en/logstash/current/configuration-file-structure.html
input {
# For detail config for log4j as input,
# See: https://www.elastic.co/guide/en/logstash/current/plugins-inputs-log4j.html
log4j {
    mode => "server"
    host => "192.168.1.100" #IP or HostName
    port => 4567
}
}
filter {
#Only matched data are send to output.
}
output {
# For detail config for elasticsearch as output,
# See: https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html
elasticsearch {
    action => "index"          #The operation on ES
    hosts=> "192.168.1.100:9200" #IP or HostName,ElasticSearch host, can be array.
    index=> "applog"         #The index to write data to.
}
}  

  启动:
  使用agent来启动它(使用-f指定配置文件):
./bin/logstash agent -f config/log4j_to_es.conf  启动成功
http://s2.运维网.com/wyfs02/M00/83/3C/wKiom1dtBNSS152DAABM913Yarw032.png
  

  

  

  

  参考文章:
  http://my.oschina.net/itblog/blog/547250
  http://blog.csdn.net/gongzi2311/article/details/51699958
  http://blog.csdn.net/laoyang360/article/details/51417097
  

  




页: [1]
查看完整版本: ELK平台搭建 ES