赞
踩
logstash能够很好的采集数据,而Kibana 作为一款可视化产品,搭载了一批经典功能:柱状图、线状图、饼,将两者结合可以很好展现数据可视化
图、旭日图,等等
server13:172.25.42.13 (已经部署ELK集群服务)
server14:172.25.42.14 (已经部署ELK集群服务)
server15:172.25.42.15 (已经部署ELK集群服务
server16:172.25.42.16 (已经下载了logstash,即将部署kibana)
ES集群服务参考往期博客:https://blog.csdn.net/weixin_48819467/article/details/119649102
logstash参考往期博客:https://blog.csdn.net/weixin_48819467/article/details/119697415
server13
开启es集群、方便查看可以开启监控土星
[root@server13 ~] systemctl start elasticsearch 开es
[root@server13 _site] cd /root/elasticsearch-head-master/_site 进入head文件
[root@server13 _site] cnpm run start & 开启head插件,便于图像查看
登陆监控
http://172.25.42.13:9100/ (未注册密码使用)
http://172.25.0.13:9100/?auth_user=elastic&auth_password=westos (注册密码后使用这个个登陆)
server14、15
开启es集群
systemctl start elasticsearch
1、下载
下载地址:https://elasticsearch.cn/download/
和java和logstash的版本保持一致,便于后期配合
[root@server16 mnt] rpm -ivh kibana-7.6.1-x86_64.rpm
2、修改配置文件
vim /etc/kibana/kibana.yml
3、启动服务
[root@server16 mnt] systemctl enable kibana
[root@server16 mnt] systemctl start kibana
[root@server16 mnt] netstat -antlp|grep :5601
端口已经开启
4、访问界面进行安装
访问server16的5601端口
http://172.25.42.16:5601
按照如下步骤即可
完成可kibana的安装
选择设置,再选者索引模式
创建索引模式
创建索引
es服务和kibana索引内容是同步的
在es集群里面的服务
这里以apachelog为例
创建后的界面如下,索引创建完毕
选择图像可视化展示我们的输出
1、选择指标统计
这里的有多种可视化工具,选择指标
2、开启动态统计
(动态测试的grok.conf文件及过程在附录提供了)
目前只能显示以前的数据,并没有进行动态联系,将logstash中统计apache日志的API文件运用,进行动态统计。(apachelog-*统计和server16的grock.conf文件统计内容相对应)
[root@server16 logstash] cd conf.d/
[root@server16 conf.d] ls
apache.conf es.conf grok.conf syslog.conf test.conf
[root@server16 conf.d] cat grok.conf
input {
file {
path => "/var/log/httpd/access_log"
start_position => "beginning"
}
}
filter {
grok {
match => { "message" => "%{HTTPD_COMBINEDLOG}" }
}
}
output {
stdout {}
elasticsearch {
hosts => ["172.25.42.13:9200"]
index => "apachelog-%{+yyyy.MM.dd}"
user => "elastic"
password => "westos"
}
}
[root@server16 conf.d] /usr/share/logstash/bin/logstash -f grok.conf
3、其他服务器对监控主机(server16)进行访问测试
手动刷新后查看到访问结果(可以设置刷新时间,变成自动刷新)
当我们使用不同的主机进行访问测试,想查看不同ip的访问量时可以使用柱状图
分别使用server13、server14、server15多次访问server16的发布目录
选择条形图进行查看
选择关键词
选择访问量
执行
查看访问量的情况
然后选择内置监控,打开monitor,会自动对es集群进行监控
可以看到如下的界面,选择节点3
进入到如下界面、进入设置模式它提醒我们进行证书认证
1、进行xpack认证
cd /usr/share/elasticsearch/
bin/elasticsearch-certutil ca 图1
bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 图2
cp elastic-certificates.p12 elastic-stack-ca.p12 /etc/elasticsearch
cd /etc/elasticsearch
chown elasticsearch elastic-certificates.p12 elastic-stack-ca.p12
图1
图2
2、更改配置文件
vim /etc/elasticsearch/elasticsearch.yml
加入下面的认证
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /etc/elasticsearch/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /etc/elasticsearch/elastic-certificates.p12
/
3、重启elasticsearch,同步证书
[root@server13 elasticsearch] systemctl restart elasticsearch.service
[root@server13 elasticsearch] scp elastic-certificates.p12 root@172.25.42.14:/etc/elasticsearch
[root@server13 elasticsearch] scp elastic-certificates.p12 root@172.25.42.15:/etc/elasticsearch
server14,15
修改文件权限
cd /etc/elasticsearch
chown elasticsearch elastic-certificates.p12 elastic-stack-ca.p12
更改文件配置和server13一样
vim /etc/elasticsearch/elasticsearch.yml
加入下面的认证
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /etc/elasticsearch/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /etc/elasticsearch/elastic-certificates.p12
/
重启节点
systemctl restart elasticsearch.service
4、server13给予用户登陆密码
[root@server13 bin] cd /usr/share/elasticsearch/bin
[root@server13 bin] ./elasticsearch-setup-passwords interactive
5、设置kibana连接ES的用户密码:
server16kibana主机
[root@server16 conf.d] vim /etc/kibana/kibana.yml
[root@server16 conf.d] elasticsearch.username: "kibana"
[root@server16 conf.d] elasticsearch.password: "westos"
[root@server16 conf.d] systemctl restart kabina 重启
6、登陆kibana
再次登陆时输入账户elastic和密码westos即可进入界面
再次选择内部收集数据
此时不会有提醒xpack认证提醒
sever16
现在执行文件时要添加账户和密码才能执行
[root@server16 conf.d] cd /etc/logstash/conf.d
[root@server16 conf.d] cat grok.conf
input {
file {
path => "/var/log/httpd/access_log"
start_position => "beginning"
}
}
filter {
grok {
match => { "message" => "%{HTTPD_COMBINEDLOG}" }
}
}
output {
stdout {}
elasticsearch {
hosts => ["172.25.42.13:9200"]
index => "apachelog-%{+yyyy.MM.dd}"
user => "elastic" 给予账户
password => "westos" 给予密码
}
}
再次执行文件即可正常动态传输数据
[root@server16 conf.d] /usr/share/logstash/bin/logstash -f grok.conf
此时会存在登陆不上elastic网页的情况
server13
1、修改配置文件
[root@server13 elasticsearch] cd /etc/elasticsearch/
[root@server13 elasticsearch] vim elasticsearch.yml 图1
[root@server13 elasticsearch] systemctl restart elasticsearch.service
图1、添加文件
2、添加用户和密码认证即可访问
http://172.25.42.13:9100/?auth_user=elastic&auth_password=westos
当我们进入监控的设置模式后会推荐我们使用Metricbeat监控,这种监控的性能更好
1、安装启用
获取Metricbeat安装包保持kibana一样的版本
[root@server13 mnt] rpm -ivh metricbeat-7.6.1-x86_64.rpm
[root@server13 mnt] metricbeat modules enable elasticsearch-xpack 图1、开启此模块
[root@server13 mnt] cd /etc/metricbeat/modules.d
[root@server13 modules.d] vim elasticsearch-xpack.yml 图2、metrics修改el-xpack文件的
[root@server13 metricbeat] cd /etc/metricbeat
[root@server13 metricbeat] vim metricbeat.yml
[root@server13 metricbeat] systemctl enable --now metricbeat.service
图1
图2、修改用户和密码
3、设置metricbeat的配置文件,给予用户和权限
输出的地点写server13,因为kibana也是从ES集群中获取的信息
server14、15ES集群进行和server13同样的操作
4、图像界面设置
这里建议监控的主机能另外设置一台,使得处理数据的集群ES和监控的主机能分开。由于条件限制,这里还是选择ES的主机进行监控
点击下一步即可,等待自动完成检测
server14、15进行相同操作即可,kibana即可自动检测更新
为方便实验,在下面给了apache日志生成,传输到es集群的过程
输出grok过滤——统计appache日志
1、下载安装apache
server16
[root@server16 conf.d] yum install -y httpd
[root@server16 conf.d] systemctl start httpd
[root@server16 conf.d] cd /var/www/html/
[root@server16 html] echo hhh > index.html
[root@server16 conf.d] chmod 644 /var/log/httpd/access_log
[root@server16 conf.d] ll /var/log/httpd/access_log
-rw-r--r--. 1 root root 1143 Aug 14 22:21 /var/log/httpd/access_log
server13
多次访问server16的地址,生成日志
[root@server13 elasticsearch] curl 172.25.42.16
hhh
[root@server13 elasticsearch] curl 172.25.42.16
hhh
[root@server13 elasticsearch] curl 172.25.42.16
hhh
[root@server13 elasticsearch] curl 172.25.42.16
hhh
2、生成、应用文件
[root@server16 html] cd /etc/logstash/conf.d/
[root@server16 conf.d] ls
apache.conf es.conf grok.conf syslog.conf test.conf
[root@server16 conf.d] cat apache.conf
/
input {
file {
path => "/var/log/httpd/access_log"
start_position => "beginning"
}
}
filter {
grok {
match => { "message" => "%{HTTPD_COMBINEDLOG}" }
}
}
output {
stdout {}
elasticsearch {
hosts => ["172.25.42.13:9200"]
index => "apachelog1-%{+yyyy.MM.dd}"
}
}
/
结果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。