天天看点

源码安装软件

1、 前言

在进行安装软件的时候,一般是使用yum进行安装,但是在使用yum进行安装的时候,可能会造成软件的版本低,从而需要手动进行编译安装软件;还有一种情况就是需要指定额外的参数进行编译安装,来开启软件的不同功能,如果是使用二进制进行安装,那么有些功能无法使用,从而在这介绍使用软件安装的三步骤。

在进行了重新安装了一些依赖包的时候,软件需要重新进行编译安装。(依赖关系的存在)

2、 编译安装基本步骤

基本步骤如下所示:

[root@rsyncserverinstall]# cd httpd-2.2.31

[[email protected]]# ./configure --help(选项--help查看可以使用的参数,从而选定功能参数进行编译)

[[email protected]]# ./configure --prefix=/usr/local/apache/(进行编译,使用--prefix指定安装的路径)

[[email protected]]# make && make install(安装)

[[email protected]]# echo $?(可以用来检查执行结果,0表示正常,1-255表示安装错误)

在进行编译安装的时候,最常出现的问题就是在进行configure的时候出现错误,主要是依赖关系的问题,这个时候就需要安装其他的一些包进行支持,在查看依赖包的时候,可以查看源文件的目录中如下文件:

[[email protected]]# ls -l README INSTALL(帮助文件,主要用来查看依赖关系)

-rw-r--r-- 11000 1000 4372 Jan 18  2012 INSTALL

-rw-r--r-- 11000 1000 5954 Jan 10  2007 README

在一般的软件下载之后,均有此两文件。

3、 安装结束后的步骤

安装后,软件一般会存在如下的目录:

[root@rsyncserverapache]# ls -dl {bin,lib,include,man}

drwxr-xr-x 2root root 4096 Oct 13 00:44 bin

drwxr-xr-x 2root root 4096 Oct 13 00:44 include

drwxr-xr-x 3root root 4096 Oct 13 00:44 lib

drwxr-xr-x 4root root 4096 Oct 13 00:44 man

在其中,bin表示可执行二进制文件,需要将路径加入的环境变量中,man主要是man手册的查看,include表示在进行二次开发的时候,用到的函数与方法,lib表示程序在运行的时候,需要加载的类库文件。

3.1 修改环境变量

在安装结束后,在使用刚安装的软件的时候,命令无法找到,从而需要修改环境变量,如下:

[root@rsyncserver~]# httpd(环境变量没有设置搜索路径,从而命令无法找到)

-bash: httpd:command not found         

[root@rsyncserver~]# echo "export PATH=$PATH:/usr/local/apache/bin" >>/etc/profile(环境变量中添加刚安装的apache的bin文件搜索路径)

[root@rsyncserver~]# tail -1 /etc/profile(查看添加的内容)

exportPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/apache/bin

[root@rsyncserver~]# . /etc/profile(让刚加入的环境变量生效)

[root@rsyncserver~]# httpd (检查命令,命令可以使用)

httpd: Could notreliably determine the server's fully qualified domain name, using 127.0.0.1for ServerName

3.2 运行时加载类库

在程序运行的时候,需要加载相关的库文件,也就是在安装目录下的lib目录中的文件,有的时候,如果缺少了搜索路径,那么会出现错误,shared object “XX.so”not found,也就是在运行时缺少类库文件。

在主要的类库搜索路径中,使用的命令为ldconfig,如下:

      /sbin/ldconfig - configure dynamic linker run-timebindings(运行时的动态绑定)

查看类库的搜索路径如下:

[root@rsyncserverapache]# ldconfig -v|grep -v "^[[:space:]]"

/usr/lib64/atlas:

/usr/lib64/mysql:

/lib:

/lib64:

/usr/lib:

/usr/lib64:

/lib64/tls:(hwcap: 0x8000000000000000)

/usr/lib64/sse2:(hwcap: 0x0000000004000000)

/usr/lib64/tls:(hwcap: 0x8000000000000000)

[[email protected]]# pwd(搜索类库的主要配置目录)

/etc/ld.so.conf.d

[[email protected]]# ls -l apache.conf (创建apache的类库搜索配置文件,配置文件必须用conf结尾,否则不生效)

-rw-r--r-- 1root root 22 Oct 13 01:35 apache.conf

[[email protected]]# cat apache.conf (直接加入apache的类库路径即可,在路径中,必须是so文件的父目录)

/usr/local/apache/lib

[[email protected]]# ldconfig -v |grep -v "^[[:space:]]"(检查类库搜索路径)

/usr/local/apache/lib:

[[email protected]]# ldconfig -v(查看搜索详细路径)

       libexpat.so.0 -> libexpat.so.0.5.0

       libapr-1.so.0 -> libapr-1.so.0.5.2

       libaprutil-1.so.0 ->libaprutil-1.so.0.5.

3.3 二次开发支持

在程序安装完成之后,会有一个include目录,主要是用来做二次开发的一些方法和函数。

在写程序的时候,默认的搜索路径为/usr/include目录下,如下:

[root@rsyncserver~]# ls -l /usr/include/()

total 1536

-rw-r--r--.  1 root root  7502 Nov  3  2011 aio.h

-rw-r--r--.  1 root root  2115 Nov  3  2011 aliases.h

-rw-r--r--.  1 root root  1289 Nov  3  2011 alloca.h

-rw-r--r--.  1 root root  4351 Nov  3  2011 a.out.h

-rw-r--r--.  1 root root 26521 Nov  3  2011 argp.h

-rw-r--r--.  1 root root  7308 Nov  3  2011 argz.h

[root@rsyncserverinclude]# ls -l /usr/local/apache/include/ |wc -l(会自动将文件进行拷贝到程序库中)

119

[root@rsyncserverinclude]# ls -l /usr/include/apache/|wc -l(会自动将文件进行拷贝到程序库中)

[root@rsyncserver~]# ln -s /usr/local/apache/include/ /usr/include/apache/ (在没有的时候才能创建,否则会造成死循环)

[root@rsyncserver apache]# ls -l(死循环指向)

total 0

lrwxrwxrwx 1 root root 26 Oct 13 03:12 include ->/usr/local/apache/include/

[root@rsyncserver apache]# cd include/

[root@rsyncserver include]# ls

include

[root@rsyncserver include]# cd include/

[root@rsyncserver include]# ls -l

[root@rsyncserver~]# ls -l /usr/include/apache (必须链接失效才能删除链接文件)

lrwxrwxrwx 1root root 26 Oct 13 02:56 /usr/include/apache -> /usr/local/apache/include/

[root@rsyncserver~]# rm -rf /usr/include/apache

[root@rsyncserver~]# ls -l /usr/include/apache

ls: cannotaccess /usr/include/apache: No such file or directory

删除链接目录的时候,不是删除目录,而是删除目录下的所有文件,链接依旧存在不会被删除,链接依然有效。

[root@rsyncserver~]# ln -s /usr/local/apache/include/ /usr/include/apache(创建目录链接无需添加最后的/,否则会造成死循环,如果链接存在,会报错)

ln: creatingsymbolic link `/usr/include/apache/include':File exists

3.4 man手册

在使用刚安装的软件的时候,如果具有帮助手册,那么可能会找不到,从而需要添加man手册信息,如下所示:

[root@rsyncserverman1]# man dbmmanage(不能找到man手册)

No manual entryfor dbmmanage

[root@rsyncserverman1]# vim /etc/man.config (修改man配置文件)

[root@rsyncserverman1]# man dbmmanage