运行一个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'