自定义创建Docker镜像,上传至Docker Hub并使用
自定义创建Docker镜像
选择基础镜像系统
首先第一步是需要拉取
centos:7
作为基础镜像系统,以后所有操作均在此基础之上构建。
docker pull centos:7
确定镜像的功能
确定自己创建镜像应该提供一个怎样的功能,或者说该镜像做一件什么样的事情。
最近刚好需要对Linux服务器系统资源做一定监控,恰好发现
Ganglia
可以实现,于是决定将其封装成docker镜像使用。
基于选择的基础镜像创建容器
docker run -itd --name ganglia --privileged=true centos:7
Ganglia概述
Ganglia是一个开源大规模集群监控软件,用于测量数以千计的节点,适合分布式集群或并行集群监控。主要是用来监控系统性能,如:cpu 、mem、硬盘利用率,I/O负载、网络流量情况等
官网地址:http://ganglia.info/
核心组成
Ganglia由gmond、gmetad和ganglia-web三部分组成。
gmond(Ganglia Monitoring Daemon)是一种轻量级服务,安装在每台需要收集指标数据的节点主机上。使gmond,可以很容易收集很多系统指标数据,如CPU、内存、磁盘、网络和活跃进程的数据等。
gmetad(Ganglia Meta Daemon)定期检查gmonds,从那里拉取数据,整合所有信息,并将其以RRD格式存储至磁盘的服务。
gweb(Ganglia Web)Ganglia可视化工具,安装在有gmetad运行的机器上,以便读取RRD文件。 gweb是一种利用浏览器显示gmetad所存储数据的PHP前端。在Web界面中以图表方式展现集群的运行状态下收集的多种不同指标数据。
开始构建
进入容器内部进行构建操作
docker exec -it ganglia /bin/bash
安装httpd服务与php
yum -y install httpd php
安装其他依赖
yum -y install rrdtool perl-rrdtool rrdtool-devel
yum -y install apr-devel
安装ganglia
yum -y install ganglia-gmetad
yum -y install ganglia-web
yum install -y ganglia-gmond
配置
修改配置文件 vim /etc/httpd/conf.d/ganglia.conf
Alias /ganglia /usr/share/ganglia
<Location /ganglia>
Order deny,allow
Deny from all
# Allow from 127.0.0.1
# Allow from ::1
# Allow from .example.com
</Location>
Alias /ganglia /usr/share/ganglia
<Location /ganglia>
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
# Allow from ::1
Allow from all
# Allow from .example.com
Require all granted
</Location>
修改配置文件vim /etc/ganglia/gmetad.conf
data_source "my cluster" localhost(本机的ip地址)
修改配置文件vim /etc/ganglia/gmond.conf
cluster {
name = "unspecified"
owner = "unspecified"
latlong = "unspecified"
url = "unspecified"
}
cluster {
name = "my_cluster"
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
}
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=127.0.0.1
port = 8649
ttl = 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
}
udp_recv_channel {
# mcast_join = 239.2.11.71
port = 8649
bind = 127.0.0.1
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
}
修改配置文件vim /etc/selinux/config
SELINUX=disabled
启动相关服务
启动服务
systemctl httpd start
systemctl gmetad start
systemctl gmond start
设置开机启动
systemctl enable start
systemctl enable start
systemctl enable start
将容器提交为镜像
基于基础容器之上进行操作完成后,将其提交为新的镜像
docker commit ganglia ganglia:latest
使用创建的镜像创建容器
docker run -itd --name ganglia -p 8080:80 -p 8081:8649 --privileged=true ganglia:latest
访问:IP:8080/ganglia
Docker Hub
注册账号
访问: https://hub.docker.com/
注册账号
登录账号
命令行登录账号
docker login -u username
Tag镜像
新建一个tag,名字必须跟注册账号一样
docker tag test:v1 username/test:v1
推送
docker push username/test:v1
拉取
docker pull username/test:v1
部署
docker run -itd 8080:80 username/test:v1
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/136958.html