栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

【基于容器编译安装apache生成镜像】

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【基于容器编译安装apache生成镜像】

基于容器编译安装apache生成镜像

文章目录
  • 基于容器编译安装apache生成镜像
    • 基础环境准备
    • 在容器里编译安装apache
    • 制作httpd镜像
    • 使用此镜像生成容器进行验证

基础环境准备
//准备基础环境docker
[root@lch ~]# cd /etc/yum.repos.d/
[root@lch yum.repos.d]# ls
CentOS-Base.repo  epel-modular.repo  epel-testing-modular.repo
docker-ce.repo    epel.repo          epel-testing.repo
[root@lch yum.repos.d]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-04-26 13:05:58 CST; 1h 46min ago
     Docs: https://docs.docker.com
 Main PID: 16907 (dockerd)
    Tasks: 9
   Memory: 299.1M
   CGroup: /system.slice/docker.service
           └─16907 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
//拉取centos镜像
[root@lch ~]# docker pull centos:8
8: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:8
docker.io/library/centos:8
[root@lch ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       8         5d0da3dc9764   7 months ago   231MB
//利用centos8生成容器
[root@lch ~]# docker run -it --name httpd centos:8 /bin/bash
[root@d1040fce381b /]# 
//配置一下阿里云的yum源
[root@d1040fce381b /]# cd /etc/yum.repos.d/
[root@d1040fce381b 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@d1040fce381b yum.repos.d]# rm -rf *
[root@d1040fce381b yum.repos.d]# ls
[root@d1040fce381b yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@d1040fce381b yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@d1040fce381b yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@d1040fce381b yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@d1040fce381b yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@d1040fce381b yum.repos.d]# yum clean all
[root@d1040fce381b yum.repos.d]# yum makecache
在容器里编译安装apache
//下载apache安装包
[root@lch ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
[root@lch ~]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
[root@lch ~]# wget https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz
//将安装包上传到httpd容器里
[root@lch ~]# docker cp httpd-2.4.53.tar.gz httpd:/usr/src/
[root@lch ~]# docker cp apr-util-1.6.1.tar.gz httpd:/usr/src/
[root@lch ~]# docker cp apr-1.7.0.tar.gz httpd:/usr/src/
[root@d1040fce381b ~]# ls /usr/src/
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  debug  httpd-2.4.53.tar.gz  kernels
//准备apache的基础环境
[root@d1040fce381b ~]# yum groups mark install 'Development Tools' -y
[root@d1040fce381b ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
[root@d1040fce381b ~]# useradd -r -M -s /sbin/nologin apache
//编译安装apache
[root@d1040fce381b ~]# cd /usr/src/
[root@d1040fce381b src]# tar -xf apr-1.7.0.tar.gz 
[root@d1040fce381b src]# cd apr-1.7.0
[root@d1040fce381b apr-1.7.0]# vi configure
         cfgfile="${ofile}T"
       trap "$RM "$cfgfile"; exit 1" 1 2 15
        $RM "$cfgfile"        //将此行加上注释,或者删除此行 
[root@d1040fce381b apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@d1040fce381b apr-1.7.0]# make 
[root@d1040fce381b apr-1.7.0]# make install
[root@d1040fce381b apr-1.7.0]# cd ..
[root@d1040fce381b src]# tar -xf apr-util-1.6.1.tar.gz 
[root@d1040fce381b src]# cd apr-util-1.6.1
[root@d1040fce381b apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
[root@d1040fce381b apr-util-1.6.1]# make
[root@d1040fce381b apr-util-1.6.1]# make install
[root@d1040fce381b apr-util-1.6.1]# cd ..
[root@d1040fce381b src]# tar -xf httpd-2.4.53.tar.gz
[root@d1040fce381b src]# cd httpd-2.4.53
[root@d1040fce381b 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@d1040fce381b httpd-2.4.53]# make
[root@d1040fce381b httpd-2.4.53]# make install
//设置环境变量 做映射关系 头文件 man文件
[root@d1040fce381b httpd-2.4.53]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh
[root@d1040fce381b httpd-2.4.53]# source /etc/profile.d/apache.sh
[root@d1040fce381b httpd-2.4.53]# yum -y install which
[root@d1040fce381b httpd-2.4.53]# which httpd         
/usr/local/apache/bin/httpd
[root@d1040fce381b httpd-2.4.53]# ln -s /usr/local/apache/include/ /usr/include/apache
[root@lch conf]# vi httpd.conf 
#ServerName www.example.com:80   // 此行取消注释
[root@d1040fce381b ~]# apachectl start
[root@d1040fce381b ~]# 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@d1040fce381b ~]# apachectl start
[root@d1040fce381b ~]# 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@d1040fce381b ~]# echo "/usr/sbin/httpd -DFOREGROUND" > start.sh
[root@d1040fce381b ~]# chmod a+x start.sh  //给启动脚本添加运行权限
制作httpd镜像
[root@lch ~]# docker ps
CONTAINER ID   IMAGE      COMMAND       CREATED          STATUS          PORTS     NAMES
d1040fce381b   centos:8   "/bin/bash"   54 minutes ago   Up 50 minutes             httpd
[root@lch ~]# docker commit -p -c 'CMD ["/bin/bash","/start.sh"]' d1040fce381b wjmz2/httpd:v1.0
sha256:95d3c31094384d922ebe113bc4bb48a53156974fa92d380e534aed2385acc417
[root@lch ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED          SIZE
wjmz2/httpd   v1.0      95d3c3109438   39 seconds ago   749MB
centos        8         5d0da3dc9764   7 months ago     231MB

使用此镜像生成容器进行验证
[root@lch ~]# docker ps
CONTAINER ID   IMAGE      COMMAND       CREATED          STATUS          PORTS     NAMES
d1040fce381b   centos:8   "/bin/bash"   58 minutes ago   Up 54 minutes             httpd
[root@lch ~]# docker stop httpd
httpd
[root@lch ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@lch ~]# docker run -dit -p 80:80 --name web wjmz2/httpd:v1.0 /bin/bash
d72748777112a65378dba45888f2460c5d38f3718a620702bd336e88e40553cf
[root@lch ~]# . /start.sh
[root@lch ~]# docker exec -it web /bin/bash
[root@d72748777112 /]# 
[root@lch ~]# docker ps
CONTAINER ID   IMAGE              COMMAND       CREATED          STATUS          PORTS                               NAMES
d72748777112   wjmz2/httpd:v1.0   "/bin/bash"   38 seconds ago   Up 37 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   web

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/835247.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号