天天看点

linux下源码软件包的安装

我们在使用linux做服务器的时候,因为linux自带的软件包都有些老,不是最新的,但是有时候我们为了使用最新的软件,会使用最新的软件的源码来进行安装。

所以我们需要用心去做了...

在我们拿到一个软件的源码时,源码一般都是使用tar.gz或tar.bz2结尾。

源码--》配置文件(./configure)--》编译(makefile)--》(可执行 头文件 库文件 手册)--》安装

对于源码的安装,我们说西安要确定机器安装了编译环境

使用yum  grouplist |less 查看是否安装了

Develoment Libraries 和Develoment Tools开发环境,如果没有,

请先安装,否则没法源码安装

那我们首先要对源码进行包的拆解

tar -zxvf 源码 -C /usr/local/src/(对源码包解压到一个路径,/usr/local/src/是系统给我们用来存放源码拆解后的文件路径)

源码解压后我们就可以对源码安装了。

源码文件解压后进入拆解后的文件,一般会看到很多个文件夹或文件,其中有一个INSTALL文件或README文件,以及配置文件这是我们安装前必看的说明书

我们一安装apache服务为例做个实验。

安装前先把源码下载到机器里,进入所在目录

<a href="http://blog.51cto.com/attachment/201307/232450669.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201307/232450405.png" target="_blank"></a>

进入apsche拆解后的目录

<a href="http://blog.51cto.com/attachment/201307/232450849.png" target="_blank"></a>

我们看到一个INSTALL文件,查看一下

<a href="http://blog.51cto.com/attachment/201307/232450693.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201307/232451375.png" target="_blank"></a>

我们要查看一下configure的使用说明

<a href="http://blog.51cto.com/attachment/201307/232451304.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201307/232452848.png" target="_blank"></a>

接下来开始配置安装apache

<a href="http://blog.51cto.com/attachment/201307/232452868.png" target="_blank"></a>

报错了,我们来看啊可能否安装了apr

<a href="http://blog.51cto.com/attachment/201307/232452695.png" target="_blank"></a>

我们装了apr,但是有的调用的文件并不都在apr里,有的在apr-devel里,我们去在安装看下,

<a href="http://blog.51cto.com/attachment/201307/232453776.png" target="_blank"></a>

然后我们再次执行apache的安装

<a href="http://blog.51cto.com/attachment/201307/232453283.png" target="_blank"></a>

这次有报错了,但是说的明确了,说我们的apr的版本太低了,那我们重新安装

我们把apr新版的拆解到/usr/local 下

<a href="http://blog.51cto.com/attachment/201307/232453956.png" target="_blank"></a>

我们安装apr包和apr-util包

<a href="http://blog.51cto.com/attachment/201307/232453865.png" target="_blank"></a>

我们会看到生成了很多的makefile文件,那我们直接make

<a href="http://blog.51cto.com/attachment/201307/232454949.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201307/232454819.png" target="_blank"></a>

安装后我们进入apr文件内,因为apache要调用他的库,可是apr是我们自己安装的,不是默认的路径,所以我们要对apr库进行连接处理,使apache可以调用

<a href="http://blog.51cto.com/attachment/201307/232454906.png" target="_blank"></a>

那么我没呢可以简单些直接建立一个系统可是识别的文件,这样可以避免对所有的库文件做链接

<a href="http://blog.51cto.com/attachment/201307/232454267.png" target="_blank"></a>

建立apr.conf文件,把apr的库路径加入进去就ok!

然后我们要更新缓存,在查看是否成功

<a href="http://blog.51cto.com/attachment/201307/232454581.png" target="_blank"></a>

接着安装apr-util

<a href="http://blog.51cto.com/attachment/201307/232455695.png" target="_blank"></a>

然后make和make install

<a href="http://blog.51cto.com/attachment/201307/232455876.png" target="_blank"></a>

现在apr的问题已经解决了,那我们重新安装apache

<a href="http://blog.51cto.com/attachment/201307/232455195.png" target="_blank"></a>

但是还是报错 ,说我们缺少apr-1-config ,那我们在说明一次,添加他的路径

<a href="http://blog.51cto.com/attachment/201307/232455704.png" target="_blank"></a>

为了避免麻烦,我们再次查询一下所有与apr相关的配置 ,全部带上

<a href="http://blog.51cto.com/attachment/201307/232455388.png" target="_blank"></a>

找到后,我们再次重新安装

<a href="http://blog.51cto.com/attachment/201307/232455348.png" target="_blank"></a>

但是又报错了。说我们的pcre没有找到

<a href="http://blog.51cto.com/attachment/201307/232457360.png" target="_blank"></a>

我们来解决他,安装prec

<a href="http://blog.51cto.com/attachment/201307/232457948.png" target="_blank"></a>

我们再来安装apache的源码

没有报错,安装成功,生成了很多的makefile文件

那我们就安装apache  make &amp;&amp; make install

<a href="http://blog.51cto.com/attachment/201307/232457921.png" target="_blank"></a>

到此,我们的apache就是安装完成了

我们看到了,源码的安装很复杂,而且很容易出错,我们需要做很多的调试

在我们安装完成后,但是不完美,没法开机自动启动

没关系,我们来帮他,手动启动或自动启动

进入/usr/local/apache/bin 目录下

<a href="http://blog.51cto.com/attachment/201307/232458168.png" target="_blank"></a>

我们只需要在命令行下输入 ./httpd -f /usr/local/apache/http.conf 就可以启动,但是不是很完美,我们可以给他写一个启动脚本

一般的服务的脚本放在rtc/init.d/目录下,我们就去这里写apache服务脚本

脚本如下:(个人写的,有些简陋,请见谅)

#!/bin/bash

prog=/usr/local/apache/bin/httpd

configfile=/etc/apache/httpd.conf

lockfile=/var/lock/subsys/httpd

. /etc/init.d/functions

start() {

  if [ -e $lockfile ];then

     echo "The program `basename $prog` is started!"

  else

     echo "The program `basename $prog` is starting......"

     sleep 2

     $prog &amp;&amp; echo -e "[ok]" &amp;&amp; touch $lockfile || echo -e  "[fail]"

  fi

}

stop() {

     echo "The program `basename $prog` is stoping......"

     killproc httpd &amp;&amp; echo "[ok]" &amp;&amp; rm -rf $lockfile || echo "[fail]"

     echo "The program `basename $prog` is stoped!"

status() {

     echo "The program `basename $prog` is running......"

     echo "The program `basename $prog` is stop......"

fi

case "$1" in

start)

     start

     ;;

stop)

     stop

status)

     status

restart)

*)

     echo "usage: start|stop|status|restart"

esac

我们对写下的脚本测试一下

<a href="http://blog.51cto.com/attachment/201307/232458879.png" target="_blank"></a>

上面的是我们手动的启动我们的服务,我们可以让它开机启动,使用chkconfig命令来实现,我们要在/etc/init.d/httpd 内增加chkconfig

<a href="http://blog.51cto.com/attachment/201307/232458859.png" target="_blank"></a>

把httpd的启动缓存加入chkconfig

<a href="http://blog.51cto.com/attachment/201307/232458669.png" target="_blank"></a>

这样子httpd服务开机启动的目地就达到了!

    本文转自Tar0 51CTO博客,原文链接:http://blog.51cto.com/tar0cissp/1260058,如需转载请自行联系原作者