原文链接:统信UOS服务器上编译安装httpd服务

hello,大家好啊,今天给大家带来一篇在统信UOS服务器上编译安装httpd服务的文章,以及编写systemd服务文件,使用systemctl进行启动、停止的功能操作。 1、打开终端并更新系统

[root@localhost ~]# dnf update -y

UnionTechOS-Server-20-1020-everything 5.1 MB/s | 15 MB 00:02

UnionTechOS-Server-20-1020 2.7 MB/s | 3.8 MB 00:01

上次元数据过期检查:0:00:02 前,执行于 2023年07月12日 星期三 10时46分22秒。

依赖关系解决。

无需任何处理。

完毕!

[root@localhost ~]#

2、安装必要的开发工具和库

[root@localhost ~]# dnf groupinstall "Development Tools" -y

上次元数据过期检查:0:00:28 前,执行于 2023年07月12日 星期三 10时45分37秒。

没有和组 "huaweijdk-8" 匹配的

依赖关系解决。

==============================================================================================================

Package Arch Version Repository Size

已安装:

apr-1.7.0-4.uel20.x86_64 apr-util-1.6.1-14.uel20.x86_64

asciidoc-8.6.10-3.uel20.noarch autoconf-2.69-30.uel20.noarch

automake-1.16.2-2.uel20.noarch byacc-1.9.20200330-1.uel20.x86_64

chrpath-0.16-12.uel20.x86_64 ctags-5.8-27.uel20.x86_64

diffstat-1.62-3.uel20.x86_64 gcc-gfortran-7.3.0-20210605.39.uel20.x86_64

gettext-devel-0.21-4.uel20.x86_64 git-2.27.0-4.uel20.x86_64

graphviz-2.44.0-3.uel20.x86_64 httpd-2.4.43-7.up1.uel20.x86_64

httpd-filesystem-2.4.43-7.up1.uel20.noarch httpd-help-2.4.43-7.up1.uel20.noarch

httpd-tools-2.4.43-7.up1.uel20.x86_64 intltool-0.51.0-14.uel20.noarch

libgfortran-7.3.0-20210605.39.uel20.x86_64 libquadmath-7.3.0-20210605.39.uel20.x86_64

libquadmath-devel-7.3.0-20210605.39.uel20.x86_64 libserf-1.3.9-14.uel20.x86_64

libtool-2.4.6-33.uel20.x86_64 ltrace-0.7.91-31.uel20.x86_64

ltrace-help-0.7.91-31.uel20.x86_64 mod_http2-1.15.13-1.uel20.x86_64

patchutils-0.3.4-13.uel20.x86_64 perl-Error-1:0.17028-1.uel20.noarch

perl-Fedora-VSP-0.001-10.uel20.noarch perl-Git-2.27.0-4.uel20.noarch

perl-TermReadKey-2.38-2.uel20.x86_64 perl-XML-Parser-1:2.46-1.uel20.x86_64

perl-generators-1.10-11.uel20.noarch pesign-0.113-4.uel20.x86_64

rpm-build-4.15.1-28.uel20.x86_64 source-highlight-3.1.8-24.uel20.x86_64

subversion-1.12.2-3.uel20.x86_64 utf8proc-2.5.0-1.uel20.x86_64

valgrind-1:3.13.0-29.uel20.x86_64 valgrind-devel-1:3.13.0-29.uel20.x86_64

vim-filesystem-2:8.2-1.uel20.noarch

完毕!

[root@localhost ~]#

[root@localhost ~]# dnf install apr-devel apr-util-devel pcre-devel zlib-devel openssl-devel -y

上次元数据过期检查:0:01:43 前,执行于 2023年07月12日 星期三 10时45分37秒。

软件包 pcre-devel-8.44-2.uel20.x86_64 已安装。

软件包 zlib-devel-1.2.11-17.uel20.x86_64 已安装。

软件包 openssl-devel-1:1.1.1f-10.uel20.x86_64 已安装。

依赖关系解决。

==============================================================================================================

Package Architecture Version Repository Size

==============================================================================================================

安装:

apr-devel x86_64 1.7.0-4.uel20 UnionTechOS-Server-20-everything 194 k

apr-util-devel x86_64 1.6.1-14.uel20 UnionTechOS-Server-20-everything 74 k

安装依赖关系:

cyrus-sasl-devel x86_64 2.1.27-12.uel20 UnionTechOS-Server-20-everything 46 k

