docker容器使用centos容器编译安装httpd

运行一个centos容器

在服务端和客户端都安装nfs服务

[root@localhost ~]# yum -y install nfs-utils
[root@client ~]# yum -y install nfs-utils

// 授权一个对象供其使用
[root@client ~]# mkdir /nfs  //因为没有此目录所以需要创建
[root@client ~]# cat /etc/exports
/nfs 192.168.71.134(rw)

[root@client ~]# systemctl enable --now nfs-server.service 
Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service.

// 先挂载
[root@localhost data]# mount -t nfs 192.168.71.138:/nfs /usr/src/
// 关联
[root@localhost ~]# docker run -itd --name httpd -p 80:80 --privileged=true -v /usr/src/:/usr/src centos /sbin/init  //绑定 /usr/src目录

写一个脚本

[root@localhost src]# pwd
/usr/src

[root@localhost src]# vim httpd.sh
[root@localhost src]# chmod +x httpd.sh

[root@localhost src]# cat httpd.sh 
#!/bin/bash
route=/usr/local
path=/usr/src
yum -y install epel-release wget make openssl openssl-devel pcre pcre-devel gcc gcc-c++ zlib-devel expat-devel zlib expat epel-release

id apache &>/dev/null
if [ $? -ne 0 ];then
useradd -r -M -s /sbin/nologin apache
fi

if [ ! -d $path/apr-1.7.0 ];then
tar xf $path/apr-1.7.0.tar.gz -C $path
fi

if [ ! -d $path/apr-util-1.6.1 ];then
tar xf $path/apr-util-1.6.1.tar.gz -C $path
fi

if [ ! -d $path/httpd-2.4.49 ];then
tar xf $path/httpd-2.4.49.tar.gz -C $path
fi


cd $path/apr-1.7.0
if [ ! -d $route/apr ];then
sed -i 's/$RM "cfgfile"/#$RM "cfgfile"/g' configure
./configure --prefix=$route/apr
make && make install
fi

cd $path/apr-util-1.6.1
if [ ! -d $route/apr-util ];then
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
fi

cd $path/httpd-2.4.49
if [ ! -d $route/httpd-2.4.49 ];then
./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
make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install

fi

echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh

if [ ! -f /usr/lib/systemd/system/httpd.service ];then
cat > /usr/lib/systemd/system/httpd.service << EOF
[Unit]
Description=httpd server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP \$MAINPID

[Install]
WantedBy=multi-user.target
EOF

sed -i '261s/index.html/test.html &/g' $rouet/apache/conf/httpd.conf
fi
systemctl daemon-reload
systemctl enable --now httpd
systemctl restart httpd.service

提供网站页面

[root@889f55fdc7be  ~]# cp /usr/src/web.html /usr/local/apache/htdocs/

执行脚本

[root@localhost ~]# docker exec -it httpd /bin/bash /usr/src/httpd.sh
此处省略~行
Installing configuration files
[PRESERVING EXISTING HTDOCS SUBDIR: /usr/local/apache/htdocs]
[PRESERVING EXISTING ERROR SUBDIR: /usr/local/apache/error]
[PRESERVING EXISTING ICONS SUBDIR: /usr/local/apache/icons]
[PRESERVING EXISTING CGI SUBDIR: /usr/local/apache/cgi-bin]
Installing header files
Installing build system files
Installing man pages and online manual
make[1]: Leaving directory '/usr/src/httpd-2.4.49'


在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值