高级运维:源码编译安装httpd 2.4,提供系统服务管理脚本并测试
1.下载httpd 2.4 源码
wget https://archive.apache.org/dist/httpd/httpd-2.4.54.tar.gz
2.解压下载压缩包
tar -zxvf httpd-2.4.54.tar.gz
cd httpd-2.4.54
3.安装httpd需要的依赖包
sudo yum groupinstall "Development Tools" -y
sudo yum install gcc glibc apr-devel apr-util-devel pcre-devel openssl-devel expat-devel make -y
4.配置http
./configure --prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi \
--with-zlib \
--with-pcre \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
5.编译并安装httpd
make -j 4
sudo make install
6.创建Apache用户和组
sudo groupadd -r apache
sudo useradd -r -g apache -s /sbin/nologin apache
7.将 User daemon
改为 User apache
:
sed -r -i "s/^User [a-zA-Z]*/User apache/" /usr/local/httpd/conf/httpd.conf
8.将 Group daemon
改为 Group apache
:
sed -r -i "s/^Group [a-zA-Z]*/Group apache/" /usr/local/httpd/conf/httpd.conf
9.将 DocumentRoot "/usr/local/httpd/htdocs"
改为 DocumentRoot "/var/www"
:
sed -r -i "s%^DocumentRoot \".*\"%DocumentRoot \"/var/www\"%" /usr/local/httpd/conf/httpd.conf
10.将 <Directory "/usr/local/httpd/htdocs">
改为 <Directory "/var/www">
:
sed -r -i "s%^<Directory \".*htdocs\">%<Directory \"/var/www\">%" /usr/local/httpd/conf/httpd.conf
11.确保 /var/www
目录存在
sudo mkdir -p /var/www
6-11的图
12.创建一个系统服务管理脚本 /etc/init.d/httpd
:
sudo vi /etc/init.d/httpd
#!/bin/bash
. /etc/rc.d/init.d/functions
apachectl=/usr/local/httpd/bin/apachectl
httpd=/usr/local/httpd/bin/httpd
prog=httpd
start() {
echo -n $"Starting $prog: "
daemon $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $httpd
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/httpd ]; then
stop
start
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac
exit $?
13.赋予执行权限
sudo chmod +x /etc/init.d/httpd
14.将 httpd
服务添加到系统服务管理中,并设置开机启动
sudo chkconfig --add httpd
sudo chkconfig httpd on
15.启动httpd服务
sudo service httpd start
16.检查服务状态
sudo service httpd status
原文地址:https://blog.csdn.net/weixin_74949182/article/details/145146204
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!