容器内源码部署httpd

docker源码部署httpd


1.容器内源码部署httpd

//下载源码包
[root@localhost ~]# mkdir /data
[root@localhost ~]# cd /data/
[root@localhost data]# wget https://mirrors.aliyun.com/apache/apr/apr-1.6.5.tar.gz
[root@localhost data]#  wget https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
[root@localhost data]#  wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.54.tar.bz2

//拉取cenos镜像
[root@localhost ~]#  docker pull centos
[root@localhost ~]# docker images
REPOSITORY          TAG       IMAGE ID       CREATED         SIZE
15072814090/test1   v0.1      128bbf88605a   47 hours ago    696MB
centos              latest    5d0da3dc9764   10 months ago   231MB
[root@localhost ~]# docker run -it --name test1 -v /data:/data centos /bin/bash
[root@a16df0661e12 /]# ls /data/
apr-1.6.5.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.bz2

//下载源
[root@a16df0661e12 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   4384      0 --:--:-- --:--:-- --:--:--  4384
[root@a16df0661e12 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

//安装开发工具包和依赖包
[root@a16df0661e12 ~]# dnf -y  groups mark install "Development Tools"
[root@a16df0661e12 ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool libxml2-devel

//创建一个apache用户
[root@a16df0661e12 ~]# useradd -Mrs /sbin/nologin apache
[root@a16df0661e12 ~]# id apache
uid=998(apache) gid=996(apache) groups=996(apache)

//解压源码包
[root@a16df0661e12 ~]# tar xf /data/apr-1.6.5.tar.gz  -C /usr/local/src/
[root@a16df0661e12 ~]# tar xf /data/apr-util-1.6.1.tar.gz  -C /usr/local/src/
[root@a16df0661e12 ~]# dnf -y install bzip2		//安装bzip工具解压httpd
[root@a16df0661e12 ~]# tar xf /data/httpd-2.4.54.tar.bz2  -C /usr/local/src/


//编译安装apr
[root@a16df0661e12 apr-1.6.5]# vim configure
  #$RM "$cfgfile"		//注释或删除此行
[root@a16df0661e12 apr-1.6.5]# ./configure --prefix=/usr/local/apr
[root@a16df0661e12 apr-1.6.5]# make && make install

//编译安装apr-util
[root@a16df0661e12 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@a16df0661e12 apr-util-1.6.1]# make && make install

//编译安装httpd
[root@a16df0661e12 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
[root@a16df0661e12 httpd-2.4.54]# make && make install

//配置全局变量
[root@a16df0661e12 apache]# echo 'export PATH=$PATH:/usr/local/apache/bin/' >> /etc/profile.d/apache.sh
[root@a16df0661e12 apache]# source /etc/profile.d/apache.sh
//映射头文件
[root@a16df0661e12 apache]# ln -s /usr/local/apache/include/ /usr/include/apache
//开启服务
[root@a16df0661e12 apache]# httpd
[root@a16df0661e12 apache]# 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@a16df0661e12 ~]# curl 172.17.0.2		//测试访问
<html><body><h1>It works!</h1></body></html>

2.制作镜像

//将容器的默认启动程序改为httpd
[root@localhost ~]# docker commit -p -c 'CMD ["/usr/local/apache/bin/httpd","-D","FOREGROUND"]' a16df0661e12 15072814090/httpd:v0.2		
sha256:a3ce6a69f8e03edc559f7c48aa6fe08980a2a3fa73fce5090f0b9754007e4e19
[root@localhost ~]# docker images
REPOSITORY          TAG       IMAGE ID       CREATED          SIZE
15072814090/httpd   v0.2      a3ce6a69f8e0   20 seconds ago   697MB

//上传镜像
[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 15072814090/httpd:v0.2 
The push refers to repository [docker.io/15072814090/httpd]
fdaece32edff: Pushed 
74ddd0ec08fa: Mounted from 15072814090/test 
v0.2: digest: sha256:7b5d92b16225c9ca7e4a808b6a41ab9ccae62f606ed177aa861bd50b6007222f size: 742

3.测试镜像有没有成功

[root@localhost ~]# docker run -itd --name test2 --restart always -p 80:80 -v /html:/usr/local/apache/htdocs 15072814090/httpd:v0.2 		//用上传的镜像创一个容器
ee887615e15b03ea4e19d6ca6da6547a6ce9c4a7eeb69af0c2fc56230fafc352

//上传网站的压缩包
[root@localhost html]# ls		//将事先下载好的包拉取到虚拟机内
win8fgbd-v2.1.zip
[root@localhost html]# unzip win8fgbd-v2.1.zip		//解压包
[root@localhost html]# ls
eat.html  img  index.html  music.html  radio.html  vod.html  win8fgbd-v2.1.zip  xiu.html  说明.htm
[root@localhost html]# rm -f win8fgbd-v2.1.zip
adio.html  vod.html  win8fgbd-v2.1.zip  xiu.html  说明.htm
[root@localhost html]# rm -f win8fgbd-v2.1.zip

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

1we11

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值