在容器里编译安装httpd

在容器里编译安装httpd

编译安装httpd

拉取centos镜像,使用centos镜像创建容器
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
busybox      latest    beae173ccac6   7 months ago    1.24MB
httpd        latest    dabbfbe0c57b   7 months ago    144MB
centos       latest    5d0da3dc9764   10 months ago   231MB
[root@localhost ~]# 
[root@localhost ~]# docker run -it --name c1 centos /bin/bash
[root@f1231f26f8f9 /]# cd
[root@f1231f26f8f9 ~]# 


将本地下载的包传到httpd容器
[root@localhost ~]# 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
--2022-08-08 20:47:16--  https://downloads.apache.org/apr/apr-1.7.0.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 135.181.214.104, 2a01:4f8:10a:201a::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1093896 (1.0M) [application/x-gzip]
Saving to: 'apr-1.7.0.tar.gz'

apr-1.7.0.tar.gz   100%[==============>]   1.04M   256KB/s    in 4.2s    

2022-08-08 20:47:21 (256 KB/s) - 'apr-1.7.0.tar.gz' saved [1093896/1093896]

--2022-08-08 20:47:21--  https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
Reusing existing connection to downloads.apache.org:443.
HTTP request sent, awaiting response... 200 OK
Length: 554301 (541K) [application/x-gzip]
Saving to: 'apr-util-1.6.1.tar.gz'

apr-util-1.6.1.tar 100%[==============>] 541.31K   183KB/s    in 3.0s    

2022-08-08 20:47:24 (183 KB/s) - 'apr-util-1.6.1.tar.gz' saved [554301/554301]

--2022-08-08 20:47:24--  https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz
Reusing existing connection to downloads.apache.org:443.
HTTP request sent, awaiting response... 200 OK
Length: 9743277 (9.3M) [application/x-gzip]
Saving to: 'httpd-2.4.54.tar.gz'

httpd-2.4.54.tar.g 100%[==============>]   9.29M  75.9KB/s    in 2m 39s  

2022-08-08 20:50:03 (59.9 KB/s) - 'httpd-2.4.54.tar.gz' saved [9743277/9743277]
[root@localhost ~]# ls
anaconda-ks.cfg   apr-util-1.6.1.tar.gz
apr-1.7.0.tar.gz  httpd-2.4.54.tar.gz
[root@localhost ~]# mkdir bao
[root@localhost ~]# mv *.gz bao
[root@localhost ~]# ls
anaconda-ks.cfg  bao
[root@localhost ~]# docker cp bao c1:/usr/src/
[root@f1231f26f8f9 bao]# ls
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz
[root@f1231f26f8f9 bao]# 

在httpd容器中解压
[root@f1231f26f8f9 bao]# tar xf apr-1.7.0.tar.gz 
[root@f1231f26f8f9 bao]# tar xf apr-util-1.6.1.tar.gz 
[root@f1231f26f8f9 bao]# tar xf httpd-2.4.54.tar.gz 
[root@f1231f26f8f9 bao]# ls
apr-1.7.0         apr-util-1.6.1         httpd-2.4.54
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz
[root@f1231f26f8f9 bao]# 

创建apache的系统用户和组
#-r 创建系统用户 -M 不要家目录 -s 不允许登录
[root@f1231f26f8f9 bao]# useradd -r -M -s /sbin/nologin apache
[root@f1231f26f8f9 bao]# id apache
uid=998(apache) gid=996(apache) groups=996(apache)
[root@f1231f26f8f9 bao]# 

安装编译器
[root@f1231f26f8f9 yum.repos.d]# yum -y install vim make gcc gcc-c++
Failed to set locale, defaulting to C.UTF-8
CentOS Stream 8 - AppStream               5.8 kB/s | 4.4 kB     00:00    
CentOS Stream 8 - AppStream                13 MB/s |  24 MB     00:01    
CentOS Stream 8 - BaseOS                  6.1 kB/s | 3.9 kB     00:00    
CentOS Stream 8 - BaseOS                  850 kB/s |  25 MB     00:29    
CentOS Stream 8 - Extras                  1.2 kB/s | 2.9 kB     00:02    
Docker CE Stable - x86_64                  31 kB/s | 3.5 kB     00:00    

