elasticsearch 安装
官方下载地址:https://www.elastic.co/downloads/elasticsearch
linux执行 :
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.tar.gz
下载解压 【建议使用zsh】
修改配置文件
config/elasticsearch.yml
# 集群的名字
cluster.name: cloud
# 节点名字
node.name: node-1
# 数据存储目录(多个路径用逗号分隔)
path.data: /usr/local/logUtils/elasticsearch/es-data
# 日志目录
path.logs: /usr/local/logUtils/elasticsearch/log
#本机的ip地址
network.host: 192.168.0.135
#设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点
discovery.zen.ping.unicast.hosts: ["192.168.161.128"]
# 设置节点间交互的tcp端口(集群),(默认9300)
transport.tcp.port: 9300
# 监听端口(默认)
http.port: 9200
# 增加参数,使head插件可以访问es
http.cors.enabled: true
http.cors.allow-origin: "*"
运行 bin下的 elasticsearch 进行启动
后台启动 bin/elasticsearch -d
启动结果如下

启动会遇到的问题
1、非root权限启动
新建用户 es
然后把 elasticsearch 文件夹权限归给 新用户es
chown -R es:es elasticsearch
2、 软硬进程限制
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
解决办法
vi /etc/security/limits.conf
文后添加

然后使用source 重新加载
并使用 ulimit -n 查看 是否为 65536 如果还是1024 那么重新连接linux 试下

3、
.max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
解决办法 :
执行 :sysctl -w vm.max_map_count=655360
查看执行结果 : sysctl -a | grep vm.max_map_count
elasticsearch 插件 head 安装
下载head插件
wget https://github.com/mobz/elasticsearch-head/archive/master.zip
安装node
wget https://npm.taobao.org/mirrors/node/latest-v4.x/node-v4.4.7-linux-x64.tar.gz
tar -zxvf node-v4.4.7-linux-x64.tar.gz
配置环境变量

安装 grunt
cd /opt/elasticsearch-head-master
npm install -g grunt-cli //执行后会生成node_modules文件夹
grunt是基于Node.js的项目构建工具,可以进行打包压缩、测试、执行等等的工作,head插件就是通过grunt启动
检查是否安装成功
grunt -version
修改head 插件源码
vi Gruntfile.js

vi _site/app.js

文件较大 建议下载下来 使用文本编辑器查找
或者使用命令替换localhost 为 你的ip
运行head
head根目录
运行 npm install
启动head grunt server
后台启动 nohup grunt server &

Logstash 安装
官方下载地址 :https://www.elastic.co/downloads/logstash
linux安装:curl -L -O https://artifacts.elastic.co/downloads/logstash/logstash-6.0.0.tar.gz
config 添加 配置文件
vi logstash.conf
input {
# stdin { }
tcp {
# host:port就是上面appender中的 destination,
# 这里其实把logstash作为服务,开启9250端口接收logback发出的消息
host => "192.168.0.135"
port => 9250
mode => "server"
tags => ["tags"]
codec => json_lines
}
}
output {
elasticsearch { hosts => ["localhost:9200"] }
stdout { codec => rubydebug }
}
启动logstash
nohup ./logstash -f ../config/logstash.conf &
Kibana 安装
官方下载地址:https://www.elastic.co/downloads/kibana
curl -L -O https://artifacts.elastic.co/downloads/kibana/kibana-6.0.0-linux-x86_64.tar.gz
修改配置文件
vim config/kibana.yml
server.host:"192.168.0.135"
elasticsearch.url:http://192.168.0.135:9200
启动kibana
bin/kibana
启动服务 http://192.168.0.135:5601
至此 ELK服务单机版部署完成
springcloud 集成logback
引入pom
<!--日志发送logstash-->
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>RELEASE</version>
</dependency>
logback-spring.xml
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<!--
destination 是 logstash 服务的 host:port,
相当于和 logstash 建立了管道,将日志数据定向传输到 logstash
-->
<destination>192.168.0.135:9250</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>
<root level="INFO">
<appender-ref ref="LOGSTASH"/>
</root>
网友评论