Metricbeat的部署

本文简单介绍Metricbeat的部署,其中重点涉及metricbeat通过https与ES、kibana的通信,以及通过keystore来存储密码,避免在metricbeat的配置文件、module的配置文件中明文暴露关联用户的密码。

【ES、Kibana、Metricbeat的版本是7.9.3】

Metricbeat的部署

下载与ES 、Kibana对应版本的Metricbeat

我们的环境中部署的ES是7.9.3版本。

1.下载
	curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.9.3-linux-x86_64.tar.gz
2.解压
	tar -zxvf metricbeat-7.9.3-linux-x86_64.tar.gz
3.切换目录
	cd metricbeat-7.9.3-linux-x86_64
4.查看metricbeat的版本信息
	./metricbeat version
	metricbeat version 7.9.3 (amd64), libbeat 7.9.3 [7aab6a9659749802201db8020c4f04b74cec2169 built 2020-10-16 09:21:04 +0000 UTC]
5.查看metricbeat的module的相关信息
	./metricbeat modules list
		Enabled:该部分是已启用的modules
		Disabled:该部分是未启用的modules

将metricbeat与ES、Kibana关联

1.切换目录
	cd metricbeat-7.9.3-linux-x86_64/
2.修改metricbeat的配置文件【因为ES配置了xpack,并启用了https访问,因此metricbeat需要指定证书,该证书同kibana中配置的证书是一样的】
{相关的参考链接:https://www.elastic.co/guide/en/beats/metricbeat/7.9/configuration-ssl.html}
	vim metricbeat.yml
		output.elasticsearch:      #关联ES
		  hosts: ["192.168.1.111:9200"]
		  protocol: "https"
		  ssl.certificate_authorities: ["/home/elasticsearch/kibana-7.9.3-linux-x86_64/config/kibana.crt.pem"]
		  ssl.certificate: "/home/elasticsearch/kibana-7.9.3-linux-x86_64/config/ca/ca.crt"
		  ssl.key: "/home/elasticsearch/kibana-7.9.3-linux-x86_64/config/ca/ca.key"
		  ssl.verification_mode: "none"
		  username: "elastic"
		  #password: "123456"
		  password: "${es_pwd}"    #该处配置的是访问ES的用户名密码,但是明文记录有一定的安全隐患,因此我们采用文章开头说的通过keystore来存储密码,通过引用key来输入密码,避免密码的暴露。
		setup.kibana:   #关联kibana,如果kibana与es部署在同一台服务器,并且kibana在localhost上面有监听且没有采用https的方式进行访问的话,就不需要对setup.kibana模块进行任何配置,由于我们开启了对kibana的https的访问,因此需要下面的配置
		  host: "https://192.168.1.111:5601"   
		  ssl.enabled: true
		  ssl.certificate_authorities: ["/home/elasticsearch/kibana-7.9.3-linux-x86_64/config/kibana.crt.pem"]
		  ssl.certificate: "/home/elasticsearch/kibana-7.9.3-linux-x86_64/config/ca/ca.crt"
		  ssl.key: "/home/elasticsearch/kibana-7.9.3-linux-x86_64/config/ca/ca.key"
		  ssl.verification_mode: "none"
		  username: "elastic"
		  #password: "123456"
		  password: "${es_pwd}"   #含义同上

至此metricbeat的配置就此结束。下面我们就介绍以下,如何将密码存储到metricbeat的keystore中,避免在配置文件中明文配置密码,增加安全风险

keystore密钥存储库的部署

参考网址:https://www.elastic.co/guide/en/beats/metricbeat/7.9/keystore.html

○ 创建存储库
	cd metricbeat-7.9.3-linux-x86_64/
	./metricbeat keystore create  
		Created metricbeat keystore
○ 向存储库中添加key【通过在配置文件中配置${es_pwd}就代表对应的密码,es_pwd自定义】
	 ./metricbeat keystore add es_pwd
		Enter value for es_pwd:        #输入你要存储的密码
		Successfully updated the keystore
	 ./metricbeat keystore add mysql_pwd   #我们再添加一个mysql_pwd,为后面监控登录MySQL做准备
		Enter value for mysql_pwd:
		Successfully updated the keystore
○ 查询存储的key有哪些
	 ./metricbeat keystore list
		es_pwd
		mysql_pwd
○ 通过--force参数可以覆盖已经已经存在的key
	 ./metricbeat keystore add es_pwd --force
○ 移除指定的key
	 ./metricbeat keystore remove es_pwd
		successfully removed key: es_pwd

根据需求启用module,比如MySQL

1.查看有哪些modules
 	./metricbeat modules list
2.启用MySQL对应的module
	./metricbeat modules enable mysql
3.在modules.d/目录下,修改启用的对应模块的配置文件。
	cd modules.d/
	vim mysql.yml    #${mysql_pwd}就是我们在keystore中生成的登录mysql的用户名的密码的key
		hosts: ["root:${mysql_pwd}@tcp(192.168.1.111:3556)/"]

Metricbeat附带了很多用于解析、索引和可视化数据的预定义模板,加载这些模板【会在kibana的dashboard中创建仪表盘】

./metricbeat setup -e
...
...
2024-08-30T14:37:48.633+0800    INFO    instance/beat.go:810    Kibana dashboards successfully loaded.
Loaded dashboards

注意观察终端的输出,是否有报错,出现上面的loaded dashboards就说明加载成功了。

启动Metricbeat

nohup /home/elasticsearch/metricbeat-7.9.3-linux-x86_64/metricbeat -e >> /home/elasticsearch/metricbeat-7.9.3-linux-x86_64/logs/run.log 2>&1 &

登录Kibana,观察dashboard

在这里插入图片描述在这里插入图片描述有一些指标没有获取到数据,这不是本文的重点,因此不再说明。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值