docker image 实践之容器化 ganglia

基础镜像

单播模式下检测效果

docker image 实践之容器化 ganglia

使用centos:6作为基础镜像,因为centos:7没有使用systemd作为系统服务管理工具.这在后面启动ganglia进程的时候会带来很多麻烦,但是有解决方案(由dockone社区微信群大神给出的解决方案,个人并未尝试):

  • 使用supervisor来统一管理进行

  • runt管理进程

Dockerfile

FROM centos:6
MAINTAINER wlu [email protected]

RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

RUN yum install -y php-common php-cli php-gb php

# install ganglia server
RUN yum install -y rrdtool rrdtool-devel ganglia-web ganglia-gmetad \
    ganglia-gmond ganglia-gmond-python httpd apr-devel zlib-devel \
    libconfuse-devel expat-devel pcre-devel

# install ganglia client
#RUN yum install -y ganglia-gmond

RUN mkdir -p /var/lib/ganglia && \
    chown nobody:nobody /var/lib/ganglia && \
    chmod 777 /var/lib/ganglia

ADD supervisord.conf /etc/supervisord.conf
RUN yum install -y python-setuptools && \
    easy_install supervisor && \
    yum clean all

RUN yum install -y vim && \
    ln -f -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]

注意:这里可以把多个指令合并以减少镜像层数.

ganglia的配置

原理图:

docker image 实践之容器化 ganglia

ganglia可以监控整个集群的信息.这里有两个概念:

  • ganglia 中央机器...对应gmetad进程.对应配置信息在/etc/ganglia/gmetad.conf(centos6下)

  • ganglia client...对应gmond进程.对应配置信息在/etc/ganglia/gmond.conf(centos6下)
    有点类似于master和slave的关系.

在集群中需要有一个中央机器来统一接收其它机器上收集到的监控信息(也可以包括中央机器自身),在这个中央机器上运行gmetad进程.

在其它机器上运行gmond进程,用来收集机器上的监控信息.

ganglia的两种模式

单播模式

这种模式下client上的数据会发送给中央机器,下面看下client(即gmond)的配置(只摘取部分需要的配置项):

gmond.conf

......
cluster {
  name = "unspecified"
  owner = "unspecified"
  latlong = "unspecified"
  url = "unspecified"
}
......
udp_send_channel {
  #bind_hostname = yes # Highly recommended, soon to be default.
                       # This option tells gmond to use a source address
                       # that resolves to the machine's hostname.  Without
                       # this, the metrics may appear to come from any
                       # interface and the DNS names associated with
                       # those IPs will be used to create the RRDs.
  mcast_join = 239.2.11.71
  port = 8649
  ttl = 1
}
......
/* You can specify as many udp_recv_channels as you like as well. */
udp_recv_channel {
  mcast_join = 239.2.11.71
  port = 8649
  bind = 239.2.11.71
  retry_bind = true
  # Size of the UDP buffer. If you are handling lots of metrics you really
  # should bump it up to e.g. 10MB or even higher.
  # buffer = 10485760
}
......
  1. cluster name,这个必须指定并且相同集群使用相同的name

  2. udp_send_channel,因为单播模式下各个client把数据以udp协议发给中央机器,所以需要配置中央机器的ip,配置后的结果:

udp_send_channel {
  #bind_hostname = yes # Highly recommended, soon to be default.
                       # This option tells gmond to use a source address
                       # that resolves to the machine's hostname.  Without
                       # this, the metrics may appear to come from any
                       # interface and the DNS names associated with
                       # those IPs will be used to create the RRDs.
  #mcast_join = 239.2.11.71
  host = host_ip
  port = 8649
  ttl = 1
}

这条需要注释:#mcast_join = 239.2.11.71,ganglia默认是多播.

  1. 注释掉多播的配置:

udp_recv_channel {
  #mcast_join = 239.2.11.71
  port = 8649
  #bind = 239.2.11.71
  retry_bind = true
  # Size of the UDP buffer. If you are handling lots of metrics you really
  # should bump it up to e.g. 10MB or even higher.
  # buffer = 10485760
}

note:这里注释掉多播和绑定的ip.我还不是太明白,详情参考这里

配置好后就可以通过service gmond start来启动client上的gmond进程了.

gmetad.conf

data_source "my cluster" localhost

改为

data_source "your cluster name" host_ip #host_ip指中央机器的配置

配置好后就可以通过service gmetad start来启动中央机器上的gmetad进程了.

多播模式

docker image 实践之容器化 ganglia

多播的特点:

  • 集群中的每个client把自己的数据发送给集群中的其它client

  • 中央机器指定一个client作为数据源.

个人觉得这种方式很浪费,因为单播模式下数据传输次数要少

参考连接

reference 1
reference 2
本项目对应的GitHub地址
httpd访问控制问题

ps

南京docker meetup已经于2015年3月份成立,将于2016年开始举办线下技术分享.诚挚欢迎各位对docker及容器技术感兴趣的同学加入Docker Nanjing meetup

相关推荐