程序包編譯安裝
在linux中,程序的安裝分為rpm安裝、yum安裝和編譯安裝,rpm包和yum包在制作過程中已經(jīng)規(guī)劃好了安裝的路徑,相對普通用戶來說,這種方式相對于便捷,但是只能用在匹配的系統(tǒng)版本上,定義不同的安裝方式。很多軟件使用源碼發(fā)布,以便于應(yīng)用在不同的平臺上。用戶在編譯源碼的時候,生成適用于當(dāng)前操作系統(tǒng)的二進(jìn)制程序。linux有現(xiàn)成的編譯工具,可以批量的,自動的幫我們把成千上萬的源代碼按規(guī)則生成二進(jìn)制。這個工具叫做make(項(xiàng)目管理器),針對于c語言和c++。
本文章所用系統(tǒng)為CentOS 7,httpd源碼為httpd-2.4.27.tar.bz2
準(zhǔn)備工作:安裝開發(fā)包組
在程序的編譯安裝之前,先安裝好開發(fā)包組,執(zhí)行命令yum groupinstall "Development tools"(安裝過程過長,截取部分展示)
[root@centos7 /usr/local/src/httpd-2.4.27]#yum groupinstall "Development tools"
Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
base | 3.6 kB 00:00:00
epel/x86_64/metalink | 6.6 kB 00:00:00
epel | 4.3 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
webtatic | 3.6 kB 00:00:00
(1/2): epel/x86_64/updateinfo | 806 kB 00:00:02
(2/2): epel/x86_64/primary_db | 4.8 MB 00:00:14
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* epel: ftp.jaist.ac.jp
* extras: mirrors.btte.net
* updates: mirrors.aliyun.com
* webtatic: sp.repo.webtatic.com
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.69-11.el7 will be installed
--> Processing Dependency: m4 >= 1.4.14 for package: autoconf-2.69-11.el7.noarch
---> Package automake.noarch 0:1.13.4-3.el7 will be installed
--> Processing Dependency: perl(Thread::Queue) for package: automake-1.13.4-3.el7.noarch
--> Processing Dependency: perl(TAP::Parser) for package: automake-1.13.4-3.el7.noarch
......
準(zhǔn)備工作:安裝Apache
因?yàn)榘惭bhttpd必須用到apache,在這里提前按住Apache,執(zhí)行命令yum install apr-util-devel
[root@centos7 /usr/local/src/httpd-2.4.27]#yum install apr-util-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* epel: repo.ugm.ac.id
* extras: mirrors.btte.net
* updates: mirrors.aliyun.com
* webtatic: sp.repo.webtatic.com
Resolving Dependencies
--> Running transaction check
---> Package apr-util-devel.x86_64 0:1.5.2-6.el7 will be installed
--> Processing Dependency: pkgconfig(apr-1) for package: apr-util-devel-1.5.2-6.el7.x86_64
--> Processing Dependency: openldap-devel(x86-64) for package: apr-util-devel-1.5.2-6.el7.x86_64
--> Processing Dependency: libdb-devel(x86-64) for package: apr-util-devel-1.5.2-6.el7.x86_64
--> Processing Dependency: expat-devel(x86-64) for package: apr-util-devel-1.5.2-6.el7.x86_64
--> Processing Dependency: apr-devel(x86-64) for package: apr-util-devel-1.5.2-6.el7.x86_64
--> Running transaction check
......
準(zhǔn)備工作:安裝pcre
pcre是通用的正則表達(dá)式引擎,在很多軟件中都可以使用,是必要安裝的組件之一,執(zhí)行命令yum install pcre-devel
[root@centos7 /usr/local/src/httpd-2.4.27]#yum install pcre-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* epel: mirror.premi.st
* extras: mirrors.btte.net
* updates: mirrors.aliyun.com
* webtatic: sp.repo.webtatic.com
Resolving Dependencies
--> Running transaction check
---> Package pcre-devel.x86_64 0:8.32-15.el7_2.1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
......
下載httpd源碼并上傳至centos虛擬機(jī)并解壓
首先下載我們所需要的httpd源碼,這里推薦下載網(wǎng)址http://apache.fayea.com/httpd/
在這里我們需要用一個工具WinSCP,把我們已經(jīng)下載的httpd-2.4.27.tar.bz2上傳至CentOS 7虛擬機(jī)里。
使用XShell/CRT遠(yuǎn)程連接時,直接使用rz命令向Centos系統(tǒng)上傳文件第一步:配置WinSCP客戶端,連接到CentOS 7
第二步:找到你下載在windows系統(tǒng)下的源碼包,復(fù)制進(jìn)CentOS 7系統(tǒng)里,在linux中,有一個專門放置源碼包的目錄 /usr/local/src/,推薦源碼包統(tǒng)一放置在此文件夾
第三步:在CentOS 7中檢查是否上傳完成
[root@centos7 ~]#cd /usr/local/src/
[root@centos7 /usr/local/src]#ll
total 6376
-rw-r--r--. 1 root root 6527394 Jul 31 09:55 httpd-2.4.27.tar.bz2
第四步:用tar命令解壓已上傳的httpd源碼包,在這里已經(jīng)可以看到解壓后的httpd-2.4.27文件夾
[root@centos7 /usr/local/src]#tar xvf httpd-2.4.27.tar.bz2
httpd-2.4.27/
httpd-2.4.27/.deps
httpd-2.4.27/.gdbinit
httpd-2.4.27/ABOUT_APACHE
httpd-2.4.27/acinclude.m4
httpd-2.4.27/ap.d
httpd-2.4.27/Apache-apr2.dsw
......
[root@centos7 /usr/local/src]#ll
total 6380
drwxr-xr-x. 11 501 games 4096 Jul 7 01:38 httpd-2.4.27
-rw-r--r--. 1 root root 6527394 Jul 31 09:55 httpd-2.4.27.tar.bz2
看說明
cat README 查看使用說明(由于文件過大,截取部分展示)
[root@centos7 /usr/local/src/httpd-2.4.27]#cat README
Apache HTTP Server
What is it?
-----------
The Apache HTTP Server is a powerful and flexible HTTP/1.1 compliant
web server. Originally designed as a replacement for the NCSA HTTP
Server, it has grown to be the most popular web server on the
Internet. As a project of the Apache Software Foundation, the
developers aim to collaboratively develop and maintain a robust,
commercial-grade, standards-based server with freely available
source code.
The Latest Version
------------------
Details of the latest version can be found on the Apache HTTP
server project page under http://httpd.apache.org/.
Documentation
-------------
The documentation available as of the date of this release is
included in HTML format in the docs/manual/ directory. The most
up-to-date documentation can be found at
http://httpd.apache.org/docs/2.4/.
......
cat INSTALL 查看安裝信息(由于文件過大,截取部分展示)
[root@centos7 /usr/local/src/httpd-2.4.27]#cat INSTALL
APACHE INSTALLATION OVERVIEW
Quick Start - Unix
------------------
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
NOTES: * Replace PREFIX with the filesystem path under which
Apache should be installed. A typical installation
might use "/usr/local/apache2" for PREFIX (without the
quotes).
* Consider if you want to use a previously installed APR and
APR-Util (such as those provided with many OSes) or if you
need to use the APR and APR-Util from the apr.apache.org
project. If the latter, download the latest versions and
unpack them to ./srclib/apr and ./srclib/apr-util (no
version numbers in the directory names) and use
./configure's --with-included-apr option. This is required
if you don't have the compiler which the system APR was
built with. It can also be advantageous if you are a
developer who will be linking your code with Apache or using
a debugger to step through server code, as it removes the
possibility of version or compile-option mismatches with APR
and APR-Util code. As a convenience, prepackaged source-code
bundles of APR and APR-Util are occasionally also provided
as a httpd-2.X.X-deps.tar.gz download.
......
生成Makefile文件并安裝
執(zhí)行configure文件,定義安裝位置為/app/httpd24,開啟動態(tài)鏈接功能,開啟ssl模塊。執(zhí)行命令./configure --prefix=/app/httpd24 --enable-so --with-ssl
[root@centos7 /usr/local/src/httpd-2.4.27]#./configure --prefix=/app/httpd24 --enable-so --with-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... -std=gnu99
checking for pcre-config... /usr/bin/pcre-config
configure: Using external PCRE library from /usr/bin/pcre-config
setting PCRE_INCLUDES to ""
setting PCRE_LIBS to "-lpcre"
configure:
configure: Configuring Apache httpd...
......
執(zhí)行make命令,編譯二進(jìn)制文件,這是一個漫長的過程,等待完成即可。接著執(zhí)行make install安裝
[root@centos7 /usr/local/src/httpd-2.4.27]#make install
Making install in srclib
make[1]: Entering directory `/usr/local/src/httpd-2.4.27/srclib'
make[2]: Entering directory `/usr/local/src/httpd-2.4.27/srclib'
make[2]: Leaving directory `/usr/local/src/httpd-2.4.27/srclib'
make[1]: Leaving directory `/usr/local/src/httpd-2.4.27/srclib'
Making install in os
make[1]: Entering directory `/usr/local/src/httpd-2.4.27/os'
Making install in unix
make[2]: Entering directory `/usr/local/src/httpd-2.4.27/os/unix'
make[3]: Entering directory `/usr/local/src/httpd-2.4.27/os/unix'
make[3]: Leaving directory `/usr/local/src/httpd-2.4.27/os/unix'
make[2]: Leaving directory `/usr/local/src/httpd-2.4.27/os/unix'
make[2]: Entering directory `/usr/local/src/httpd-2.4.27/os'
make[2]: Leaving directory `/usr/local/src/httpd-2.4.27/os'
make[1]: Leaving directory `/usr/local/src/httpd-2.4.27/os'
Making install in server
make[1]: Entering directory `/usr/local/src/httpd-2.4.27/server'
Making install in mpm
make[2]: Entering directory `/usr/local/src/httpd-2.4.27/server/mpm'
Making install in worker
......
更改系統(tǒng)配置
更改配置文件,永久關(guān)閉selinux
[root@centos7 /app/httpd24]#vim /etc/selinux/config
修改文件SELINUX=permission
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=permission
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
systemctl stop firewalld 暫停防火墻
systemctl disable firewalld 取消防火墻開機(jī)自啟動
[root@centos7 /app/httpd24]#systemctl stop firewalld
[root@centos7 /app/httpd24]#systemctl disable firewalld
配置path變量
進(jìn)入安裝目錄
[root@centos7 /usr/local/src/httpd-2.4.27]#cd /app/httpd24/
設(shè)置變量腳本
[root@centos7 /app/httpd24]#echo 'export PATH=/app/httpd22/bin:$PATH' > /etc/profile.d/httpd24.sh
檢查腳本生成
[root@centos7 /app/httpd24]#cat /etc/profile.d/httpd24.sh
export PATH=/app/httpd22/bin:$PATH
運(yùn)行腳本
[root@centos7 /app/httpd24]#. /etc/profile.d/httpd24.sh
查看變量
[root@centos7 /app/httpd24]#echo $PATH
/app/httpd22/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
啟動apache
[root@centos7 /app/httpd24]#apachectl
檢查端口開放情況,80端口開啟即為正常
[root@centos7 /app/httpd24]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 *:3306 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
在瀏覽器中輸入本機(jī)ip,即可進(jìn)入主機(jī)網(wǎng)頁
安裝流程結(jié)束