Centos 7.6 Install ELK离线安装

Nginx安装

https://blog.csdn.net/hanzheng260561728/article/details/90209721

Nginx配置实例

https://blog.csdn.net/hanzheng260561728/article/details/80583051

Centos 7.6系统下载

http://mirrors.cqu.edu.cn/CentOS/7.6.1810/isos/x86_64/CentOS-7-x86_64-DVD-1810.iso

Java 安装

解压JDK
tar -zvxf jdk-8u121-linux-x64.tar.gz

mv jdk-8u121/ /usr/local/java/

编辑环境变量文件
vim /etc/profile

#文件最后部分加入
export JAVA_HOME=/usr/local/java
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

#刷新profiley文件
source /etc/profile

#查看JDK版本
java -version

 ELK端配置

mkdir -p /usr/local/es
mkdir -p /usr/local/esdata

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.3.tar.gz
tar xf elasticsearch-6.1.3.tar.gz  -C /usr/local/es

编辑Elasticsearch的配置文件
vi /usr/local/es/elasticsearch-6.1.3/config/elasticsearch.yml

cluster.name: my-application	#配置一个名称
#node.name: node-1		#elasticsearch名称
network.host: 0.0.0.0		#允许访问
node.name: elk-server		#本节名字
path.data: /usr/local/esdata	#数据存放目录运行elasticsearch

启动
/usr/local/es/elasticsearch-6.1.3/bin/elasticsearch -d	#注意是在普通用户下启动,在ELK中它要先于logstash启动

验证9200端口是否处于监听状态
ss -tnl |grep 9200 	

curl localhost:9200 
{
  "name" : "elk-server",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "JfQt3JmRTBubVgcKYfWU3w",
  "version" : {
    "number" : "6.1.3",
    "build_hash" : "af51318",
    "build_date" : "2018-01-26T18:22:55.523Z",
    "build_snapshot" : false,
    "lucene_version" : "7.1.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

 ELK端配置kibana

wget https://artifacts.elastic.co/downloads/kibana/kibana-6.1.3-linux-x86_64.tar.gz
tar xf kibana-6.1.3-linux-x86_64.tar.gz -C /usr/local/es

vi /usr/local/es/kibana-6.1.3-linux-x86_64/config/kibana.yml

server.host: 192.168.31.66
#elasticsearch的地址,如果elasticsearch与kibana安装在不同服务器上,需要手动指定地址
elasticsearch.url: "http://0.0.0.0:9200"

#kibana服务器名称,如果有多个kibana节点,建议修改这个参数以便识别
#server.name: "your-hostname"

#kibana会在elasticsearch中创建一个索引用于存储kibana的设置,索引名称可以自定义。一般无需修改
#kibana.index: ".kibana"

#elasticsearch请求超时阈值,如果数据量及其庞大,可适当增加该值
#elasticsearch.requestTimeout: 30000

启动
/usr/local/es/kibana-6.1.3-linux-x86_64/bin/kibana &

ELK端配置Logstash
wget https://artifacts.elastic.co/downloads/logstash/logstash-6.1.3.tar.gz
tar xf logstash-6.1.3.tar.gz  -C /usr/local/es

测试logstash能否正常运行(:

A:原封不动的返回
/home/es/logstash-6.1.3/bin/logstash -e 'input {stdin {}} output {stdout{}}'
#等待一会儿,你在屏幕输入hello word看是否会有输出

B:以json的格式返回
/home/es/logstash-6.1.3/bin/logstash -e 'input{stdin{}}output{stdout{codec => rubydebug}}'
#等待一会儿,你在屏幕输入hello word看是否会有输出json格式

为logstash创建conf.d目录,用于存放长久运行的配置文件(这个里面的配置文件名,建议使用数字开头,因为是按排序执行的)
mkdir /usr/local/es/logstash-6.1.3/conf.d

logstash的配置文件完全不需要修改:
vi /usr/local/es/logstash-6.1.3/config/logstash.yml

#logstash数据存储路径,保持默认即可
path.data: /var/lib/logstash
#logstash动态加载的配置文件,所有自定义的输入、输出和过滤配置都放置在这个目录中并以.conf结尾
path.config: /etc/logstash/conf.d/*.conf
#logstash日志文件路径,保持默认即可
path.logs: /var/log/logstash

logstash配置输入设置
vi /usr/local/es/logstash-6.1.3/conf.d/filebeat.conf		#创建配置文件
input {
  beats {
    port => 5044
  }
}
output {
  elasticsearch {
    hosts => ["http://0.0.0.0:9200"]
    index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
  }
}

启动
/usr/local/es/logstash-6.1.3/bin/logstash -f /usr/local/es/logstash-6.1.3/conf.d/filebeat.conf &

一会儿后检查5044端口是否开启
ss -tnl |grep 5044

客户端安装filebeat

应用服务器上部署日志搜集转发器,安装filebeat并为与logstash的通信
在应用服务器上添加官方源
vi /etc/yum.repos.d/elk.repo
[elastic-5.x]
name=Elastic repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

安装filebeat组件
yum install filebeat -y

配置filebeat
vi /etc/filebeat/filebeat.yml
filebeat.prospectors:
- type: log
  paths:
    -  /usr/local/nginx/logs/access.log
- type: log
  paths:
    -  /usr/local/nginx/logs/error.log
output.logstash:
 hosts: ["192.168.31.66:5044"]

启动filebeat
server start filebeat

你可能感兴趣的:(Centos)