docker制作 haproxy 镜像

docker制作 haproxy 镜像

一、准备haproxy 安装包

root@z2:/opt/dockerfile/web# mkdir  haproxy
root@z2:/opt/dockerfile/web# cd haproxy/
root@z2:/opt/dockerfile/web/haproxy# wget https://www.haproxy.org/download/2.0/src/haproxy-2.0.5.tar.gz

二、准备haproxy 配置文件

listen stats
 mode http
 bind 0.0.0.0:9999
 stats enable
 log global
 stats uri     /haproxy-status
 stats auth    haadmin:123456

listen  web_port
 bind 0.0.0.0:80
 mode http
 log global
 balance roundrobin
 server web1  192.168.1.101:8888 check inter 3000 fall 2 rise 5
 server web2  192.168.1.102:8888  check inter 3000 fall 2 rise 5

三、编写写dockerfile

FROM linux37-centos-base:7.8.2003  

maintainer zt "25958889@qq.com"

RUN  yum install -y yum install gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl  openssl-devel systemd-devel net-tools vim iotop bc  zip unzip zlib-devel lrzsz tree screen lsof tcpdump wget ntpdate 

ADD  haproxy-2.0.5.tar.gz  /usr/local/src

RUN cd /usr/local/src/haproxy-2.0.5 &&   make  ARCH=x86_64 TARGET=linux-glibc  USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1  USE_SYSTEMD=1  USE_CPU_AFFINITY=1  PREFIX=/usr/local/haproxy  && make install PREFIX=/usr/local/haproxy && cp haproxy  /usr/sbin/ && mkdir /usr/local/haproxy/run

ADD haproxy.cfg /etc/haproxy/ 

ADD run_haproxy.sh /usr/bin
EXPOSE 80 9999
CMD ["/usr/bin/run_haproxy.sh"]

四、准备haproxy 启动脚本

run_haproxy.sh

#!/bin/bash

haproxy -f /etc/haproxy/haproxy.cfg

tail -f /etc/hosts
root@z2:/opt/dockerfile/web/haproxy# chmod +x  run_haproxy.sh 

五、构建镜像

build.sh

#!/bin/bash

docker build -t linux37-centos-haproxy:2.0.5 .

测试

root@z2:~# docker run  -d -p  8888:80 -p 9999:9999  linux37-centos-haproxy:2.0.5
c3076a47f51122c99b52669ca903193587e07c1a92bd19025b567be03adc0aac

root@z2:~# curl 127.0.0.1:8888/app/
linux37 tomcat app2
root@z2:~# curl 127.0.0.1:8888/app/
linux37 tomcat app2

同时状态也可以访问

http://192.168.1.102:9999/haproxy-status

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读