0%

Mac环境ELK搭建

安装Java

略。。。

这里我使用brew install java命令安装

1
2
3
4
☁  ~  java -version
java version "11" 2018-09-25
Java(TM) SE Runtime Environment 18.9 (build 11+28)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11+28, mixed mode)

不要使用上述方式安装,有坑

下载这个文件安装java:https://edelivery.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/jdk-8u181-macosx-x64.dmg

Elasticsearch安装配置

安装

官网下载对应平台的安装包

下载Elasticsearch

放到合适的位置,我放置后解压的目录是/Users/zhimma/Soft/elasticsearch-6.4.1

配置

配置 Elasticsearch

下面是我的配置文件内容:

1
2
3
4
5
6
7
8
9
☁  config  pwd
/Users/zhimma/Soft/elasticsearch-6.4.1/config
☁ config grep '^[a-z]' elasticsearch.yml
cluster.name: elk-stack
path.data: /Users/zhimma/Data/elk_stack/data
path.logs: /Users/zhimma/Data/elk_stack/logs
bootstrap.memory_lock: false
network.host: 0.0.0.0
http.port: 9200

配置 Elasticsearch 内存占用

配置 jvm 最大堆和最小堆,一般为服务器物理内存的一半,最大不超过 32g

1
2
3
4
5
6
☁  config  pwd
/Users/zhimma/Soft/elasticsearch-6.4.1/config
☁ config vi jvm.options

-Xms8g
-Xmx8g

启动

进入bin目录启动Elasticsearch

1
2
3
☁  bin  pwd
/Users/zhimma/Soft/elasticsearch-6.4.1/bin
☁ bin ./elasticsearch

kibana安装配置

安装

官网下载对应平台的安装包

下载Kibana

放到合适的位置,我放置后解压的目录是/Users/zhimma/Soft/kibana-6.4.1-darwin-x86_64

配置

凭感觉配置了一些,如下所示:

1
2
3
4
5
☁  config  grep '^[a-z]' kibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://0.0.0.0:9200"
kibana.index: ".kibana"

启动

进入bin目录启动Kibana

1
2
3
☁  bin  pwd
/Users/zhimma/Soft/kibana-6.4.1-darwin-x86_64/bin
☁ bin ./kibana

Logstash安装配置

安装

官网下载对应平台的安装包

下载Logstash

放到合适的位置,我放置后解压的目录是/Users/zhimma/Soft/logstash-6.4.1

配置

配置 Logstash

不是很了解,暂时使用默认配置

配置 Logstash 内存占用

配置 jvm 最大堆和最小堆,一般为服务器物理内存的一半,最大不超过 32g

1
2
3
4
5
6
☁  config  pwd
/Users/zhimma/Soft/logstash-6.4.1/config
☁ config vi jvm.options

-Xms8g
-Xmx8g

添加项目或自定义配置文件

Logstash收集日志时候,可以对日志进行一定的操作和过滤,这里需要自定义不同的配置文件来实现,针对我们目前的项目,我简单的创建了下面的配置文件

/Users/zhimma/Soft/logstash-6.4.1/config目录下创建conf.d文件夹,这个文件夹下存放我们所有的自定义配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
input {
file {
path => [ "/data/www/XX_project/trunk/Common/Runtime/Apps/Api/*.log" ]
start_position => "beginning"
ignore_older => 0
sincedb_path => "/dev/null"
type => "Api"
codec => multiline {
pattern => "^\["
negate => true
what => "previous"
}
},
file {
path => [ "/data/www/XX_project/trunk/Common/Runtime/Apps/SDK/*.log" ]
start_position => "beginning"
ignore_older => 0
sincedb_path => "/dev/null"
type => "SDK"
codec => multiline {
pattern => "^\["
negate => true
what => "previous"
}
}
}

filter {

}

output {
if [type] == "Api" {
elasticsearch {
hosts => [ "127.0.0.1:9200" ]
index => "api"
}
},
if [type] == "SDK" {
elasticsearch {
hosts => [ "127.0.0.1:9200" ]
index => "sdk"
}
}
stdout { codec => rubydebug }
}

启动

进入bin目录启动Llogstash

1
2
3
☁  bin  pwd
/Users/zhimma/Soft/logstash-6.4.1/bin
☁ bin ./logstash -f /Users/zhimma/Soft/logstash-6.4.1/config/conf.d/default.conf

## 访问

浏览器访问0.0.0.0:5601即可