天天看點

telegraf docker容器啟動報錯:E! [inputs.docker]: Error in plugin: Cannot connect to the Docker daemon at un開啟influxdb開啟telegraf報錯解決

目錄

開啟influxdb

開啟telegraf

報錯

解決

開啟influxdb

// 挂載/root/tick/influxdb下的influxdb.conf代替預設的容器裡面的/etc/influxdb/influxdb.conf
// 把influxdb的資料挂載到主控端,influxdb的資料預設儲存在/var/lib/influxdb,現在把容器的/var/lib/influxdb資料挂載到主控端的/root/data/metric目錄
docker run -p 8086:8086 --name influxdb -v /root/tick/influxdb:/etc/influxdb -v /root/data/metric:/var/lib/influxdb -d docker.io/influxdb:1.7 
           

開啟telegraf

// 使用/root/tick/telegraf/telegraf.conf代替預設的容器自帶的/etc/telegraf/telegraf.conf
// 使用的是host網絡模式,因為influxdb也安裝在這個機器上
docker run --name telegraf --network host -v /root/tick/telegraf:/etc/telegraf -d docker.io/telegraf:1.11
           

報錯

但是telegraf啟動後,檢視日志報錯了:

[[email protected] telegraf]# docker logs -f 3179822e437b
2019-09-09T06:18:59Z I! Starting Telegraf 1.11.5
2019-09-09T06:18:59Z I! Using config file: /etc/telegraf/telegraf.conf
2019-09-09T06:18:59Z I! Loaded inputs: net system cpu disk diskio docker kernel mem
2019-09-09T06:18:59Z I! Loaded aggregators: 
2019-09-09T06:18:59Z I! Loaded processors: 
2019-09-09T06:18:59Z I! Loaded outputs: influxdb
2019-09-09T06:18:59Z I! Tags enabled: host=localhost.localdomain
2019-09-09T06:18:59Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"localhost.localdomain", Flush Interval:10s
2019-09-09T06:19:00Z E! [inputs.docker]: Error in plugin: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
2019-09-09T06:19:00Z E! [inputs.docker]: Error in plugin: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
2019-09-09T06:19:10Z E! [inputs.docker]: Error in plugin: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
           

解決

https://github.com/influxdata/TICK-docker/issues/7

把主控端的/var/run/docker.sock挂載到容器

// 把主控端的/var/run/docker.sock挂載到容器
docker run --network host --name telegraf -v /root/tick/telegraf:/etc/telegraf -v /var/run/docker.sock:/var/run/docker.sock -d docker.io/telegraf:1.11