YUM及源码包编译安装

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

概述:


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

YUM概述

CentOS可用的前端工具:yum, dnf

YUM:

  • YUM:(Yellow dogUpdate Modifier),rpm的前端程序,用来解决软件包相关依赖性,可以在多个库之间定位软件包,up2date的替代工具;

注意:

  • yum并不是rpm的取代者,只是rpm包管理器的前端工具,是依赖于rpm包管理器的,使用yum来解决安装问题,使用rpm来查询等

yum repository(仓库): yum repo

  • 仓库中存储了众多rpm包,以及包的相关的元数据文件(元数据文件放置于特定目录下:repodata

  • repodata目录所在的位置就是仓库所指向的路径;

  • 默认安装情况下,光盘即为本地仓库。

yum支持的文件服务器(仓库本身也是一个文件服务器)

YUM客户端的配置


 1.yum配置文件

yum客户端配置文件:

  • /etc/yum.conf:主配置文件,为所有仓库提供公共配置

  • /etc/yum.repos.d/*.repo:为仓库的指向提供配置

演示:

# 首先确保本地是否安装yum工具
[root@centos7 ~]# rpm -q yum
yum-3.4.3-132.el7.centos.0.1.noarch

# 查看配置文件
[root@centos7 ~]# rpm -qc yum
/etc/logrotate.d/yum
/etc/yum.conf
/etc/yum/version-groups.conf
# yum 的主配置文件
[root@centos7 ~]# cat /etc/yum.conf 
[main]  # 为所有仓库提供主配置
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release


#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d  自己定义仓库的位置在 /etc/yum.repos.d/ 下 *.repo 的文件

 2.仓库指向的定义(具体可以 man yum.conf)

格式如下:

[repositoryID]

name=Some name for this repository:

  • 当前仓库描述信息

baseurl=url://path/to/repository/ :

  • 指明访问路径:通常为一个文件服务器上输出的某repository

enabled={1|0}:

  • 是否启用仓库,默认是启用的

gpgcheck={1|0}: 

  • 是否对程序包做校验(完整性和来源合法性)

gpgkey=URL  

enablegroups={1|0}

failovermethod={roundrobin(轮循)|priority(指明优先级)}:

  • 故障转移方法,

  • 默认为:roundrobin,意为随机挑选;

cost= 默认为1000 (成本值)

 3.创建自定义yum仓库

创建自定义yum仓库

  • 在 /etc/yum.repos.d 下定义yum仓库;

  • 使用 yum repolist 来查看所有的仓库列表

演示:

[root@centos7 yum.repos.d]# pwd
/etc/yum.repos.d

[root@centos7 yum.repos.d]# vim CentOS-aliyu.repo 
[bash]
name=Base Repo 
baseurl=http://mirrors.aliyun.com/centos/7/os/x86_64/
gpgcheck=0
enabled=1

[epel]
name=Fedora-epel/7/x86_64
baseurl=http://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0
enabled=1

# 列出所有可用仓库,第一次使用会下载元数据
[root@centos7 yum.repos.d]# yum repolist
已加载插件:fastestmirror, langpacks
bash                                                                                                                                            | 3.6 kB  00:00:00     
epel                                                                                                                                            | 4.3 kB  00:00:00     
(1/7): CDROM/group_gz                                                                                                                           | 155 kB  00:00:00     
(2/7): CDROM/primary_db                                                                                                                         | 5.3 MB  00:00:01     
(3/7): epel/group_gz                                                                                                                            | 170 kB  00:00:01     
(4/7): bash/group_gz                                                                                                                            | 155 kB  00:00:03     
(5/7): epel/updateinfo                                                                                                                          | 743 kB  00:00:05     
(6/7): bash/primary_db                                                                                                                          | 5.6 MB  00:00:25     
(7/7): epel/primary_db                                                                                                                          | 4.5 MB  00:00:27     
Determining fastest mirrors
源标识                                                                   源名称                                                                                  状态
bash                                                                     Base Repo                                                                                9,363
epel                                                                     Fedora-epel/7/x86_64                                                                    11,263
repolist: 29,633

YUM命令详解

 1.yum命令的用法

语法:

  • yum [options] [command] [package ...]

显示仓库列表

  • yum repolist [all|enabled|disabled]:显示所有,启用和禁用的;

显示程序包:

  • yum list [all | glob_exp1] [glob_exp2] [...] :支持使用glob风格的通配

  • yum list {available|installed|updates} [glob_exp1] 通配符

安装程序包

  • yum install package1 [package2] [...];

  • yum reinstall package1 [package2] [...]  (重新安装)

升级程序包

  • yum update [package1] [package2] [...]

  • yum downgrade package1 [package2] [...] (降级)

检查可用升级:

  • yum check-update

卸载程序包

  • yum remove | erase package1 [package2] [...]

查看程序包简要信息information:

  • yum info [...]

查看指定的特性(可以是某文件)是由哪个程序包所提供

  • yum  provides | whatprovides feature1 [feature2] [...]

清理本地缓存

  • yum clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]

构建缓存

  • yum makecache

搜索

  • yum search string1 [string2] [...]

  • 以指定的关键字搜索程序包名及summary(总结,概括)信息

查看指定包所依赖的capabilities(依赖关系分析)

  • yum deplist package1 [package2] [...]

查看yum事务历史

  • yum history [info|list|packages-list|packages-info||redo|undo|rollback|new|sync|stats]

安装及升级本地程序包

  • * localinstall rpmfile1 [rpmfile2] [...]   (用install替代)

  • * localupdate rpmfile1 [rpmfile2] [...]  (用update替代)

日志位置:

  • /var/log/yum.log

包组管理的相关命令:

  • yum groupinstall group1 [group2] [...]

  • yum groupupdate group1 [group2] [...]

  • yum grouplist [hidden] [groupwildcard] [...]:列出所有包组

  • yum groupremove group1 [group2] [...]:卸载

  • yum groupinfo group1 [...]:显示指定包组详情

 2.yum命令行选项

yum命令行选项

  • --nogpgcheck:禁止进行gpgcheck

  • -y:自动回答为“yes”

  • -q:静默模式

  • --disablerepo=repoidglob:临时禁用此处指定的repo

  • --enablerepo=repoidglob:临时启用此处指定的repo

  • --noplugins:禁用所有插件

演示:

 1.显示库列表

[root@centos7 ~]# yum repolist all
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识                                                                源名称                                                                               状态
CDROM                                                                 CentOS 7 Release 7.2                                                                 启用:  9,007
bash                                                                  Base Repo                                                                            启用:  9,363
epel                                                                  Fedora-epel/7/x86_64                                                                 启用: 11,263

2.查看程序包简要信息

[root@centos7 ~]# yum info httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
已安装的软件包
名称    :httpd
架构    :x86_64
版本    :2.4.6
发布    :40.el7.centos
大小    :9.4 M
源    :installed
来自源:CDROM
简介    : Apache HTTP Server
网址    :http://httpd.apache.org/
协议    : ASL 2.0
描述    : The Apache HTTP Server is a powerful, efficient, and extensible
         : web server.

可安装的软件包
名称    :httpd
架构    :x86_64
版本    :2.4.6
发布    :45.el7.centos
大小    :2.7 M
源    :bash
简介    : Apache HTTP Server
网址    :http://httpd.apache.org/
协议    : ASL 2.0
描述    : The Apache HTTP Server is a powerful, efficient, and extensible
         : web server.

3.查看指定的特性(可以是某文件)是由哪个程序包所提供

[root@centos7 ~]# yum provides httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
httpd-2.4.6-40.el7.centos.x86_64 : Apache HTTP Server
源    :CDROM



httpd-2.4.6-45.el7.centos.x86_64 : Apache HTTP Server
源    :bash



httpd-2.4.6-40.el7.centos.x86_64 : Apache HTTP Server
源    :@CDROM

4.查看指定包所依赖的capabilities(依赖关系分析)

[root@centos7 ~]# yum deplist httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包:httpd.x86_64 2.4.6-45.el7.centos
   依赖:/bin/sh
   provider: bash.x86_64 4.2.46-20.el7_2
   依赖:/etc/mime.types
   provider: mailcap.noarch 2.1.41-2.el7
   依赖:/usr/sbin/groupadd
   provider: shadow-utils.x86_64 2:4.1.5.1-24.el7
   依赖:/usr/sbin/useradd
   provider: shadow-utils.x86_64 2:4.1.5.1-24.el7
   依赖:httpd-tools = 2.4.6-45.el7.centos
   provider: httpd-tools.x86_64 2.4.6-45.el7.centos
   依赖:libapr-1.so.0()(64bit)
   provider: apr.x86_64 1.4.8-3.el7
   依赖:libaprutil-1.so.0()(64bit)
   provider: apr-util.x86_64 1.5.2-6.el7
   依赖:libc.so.6(GLIBC_2.14)(64bit)
   provider: glibc.x86_64 2.17-157.el7
   依赖:libcrypt.so.1()(64bit)
   provider: glibc.x86_64 2.17-157.el7
   依赖:libdb-5.3.so()(64bit)
   provider: libdb.x86_64 5.3.21-19.el7
   依赖:libdl.so.2()(64bit)
   provider: glibc.x86_64 2.17-157.el7
   依赖:libexpat.so.1()(64bit)
   provider: expat.x86_64 2.1.0-8.el7
   依赖:liblua-5.1.so()(64bit)
   provider: lua.x86_64 5.1.4-15.el7
   依赖:libm.so.6()(64bit)
   provider: glibc.x86_64 2.17-157.el7
   依赖:libpcre.so.1()(64bit)
   provider: pcre.x86_64 8.32-15.el7_2.1
   依赖:libpthread.so.0()(64bit)
   provider: glibc.x86_64 2.17-157.el7
   依赖:systemd-units
   provider: systemd.x86_64 219-30.el7

5.查看yum事务历史

[root@centos7 ~]# yum history
已加载插件:fastestmirror, langpacks
ID     | 命令行                   | 日期和时间       | 操作           | 变更数 
-------------------------------------------------------------------------------
    23 | install tree -y          | 2017-02-25 18:32 | Install        |    1   
    22 | remove tree              | 2017-02-25 18:31 | Erase          |    1   
    21 | install patch            | 2017-02-12 12:01 | Install        |    1   
    20 | install finger           | 2017-02-10 16:18 | Install        |    1   
    19 | install -y tomcat tomcat | 2016-12-16 16:27 | Install        |   25   
    18 | install php-fpm -y       | 2016-12-12 14:45 | Install        |    1   
    17 | remove php               | 2016-12-12 14:33 | Erase          |    1   
    16 | install java-1.8.0-openj | 2016-12-11 21:44 | Install        |   10   
    15 | install /root/MHA/mha4my | 2016-12-09 14:38 | Install        |    1   
    14 | install pacemaker -y     | 2016-12-07 15:18 | Install        |    8   
    13 | install firefox -y       | 2016-11-22 15:11 | Install        |    2   
    12 | install zabbix-proxy-mys | 2016-11-16 21:24 | Install        |    5   
    11 | install net-snmp net-snm | 2016-11-16 20:06 | Install        |    2   
    10 | install ./zabbix-agent-3 | 2016-11-13 10:33 | Install        |    3   
     9 | -d 2 -y install memcache | 2016-11-12 11:12 | Install        |    1   
     8 | install keepalived -y    | 2016-11-06 15:52 | Install        |    3   
     7 | install ./nginx-1.10.0-1 | 2016-11-06 13:16 | Install        |    1 EE
     6 | install telnet-server    | 2016-11-06 13:09 | Install        |    1   
     5 | install vsftpd           | 2016-11-06 13:09 | Install        |    1   
     4 | install php php-mysql ph | 2016-11-06 13:08 | Install        |    9   
history list

如何使用光盘当做本地yum仓库

操作步骤

1.挂载光盘至某目录,例如/media/cdrom

  • # mount /dev/cdrom /media/cdrom

注意:

  • 因为我们是手动挂载,所以机器一重启,就会丢失。CentOS6 可以挂载到 /misc/cd 中,开机自动挂载,(centos 可以启用 autofs 服务,并设为开机自启,就可以自动挂载了)

2. 创建配置文件

演示:

# 启动 autofs 自动挂载服务,并且设置为开机自启
[root@centos7 ~]# systemctl start autofs   
[root@centos7 ~]# systemctl enable Cutofs

[root@centos7 ~]# systemctl status autofs
● autofs.service - Automounts filesystems on demand
   Loaded: loaded (/usr/lib/systemd/system/autofs.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2017-02-25 10:03:55 CST; 11h ago
  Process: 1045 ExecStart=/usr/sbin/automount $OPTIONS --pid-file /run/autofs.pid (code=exited, status=0/SUCCESS)
 Main PID: 1061 (automount)
   CGroup: /system.slice/autofs.service
           └─1061 /usr/sbin/automount --pid-file /run/autofs.pid

2月 25 10:03:53 centos7 systemd[1]: Starting Automounts filesystems on demand...
2月 25 10:03:55 centos7 systemd[1]: Started Automounts filesystems on demand.

# 可以看到 repodata 仓库
[root@centos7 ~]# cd /misc/cd
[root@centos7 cd]# ls
CentOS_BuildTag  EFI  EULA  GPL  p_w_picpaths  isolinux  LiveOS  Packages  repodata  RPM-GPG-KEY-CentOS-7  RPM-GPG-KEY-CentOS-Testing-7  TRANS.TBL

# 创建配置文件即可
[root@centos7 ~]# vim /etc/yum.repos.d/CentOS-local.repo 
[CDROM]
name=CentOS 7 Release 7.2
baseurl=file:///misc/cd
gpgcheck=0

yum的repo配置文件中的可用变量如何创建yum仓库

 1.yum的repo配置文件中可用的变量:

作用:

  • yum有一些内置变量,这些变量可以自动获取当前平台的相关信息;

可用变量

  • $releasever:当前OS的发行版的主版本号;

  • $arch平台,i386,i486,i586,x86_64等;

  • $basearch础平台;i386

  • $YUM0-$YUM9:自定义变量

示例:

 2.创建yum仓库:

      如果你作为一个企业的管理员,为了方便公司内部网络中的服务器安装软件,同时,也节省网络带宽,此时就在公司内部创建一个yum仓库。

语法:

  • createrepo [options] <directory>

创建步骤:

1.在基于发行版的安装树安装 createrepo 程序;

2.确定 repository 的输出方式:

   1)本地输出:提供一个放置 rpm 包的本地路径;file 的形式

   2)网络输出:提供一个文件服务器,配置好 ftp 服务或者 http 服务;

ftp 服务:

  • 安装程序包:vsftpd

  • 文件存放位置:/var/ftp/pub

  • 启动服务:service vsftpd start

http服务:

  • 安装程序包:httpd

  • 文件存放位置:/var/www/html

  • 启动服务:service httpd start

3.在准备好的目录中放置 rpm 程序包文件;

  • 可以通过 cp 命令将光盘中的程序包拷贝到以上输出目录当中;

4.对此目录运行 createrepo 命令即可;

5.测试所创建的 yum 仓库是否可用;

演示:

1.查看系统是否安装 createrepo 程序

[root@centos7 ~]# rpm -q createrepo
createrepo-0.9.9-23.el7.noarch

2.这里我以本地输出的方式创建 yum 仓库

[root@centos7 ~]# mkdir -pv /yum/repo
mkdir: 已创建目录 "/yum"
mkdir: 已创建目录 "/yum/repo"

[root@centos7 repo]# pwd
/yum/repo

# 复制 rpm 包
[root@centos7 repo]# ls
mha4mysql-node-0.56-0.el6.noarch.rpm  nginx-1.10.0-1.el7.ngx.x86_64.rpm  zabbix-agent-3.0.2-1.el7.x86_64.rpm  zabbix-sender-3.0.2-1.el7.x86_64.rpm

3.对此目录执行 createrepo 命令

[root@centos7 ~]# createrepo /yum/repo/
Spawning worker 0 with 4 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

[root@centos7 ~]# ll /yum/repo/
总用量 1244
-rw-r--r-- 1 root root  36326 2月  25 22:28 mha4mysql-node-0.56-0.el6.noarch.rpm
-rw-r--r-- 1 root root 655648 2月  25 22:27 nginx-1.10.0-1.el7.ngx.x86_64.rpm
drwxr-xr-x 2 root root   4096 2月  25 22:31 repodata
-rw-r--r-- 1 root root 329304 2月  25 22:29 zabbix-agent-3.0.2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 239024 2月  25 22:29 zabbix-sender-3.0.2-1.el7.x86_64.rpm

[root@centos7 ~]# ll /yum/repo/repodata/
总用量 32
-rw-r--r-- 1 root root 2481 2月  25 22:31 9286a9eebd089c0dab0e08a07b8b375da9c68ccd7308b1292baef4e679476f97-filelists.sqlite.bz2
-rw-r--r-- 1 root root 1300 2月  25 22:31 ab119e8fff8cc3cb0346eb296e1b5905f0b92bcdcb0cd03a38a9a025cdd722f6-other.xml.gz
-rw-r--r-- 1 root root 5452 2月  25 22:31 b4c297ac89a0e083d6733df05075ec146d87808672249bad4f5dfed4f28603d5-primary.sqlite.bz2
-rw-r--r-- 1 root root 2474 2月  25 22:31 c932b98a9102af9e173eda396ddc8b665b99ea786cdfc6493cd323a9965e4eeb-other.sqlite.bz2
-rw-r--r-- 1 root root 2122 2月  25 22:31 d1dfcb2b3995b3c2bf60dd58b70f2b8739ae8e2a0e40bf0aa0a63f99813a46f5-primary.xml.gz
-rw-r--r-- 1 root root 1088 2月  25 22:31 ef734b3c694f186378e7a62e9163236321d1bfdbc5c936a19b864b7f7ef754a6-filelists.xml.gz
-rw-r--r-- 1 root root 2972 2月  25 22:31 repomd.xml

程序包源代码编译安装

 1.介绍

编译安装:

Application-VERSION-release.src.rpm--> 安装后,使用 rpmbuild 命令制作成二进制格式的rpm包,而后再安装;

源代码-->预处理-->编译(gcc)-->汇编-->链接-->执行

源代码组织格式:

  • 多文件:文件中的代码之间,很可能存在跨文件依赖关系;

  • C、C++:make (项目管理器,configure --> Makefile.in --> makefile);

  • java:maven

 2.编译安装的三步骤、开发工具、源代码获取及编译环境

三步骤

1./configure:

  • 通过选项传递参数,指定启用特性、安装路径等;执行时会参考用户的指定以及makefile.in文件生成makefile;

  • 检查依赖到的外部环境;

2.make

  • 根据makefile文件,构建应用程序;

3.make install

  • 复制文件到相应路径

开发工具

  • autoconf:生成configure脚本

  • automake:生成Makefile.in

注意:

  • 安装前查看INSTALL,README

开源程序源代码的获取:

官方自建站点:

  • apache.org (ASF)

  • mariadb.org

    ...

代码托管:

  • SourceForge.net

  • Github.com

  • code.google.com

c/c++编译器: 

  • gcc(GNU C Complier)

编译C源代码:

前提:提供开发工具及开发环境

  • 开发工具:make, gcc等

  • 开发环境:开发库,头文件

  • glibc:标准库

通过“包组”提供开发组件

  • CentOS 6:"Development Tools", "Server Platform Development

  • CentOS 7:"Development Tools"

 3.源码包的编译和安装步骤详解:

第一步:configure脚本

  • 选项:指定安装位置、指定启用的特性

  • --help:获取其支持使用的选项

选项分类

安装路径设定:

  • --prefix=/PATH:指定默认安装位置,默认为/usr/local/

  • --sysconfdir=/PATH:配置文件安装位置

  • System types:支持交叉编译

Optional Features:可选特性

  • --disable-FEATURE

  • --enable-FEATURE[=ARG]

Optional Packages:可选包

  • --with-PACKAGE[=ARG],依赖包

  • --without-PACKAGE,禁用依赖关系

第二步:make

第三步:make install


  4.安装后的配置:

二进制程序目录导入至PATH环境变量中:

  • 编辑文件/etc/profile.d/NAME.sh

  • export PATH=/PATH/TO/BIN:$PATH

导入库文件路径

  • 编辑/etc/ld.so.conf.d/NAME.conf:添加新的库文件所在目录至此文件中;

  • 让系统重新生成缓存:ldconfig [-v]

导入头文件

  • 基于链接的方式实现:

  • ln -sv

导入帮助手册

  • 编辑/etc/man.config|man_db.conf文件,添加一个MANPATH

案例:

  编译安装apache 2.2源码包,并启动此服务

 步骤如下:

 1.首先获取源代码,下载到当前主机,并展开归档压缩文件。

[root@CentOS6 Downloads]# ls
httpd-2.2.29.tar.bz2

# 展开归档压缩文件,并进入展开的目录中,可以看到目录中的文件
[root@CentOS6 Downloads]# tar xf httpd-2.2.29.tar.bz2 
[root@CentOS6 Downloads]# ls
httpd-2.2.29  httpd-2.2.29.tar.bz2

[root@CentOS6 Downloads]# cd httpd-2.2.29
[root@CentOS6 httpd-2.2.29]# ls
ABOUT_APACHE  BuildAll.dsp  config.layout  emacs-style  httpd.spec      LAYOUT        LICENSE       NOTICE         README.platforms  srclib
acinclude.m4  BuildBin.dsp  configure      httpd.dep    include         libhttpd.dep  Makefile.in   NWGNUmakefile  README-win32.txt  support
Apache.dsw    buildconf     configure.in   httpd.dsp    INSTALL         libhttpd.dsp  Makefile.win  os             ROADMAP           test
build         CHANGES       docs           httpd.mak    InstallBin.dsp  libhttpd.mak  modules       README         server            VERSIONING

 2.进到目录当中,可以看到有configure脚本,是可执行的,但不要着急执行,先看一下安装的说明,及步骤,INSTALL,README和configure脚本帮助文档;


# 查看 INSTALL 文档
[root@CentOS6 httpd-2.2.29]# less INSTALL
  APACHE INSTALLATION OVERVIEW

  Quick Start - Unix
  ------------------

  For complete installation documentation, see [ht]docs/manual/install.html or
  http://httpd.apache.org/docs/2.2/install.html

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

# 查看 configure 的帮助文档    
[root@CentOS6 httpd-2.2.29]# ./configure --help
`configure' configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local/apache2]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]



3.安装

  1)准备开发环境,执行configure脚本,并指定安装路径等;


# 准备开发环境,安装包组
[root@CentOS6 httpd-2.2.29]# yum groupinstall Development tools -y
[root@CentOS6 httpd-2.2.29]# yum groupinstall Server Platform Development -y

# 执行 configure 脚本,并指明安装路径,默认所有文件都安装到 /usr/local/apache2 目录下
[root@CentOS6 apache2]# ./configure --prefix=/usr/local/apache2

 2)第二步,执行make

 3)第三步,执行make install 生成目录,并查看,指定的安装路径下是否有目录生成;

# 进入指定安装的目录中
[root@CentOS6 httpd-2.2.29]# cd /usr/local/apache2/

# 可以看到生成的文件(二进制文件bin,配置文件conf,库文件lib,头文件include等...)
[root@CentOS6 apache2]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules

# 查看二进制文件,可以看到 httpd 和 apachectl 启动脚本文件
[root@CentOS6 apache2]# ls bin
ab         apr-1-config  apxs      dbmmanage  envvars-std   htdbm     htpasswd  httxt2dbm   rotatelogs
apachectl  apu-1-config  checkgid  envvars    htcacheclean  htdigest  httpd     logresolve

# 查看配置文件
[root@CentOS6 apache2]# ls conf/
extra  httpd.conf  magic  mime.types  original

 4.安装后的配置   

   1)二进制程序目录导入至PATH环境变量中,并为配置文件创建软连接

# 为配置文件创建软连接,注意要使用绝对路径
[root@CentOS6 apache2]# ln -s /usr/local/apache2/conf/ /etc/httpd2
[root@CentOS6 apache2]# ll /etc/httpd2
lrwxrwxrwx 1 root root 24 Feb 26 10:39 /etc/httpd2 -> /usr/local/apache2/conf/

# 将二进制程序导入 PATH环境变量中
[root@CentOS6 apache2]# vim /etc/profile.d/httpd2.sh
PATH=/usr/local/apache2/bin:$PATH

# 重读配置文件,并查看环境变量是否导入成功
[root@CentOS6 apache2]# . /etc/profile.d/httpd2.sh
[root@CentOS6 apache2]# echo $PATH
/usr/local/apache2/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

 2)导入帮助手册。编辑/etc/man.config|man_db.conf文件,添加一个MANPATH;

wKioL1iySVORYMR_AAAp3pQbaTg822.png

3)导入库文件路径,编辑/etc/ld.so.conf.d/NAME.conf,添加新的库文件所在目录至此文件中,让系统重新生成缓存

[root@CentOS6 apache2]# vim /etc/ld.so.conf.d/httpd2.conf
 /usr/local/apache2/lib

# 让系统重新生成缓存
[root@CentOS6 apache2]# ldconfig -v
/usr/local/apache2/lib:
	libapr-1.so.0 -> libapr-1.so.0.5.1
	libaprutil-1.so.0 -> libaprutil-1.so.0.5.3
	libexpat.so.0 -> libexpat.so.0.5.0
/usr/lib64/mysql:
	libmysqlclient.so.16 -> libmysqlclient.so.16.0.0
	libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0
/usr/lib64/qt-3.3/lib:
	libqui.so.1 -> libqui.so.1.0.0
	libqt-mt.so.3 -> libqt-mt.so.3.3.8
/usr/lib64/xulrunner:
	libxpcom.so -> libxpcom.so
	libmozalloc.so -> libmozalloc.so
	libmozsqlite3.so -> libmozsqlite3.so
	libxul.so -> libxul.so
/lib:
/lib64:

  4)导入头文件,基于为目录创建符号链接的方式实现:

[root@CentOS6 apache2]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules

# 创建软链接
[root@CentOS6 apache2]# ln -sv /usr/local/apache2/include/  /usr/include/httpd2
`/usr/include/httpd2' -> `/usr/local/apache2/include/'

[root@CentOS6 apache2]# ll /usr/include/httpd2
lrwxrwxrwx 1 root root 27 Feb 26 11:12 /usr/include/httpd2 -> /usr/local/apache2/include/

  5.测试可否连接访问,查看80口是否监听

# 启动服务,查看 80 端口是否正常监听
[root@CentOS6 ~]# apachectl start

[root@CentOS6 ~]# netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:60690               0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:6010              0.0.0.0:*                   LISTEN      
tcp        0      0 :::111                      :::*                        LISTEN      
tcp        0      0 :::80                       :::*                        LISTEN      
tcp        0      0 :::43346                    :::*                        LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:631                     :::*                        LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN      
tcp        0      0 ::1:6010                    :::*                        LISTEN

 访问王页如下:

wKiom1iySqzhcQk4AAA7nIp29LE180.png