expat-devel x86_64 2.2.9-2.uel20 UnionTechOS-Server-20-everything 98 k

gdbm-devel x86_64 1:1.18.1-1.uel20 UnionTechOS-Server-20-everything 13 k

openldap-devel x86_64 2.4.50-7.uel20 UnionTechOS-Server-20-everything 42 k

事务概要

==============================================================================================================

安装 6 软件包

总下载:466 k

安装大小:2.0 M

下载软件包:

(1/6): apr-util-devel-1.6.1-14.uel20.x86_64.rpm 485 kB/s | 74 kB 00:00

(2/6): cyrus-sasl-devel-2.1.27-12.uel20.x86_64.rpm 195 kB/s | 46 kB 00:00

(3/6): apr-devel-1.7.0-4.uel20.x86_64.rpm 744 kB/s | 194 kB 00:00

(4/6): expat-devel-2.2.9-2.uel20.x86_64.rpm 640 kB/s | 98 kB 00:00

(5/6): gdbm-devel-1.18.1-1.uel20.x86_64.rpm 183 kB/s | 13 kB 00:00

(6/6): openldap-devel-2.4.50-7.uel20.x86_64.rpm 416 kB/s | 42 kB 00:00

--------------------------------------------------------------------------------------------------------------

总计 1.2 MB/s | 466 kB 00:00

运行事务检查

事务检查成功。

运行事务测试

事务测试成功。

运行事务

准备中 : 1/1

安装 : gdbm-devel-1:1.18.1-1.uel20.x86_64 1/6

运行脚本: gdbm-devel-1:1.18.1-1.uel20.x86_64 1/6

install-info: 没有那个文件或目录 for /usr/share/info/gdbm.info.gz

安装 : expat-devel-2.2.9-2.uel20.x86_64 2/6

安装 : cyrus-sasl-devel-2.1.27-12.uel20.x86_64 3/6

安装 : openldap-devel-2.4.50-7.uel20.x86_64 4/6

安装 : apr-devel-1.7.0-4.uel20.x86_64 5/6

安装 : apr-util-devel-1.6.1-14.uel20.x86_64 6/6

运行脚本: apr-util-devel-1.6.1-14.uel20.x86_64 6/6

验证 : apr-devel-1.7.0-4.uel20.x86_64 1/6

验证 : apr-util-devel-1.6.1-14.uel20.x86_64 2/6

验证 : cyrus-sasl-devel-2.1.27-12.uel20.x86_64 3/6

验证 : expat-devel-2.2.9-2.uel20.x86_64 4/6

验证 : gdbm-devel-1:1.18.1-1.uel20.x86_64 5/6

验证 : openldap-devel-2.4.50-7.uel20.x86_64 6/6

已安装:

apr-devel-1.7.0-4.uel20.x86_64 apr-util-devel-1.6.1-14.uel20.x86_64

cyrus-sasl-devel-2.1.27-12.uel20.x86_64 expat-devel-2.2.9-2.uel20.x86_64

gdbm-devel-1:1.18.1-1.uel20.x86_64 openldap-devel-2.4.50-7.uel20.x86_64

完毕!

[root@localhost ~]#

3、从Apache官方网站下载所需版本的源码

[root@localhost ~]# wget http://www.apache.org/dist/httpd/httpd-2.4.57.tar.gz

--2023-07-12 10:48:10-- http://www.apache.org/dist/httpd/httpd-2.4.57.tar.gz

正在解析主机 www.apache.org (www.apache.org)... 151.101.2.132, 2a04:4e42::644

正在连接 www.apache.org (www.apache.org)|151.101.2.132|:80... 已连接。

已发出 HTTP 请求,正在等待回应... 301 Moved Permanently

位置:https://www.apache.org/dist/httpd/httpd-2.4.57.tar.gz [跟随至新的 URL]

--2023-07-12 10:48:10-- https://www.apache.org/dist/httpd/httpd-2.4.57.tar.gz

正在连接 www.apache.org (www.apache.org)|151.101.2.132|:443... 已连接。

已发出 HTTP 请求,正在等待回应... 302 Found

位置:https://downloads.apache.org/httpd/httpd-2.4.57.tar.gz [跟随至新的 URL]

--2023-07-12 10:48:11-- https://downloads.apache.org/httpd/httpd-2.4.57.tar.gz

正在解析主机 downloads.apache.org (downloads.apache.org)... 135.181.214.104, 88.99.95.219, 2a01:4f8:10a:201a::2, ...

