CentOS 7安装部署ELK 6.2.4-SUCCESS

1、ELK介绍

ELK是三款开源软件的缩写,即:ElasticSearch + Logstash + Kibana。这三个工具组合造成了一套实用、易用的监控架构,可抓取系统日志、apache日志、nginx日志、mysql日志等多种日志类型,目前不少公司用它来搭建可视化的集中式日志分析平台。
ElasticSearch:是一个分布式的RESTful风格的搜索和数据分析引擎,同时还提供了集中存储功能,它主要负责将logstash抓取来的日志数据进行检索、查询、分析等。
Logstash:日志处理工具,负责日志收集、转换、解析等,并将解析后的日志推送给ElasticSearch进行检索。
Kibana:Web前端,能够将ElasticSearch检索后的日志转化为各类图表,为用户提供数据可视化支持。
Filebeat:轻量型日志采集器,负责采集文件形式的日志,并将采集来的日志推送给logstash进行处理。
Winlogbeat:轻量型windows事件日志采集器,负责采集wondows的事件日志,并将采集来的日志推送给logstash进行处理。javascript

2、部署环境

因为我这边是测试环境,因此ElasticSearch + Logstash + Kibana这三个软件我都是装在一台机器上面,若是是生产环境,建议分开部署,而且ElasticSearch可配置成集群方式。
IP:192.168.2.207(ELK服务器,CentOS 7)
IP:192.168.2.203(filebeat,nginx服务器,CentOS 7)
IP:192.168.2.204(filebeat,apache服务器,CentOS 7)
IP:192.168.2.206(winlogbeat,windows 10)php

3、安装前的准备工做

一、关闭 selinux 和防火墙(这里暂时关闭iptables,部署完成后再开启)css

sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config sed -i 's/SELINUXTYPE=targeted/#&/' /etc/selinux/config setenforce 0 # 能够设置配置文件永久关闭 systemctl stop firewalld.service

二、安装配置iptables前端

yum -y install iptables iptables-services vim /etc/sysconfig/iptables # 添加以下端口策略 -A INPUT -p tcp -m state --state NEW -m tcp --dport 9200 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 5601 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 5044 -j ACCEPT

启动iptablesjava

systemctl start iptables.service
systemctl enable iptables.service # 将iptables加入开机启动

查看iptables状态
systemctl status iptables.service
重启系统
reboot # 更改selinux须要重启系统才会生效
三、安装java 8及相关软件
yum -y install vim wget java java-devel
查看java版本
java -version
CentOS 7安装部署ELK 6.2.4
四、下载ELK及相关软件
ELK服务器需下载
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.rpm
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.2.4-x86_64.rpm
wget https://artifacts.elastic.co/downloads/logstash/logstash-6.2.4.rpm
Linux节点服务器需下载
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.2.4-x86_64.rpm
windows节点服务器需下载
CentOS 7安装部署ELK 6.2.4node

4、安装配置ELK

一、yum方式安装ELKmysql

yum localinstall -y elasticsearch-6.2.4.rpm yum localinstall -y kibana-6.2.4-x86_64.rpm yum localinstall -y logstash-6.2.4.rpm

二、建立ELK存放数据和日志目录linux

mkdir -pv /data/elasticsearch/{data,logs} mkdir -pv /data/logstash/{data,logs} chown -R elasticsearch.elasticsearch /data/elasticsearch/ chown -R logstash.logstash /data/logstash/

三、修改ELK配置文件nginx

vim /etc/elasticsearch/elasticsearch.yml
path.data: /data/elasticsearch/data path.logs: /data/elasticsearch/logs network.host: 0.0.0.0 http.port: 9200 vim /etc/logstash/logstash.yml path.data: /data/logstash/data path.logs: /data/logstash/logs
vim /etc/logstash/conf.d/logstash.conf  # 添加以下内容 input { beats { port => 5044 codec => plain { charset => "UTF-8" } } } output { elasticsearch { hosts => "127.0.0.1:9200" manage_template => false index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}" document_type => "%{[@metadata][type]}" } }
vim /etc/kibana/kibana.yml
server.port: 5601 server.host: "192.168.2.207" elasticsearch.url: "http://localhost:9200"

四、安装配置nginx
安装nginx和http用户认证工具sql

yum -y install epel-release yum -y install nginx httpd-tools

修改nginx配置

cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak vim /etc/nginx/nginx.conf

把下图中这一段注释掉
CentOS 7安装部署ELK 6.2.4

vim /etc/nginx/conf.d/kibana.conf  # 添加以下内容 server { listen 80; server_name kibana; auth_basic "Restricted Access"; auth_basic_user_file /etc/nginx/kibana-user; //http认证文件 location / { proxy_pass http://192.168.2.207:5601; //代理的kibana地址 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }

生成http用户认证文件,生成文件kibana-user,并添加用户henhh
htpasswd -cm /etc/nginx/kibana-user henhh
此处须要输入两遍密码
五、启动ELK和nginx

systemctl daemon-reload  # 从新加载全部配置文件 systemctl start elasticsearch logstash kibana nginx # 启动ELK和nginx systemctl enable elasticsearch logstash kibana nginx # 将ELK和nginx加入开机启动 systemctl status elasticsearch logstash kibana nginx #查看ELK和nginx启动状态

查看端口是否已监听
CentOS 7安装部署ELK 6.2.4
六、查看elasticsearch状态
curl -XGET 'http://192.168.2.207:9200/_cluster/state/nodes?pretty'
CentOS 7安装部署ELK 6.2.4
查看elasticsearch的master

curl -XGET 'http://192.168.2.207:9200/_cluster/state/master_node?pretty' curl -XGET 'http://192.168.2.207:9200/_cat/master?v'

CentOS 7安装部署ELK 6.2.4
查看健康状态

curl -XGET 'http://192.168.2.207:9200/_cat/health?v' curl -XGET 'http://192.168.2.207:9200/_cluster/health?pretty'

CentOS 7安装部署ELK 6.2.4
对于这个健康状态green(绿色)为最好

5、Linux节点服务器安装配置filebeat

安装filebeat,进入到以前下载安装包的目录,执行yum方式安装
yum localinstall -y filebeat-6.2.4-x86_64.rpm
修改filebeat配置

vim /etc/filebeat/filebeat.yml
- type: log enabled: true - /var/log/*.log - /var/log/messages filebeat.config.modules: path: ${path.config}/modules.d/*.yml reload.enabled: false setup.template.settings: index.number_of_shards: 3 setup.kibana: host: "192.168.2.207:5601" #output.elasticsearch: //咱们输出到logstash,把这行注释掉 #hosts: ["localhost:9200"] //这行也注释掉 output.logstash: hosts: ["192.168.2.207:5044"]

启用nginx模块
filebeat modules enable nginx
修改nginx模块配置

vim /etc/filebeat/modules.d/nginx.yml
- module: nginx access: enabled: true var.paths: ["/var/log/nginx/access.log*"] error: enabled: true var.paths: ["/var/log/nginx/error.log*"]

启用apache模块
filebeat modules enable apache2
修改apache模块配置

vim /etc/filebeat/modules.d/apache2.yml
- module: apache2 access: enabled: true var.paths: ["/var/log/httpd/access_log*"] error: enabled: true var.paths: ["/var/log/httpd/error_log*"]

启动filebeat

systemctl start filebeat systemctl enable filebeat systemctl status filebeat

6、windows节点服务器安装配置winlogbeat

解压winlogbeat-6.2.4-windows-x86_64.zip,以管理员方式运行PowerShell,进入到解压后的目录,执行.\install-service-winlogbeat.ps1来安装服务。若是报错提示在此系统上禁止脚本运行,那就执行PowerShell.exe -ExecutionPolicy UnRestricted -File .\install-service-winlogbeat.ps1,即可安装成功。
CentOS 7安装部署ELK 6.2.4
修改配置文件 :winlogbeat.yml

winlogbeat.event_logs: - name: Application ignore_older: 72h - name: Security - name: System setup.template.settings: index.number_of_shards: 3 setup.kibana: host: "192.168.2.207:5601" #output.elasticsearch: //咱们输出到logstash,因此这行注释掉 #hosts: ["localhost:9200"] //这行也注释掉 output.logstash: hosts: ["192.168.2.207:5044"] logging.to_files: true logging.files: path: D:/winlogbeat/winlogbeat/Logs logging.level: info

使用如下命令检查配置文件的正确性,出现Config OK说明配置文件正确。
.\winlogbeat.exe test config -c .\winlogbeat.yml -e
CentOS 7安装部署ELK 6.2.4
启动winlogbeat服务
打开service(服务),找到winlogbeat,启动它。
CentOS 7安装部署ELK 6.2.4
命令行启动方式,执行下面命令
Start-Service winlogbeat

7、建立索引模式

浏览器访问http://192.168.2.207,输入以前经过htpasswd认证的用户名和密码登录kibana。
CentOS 7安装部署ELK 6.2.4
点击Management,而后点击Index Patterns,再点击Create index pattern
CentOS 7安装部署ELK 6.2.4
输入filebeat-,而后点击Next step
CentOS 7安装部署ELK 6.2.4
选择@timestamp,而后点击Create index pattern
CentOS 7安装部署ELK 6.2.4
按照此方法再建立一个名为winlogbeat-
的索引模式。
CentOS 7安装部署ELK 6.2.4
建立好后,点击Discover,就能够看到以下图页面的日志内容了。
CentOS 7安装部署ELK 6.2.4

相关文章
相关标签/搜索