我在 docker 容器中启动了一个服务器实例,并与 Facette 前端连接,看起来很酷,facette 读取 rrd 数据。
当我想从其他计算机接收数据时,问题就开始了。我尝试在本地将端口从docker暴露给本地机器。
version: '2.1'
services:
collectd:
build: ./containers/collectd
ports:
- 28596:28596
- 8125:8125
volumes:
- ./var/rrd/:/var/lib/collectd/rrd
frontend:
build: ./containers/facette
ports:
- 12003:12003
volumes:
- ./var/rrd:/var/lib/collectd/rrd
- ./var/facette:/var/lib/facette/
服务器的Dockerfile:
FROM alpine:latest
ENV ARCH=x86
RUN apk --update add perl-dev python3-dev wget alpine-sdk linux-headers rsyslog rrdtool rrdtool-dev rrdtool-utils
# Get and untar sources files
RUN wget https://collectd.org/files/collectd-5.7.1.tar.bz2
RUN tar jxvf collectd-5.7.1.tar.bz2 && rm collectd-5.7.1.tar.bz2
# Compile and purge source files
RUN cd collectd-5.7.1 && ./configure --with-rrdtool && make all install
RUN cd .. && rm -rf collectd-5.7.1
# Optionnal post installation tasks
RUN ln -s /opt/collectd/sbin/collectd /usr/sbin/collectd
RUN ln -s /opt/collectd/sbin/collectdmon /usr/sbin/collectdmon
RUN rm -rf /var/cache/apk/*
RUN apk del alpine-sdk linux-headers perl-dev python3-dev
#RUN apk add --update collectd rrdtool rsyslog collectd-dns collectd-curl collectd-sensors collectd-ping collectd-utils collectd-nginx collectd-iptables collectd-bind collectd-write_http collectd-rrdtool collectd-network collectd-disk collectd-libs
ADD ./etc/* /etc/
ADD ./entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
服务器的 collectd.conf
Hostname "bakunin-tower"
FQDNLookup true
LoadPlugin syslog
<plugin syslog>
LogLevel info
File "/var/log/collectd.log"
Timestamp true
</plugin>
LoadPlugin cpu
LoadPlugin disk
LoadPlugin interface
LoadPlugin load
LoadPlugin memory
LoadPlugin network
LoadPlugin nfs
LoadPlugin rrdtool
LoadPlugin swap
<plugin network>
Listen "0.0.0.0" "28596"
</plugin>
<plugin rrdtool>
DataDir "/var/lib/collectd/rrd"
</plugin>
#Include "/etc/collectd.d/*.conf"
客户端的 collectd.conf
Hostname "kropotkin"
FQDNLookup true
LoadPlugin syslog
LoadPlugin "logfile"
<Plugin "logfile">
LogLevel "info"
File "/var/log/collectd.log"
Timestamp true
</Plugin>
<plugin syslog>
LogLevel info
</plugin>
LoadPlugin cpu
LoadPlugin disk
LoadPlugin interface
LoadPlugin load
LoadPlugin memory
LoadPlugin network
<Plugin network>
Server "127.0.0.1" "28596"
</Plugin>
在服务器上,我只在 rrd 目录中看到“bakunin-tower”,但我希望 kropotkin 也会出现。怎么回事?我的头快炸了。
谢谢。
答案1
我研究了好几天,都没有找到解决方案。然后我突然想到了一个主意 - 在 Docker 之外尝试相同的配置怎么样?我试过了,它成功了,然后我将 docker-compose.yml 配置更正为:
version: '2.1'
services:
collectd:
build: ./containers/collectd
ports:
- 25826:25826
- 8125:8125
volumes:
- ./var/rrd/:/var/lib/collectd/rrd
network_mode: host
frontend:
build: ./containers/facette
ports:
- 12003:12003
volumes:
- ./var/rrd:/var/lib/collectd/rrd
- ./var/facette:/var/lib/facette/
答案2
我知道有点晚了,但克鲁泡特金的配置文件不应该说
Server "127.0.0.1" "28596"
但
Server "ip-address-of-bakunin" "28596"
。