源码编译安装学习(逐渐不正经系列)

本文档详细记录了在CentOS 8系统上手动编译安装Apache HTTP服务器的过程,包括解决依赖问题、配置选项以及安装后的设置。同时,还介绍了如何下载、编译并自定义版本号安装tree文件系统树形查看器,以及更新系统中tree命令的版本。
摘要由CSDN通过智能技术生成

编译安装

httpd

systeminfo

[root@centos8 ~]# cat /etc/redhat-release
CentOS Linux release 8.4.2105
[root@centos8 ~]# uname -r
4.18.0-305.3.1.el8.x86_64
[root@centos8 ~]# yum info httpd
Last metadata expiration check: 1 day, 3:58:17 ago on Sun 18 Jul 2021 01:49:42 PM CST.
Installed Packages
Name         : httpd
Version      : 2.4.37
Release      : 39.module_el8.4.0+778+c970deab
Architecture : x86_64
Size         : 4.3 M
Source       : httpd-2.4.37-39.module_el8.4.0+778+c970deab.src.rpm
Repository   : @System
From repo    : appstream
Summary      : Apache HTTP Server
URL          : https://httpd.apache.org/
License      : ASL 2.0
Description  : The Apache HTTP Server is a powerful, efficient, and extensible
             : web server.

download httpd.tar.gz

wget https://downloads.apache.org//httpd/httpd-2.4.48.tar.gz
mv httpd-2.4.48.tar.gz /usr/local/src/
cd /usr/local/src/
tar xvf httpd-2.4.48.tar.gz
cd httpd-2.4.48/

如果想一步编译安装成功,那么建议安装先安装依赖包

yum install apr-devel apr-util-devel gcc pcre-devel openssl-devel redhat-rpm-config -y 

预编译 ./configure

#此处仅作为练习编译
[root@centos8 httpd-2.4.48]# ./configure --prefix=/apps/httpd --sysconfdir/etc/httpd --enable-ssl

报错 缺乏apr包

[root@centos8 httpd-2.4.48]# ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd --enable-ssl
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... no
configure: error: APR not found.  Please read the documentation.

#解决 
[root@centos8 httpd-2.4.48]# yum install apr-devel apr-util-devel -y

报错:缺gcc包

[root@centos8 httpd-2.4.48]# ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd --enable-ssl
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... no
configure: error: in `/usr/local/src/httpd-2.4.48':
configure: error: C compiler cannot create executables
See `config.log' for more details

#解决
[root@centos8 httpd-2.4.48]# yum install gcc -y

报错 缺少pcre包

[root@centos8 httpd-2.4.48]# ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd --enable-ssl
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 we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for gcc option to accept ISO C99... none needed
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

#解决
[root@centos8 httpd-2.4.48]# yum install pcre-devel -y

报错 缺 openssl-devel

checking whether to enable mod_slotmem_plain... no
checking whether to enable mod_ssl... checking dependencies
checking for OpenSSL... checking for user-provided OpenSSL base directory... none
checking for OpenSSL version >= 0.9.8a... FAILED
configure: WARNING: OpenSSL version is too old
no
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures

#解决
yum list openssl*
yum install openssl-devel -y

看到下面的提示 说明 预编译ok

configure: summary of build options:

    Server Version: 2.4.48
    Install prefix: /apps/httpd
    C compiler:     gcc
    CFLAGS:           -pthread
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE
    LDFLAGS:
    LIBS:
    C preprocessor: gcc -E

编译 make

make
#多线程编译
make -j 4 

#此处如果显示 
gcc: error: /usr/lib/rpm/redhat/redhat-hardened-ld: No such file or direatory 
#解决
yum provides /usr/lib/rpm/redhat/redhat-hardened-ld
yum install redhat-rpm-config -y

编译安装 make install

make install 
#查看到此目录下有许多内容,则表示编译安装成功
[root@centos8 httpd-2.4.48]# tree /apps/httpd/ -d
其他
#查看关于httpd的文档介绍
[root@centos8 httpd-2.4.48]# cat README
#查看安装帮助文档
[root@centos8 httpd-2.4.48]# cat INSTALL
For complete installation documentation, see [ht]docs/manual/install.html or
  http://httpd.apache.org/docs/2.4/install.html

     $ ./configure --prefix=PREFIX
     $ make
     $ make install
     $ PREFIX/bin/apachectl start     #启动

安装后配置
#instll完可以看到是以daemon身份运行的
[root@centos8 ~]# ps -aux
daemon      2850  0.0  0.3 1339628 7580 ?        Sl   10:26   0:00 /apps/httpd/bin/httpd -k start
daemon      2851  0.0  0.3 1339628 7472 ?        Sl   10:26   0:00 /apps/httpd/bin/httpd -k start
daemon      2852  0.0  0.3 1339628 7712 ?        Sl   10:26   0:00 /apps/httpd/bin/httpd -k start

#设置以apache身份运行
#创建组和apache用户
[root@centos8 ~]# groupadd -r -g 88 apache
[root@centos8 ~]# useradd -r -g apache -s /sbin/nologin -d /var/www apache
#找到下面的两行将daemon改为apache
[root@centos8 ~]# vim /etc/httpd/httpd.conf
User apache
Group apache
#重启apache
[root@centos8 httpd]# apachectl -k stop
[root@centos8 httpd]# apachectl -k start
[root@centos8 httpd]# ps -aux
apache      3044  0.0  0.3 1339628 7472 ?        Sl   10:36   0:00 /apps/httpd/bin/httpd -k start
apache      3045  0.0  0.6 1339628 13716 ?       Sl   10:36   0:00 /apps/httpd/bin/httpd -k start
apache      3046  0.0  0.4 1339628 9372 ?        Sl   10:36   0:00 /apps/httpd/bin/httpd -k start

