1,下载centos 基础镜像(centos.tar.gz)并上传至master主机/root/下面

制作Apache镜像
2,编写httpd的Dockerfile文件

[root@master ~]# docker load -i centos.tar.gz
[root@master ~]# mkdir bb
[root@master ~]# cd bb/
[root@master bb]# cp /etc/yum.repos.d/CentOS-Base.repo ./
[root@master bb]# echo "hello world" > index.html
[root@master bb]# vim Dockerfile
FROM centos:latest
RUN rm -rf /etc/yum.repos.d/*
ADD CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo
RUN yum -y install httpd
ENV LANG=C
EXPOSE 80 443
WORKDIR /var/www/html
ADD index.html /var/www/html/index.html
CMD ["/usr/sbin/httpd","-DFOREGROUND"]

3,build 创建新镜像;-t 指定新镜像名字和标签;. 指定Dockerfile文件所在的目录

[root@master bb]# docker build -t myos:httpd .

4,验证结果:

[root@master bb]# docker images
[root@master bb]# docker run -itd myos:httpd #后台启动容器,因为是一个服务
[root@master bb]# docker ps #查看正在使用的容器
[root@master bb]# docker inspect 800b21aa9736 #查看容器的详细信息
[root@master bb]# curl http://172.17.0.2
hello world

5,上传镜像到harbor主机

[root@master bb]# docker tag myos:httpd 192.168.1.100:80/library/myos:httpd
[root@master bb]# docker push 192.168.1.100:80/library/myos:httpd


制作filebeat镜像

6,随便找一台机器,安装filebeat的软件包,生成并修改filebeat配置文件。(此步骤为了起容器时有相应的配置文件)

[root@es-0002 ~]# yum -y install filebeat-1.2.3-x86_64.rpm
修改filebeat的配置文件
[root@es-0002 ~]# vim /etc/filebeat/filebeat.yml
登录harbor查看,可以看到此镜像
15 - /var/weblog/access_log #指定filebeat要读取的日志文件
72 document_type: apache_log #修改日志的标签,方便用户区分日志的来源;不同服务的日志,修改
成不同的标签
183 # elasticsearch: #注释掉elasticsearch
188 # hosts: ["localhost:9200"] #注释掉hosts
278 logstash: #取消logstash的注释
280 hosts: ["192.168.1.75:5044"] #指定logstash主机IP地址
[root@es-0002 ~]# systemctl restart filebeat
[root@es-0002 ~]# ps -C filebeat
PID TTY TIME CMD
1321 ? 00:00:00 filebeat


7,master主机制作filebeat镜像并上传至harbor主机

[root@master bb]# mkdir /root/cc
[root@master bb]# cd /root/cc
[root@master bb]# cp /etc/yum.repos.d/CentOS-Base.repo ./
拷贝filebeat配置文件到master主机
[root@es-0002 ~]# scp /etc/filebeat/filebeat.yml /root/filebeat-1.2.3-x86_64.rpm 192.168.1.21:/root/cc #将上一步获得的filebeat配置文件传给master
[root@master cc]# vim Dockerfile
FROM centos:latest
RUN rm -rf /etc/yum.repos.d/*
ADD CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo
ADD filebeat-1.2.3-x86_64.rpm ./
RUN yum -y install ./filebeat-1.2.3-x86_64.rpm
ADD filebeat.yml /etc/filebeat/filebeat.yml
CMD ["/usr/bin/filebeat", "-c", "/etc/filebeat/filebeat.yml"]

[root@master bb]# docker build -t myos:filebeat .
[root@master bb]# docker tag myos:filebeat 192.168.1.100:80/library/myos:filebeat
[root@master bb]# docker push 192.168.1.100:80/library/myos:filebeat
[root@master bb]# docker run -itd myos:filebeat #后台启动容器,因为是一个服务
[root@master bb]# docker ps #查看正在使用的容器
[root@master bb]# docker inspect d2961ac12573 #查看容器的详细信息

8,登录harbor查看,可以看到这两个镜像。

制作Apache和filebeat镜像,并上传至Harbor仓库_k8s