自定義建立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
新增賬號
登入賬号
docker login -u username
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