
主要参考 ELK(Elasticsearch、Logstash、Kibana)安装_慕菲烟云的博客-CSDN博客
cd /usr/local
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.3.tar.gz
vim /usr/local/elasticsearch-6.4.3/config/elasticsearch.yml
#配置es的集群名称,默认是elasticsearch,es会自动发现在同一网段下的es,如果在同一网段下有多个集群,就可以用这个属性来区分不同的集群。
cluster.name: my-es
#节点名称
node.name: node-1
#设置索引数据的存储路径
path.data: /usr/local/elasticsearch-6.4.3/data
#设置日志的存储路径
path.logs: /usr/local/elasticsearch-6.4.3/logs
#设置当前的ip地址,通过指定相同网段的其他节点会加入该集群中
network.host: 0.0.0.0
#设置对外服务的http端口
http.port: 9200
#设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点
discovery.zen.ping.unicast.hosts: ["127.0.0.1","10.10.10.34:9200"]
## 1.不允许使用 root 启动 es
useradd esuser
passwd esuser
chown -R esuser:esuser /usr/local/elasticsearch-6.4.3
cd /usr/local/elasticsearch
bin/elasticsearch
## 2.无法创建本地文件问题,用户最大可创建文件数太小
sudo vi /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
## 3.最大虚拟内存太小
sudo vi /etc/sysctl.conf
vm.max_map_count=655360
sudo sysctl -p
## 启动服务(需要后台启动 加上 -d)
bin/elasticsearch
## 访问测试
http://xxxx:9200/
## elasticsearch-head
git clone https://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head/
# 这一步可能存在有个插件无法安装,手动下载,按照报错提示手动安装
npm install
## 配置elasticsearch,允许head插件远程访问
cd /usr/local/elasticsearch-6.4.3/config
vi elasticsearch.yml
#在配置文件末尾添加如下内容,重新启动elasticsearch服务
http.cors.enabled: true
http.cors.allow-origin: "*"
# 启动elasticsearch-head服务
cd /usr/local/elasticsearch-head/
npm run start
#如果后台启动使用
nohup npm run start &
## 访问 http://xxxx:9100/
## 安装 Logstash
wget https://artifacts.elastic.co/downloads/logstash/logstash-6.4.3.tar.gz
tar -zxvf logstash-6.4.3.tar.gz
cd /usr/local/logstash-6.4.3/config/
mkdir conf.d
vi conf.d/logstash-es.conf
#输入以下内容
input {
tcp {
port => 10514
codec=>json_lines
host => "0.0.0.0"
}
}
output {
stdout{
codec => rubydebug
}
elasticsearch {
action => "index"
hosts => ["localhost:9200"]
index => "renren"
}
}
## 10514:接受日志端口
## hosts => ["localhost:9200"] :es的ip和端口
## "%{[appname]}" :取值日志中appname值为索引
## 检测配置文件是否有错
/usr/local/logstash-6.4.3/bin/logstash --path.settings /usr/local/logstash-6.4.3/config/ -f /usr/local/logstash-6.4.3/config/conf.d/logstash-es.conf --config.test_and_exit
/usr/local/logstash-6.4.3/bin/logstash --path.settings /usr/local/logstash-6.4.3/config/ -f /usr/local/logstash-6.4.3/config/conf.d/logstash-es.conf
# Kibana
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.4.3-linux-x86_64.tar.gz
tar -zxvf kibana-6.4.3-linux-x86_64.tar.gz
cd /usr/local/kibana-6.4.3-linux-x86_64
vi config/kibana.yml
#修改一下内容
server.port: 5601 ##服务端口
server.host: "0.0.0.0" ##服务器ip 本机
elasticsearch.url: "http://localhost:9200" ##elasticsearch服务地址 与elasticsearch对应
# 启动
/usr/local/kibana-6.4.3-linux-x86_64/bin/kibana
# 访问 5601
依赖
<dependency>
<groupId>net.logstash.logbackgroupId>
<artifactId>logstash-logback-encoderartifactId>
<version>7.2version>
dependency>
logback-spring.xml
<appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>192.168.x.x:10514destination>
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
appender>
<root level="info">
<appender-ref ref="stash"/>
root>
启动SpringBoot项目后,会输出到 logstash,观察 控制台
kibana dev tool
discovery
首先需要手动配置 index partterns
然后看 discovery

对这块的原理还是使用细节还需要后续打磨