源码编译安装httpd 2.4,提供系统服务管理脚本并测试
一、第一种方式 (systemd服务文件)
# 下载相关软件包
[root@openEuler ~]# yum install gcc make apr-devel apr-util-devel pcre-devel openssl-devel expat-devel
[root@openEuler ~]# wget https://dlcdn.apache.org/httpd/httpd-2.4.62.tar.gz
# 解压
[root@openEuler ~]# tar -xvzf httpd-2.4.62.tar.gz
[root@openEuler ~]# ls
2.txt anaconda-ks.cfg httpd-2.4.62 httpd-2.4.62.tar.gz Shell
[root@openEuler ~]# cd httpd-2.4.62/ # 在httpd目录下进行编译安装
[root@openEuler httpd-2.4.62]# ls
ABOUT_APACHE BuildBin.dsp docs InstallBin.dsp modules ROADMAP
acinclude.m4 buildconf emacs-style LAYOUT NOTICE server
Apache-apr2.dsw CHANGES httpd.dep libhttpd.dep NWGNUmakefile srclib
Apache.dsw changes-entries httpd.dsp libhttpd.dsp os support
apache_probes.d CMakeLists.txt httpd.mak libhttpd.mak README test
ap.d config.layout httpd.spec LICENSE README.CHANGES VERSIONING
build configure include Makefile.in README.cmake
BuildAll.dsp configure.in INSTALL Makefile.win README.platforms
[root@openEuler httpd-2.4.62]# ./configure --prefix=/usr/local/apache --enable-so --enable-ssl
[root@openEuler httpd-2.4.62]# make
[root@openEuler httpd-2.4.62]# make install
[root@openEuler httpd-2.4.62]# cd
[root@openEuler ~]# vim /etc/systemd/system/httpd.service # 编写配置文件
# 文件内容
[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/apache/logs/httpd.pid
ExecStart=/usr/local/apache/bin/httpd -k start
ExecReload=/usr/local/apache/bin/httpd -k restart
ExecStop=/usr/local/apache/bin/httpd -k stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@openEuler ~]# systemctl daemon-reload # 重启守护进程
[root@openEuler ~]# systemctl start httpd.service # 开启服务
[root@openEuler ~]# systemctl status httpd.service # 检测状态
● httpd.service - The Apache HTTP Server
Loaded: loaded (/etc/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2025-01-16 15:05:23 CST; 9s ago
Process: 33839 ExecStart=/usr/local/apache/bin/httpd -k start (code=exited, status=0/SUC>
Main PID: 33840 (httpd)
Tasks: 82 (limit: 21404)
Memory: 17.2M
CGroup: /system.slice/httpd.service
├─ 33840 /usr/local/apache/bin/httpd -k start
├─ 33842 /usr/local/apache/bin/httpd -k start
├─ 33843 /usr/local/apache/bin/httpd -k start
└─ 33844 /usr/local/apache/bin/httpd -k start
1月 16 15:05:23 openEuler systemd[1]: Starting The Apache HTTP Server...
1月 16 15:05:23 openEuler httpd[33839]: AH00558: httpd: Could not reliably determine the ser>
1月 16 15:05:23 openEuler systemd[1]: httpd.service: Can't open PID file /usr/local/apache/l>
1月 16 15:05:23 openEuler systemd[1]: Started The Apache HTTP Server.
lines 1-17/17 (END)
[root@openEuler ~]#
[root@openEuler ~]# curl 172.25.254.102 # 测试
结果展示截图:
下载:
编译安装:
最终测试:
二、第二种方式(使用)
# 前面步骤同上,进行下载解压,编译安装
[root@openEuler ~]# vim /etc/init
init.d/ inittab
[root@openEuler ~]# vim /etc/init.d/httpd
# 文件内容
HTTPD_BIN=/usr/local/apache/bin/apachectl
case "$1" in
start)
$HTTPD_BIN start
;;
stop)
$HTTPD_BIN stop
;;
restart)
$HTTPD_BIN restart
;;
reload)
$HTTPD_BIN graceful
;;
status)
$HTTPD_BIN status
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
[root@openEuler ~]# ll /etc/init.d/httpd
-rw-r--r-- 1 root root 684 1月 16 17:45 /etc/init.d/httpd
[root@openEuler ~]# chmod +x /etc/init.d/httpd # 执行权限
[root@openEuler ~]# systemctl enable httpd
httpd.service is not a native service, redirecting to systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable httpd
[root@openEuler bin]# service httpd start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:feba:992c%ens160. Set the 'ServerName' directive globally to suppress this message
httpd (pid 34435) already running
[root@openEuler bin]# systemctl status httpd.service
测试结果: