当前位置: 首页 > news >正文

dockerfile构建haproxy

1. 结构目录

[root@localhost ~]# tree haproxy/
haproxy/
├── dockerfile
└── files├── haproxy-2.5.0.tar.gz├── haproxy.cfg├── install.sh└── start.sh1 directory, 5 files
[root@localhost ~]# 
[root@localhost ~]# cd haproxy/
[root@localhost haproxy]# ls
dockerfile  files
[root@localhost haproxy]# cat dockerfile 
FROM centosLABEL MAINTAINER='pengyudong 1@2.com@qq.com'
ENV version 2.5.0
ADD files/haproxy-${version}.tar.gz /usr/src
ADD files/haproxy.cfg /etc/haproxy/
ADD files/install.sh /tmp/
ADD files/start.sh /usr/local/
RUN ["/bin/bash","-c","/tmp/install.sh"]
EXPOSE 80 8189WORKDIR /usr/local/haproxyCMD ["/usr/local/start.sh"]
[root@localhost haproxy]# [root@localhost haproxy]# cd files/
[root@localhost files]# ls
haproxy-2.5.0.tar.gz  haproxy.cfg  install.sh  start.sh
[root@localhost files]# vim start.sh 
[root@localhost files]# cat start.sh 
#!/bin/sh/usr/local/haproxy/sbin/haproxy -f /etc/haproxy/haproxy.cfg/bin/bash[root@localhost files]# cat install.sh 
#!/bin/bash rm -rf /etc/yum.repos.d/* curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-$(awk -F'"' 'NR==2{print $2}' /etc/os-release).repo yum -y install make gcc gcc-c++ pcre-devel bzip2-devel openssl-devel systemd-devel useradd -r -M -s /sbin/nologin haproxy cd /usr/src/haproxy-${version} cd /usr/src/haproxy-${version} && make clean && \
make -j $(nproc) TARGET=linux-glibc USE_OPENSSL=1 USE_PCRE=1 USE_SYSTEMD=1 && \
make install PREFIX=/usr/local/haproxy && \yum -y remove make gcc gcc-c++ && \
rm -rf /usr/src/haproxy-*[root@localhost files]# cat haproxy.cfg 
#--------------全局配置----------------
globallog 127.0.0.1 local0  info#log loghost local0 infomaxconn 20480
#chroot /usr/local/haproxypidfile /var/run/haproxy.pid#maxconn 4000user haproxygroup haproxydaemon
#---------------------------------------------------------------------
#common defaults that all the 'listen' and 'backend' sections will
#use if not designated in their block
#---------------------------------------------------------------------
defaultsmode httplog globaloption dontlognulloption httpcloseoption httplog#option forwardforoption redispatchbalance roundrobintimeout connect 10stimeout client 10stimeout server 10stimeout check 10smaxconn 60000retries 3
#--------------统计页面配置------------------
listen admin_statsbind 0.0.0.0:8189stats enablemode httplog globalstats uri /haproxy_statsstats realm Haproxy\ Statisticsstats auth admin:admin#stats hide-versionstats admin if TRUEstats refresh 30s
#---------------web设置-----------------------
listen webclusterbind 0.0.0.0:80mode http#option httpchk GET /index.htmllog globalmaxconn 3000balance roundrobincookie SESSION_COOKIE insert indirect nocacheserver web01 172.17.0.3:80 check inter 2000 fall 5server web02 172.17.0.4:80 check inter 2000 fall 5[root@localhost files]#

2. 构建镜像

[root@localhost ~]# docker build -t pengyudong/haproxy:v1.0 haproxy/
root@localhost ~]# docker images
pengyudong/haproxy   v1.0      8819e319cf32   19 minutes ago   418MB
[root@localhost ~]# 

3. 创建容器

[root@localhost ~]# docker run -itd --name haproxy -p 8080:80 haproxy:v1.0
[root@localhost ~]# docker exec -it haproxy /bin/bash
[root@ce02ae7f027e haproxy]# ss -antl
State       Recv-Q      Send-Q           Local Address:Port            Peer Address:Port      Process      
LISTEN      0           128                    0.0.0.0:80                   0.0.0.0:*                      
LISTEN      0           128                    0.0.0.0:8189                 0.0.0.0:*                      
[root@ce02ae7f027e haproxy]# 
[root@localhost ~]# docker run -itd --name httpd pengyudong/httpd
462bd9babdcdac7f2abbb6da551858466659602bb3031129bb5b5de6e71853eb
[root@localhost ~]#  docker run -itd --name nginx nginx
0dffef28f17692db84e93c7caece9fbfe303d66b042bc1f40f13e0304c09227f
[root@localhost ~]# docker ps 
CONTAINER ID   IMAGE                     COMMAND                  CREATED          STATUS          PORTS                                             NAMES
0dffef28f176   nginx                     "/docker-entrypoint.…"   8 minutes ago    Up 8 minutes    80/tcp                                            nginx
462bd9babdcd   pengyudong/httpd          "/usr/local/apache/b…"   8 minutes ago    Up 8 minutes    80/tcp                                            httpd
ce02ae7f027e   pengyudong/haproxy:v1.0   "/usr/bin/start.sh"      22 minutes ago   Up 22 minutes   8189/tcp, 0.0.0.0:8080->80/tcp, :::8080->80/tcp   haproxy
[root@localhost ~]# 

在这里插入图片描述
在这里插入图片描述


http://www.mrgr.cn/news/92119.html

相关文章:

  • superset
  • 本地部署AI模型 --- DeepSeek(一)
  • Day9 25/2/22 SAT
  • 玩机日记 13.5 群晖部署AList并配置SSL,安装opkg,使用rclone挂载到本地
  • 记录一次 ALG 的处理过程
  • 数据结构绪论
  • 关于Transparent native-to-ascii conversion
  • Spring Boot3+Vue2极速整合:10分钟搭建DeepSeek AI对话系统
  • Android KMP初探
  • Java 大视界 -- 总结与展望:Java 大数据领域的新征程与无限可能(96)
  • 【大模型系列篇】DeepSeek-R1如何通过强化学习有效提升大型语言模型的推理能力?
  • Spring Boot 日志管理(官网文档解读)
  • VSCode自定义快捷键和添加自定义快捷键按键到状态栏
  • 低功耗设计:(3)架构级优化
  • 被裁20240927 --- WSL-Ubuntu20.04安装cuda、cuDNN、tensorRT
  • RoCEv2 高性能传输协议与 Lossless 无损网络
  • Deepseek快速做PPT
  • 【前端】react大全一本通
  • 第9章:LangChain让大模型结构化输出
  • 计算机网络————(一)HTTP讲解