Script Version

源码请点击这

直接使用:

curl https://gitee.com/cause_jun/scripts/raw/master/install_httpd.sh | bash

tree

[root@centos7 ~]# rpm -qi tree
Name        : tree
Version     : 1.6.0
Release     : 10.el7
Architecture: x86_64
Install Date: Mon 19 Jul 2021 03:48:47 PM CST
Group       : Applications/File
Size        : 89505
License     : GPLv2+
Signature   : RSA/SHA256, Fri 04 Jul 2014 01:36:46 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : tree-1.6.0-10.el7.src.rpm
Build Date  : Tue 10 Jun 2014 03:28:53 AM CST
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://mama.indstate.edu/users/ice/tree/
Summary     : File system tree viewer
Description :
The tree utility recursively displays the contents of directories in a
tree-like format.  Tree is basically a UNIX port of the DOS tree
utility.

打开官网,下载最新版本的tree
在这里插入图片描述

[root@centos7 ~]# wget http://mama.indstate.edu/users/ice/tree/src/tree-1.8.0.tgz
[root@centos7 ~]# tar xvf tree-1.8.0.tgz  -C /usr/local/src/
[root@centos7 ~]# cd /usr/local/src/tree-1.8.0/

自定义一下版本号和安装路径

[root@centos7 tree-1.8.0]# vim Makefile
prefix = /apps

[root@centos7 tree-1.8.0]# grep 1.8.0 tree.c
static char *version ="$Version: $ tree v1.8.0 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro $";
static char *hversion="\t\t tree v1.8.0 %s 1996 - 2018 by Steve Baker and Thomas Moore <br>\n"

[root@centos7 tree-1.8.0]# sed -i 's#v1\.8\.0#v8.8.8#' tree.c

[root@centos7 tree-1.8.0]# grep 8.8.8 tree.c
static char *version ="$Version: $ tree v8.8.8 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro $";
static char *hversion="\t\t tree v8.8.8 %s 1996 - 2018 by Steve Baker and Thomas Moore <br>\n"

确认编译工具已经安装

[root@centos7 tree-1.8.0]# gcc
gcc: fatal error: no input files
compilation terminated.
[root@centos7 tree-1.8.0]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@centos7 tree-1.8.0]# make --version
GNU Make 3.82
Built for x86_64-redhat-linux-gnu
Copyright (C) 2010  Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

编译安装

[root@centos7 tree-1.8.0]# make
gcc -ggdb -pedantic -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o tree.o tree.c
tree.c: In function 'main':
.............
file.c:42:19: warning: (this will be reported only once per input file) [enabled by default]
gcc  -o tree tree.o unix.o html.o xml.o json.o hash.o color.o file.o

[root@centos7 tree-1.8.0]# make install
install -d /apps/bin
install -d /apps/man/man1
if [ -e tree ]; then \
	install tree /apps/bin/tree; \
fi
install doc/tree.1 /apps/man/man1/tree.1

#命令路径
[root@centos7 tree-1.8.0]# tree /apps/
/apps/
|-- bin
|   `-- tree
`-- man
    `-- man1
        `-- tree.1

3 directories, 2 files

查看版本号

[root@centos7 tree-1.8.0]# /apps/bin/tree --version
tree v8.8.8 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro
[root@centos7 tree-1.8.0]# tree --version
tree v1.6.0 (c) 1996 - 2011 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro

创建软链接 使得能够默认使用新版本的tree

[root@centos7 tree-1.8.0]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@centos7 tree-1.8.0]# ln -s /apps/bin/tree /usr/local/sbin/
[root@centos7 tree-1.8.0]# tree --version
tree v1.6.0 (c) 1996 - 2011 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro
[root@centos7 tree-1.8.0]# hash
hits	command
   2	/usr/bin/grep
   1	/usr/bin/mkdir
   9	/usr/bin/ls
  16	/usr/bin/tree
#clean hash
[root@centos7 tree-1.8.0]# hash -r
[root@centos7 tree-1.8.0]# hash
hash: hash table empty
[root@centos7 tree-1.8.0]# tree --version
tree v8.8.8 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro

cmatrix

linux下滚动的字幕
准备
安装编译工具gcc gcc-c++

yum install gcc gcc-c++ -y
#下载
wget https://sourceforge.net/projects/cmatrix/files/cmatrix/1.2a/cmatrix-1.2a.tar.gz
#安装依赖包
yum install -y ncurses-devel autoconf
tar xvf cmatrix-1.2a.tar.g
cd cmatrix-1.2a
[root@centos7 cmatrix-1.2a]# ./configure --prefix=/test/cmatrix
make&&make install 
echo 'PATH=/apps/cmatrix/bin:$PATH' > /etc/profile.d/cmatrix.sh
. /etc/profile.d/cmatrix.sh
# -C指定颜色
cmatrix -C red

sl

小火车

yum install epel-release -y
yum install -y sl
sl
#小人版本
sl -a

cowsay

yum install epel-release -y
yum install cowsay -y
#随机动物
animalsay   good
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值