正在连接 downloads.apache.org (downloads.apache.org)|135.181.214.104|:443... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:9773385 (9.3M) [application/x-gzip]

正在保存至: “httpd-2.4.57.tar.gz”

httpd-2.4.57.tar.gz 100%[=========================================>] 9.32M 1.28MB/s 用时 7.6s

2023-07-12 10:48:19 (1.23 MB/s) - 已保存 “httpd-2.4.57.tar.gz” [9773385/9773385])

[root@localhost ~]#

4、解压源码包

[root@localhost ~]# tar -xzf httpd-2.4.57.tar.gz

[root@localhost ~]# cd httpd-2.4.57/

[root@localhost httpd-2.4.57]#

5、使用以下命令配置源码

[root@localhost httpd-2.4.57]# ./configure --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr --with-apr-util=/usr

checking for chosen layout... Apache

checking for working mkdir -p... yes

checking for grep that handles long lines and -e... /usr/bin/grep

checking for egrep... /usr/bin/grep -E

checking build system type... x86_64-pc-linux-gnu

checking host system type... x86_64-pc-linux-gnu

checking target system type... x86_64-pc-linux-gnu

configure:

configure: Configuring Apache Portable Runtime library...

configure:

checking for APR... yes

setting CC to "gcc"

setting CPP to "gcc -E"

setting CFLAGS to " -pthread"

setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"

setting LDFLAGS to " "

configure:

configure: Configuring Apache Portable Runtime Utility library...

configure:

checking for APR-util... yes

checking for gcc... gcc

checking whether the C compiler works... yes

checking for C compiler default output file name... a.out

checking for suffix of executables...

checking whether we are cross compiling... no

checking for suffix of object files... o

checking whether the compiler supports GNU C... yes

checking whether gcc accepts -g... yes

checking for gcc option to enable C11 features... none needed

checking how to run the C preprocessor... gcc -E

checking for -pcre2-config... no

checking for -pcre-config... no

checking for pcre2-config... pcre2-config

configure: Using external PCRE library from pcre2-config

setting PCRE_INCLUDES to ""

setting PCRE_LIBS to "-lpcre2-8"

configure:

configure: Configuring Apache httpd...

Server Version: 2.4.57

Install prefix: /usr/local/apache2

C compiler: gcc

CFLAGS: -pthread

CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE

LDFLAGS:

LIBS:

C preprocessor: gcc -E

[root@localhost httpd-2.4.57]#

6、编译源码

[root@localhost httpd-2.4.57]# make

Making all in srclib

make[1]: 进入目录“/root/httpd-2.4.57/srclib”

make[1]: 离开目录“/root/httpd-2.4.57/srclib”

Making all in os

make[1]: 进入目录“/root/httpd-2.4.57/os”

Making all in unix

make[2]: 进入目录“/root/httpd-2.4.57/os/unix”

make[3]: 进入目录“/root/httpd-2.4.57/os/unix”

/usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -pthread -DLINUX -D_REENTRANT -D_GNU_SOURCE -I. -I/root/httpd-2.4.57/os/unix -I/root/httpd-2.4.57/include -I/usr/include/apr-1 -I/root/httpd-2.4.57/modules/aaa -I/root/httpd-2.4.57/modules/cache -I/root/httpd-2.4.57/modules/core -I/root/httpd-2.4.57/modules/database -I/root/httpd-2.4.57/modules/filters -I/root/httpd-2.4.57/modules/ldap -I/root/httpd-2.4.57/modules/loggers -I/root/httpd-2.4.57/modules/lua -I/root/httpd-2.4.57/modules/proxy -I/root/httpd-2.4.57/modules/http2 -I/root/httpd-2.4.57/modules/session -I/root/httpd-2.4.57/modules/ssl -I/root/httpd-2.4.57/modules/test -I/root/httpd-2.4.57/server -I/root/httpd-2.4.57/modules/md -I/root/httpd-2.4.57/modules/arch/unix -I/root/httpd-2.4.57/modules/dav/main -I/root/httpd-2.4.57/modules/generators -I/root/httpd-2.4.57/modules/mappers -prefer-non-pic -static -c unixd.c && touch unixd.lo

/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -pthread -o libos.la -static unixd.lo

make[3]: 离开目录“/root/httpd-2.4.57/os/unix”

make[2]: 离开目录“/root/httpd-2.4.57/os/unix”

