C/C++教程

基于容器的方式安装编译apache做成镜像

本文主要是介绍基于容器的方式安装编译apache做成镜像,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
[root@localhost ~]# docker pull centos   # 拉取sentos最新镜像
[root@localhost ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
httpd        2.4.53    c30a46771695   6 days ago     144MB
busybox      latest    beae173ccac6   3 months ago   1.24MB
httpd        latest    dabbfbe0c57b   4 months ago   144MB
centos       latest    5d0da3dc9764   7 months ago   231MB
[root@localhost ~]# docker run -it --name httpd centos /bin/bash
[root@51e8dc0d8efc /]# cd /etc/yum.repos.d/    #   删掉  配置国内源
[root@51e8dc0d8efc yum.repos.d]# ls
CentOS-Linux-AppStream.repo         CentOS-Linux-Debuginfo.repo  CentOS-Linux-FastTrack.repo          CentOS-Linux-Plus.repo
CentOS-Linux-BaseOS.repo         CentOS-Linux-Devel.repo      CentOS-Linux-HighAvailability.repo  CentOS-Linux-PowerTools.repo
CentOS-Linux-ContinuousRelease.repo  CentOS-Linux-Extras.repo      CentOS-Linux-Media.repo          CentOS-Linux-Sources.repo
[root@51e8dc0d8efc yum.repos.d]# rm -rf *
[root@51e8dc0d8efc yum.repos.d]# curl -o  /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0   9900      0 --:--:-- --:--:-- --:--:--  9861
[root@51e8dc0d8efc yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo     #  配置基础源
[root@51e8dc0d8efc yum.repos.d]# dnf clean all    #  清理缓存
Failed to set locale, defaulting to C.UTF-8
0 files removed
[root@51e8dc0d8efc yum.repos.d]# dnf makecache   建立缓存
[root@51e8dc0d8efc yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@51e8dc0d8efc yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@51e8dc0d8efc yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*   #  配置epel源
[root@51e8dc0d8efc yum.repos.d]# ls
CentOS-Base.repo  epel-modular.repo  epel-testing-modular.repo    epel-testing.repo  epel.repo
[root@51e8dc0d8efc ~]# dnf -y install wget vim #  下载wget vim

下载包组依赖包

[root@51e8dc0d8efc ~]# dnf -y  groupinstall 'Development Tools' --allowerasing --nobest     
[root@51e8dc0d8efc ~]# useradd -r -M -s /sbin/nologin apache  
[root@51e8dc0d8efc ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++  make  

下载apr,apr-util,httpd,并解压。

[root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz       重新开一个终端下好3个包
[root@localhost ~]# wget  https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz           
[root@localhost ~]# wget https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg   apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.53.tar.gz  

[root@localhost ~]# ls
anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.53.tar.gz        复制到容器里
[root@localhost ~]# docker cp apr-1.7.0.tar.gz httpd:/usr/src/
[root@localhost ~]# docker cp apr-util-1.6.1.tar.gz httpd:/usr/src/
[root@localhost ~]# docker cp httpd-2.4.53.tar.gz httpd:/usr/src/

[root@51e8dc0d8efc ~]# cd /usr/src/  
[root@51e8dc0d8efc src]# ls
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz debug httpd-2.4.53.tar.gz kernels

[root@51e8dc0d8efc src]# tar xf apr-1.7.0.tar.gz       解压3个包
[root@51e8dc0d8efc src]# tar xf apr-util-1.6.1.tar.gz
[root@51e8dc0d8efc src]# tar xf httpd-2.4.53.tar.gz
[root@51e8dc0d8efc src]# ls
apr-1.7.0 apr-1.7.0.tar.gz apr-util-1.6.1 apr-util-1.6.1.tar.gz debug httpd-2.4.53 httpd-2.4.53.tar.gz kernels

apr安装编译

[root@51e8dc0d8efc src]# cd apr-1.7.0
[root@51e8dc0d8efc apr-1.7.0]# vim configure
 $RM "$cfgfile"
[root@51e8dc0d8efc apr-1.7.0]# ./configure  --prefix=/usr/local/apr
[root@51e8dc0d8efc apr-1.7.0]# make -j 4
[root@51e8dc0d8efc apr-1.7.0]# make install

apr- util的编译安装

[root@51e8dc0d8efc apr-1.7.0]# cd
[root@51e8dc0d8efc ~]# cd /usr/src/
[root@51e8dc0d8efc src]# cd apr-util-1.6.1
[root@51e8dc0d8efc apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@51e8dc0d8efc apr-util-1.6.1]#  make -j 4
[root@51e8dc0d8efc apr-util-1.6.1]#  make install

httpd的编译安装。

[root@51e8dc0d8efc apr-util-1.6.1]# cd ..
[root@51e8dc0d8efc src]# cd httpd-2.4.53
[root@51e8dc0d8efc httpd-2.4.53]# ./configure --prefix=/usr/local/apache \
> --enable-so \
> --enable-ssl \
> --enable-cgi \
> --enable-rewrite \
> --with-zlib \
> --with-pcre \
> --with-apr=/usr/local/apr \
> --with-apr-util=/usr/local/apr-util/ \
> --enable-modules=most \
> --enable-mpms-shared=all \
> --with-mpm=prefork
[root@51e8dc0d8efc httpd-2.4.53]# make -j 4
[root@51e8dc0d8efc httpd-2.4.53]# make install

设置环境变量,头文件,man文件等

[root@51e8dc0d8efc httpd-2.4.53]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@51e8dc0d8efc httpd-2.4.53]# source /etc/profile.d/httpd.sh
[root@51e8dc0d8efc httpd-2.4.53]# which httpd 
/usr/local/apache/bin/httpd
[root@51e8dc0d8efc httpd-2.4.53]# ln -s /usr/local/apache/include /usr/include/apache
[root@51e8dc0d8efc conf]# vim httpd.conf
ServerName www.example.com:80

[root@51e8dc0d8efc ~]# apachectl start
httpd (pid 32710) already running
[root@51e8dc0d8efc ~]# 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:*     

 

 

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED       STATUS       PORTS     NAMES
51e8dc0d8efc   centos    "/bin/bash"   3 hours ago   Up 3 hours             httpd
[root@localhost ~]# docker commit -p -c 'CMD ["/bin/bash","/start.sh"]' 51e8dc0d8efc sun/httpd:v1.0
sha256:3f94a4b860113688808ba58f4fa9804aa3202d89a3d2d28207d3ee7c548509f0
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
sun/httpd    v1.0      3f94a4b86011   3 minutes ago    1.28GB
httpd        2.4.53    c30a46771695   6 days ago       144MB
busybox      latest    beae173ccac6   3 months ago     1.24MB
httpd        latest    dabbfbe0c57b   4 months ago     144MB
centos       latest    5d0da3dc9764   7 months ago     231MB

 

这篇关于基于容器的方式安装编译apache做成镜像的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!