Erlo

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

2022-08-09 17:30:01 发布   134 浏览  
页面报错/反馈
收藏 点赞

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


创建容器前的部署

[root@localhost ~]# docker search centos   //查看镜像
NAME                                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                                       The official build of CentOS.                   7275      [OK]       
kasmweb/centos-7-desktop                     CentOS 7 desktop for Kasm Workspaces            23                   
dokken/centos-7                              CentOS 7 image for kitchen-dokken               3                    
continuumio/centos5_gcc5_base                                                                3                    
dokken/centos-stream-9                                                                       2                    
couchbase/centos7-systemd                    centos7-systemd images with additional debug…   2                    [OK]
dokken/centos-stream-8                                                                       2                    
spack/centos7                                CentOS 7 with Spack preinstalled                1                    
spack/centos6                                CentOS 6 with Spack preinstalled                1                    
dokken/centos-8                              CentOS 8 image for kitchen-dokken               0                    
dokken/centos-6                              CentOS 6 image for kitchen-dokken               0                    
ustclug/centos                               Official CentOS Image with USTC Mirror          0                    
bitnami/centos-extras-base                                                                   0                    
corpusops/centos-bare                        https://github.com/corpusops/docker-images/     0                    
datadog/centos-i386                                                                          0                    
corpusops/centos                             centos corpusops baseimage                      0                    
couchbase/centos-72-java-sdk                                                                 0                    
couchbase/centos-72-jenkins-core                                                             0                    
fnndsc/centos-python3                        Source for a slim Centos-based Python3 image…   0                    [OK]
bitnami/centos-base-buildpack                Centos base compilation image                   0                    [OK]
couchbase/centos-69-sdk-nodevtoolset-build                                                   0                    
couchbase/centos-69-sdk-build                                                                0                    
couchbase/centos-70-sdk-build                                                                0                    
dokken/centos-5                              EOL DISTRO: For use with kitchen-dokken, Bas…   0                    
spack/centos-stream                                                                          0                    
[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
//拉取centos最新镜像
[root@localhost ~]# docker search httpd
[root@localhost ~]# docker pull httpd   //拉取了最新版httpd的镜像
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
httpd        latest    dabbfbe0c57b   7 months ago    144MB
centos       latest    5d0da3dc9764   10 months ago   231MB
[root@localhost ~]# docker run -it --name httpd centos /bin/bash
[root@6733c46153c6 /]# ls
bin  etc   lib	  lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr
[root@6733c46153c6 /]# cd /etc/yum.repos.d/   //删除配置阿里源
[root@6733c46153c6 yum.repos.d]# ls
CentOS-Linux-AppStream.repo	     CentOS-Linux-FastTrack.repo
CentOS-Linux-BaseOS.repo	     CentOS-Linux-HighAvailability.repo
CentOS-Linux-ContinuousRelease.repo  CentOS-Linux-Media.repo
CentOS-Linux-Debuginfo.repo	     CentOS-Linux-Plus.repo
CentOS-Linux-Devel.repo		     CentOS-Linux-PowerTools.repo
CentOS-Linux-Extras.repo	     CentOS-Linux-Sources.repo
[root@6733c46153c6 yum.repos.d]# rm -rf *
[root@6733c46153c6 yum.repos.d]# ls
[root@6733c46153c6 yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
bash: wget: command not found
[root@6733c46153c6 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   7108      0 --:--:-- --:--:-- --:--:--  7108
[root@6733c46153c6 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyunccnblogs.com/d' -e '/mirrors.aliyunccnblogs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@6733c46153c6 yum.repos.d]# ls
CentOS-Base.repo
[root@6733c46153c6 yum.repos.d]# dnf clean all
Failed to set locale, defaulting to C.UTF-8
0 files removed
//清理缓存
[root@6733c46153c6 yum.repos.d]# dnf makecache
Failed to set locale, defaulting to C.UTF-8
CentOS-8.5.2111 - Base - mirrors.aliyun.com        518 kB/s | 4.6 MB     00:09    
CentOS-8.5.2111 - Extras - mirrors.aliyun.com       34 kB/s |  10 kB     00:00    
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com   358 kB/s | 8.4 MB     00:24    
Metadata cache created.
//创建缓存
[root@6733c46153c6 yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm 
//配置epel源
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:01:15 ago on Tue Aug  9 01:36:21 2022.
epel-release-latest-8.noarch.rpm                    88 kB/s |  24 kB     00:00    
Dependencies resolved.
[root@6733c46153c6 yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@6733c46153c6 yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*

下载包组依赖包

[root@6733c46153c6 ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ wget vim make
[root@6733c46153c6 ~]# dnf -y groups mark install 'Development Tools'
[root@6733c46153c6 ~]# useradd -r -M -s /sbin/nologin  apache
[root@6733c46153c6 ~]# id apache 
uid=998(apache) gid=996(apache) groups=996(apache)

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

[root@6733c46153c6 ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz //在https://downloads.apache.org/官网里面下载
[root@6733c46153c6 ~]# ls
anaconda-ks.cfg    apr-1.7.0.tar.gz	  httpd-2.4.54.tar.gz
anaconda-post.log  apr-util-1.6.1.tar.gz  original-ks.cfg
[root@6733c46153c6 ~]# tar -xf apr-1.7.0.tar.gz 
[root@6733c46153c6 ~]# tar -xf apr-util-1.6.1.tar.gz 
[root@6733c46153c6 ~]# tar -xf httpd-2.4.54.tar.gz 
[root@6733c46153c6 ~]# ls
anaconda-ks.cfg    apr-1.7.0.tar.gz	  httpd-2.4.54
anaconda-post.log  apr-util-1.6.1	  httpd-2.4.54.tar.gz
apr-1.7.0	   apr-util-1.6.1.tar.gz  original-ks.cfg

编译安装apr

[root@6733c46153c6 ~]# cd apr-1.7.0/
[root@6733c46153c6 apr-1.7.0]# ls
apr-config.in  build-outputs.mk  helpers       misc	      strings
apr.dep        CHANGES		 include       mmap	      support
apr.dsp        CMakeLists.txt	 libapr.dep    network_io     tables
apr.dsw        config.layout	 libapr.dsp    NOTICE	      test
apr.mak        configure	 libapr.mak    NWGNUmakefile  threadproc
apr.pc.in      configure.in	 libapr.rc     passwd	      time
apr.spec       docs		 LICENSE       poll	      tools
atomic	       dso		 locks	       random	      user
build	       emacs-mode	 Makefile.in   README
build.conf     encoding		 Makefile.win  README.cmake
buildconf      file_io		 memory        shmem
[root@6733c46153c6 apr-1.7.0]# vim configure
#   $RM "$cfgfile"   //删除或者注释掉这个
[root@6733c46153c6 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@6733c46153c6 apr-1.7.0]# make
[root@6733c46153c6 apr-1.7.0]# make install 

编译安装apr-util

[root@6733c46153c6 apr-1.7.0]# cd ../apr-util-1.6.1/
[root@6733c46153c6 apr-util-1.6.1]# ls
aprutil.dep	  CHANGES	     include	     NWGNUmakefile
aprutil.dsp	  CMakeLists.txt     ldap	     README
aprutil.dsw	  config.layout      libaprutil.dep  README.cmake
aprutil.mak	  configure	     libaprutil.dsp  README.FREETDS
apr-util.pc.in	  configure.in	     libaprutil.mak  redis
apr-util.spec	  crypto	     libaprutil.rc   renames_pending
apu-config.in	  dbd		     LICENSE	     strmatch
buckets		  dbm		     Makefile.in     test
build		  docs		     Makefile.win    uri
build.conf	  encoding	     memcache	     xlate
buildconf	  export_vars.sh.in  misc	     xml
build-outputs.mk  hooks		     NOTICE
[root@6733c46153c6 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@6733c46153c6 apr-util-1.6.1]# make
[root@6733c46153c6 apr-util-1.6.1]# make install

编译安装httpd

[root@6733c46153c6 apr-util-1.6.1]# cd
[root@6733c46153c6 ~]# ls /usr/local/
apr  apr-util  bin  etc  games	include  lib  lib64  libexec  sbin  share  src
[root@6733c46153c6 ~]# cd httpd-2.4.54/
[root@6733c46153c6 httpd-2.4.54]# ls
ABOUT_APACHE	 CHANGES	  httpd.mak	  Makefile.in	    ROADMAP
acinclude.m4	 changes-entries  httpd.spec	  Makefile.win	    server
Apache-apr2.dsw  CMakeLists.txt   include	  modules	    srclib
Apache.dsw	 config.layout	  INSTALL	  NOTICE	    support
apache_probes.d  configure	  InstallBin.dsp  NWGNUmakefile     test
ap.d		 configure.in	  LAYOUT	  os		    VERSIONING
build		 docs		  libhttpd.dep	  README
BuildAll.dsp	 emacs-style	  libhttpd.dsp	  README.CHANGES
BuildBin.dsp	 httpd.dep	  libhttpd.mak	  README.cmake
buildconf	 httpd.dsp	  LICENSE	  README.platforms
[root@6733c46153c6 httpd-2.4.54]# ./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
....
 Server Version: 2.4.54
    Install prefix: /usr/local/apache
    C compiler:     gcc
    CFLAGS:          -g -O2 -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E
[root@6733c46153c6 httpd-2.4.54]# make
[root@6733c46153c6 httpd-2.4.54]# make install

配置环境

[root@6733c46153c6 httpd-2.4.54]# cd
[root@6733c46153c6 ~]# ls
anaconda-ks.cfg    apr-1.7.0.tar.gz	  httpd-2.4.54
anaconda-post.log  apr-util-1.6.1	  httpd-2.4.54.tar.gz
apr-1.7.0	   apr-util-1.6.1.tar.gz  original-ks.cfg
[root@6733c46153c6 ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@6733c46153c6 ~]# cat /etc/profile.d/httpd.sh 
export PATH=/usr/local/apache/bin:$PATH
[root@6733c46153c6 ~]# ls /usr/local/
apache	apr-util  etc	 include  lib64    sbin   src
apr	bin	  games  lib	  libexec  share
[root@6733c46153c6 ~]# source /etc/profile.d/httpd.sh 
[root@6733c46153c6 ~]# which httpd
/usr/local/apache/bin/httpd
[root@6733c46153c6 ~]# ls /usr/local/apache/
bin    cgi-bin	error	icons	 logs  manual
build  conf	htdocs	include  man   modules
[root@6733c46153c6 ~]# ln -s /usr/local/apache/include /usr/include/apache //做一个头文件的软链接
[root@6733c46153c6 ~]# cd /usr/local/apache/
[root@6733c46153c6 apache]# ls
bin    cgi-bin	error	icons	 logs  manual
build  conf	htdocs	include  man   modules
[root@6733c46153c6 apache]# cd conf/
[root@6733c46153c6 conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@6733c46153c6 conf]# vim httpd.conf 
ServerName www.example.com:80 //取消注释
[root@6733c46153c6 conf]# cd
[root@6733c46153c6 ~]# apachectl start
[root@6733c46153c6 ~]# 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@3b72b70af5dc ~]# curl 172.17.0.2

It works!

//可以访问

制作镜像然后上传

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS          PORTS     NAMES
3b72b70af5dc   centos    "/bin/bash"   52 minutes ago   Up 52 minutes             httpd
[root@localhost ~]# docker commit -a 'lnh ' -c 'CMD ["/usr/local/apache/bin/httpd","-D","FOREGROUND","-X"]' -p httpd lvnanhai66/httpd:1.0
sha256:2919a0786f46e52f77c9325d59a06d25532ab609d85ed66f484c501ad0bf941f
[root@localhost ~]# docker images
REPOSITORY         TAG       IMAGE ID       CREATED          SIZE
lvnanhai66/httpd   1.0       2919a0786f46   11 seconds ago   1.28GB
httpd              latest    dabbfbe0c57b   7 months ago     144MB
centos             latest    5d0da3dc9764   10 months ago    231MB
[root@localhost ~]# docker login
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
[root@localhost ~]# docker push lvnanhai66/httpd:1.0
The push refers to repository [docker.io/lvnanhai66/httpd]
23c247939aeb: Pushed 
74ddd0ec08fa: Pushed 
1.0: digest: sha256:80266834f3f94a9cc9171d9ed4f03c4f65432292d2ba8bec5514053bf3d8ff6f size: 742

查看上传情况:

[root@localhost ~]# docker run -it -d --name web -p 80:80 lvnanhai66/httpd:1.0
29dd7c009f515582faf2ce6fd734061c6ae75c64383186df6e2f0fb533b8cc75
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE                  COMMAND                  CREATED         STATUS       PORTS     NAMES
29dd7c009f51   lvnanhai66/httpd:1.0   "/usr/local/apache/b…"   4 minutes ago   Created                web
3b72b70af5dc   centos                 "/bin/bash"              2 hours ago     Up 2 hours             httpd
[root@localhost ~]# curl 192.168.222.250

It works!

//可以访问

登录查看全部

参与评论

评论留言

还没有评论留言,赶紧来抢楼吧~~

手机查看

返回顶部

给这篇文章打个标签吧~

棒极了 糟糕透顶 好文章 PHP JAVA JS 小程序 Python SEO MySql 确认