目录
-
一、Telegraf
-
1、Telegraf下载及安装
telegraf版本:Telegraf v1.13
RedHat & CentOS,使用yum安装
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
通过以下命令安装并启动telegraf(版本小于7的系统)
sudo yum install telegraf
sudo service telegraf start
或者使用systemd命令(CentOS 7 +,RHEL 7+):
sudo yum install telegraf
sudo systemctl start telegraf
-
2、修改配置文件
我们需要配置telegraf需要写入的数据源,我们选择本机的influxdb作为数据源写入,配置如下:输入命令 vim /etc/telegraf/telegraf.conf
[[outputs.influxdb]]
urls = ["http://localhost:18086"] # required
database = "telegraf" # required
retention_policy = ""
precision = "s"
timeout = "5s"
username = "telegraf"
password = " telegraf "
然后保存修改,输入命令 service telegraf restart ,重启telegraf。
-
3、连接influxdb并进行数据采集
如果想利用telegraf采集数据并保存到influxdb中,必须在influxdb中创建对应的用户和数据库。
[root@test ~]# influx -host 'localhost' -port '18086'
Connected to http://localhost:18086 version 1.7.10
InfluxDB shell version: 1.7.10
>create user "telegraf" with password 'telegraf'
>create database telegraf
> show databases
name: databases
name
----
_internal
mydb
telegraf
>
> show users
user admin
---- -----
telegraf false
>
> exit
创建成功后,重启influxdb