Telegraf+InfluxDB+Grafana【上】Centos篇

influxdb

添加源

cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
EOF

安装
yum -y install influxdb

设置用户名密码
influx
CREATE USER "root" WITH PASSWORD 'root' WITH ALL PRIVILEGES

注:先设置用户名密码再改如下配置,因为涉及auth-enabled = true

vim /etc/influxdb/influxdb.conf
[http]下
enabled = true
bind-address = ":8086"
auth-enabled = true
[Http]模块上方加入
[admin]
# 是否启用该模块,默认值 : false
enabled = true
# 绑定地址,默认值 :":8083"
bind-address = ":8083"

启动
systemctl start influxdb

接口进行访问
curl -G http://localhost:8086/query --data-urlencode "q=show databases"

开机启动
systemctl enable influxdb
卸载
yum -y remove influxdb

备份出配置文件
mkdir /opt/influxdb-docker/
cp /etc/influxdb/influxdb.conf /opt/influxdb-docker/
用于下篇docker

telegraf


前面安装influxdb时已经添加了源
yum -y install telegraf

修改配置
vim /etc/telegraf/telegraf.conf

[[outputs.influxdb]]模块下
解锁urls = ["http://127.0.0.1:8086"]
解锁database = "telegraf"
解锁timeout = "5s"
若influxdb设置了auth-enabled = true,这里需要设置用户名密码
username = "root"
password = "root"
配置官方文档见:https://docs.influxdata.com/telegraf

设置后auth-enabled=true后在linux操作influx需要用户名密码,命令为auth
influx
auth
show databases

先运行influxdb
然后启动telegraf
systemctl start telegraf
启用
systemctl enable telegraf

查看运行状态
systemctl status telegraf

卸载
yum -y remove telegraf

备份出配置文件
mkdir /opt/telegraf-docker/
cp /etc/telegraf/telegraf.conf /opt/telegraf-docker/
用于下篇docker

grafana

添加源
见https://grafana.com/docs/installation/rpm/
cat <<EOF | sudo tee /etc/yum.repos.d/grafana.repo
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
EOF

yum -y install grafana


启动
systemctl start grafana-server
启用
systemctl enable grafana-server

卸载
yum -y remove grafana-server

进入网站 用户名密码都是admin


第一步创建datasource
Name为telegraf与上面telegraf配置的数据库名一致
influxdb开启了auth-enabled = true
需要勾选Basic Auth 数据库用户名密码都是root

见图:

后面的dashboard随意了,记得在sql语句中选择表和列,部分列可以按*显示,否则不会展示数据。

猜你喜欢

转载自www.cnblogs.com/wintersoft/p/10957256.html
今日推荐