[root@master files]# wget http://download.openpkg.org/components/cache/haproxy/haproxy-2.4.0.tar.gz --2021-12-10 23:17:31-- http://download.openpkg.org/components/cache/haproxy/haproxy-2.4.0.tar.gz 正在解析主机 download.openpkg.org (download.openpkg.org)... 148.251.204.41 正在连接 download.openpkg.org (download.openpkg.org)|148.251.204.41|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:3570069 (3.4M) [application/x-gzip] 正在保存至: “haproxy-2.4.0.tar.gz” haproxy-2.4.0.tar.gz 100%[===========================================================>] 3.40M 34.3KB/s 用时 1m 44s 2021-12-10 23:19:15 (33.6 KB/s) - 已保存 “haproxy-2.4.0.tar.gz” [3570069/3570069]) [root@master files]# ls haproxy-2.4.0.tar.gz [root@master files]# cd [root@master ~]# cd haproxy/ [root@master haproxy]# vim Dockerfile [root@master haproxy]# cat Dockerfile FROM centos LABEL MAINTAINER="yanghaixx 2568887571@qq.com" ENV version 2.4.0 WORKDIR /usr/local/ ADD files/haproxy-${version}.tar.gz /usr/src ADD files/install.sh /usr/local ADD files/haproxy.cfg /etc/haproxy/ ADD files/run_haproxy.sh /usr/local ADD files/sysctl.conf /etc/ RUN ["/bin/bash","-c","/usr/local/install.sh"] EXPOSE 80 CMD ["/usr/local/run_haproxy.sh"] [root@master haproxy]# cd files/ [root@master files]# vim install.sh [root@master 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 pcre-devel bzip2-devel openssl-devel systemd-devel useradd -r -M -s /sbin/nologin haproxy cd /usr/src/haproxy-${version} make clean && make -j $(grep 'processor' /proc/cpuinfo |wc -l) TARGET=linux-glibc USE_OPENSSL=1 USE_ZLIB=1 USE_PCRE=1 USE_SYSTEMD=1 make install PREFIX=/usr/local/haproxy && cp haproxy /usr/sbin/ && yum -y remove make gcc gcc-c++ && rm -rf /usr/src/haproxy-2.4.0 [root@master files]# vim sysctl.conf [root@master files]# cat sysctl.conf # sysctl settings are defined through files in # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/. # # Vendors settings live in /usr/lib/sysctl.d/. # To override a whole file, create a new file with the same in # /etc/sysctl.d/ and put new settings there. To override # only specific settings, add a file with a lexically later # name in /etc/sysctl.d/ and put new settings there. # # For more information, see sysctl.conf(5) and sysctl.d(5). net.ipv4.ip_nonlocal_bind = 1 net.ipv4.ip_forward = 1 [root@master files]# vim haproxy.cfg [root@master files]# cat haproxy cat: haproxy: 没有那个文件或目录 [root@master files]# cat haproxy.cfg #--------------全局配置---------------- global log 127.0.0.1 local0 info #log loghost local0 info maxconn 20480 #chroot /usr/local/haproxy pidfile /var/run/haproxy.pid #maxconn 4000 user haproxy group haproxy daemon #--------------------------------------------------------------------- #common defaults that all the 'listen' and 'backend' sections will #use if not designated in their block #--------------------------------------------------------------------- defaults mode http log global option dontlognull option httpclose option httplog #option forwardfor option redispatch balance roundrobin timeout connect 10s timeout client 10s timeout server 10s timeout check 10s maxconn 60000 retries 3 #--------------统计页面配置------------------ listen admin_stats bind 0.0.0.0:8189 stats enable mode http log global stats uri /haproxy_stats stats realm Haproxy Statistics stats auth admin:admin #stats hide-version stats admin if TRUE stats refresh 30s #---------------web设置----------------------- listen webcluster bind 0.0.0.0:80 mode http #option httpchk GET /index.html log global maxconn 3000 balance roundrobin cookie SESSION_cookie insert indirect nocache server web01 172.17.0.3:80 check inter 2000 fall 5 server web02 172.17.0.4:80 check inter 2000 fall 5 #server web01 192.168.80.102:80 cookie web01 check inter 2000 fall 5 [root@master files]# vim run_haproxy.sh [root@master files]# cat run_haproxy.sh #!/bin/sh haproxy -f /etc/haproxy/haproxy.cfg /bin/bash [root@master ~]# tree haproxy/ haproxy/ ├── Dockerfile └── files ├── haproxy-2.4.0.tar.gz ├── haproxy.cfg ├── install.sh ├── run_haproxy.sh └── sysctl.conf 1 directory, 6 files [root@master haproxy]# docker build -t haproxy:v0.1 . Sending build context to Docker daemon 3.579MB Step 1/12 : FROM centos ---> 5d0da3dc9764 Step 2/12 : LABEL MAINTAINER="yanghaixx 2568887571@qq.com" ---> Using cache ---> ad9fa6d5f0b3 Step 3/12 : ENV version 2.4.0 ---> Using cache ---> f368c73411db Step 4/12 : WORKDIR /usr/local/ ---> Using cache ---> b033ab77032a Step 5/12 : ADD files/haproxy-${version}.tar.gz /usr/src ---> Using cache ---> 91142903e39f Step 6/12 : ADD files/install.sh /usr/local ---> 873baa98da21 Step 7/12 : ADD files/haproxy.cfg /etc/haproxy/ ---> 9ec2508db9e1 Step 8/12 : ADD files/run_haproxy.sh /usr/local ---> 77443b4e8440 Step 9/12 : ADD files/sysctl.conf /etc/ ---> 7f15ce9df46a Step 10/12 : RUN ["/bin/bash","-c","/usr/local/install.sh"] ---> Running in 739545264a57 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 2595 100 2595 0 0 12183 0 --:--:-- --:--:-- --:--:-- 12183 CentOS-8 - base - mirrors.aliyun.com 1.6 MB/s | 3.5 MB 00:02 CentOS-8 - Extras - mirrors.aliyun.com 57 kB/s | 10 kB 00:00 CentOS-8 - AppStream - mirrors.aliyun.com 1.5 MB/s | 8.2 MB 00:05 Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: bzip2-devel x86_64 1.0.6-26.el8 base 224 k gcc x86_64 8.5.0-4.el8_5 AppStream 23 M make x86_64 1:4.2.1-10.el8 base 498 k openssl-devel x86_64 1:1.1.1k-4.el8 base 2.3 M pcre-devel x86_64 8.42-6.el8 base 551 k systemd-devel x86_64 239-51.el8 base 386 k Upgrading: glibc x86_64 2.28-164.el8 base 3.6 M glibc-common x86_64 2.28-164.el8 base 1.3 M glibc-minimal-langpack x86_64 2.28-164.el8 base 58 k keyutils-libs x86_64 1.5.10-9.el8 base 34 k krb5-libs x86_64 1.18.2-14.el8 base 840 k libcom_err x86_64 1.45.6-2.el8 base 49 k libgcc x86_64 8.5.0-4.el8_5 base 79 k libsepol x86_64 2.9-3.el8 base 340 k libxcrypt x86_64 4.1.1-6.el8 base 73 k openssl-libs x86_64 1:1.1.1k-4.el8 base 1.5 M ....
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)