一:简单介绍:
ELK是三个开源工具组成,Elasticsearch、Logstash、Kibana ,这三者的关系按照下图所示
Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。
Logstash是一个完全开源的工具,它可以对你的日志进行收集、过滤,并将其存储供以后使用(如,搜索)。
Kibana 也是一个开源和免费的工具,它可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。
二:环境准备
三:安装elasticsearch
3.1创建elasticsearch用户。不能使用root用户,这里有坑需注意。
3.2切换elasticsearch用户
3.3输入命令 tar -zxvf elasticsearch-5.6.7.tar.gz解压
3.4 cd elasticsearch-5.6.7/config/ 进入config文件夹
3.5 vim elasticsearch.yml 修改
cluster.name: elk
node.name: node-1
network.host: 10.104.227.15
http.port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["111.230.131.178:9300"]
node.master: true
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
这里设置了三个实例。集群化部署
复制两个实例修改 vim elasticsearch.yml
一个修改成:
cluster.name: elk
node.name: node-2
http.port: 9201
transport.tcp.port: 9301
node.master: false
node.data: true
discovery.zen.ping.unicast.hosts: ["111.230.131.178"]
http.cors.enabled: true
http.cors.allow-origin: "*"
另一个修改成:
cluster.name: elk
node.name: node-3
network.host: 10.104.227.15
http.port: 9202
transport.tcp.port: 9302
discovery.zen.ping.unicast.hosts: ["111.230.131.178"]
node.master: false
node.data: false
3.6 vim jvm.options 修改
-Xms256m
-Xmx256m
3.7: 进入bin文件夹 nohup sh elasticsearch & 后台启动
3.8 :cat nohup.out 查看启动日志启动报错
3.9 切换root用户
3.9.1 vim /etc/sysctl.conf 修改 vm.max_map_count=655360
3.9.2 sysctl -p
3.9.3 vim /etc/security/limits.conf 修改
* soft nofile 655360
* hard nofile 655360
3.9.4 退出重新登陆
3.10 进入bin文件夹 nohup sh elasticsearch & 后台启动
3.11 jps查看 启动成功
3.12:修改阿里云安全组
3.13: 浏览器输入http://112.124.116.67:9200/
四:安装 logstash-6.3.2
4.1:输入tar -zxvf logstash-6.3.2.tar.gz 解压
4.2:进入bin文件夹 输入vim logstash.conf
input {
log4j {
mode => "server"
host => "10.47.135.225"
port => 4567
}
}
filter {
#Only matched data are send to output.
}
output {
elasticsearch {
action => "index"
hosts => "10.47.135.225:9200"
index => "applog"
}
}
4.3:进入bin目录下启动 ./logstash -f ../bin/logstash.conf
conf的地址就是自己新建的地址
五:安装kibana-5.6.8
5.1:输入tar -zxvf kibana-5.6.8-linux-x86_64.tar.gz解压
5.2:进入config vim kibana.yml 修改:
server.port: 5601
elasticsearch.url: "http://10.47.135.225:9200"
5.3:./bin/kibana 启动
6.1:在github上下载 elasticsearch-head-master.zip 并解压重命名elasticsearch-head 上传linux服务器
6.2:需安装node环境:
6.2.1:下载node-v10.8.0-linux-x64.tar 并解压 tar -xvf node-v10.8.0-linux-x64.tar
6.2.2 : mv node-v10.8.0-linux-x64 nodejs
6.2.3: 配置环境变量 vim /etc/profile
6.2.4: source /etc/profile
6.2.5: node -v 检测是否安装成功
6.3:安装grunt
6.3.1:cd elasticsearch-head/
6.3.2:npm install -g grunt -cli
6.3.3:npm install
6.3.4:npm install [email protected] --ignore-scripts
6.4:进入elasticsearch中 vim elasticsearch.yml 添加
6.5:进入elasticsearch-head 编辑 vim Gruntfile.js 找到 connect,新增hostname
6.6:进入/_site/app.js修改
6.7: 启动 nohup grunt server &
欢迎交流:[email protected]
github: https://github.com/songxiaojun