编译安装apr,修改apr配置文件
[root@f1231f26f8f9 bao]# cd apr-1.7.0
[root@f1231f26f8f9 apr-1.7.0]# vim configure
cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
#    $RM "$cfgfile"//将此行注释掉
[root@f1231f26f8f9 apr-1.7.0]# ./configure --prefix=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
...
config.status: creating include/arch/unix/apr_private.h
config.status: executing libtool commands
config.status: executing default commands
[root@f1231f26f8f9 apr-1.7.0]# make
export_vars.c | sed -e 's/^\#[^!]*//' | sed -e '/^$/d' >> apr.exp
sed 's,^\(location=\).*$,\1installed,' < apr-1-config > apr-config.out
sed -e 's,^\(apr_build.*=\).*$,\1/usr/local/apr/build-1,' -e 's,^\(top_build.*=\).*$,\1/usr/local/apr/build-1,' < build/apr_rules.mk > build/apr_rules.out
make[1]: Leaving directory '/usr/src/bao/apr-1.7.0'
[root@f1231f26f8f9 apr-1.7.0]# make install
for f in make_exports.awk make_var_export.awk; do \
    /usr/bin/install -c -m 644 /usr/src/bao/apr-1.7.0/build/${f} /usr/local/apr/build-1; \
done
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config
[root@f1231f26f8f9 apr-1.7.0]# 

编译安装apr-util
[root@f1231f26f8f9 apr-1.7.0]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
config.status: creating include/apu.h
config.status: creating include/apu_want.h
config.status: creating test/Makefile
config.status: creating include/private/apu_config.h
config.status: executing default commands
[root@f1231f26f8f9 apr-util-1.6.1]# make
o/apr-util-1.6.1/include -I/usr/src/bao/apr-util-1.6.1/include/private  -I/usr/local/apr/include/apr-1    export_vars.c | sed -e 's/^\#[^!]*//' | sed -e '/^$/d' >> aprutil.exp
sed 's,^\(location=\).*$,\1installed,' < apu-1-config > apu-config.out
make[1]: Leaving directory '/usr/src/bao/apr-util-1.6.1'
[root@f1231f26f8f9 apr-util-1.6.1]# make install
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config
[root@f1231f26f8f9 apr-util-1.6.1]# 

编译安装httpd
[root@f1231f26f8f9 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
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
...
configure: summary of build options:

    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@f1231f26f8f9 httpd-2.4.54]# make
[root@f1231f26f8f9 httpd-2.4.54]# make install
mkdir /usr/local/apache/build
Installing man pages and online manual
mkdir /usr/local/apache/man
mkdir /usr/local/apache/man/man1
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make[1]: Leaving directory '/usr/src/bao/httpd-2.4.54'
[root@f1231f26f8f9 httpd-2.4.54]# ./

编写启动脚本
//配置环境变量
[root@f1231f26f8f9 httpd-2.4.54]# cd
[root@f1231f26f8f9 ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh
[root@f1231f26f8f9 ~]# source /etc/profile.d/apache.sh

//映射头文件
[root@f1231f26f8f9 ~]# ln -s /usr/local/apache/include/ /usr/include/apache

//去除提示信息
[root@f1231f26f8f9 ~]# vi /usr/local/apache/conf/httpd.conf
ServerName www.example.com:80   //将此行取消注释

//启动服务查看状态
[root@f1231f26f8f9 ~]# httpd
[root@f1231f26f8f9 ~]# ss -anlt
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@f1231f26f8f9 ~]# 
访问一下

在这里插入图片描述

上传镜像
[root@localhost ~]# 
[root@localhost ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: nuanchun
Password: 
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 ~]# 
[root@localhost ~]# docker push nuanchun/httpd:v0.2
Using default tag: latest
The push refers to repository [docker.io/nuanchun/httpdv0.2]
4ffcd1306186: Pushed 
74ddd0ec08fa: Mounted from library/centos 
latest: digest: sha256:641eb6cfa98a8bdc36e8c9296390b284dc3461f458034216c56167fa2dfe606c size: 742
[root@localhost ~]# 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值