221rrere 发表于 2016-6-27 09:15:12

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用户启动

1
#useradd elk




JDK或JRE下载安装:
java也可到这个地址下载https://www.reucon.com/cdn/java/

1
2
3
# mkdir /usr/java/
# cd /usr/java
# tar -zxvf jdk-8u71-linux-x64.tar.gz






1
2
3
4
5
6
7
8
9
10
11
12
# 修改文件夹名,防止异常,养成好习惯
# 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安装

1
2
# yum install epel-release –y
# yum install redis –y




修改redis配置文件使redis监听所有ip,默认情况下只监听127.0.0.01

1
2
# vi /etc/redis.conf
   bind 0.0.0.0




启动Redis
CentOS 6

1
# service redis start




CentOS 7

1
# systemctl restart redis.service






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


ElasticSearch安装:
建立存放目录:
切记:涉及ElasticSearch的目录和文件,一定要全修改权限,否则启动会报错。

1
2
# mkdir -p /elk/{data,logs,work,plugins,scripts}
# chown -R elk:elk /elk




配置ElasticSearch:

1
2
3
# tar -zxvf elasticsearch-2.3.3.tar.gz
#chown -R elk:elk elasticsearch-2.3.3
# cd elasticsearch-2.3.3




安装Head插件(Optional):

1
# ./bin/plugin install mobz/elasticsearch-head





然后编辑ES的配置文件:

1
# vi config/elasticsearch.yml




修改以下配置项:

1
2
3
4
5
6
7
8
9
10
11
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 或& 为后台启动

1
$ ./bin/elasticsearch -d






1
$ ./bin/elasticsearch &




测试:

1
curl -X GET http://IP:9200




返回展示了配置的cluster_name和name,以及安装的ES的版本等信息。刚刚安装的head插件,它是一个用浏览器跟ES集群交互的插件,可以查看集群状态、集群的doc内容、执行搜索和普通的Rest请求等。
现在也可以使用它打开http://IP:9200/_plugin/head页面来查看ES集群状态。
可以看到,现在,ES集群中没有index,也没有type,因此这两条是空的。

Logstash安装:

配置Logstash:

1
2
tar -zxvf logstash-2.1.1.tar.gz
cd logstash-2.1.1





编写配置文件(名字和位置可以随意,这里我放在config目录下,取名为log4j_to_es.conf):

1
2
mkdir config
vi config/log4j_to_es.conf




输入以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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指定配置文件):

1
./bin/logstash agent -f config/log4j_to_es.conf




启动成功





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