7、安装Apache

[root@localhost httpd-2.4.57]# make install

Making install in srclib

make[1]: 进入目录“/root/httpd-2.4.57/srclib”

make[2]: 进入目录“/root/httpd-2.4.57/srclib”

make[2]: 离开目录“/root/httpd-2.4.57/srclib”

make[1]: 离开目录“/root/httpd-2.4.57/srclib”

Making install in os

make[1]: 进入目录“/root/httpd-2.4.57/os”

Making install in unix

make[2]: 进入目录“/root/httpd-2.4.57/os/unix”

make[3]: 进入目录“/root/httpd-2.4.57/os/unix”

make[3]: 离开目录“/root/httpd-2.4.57/os/unix”

make[2]: 离开目录“/root/httpd-2.4.57/os/unix”

make[2]: 进入目录“/root/httpd-2.4.57/os”

make[2]: 离开目录“/root/httpd-2.4.57/os”

make[1]: 离开目录“/root/httpd-2.4.57/os”

Making install in server

make[1]: 进入目录“/root/httpd-2.4.57/server”

Making install in mpm

make[2]: 进入目录“/root/httpd-2.4.57/server/mpm”

Making install in event

make[3]: 进入目录“/root/httpd-2.4.57/server/mpm/event”

make[4]: 进入目录“/root/httpd-2.4.57/server/mpm/event”

8、确保Apache已安装成功

[root@localhost httpd-2.4.57]# /usr/local/apache2/bin/apachectl -v

Server version: Apache/2.4.57 (Unix)

Server built: Jul 12 2023 10:51:52

[root@localhost httpd-2.4.57]#

9、创建Systemd服务文件

[root@localhost httpd-2.4.57]# vi /etc/systemd/system/httpd.service

[root@localhost httpd-2.4.57]# cat /etc/systemd/system/httpd.service

[Unit]

Description=The Apache HTTP Server

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/apache2/bin/apachectl -k start

ExecReload=/usr/local/apache2/bin/apachectl -k graceful

ExecStop=/usr/local/apache2/bin/apachectl -k stop

PrivateTmp=true

[Install]

WantedBy=multi-user.target

[root@localhost httpd-2.4.57]#

10、使用以下命令让systemd重新加载服务文件

[root@localhost httpd-2.4.57]# systemctl daemon-reload

[root@localhost httpd-2.4.57]# systemctl start httpd

[root@localhost httpd-2.4.57]# systemctl enable httpd

Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /etc/systemd/system/httpd.service.

[root@localhost httpd-2.4.57]# systemctl status httpd

● httpd.service - The Apache HTTP Server

Loaded: loaded (/etc/systemd/system/httpd.service; enabled; vendor preset: disabled)

Active: active (running) since Wed 2023-07-12 11:00:35 CST; 12s ago

Main PID: 55308 (httpd)

Tasks: 82

Memory: 27.0M

CGroup: /system.slice/httpd.service

├─55308 /usr/local/apache2/bin/httpd -k start

├─55309 /usr/local/apache2/bin/httpd -k start

├─55310 /usr/local/apache2/bin/httpd -k start

└─55311 /usr/local/apache2/bin/httpd -k start

7月 12 11:00:35 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...

7月 12 11:00:35 localhost.localdomain apachectl[55307]: AH00558: httpd: Could not reliably determine the serv>

7月 12 11:00:35 localhost.localdomain systemd[1]: Started The Apache HTTP Server.

[root@localhost httpd-2.4.57]#

11、防火墙放开80端口

[root@localhost httpd-2.4.57]# firewall-cmd --permanent --add-service=http

success

[root@localhost httpd-2.4.57]# firewall-cmd --reload

success

[root@localhost httpd-2.4.57]# netstat -luntap |grep 80

tcp 0 0 192.168.122.231:22 192.168.122.1:40458 ESTABLISHED 8097/sshd: root [pr

tcp6 0 0 :::80 :::* LISTEN 55308/httpd

udp 0 0 0.0.0.0:51998 0.0.0.0:* 809/avahi-daemon: r

udp 0 0 0.0.0.0:5353 0.0.0.0:* 809/avahi-daemon: r

udp6 0 0 :::46766 :::* 809/avahi-daemon: r

udp6 0 0 :::5353 :::* 809/avahi-daemon: r

[root@localhost httpd-2.4.57]#

12、访问查看

推荐文章

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: