标题1、ELK的作用和特点
1)ELK的作用
集中化管理日志
对日志配置群集避免单节点故障,日志丢失
2)ELK特点
开源
不支持日志分析
支持集中化管理
标题2、ELK组成
1)elasticsearch
开源的日志搜索和存储引擎
采用分布式设计
自动配置日志群集
支持零配置负载均衡功能
2)logstash
负责日志采集
对客户端日志进行采集、格式化、输出到elasticsearch存储
安装在客户端上
3)kibana
支持图形化界面查看日志
兼容强
安装在服务器端
标题3、logstash组成
1)shipper
日志采集
实时监控日志变化
将日志格式化上传到elasticsearch
2)indexer
日志存储
创建索引
3)broker
接收多个shipper采集的日志
4)search and stroage
允许用户搜索和存储日志信息
5)web interface
支持kibana访问平台中的数据
支持WEB页面查看日志
配置ELK
解压node
[root@centos01 ~]# tar zxvf /mnt/node-v8.2.1.tar.gz -C /usr/src/
指定安装位置
[root@centos01 ~]# mv /usr/src/node-v8.2.1/ /usr/local/node
编译安装
【时间略长,耐心等待】
[root@centos01 ~]# ./configure && make && make install
安装 Elasticsearch
[root@centos01 ~]# rpm -ivh /mnt/elasticsearch-5.5.0.rpm
修改配置文件
[root@centos01 ~]# vim /etc/elasticsearch/elasticsearch.yml
启动服务设置开机自动启动
[root@centos01 ~]# systemctl daemon-reload
[root@centos01 ~]# systemctl start elasticsearch
[root@centos01 ~]# systemctl enable elasticsearch
修改hosts文件
[root@centos01 ~]# vim /etc/hosts
安装依赖node
[root@centos01 ~]# tar zxvf /mnt/node-v8.2.1.tar.gz -C/usr/src/
指定安装位置
[root@centos01 ~]# mv /usr/src/node-v8.2.1/ /usr/local/node
编译安装
[root@centos02 node]# ./configure && make && make install
安装phantomjs
[root@centos01 bin]# cp phantomjs /usr/local/bin/
[root@centos01 bin]# chmod +x /usr/local/bin/phantomjs
移动elasticsearch-head
[root@centos01 ~]# tar zxvf /mnt/elasticsearch-head.tar.gz -C /usr/src/
[root@centos01 ~]# mv /usr/src/elasticsearch-head/ /usr/local/
[root@centos01 ~]# cd /usr/local/elasticsearch-head/
[root@centos01 elasticsearch-head]# npm install
修改elasticsearch跨域访问
[root@centos01 ~]# vim /etc/elasticsearch/elasticsearch.yml
[root@centos01 ~]# /etc/init.d/elasticsearch restart
修改修改elasticsearch-head配置文件监听9100端口
[root@centos01 ~]# vim /usr/local/elasticsearch-head/Gruntfile.js
启动服务
[root@centos01 ~]# cd /usr/local/elasticsearch-head/
[root@centos01 elasticsearch-head]# npm run start&
监听9100端口
[root@centos01 ~]# netstat -anptu | grep 9100
访问
安装http
[root@centos03 ~]# yum -y install httpd
[root@centos03 ~]# echo "www.benet.com" > /var/www/html/index.html
[root@centos03 ~]# systemctl start httpd
[root@centos03 ~]# systemctl enable httpd
安装logstash
[root@centos03 ~]# rpm -ivh logstash-5.5.1.rpm
优化命令
[root@centos03 ~]# ln -s /usr/share/logstash/bin/logstash /usr/local/bin/
启动服务设置开机自动启动
[root@centos03 ~]# systemctl start logstash
[root@centos03 ~]# systemctl enable logstas
插入测试数据
[root@centos03 ~]# logstash -e 'input { stdin{}} output { stdout{}}'
提交数据
[root@centos03 ~]# logstash -e 'input { stdin{}} output { stdout{ codec=>rubydebug}}'
[root@centos03 ~]# logstash -e ‘input { stdin{}} output { elasticsearch{hosts => [“192.168.100.10:9200”]}}’
设置允许日志读取
[root@centos03 ~]# chmod o+r /var/log/httpd/access_log
创建采集日志文件
[root@centos03 ~]# touch /etc/logstash/conf.d/apache.conf
[root@centos03 ~]# chmod +x /etc/logstash/conf.d/apache.conf
[root@centos03 ~]# vim /etc/logstash/conf.d/apache.conf
检查日志采集文件是否有问题
[root@centos03 ~]# logstash -f /etc/logstash/conf.d/apache.conf
重新启动logstash
[root@centos03 ~]# systemctl restart logstash.service
安装
[root@centos01 ~]# rpm -ivh /mnt/kibana-5.5.1-x86_64.rpm
修改主配置文件
[root@centos01 ~]# vim /etc/kibana/kibana.yml
启动服务
[root@centos01 ~]# systemctl start kibana
[root@centos01 ~]# systemctl enable kibana
访问