elk日志收集展示

【elasticsearch6.6安装】
系统准备:
操作系统:centos 7 x64
JAVA软件版本:java8(官方文档)
Elasticsearch版本:6.6.2

安装JDK并设置环境变量:
rpm -ivh jdk-8u192-linux-x64.rpm

vi /etc/profile
export JAVA_HOME=/usr/java/latest

vi .bash_profile
export PATH=$JAVA_HOME/bin:$PATH

查看java版本:
java -version

安装elasticsearch:
tar zxvf elasticsearch-6.6.2.tar.gz
修改配置文件:
config\elasticsearch.yml
cluster.name 集群名称
node.name 节点名称
path.data
path.logs
network.host 0:0:0:0 所有外网IP可访问
http.port http请求端口号,默认为9200
修改配置文件
config\jvm.options
-Xms1g
-Xmx1g

启动elasticsearch
bin\elasticsearch
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
elasticsearch不允许使用root用户启动。

useradd elk

chown -R elk:elk elasticsearch-6.6.2
chown -R elk:elk elk
./elasticsearch

vi /etc/security/limits.conf

  • soft nofile 65536
  • hard nofile 65536
    vi /etc/sysctl.conf
    vm.max_map_count=262144

访问elasticsearch
http://192.168.1.129:9200
新建启动脚本
vi startup.sh
nohup /usr/local/elasticsearch-6.6.2/bin/elasticsearch >> /usr/local/elasticsearch-6.6.2/output.log 2>&1 &
chmod a+x startup.sh
关闭elasticsearch:
jps
kill -9 进程号

【安装kibana】
tar zxvf kibana-6.6.2-linux-x86_64.tar.gz
Kibana是一个开源的分析与可视化平台,设计出来用于和Elasticsearch一起使用的。
你可以用kibana搜索、查看、交互存放在Elasticsearch索引里的数据,
使用各种不同的图表、表格、地图等kibana能够很轻易地展示高级数据分析与可视化。

配置文件config\bibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://localhost:9200"]

访问:
http://127.0.0.1:5601

vi startup.sh
nohup /usr/local/kibana-6.6.2-linux-x86_64/bin/kibana >> /usr/local/kibana-6.6.2-linux-x86_64/output.log 2>&1 &

【kibana面板使用】
GET /kibana_sample_data_logs/_settings

【logstash安装及配置】
tar logstash-6.6.2.tar.gz

使用logstash收集nginx日志并在kibana展示,修改配置文件config\logstash.conf
input {
file {
path => "/usr/local/nginx/logs/access.log"
type => "nginxaccess"
start_position => "beginning"
}
}

filter {
grok {
match => { "message" => "%{HTTPD_COMBINEDLOG}" }
}
}

output {
#输出到elasticsearch:
elasticsearch {
hosts => ["127.0.0.1:9200"]
index => "nginx-%{+YYYY.MM.dd}"
}
}
启动脚本:
startup.sh
#!/bin/bash
nohup /usr/local/logstash-6.6.2/bin/logstash -f /usr/local/logstash-6.6.2/config/logstash.conf >> /usr/local/logstash-6.6.2/output.log 2>&1 &

猜你喜欢

转载自blog.51cto.com/13088442/2454408