使用CentOS软件过程中,可能需要用编译使用.src的软件源码包,有些是因为需要某些功能,有些是需要某个版本,以下以httpd为例:

下载源码httpd并编译 [root@www1 ~]# tar -xf httpd-2.4.6.tar.bz2 [root@www1 ~]# cd httpd-2.4.6; ls #看到install文件 [root@www1 httpd-2.4.6]# cat install #查看帮助,有些软件是README ... $ ./configure --prefix=PREFIX $ make $ make install $ PREFIX/bin/apachectl start ... [root@www1 httpd-2.4.6]#./configure --help #查看编译帮助 [root@www1 httpd-2.4.6]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd2 ... #出现错误提示,如果没有此提示,则跳过错误步骤 configure: error: APR not found. Please read the documentation.

[root@www1 ~]# yum install apr apr-util [root@www1 httpd-2.4.6]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd2 --with-apr-util=/usr/local/apr-util --with-apr=/usr/local/apr configure: error: pcre-config for libpcre not found. PCRE is required and available from #错误提示

[root@www1 ~]# yum install pcre [root@www1 httpd-2.4.6]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd2 --with-apr-util=/usr/local/apr-util --with-apr=/usr/local/apr --with-pcre=/usr/local/pcre

[root@www1 httpd-2.4.6]# make [root@www1 httpd-2.4.6]# make install

[root@www1 httpd-2.4.6]# cd /usr/local/apache2;ls bin build cgi-bin error htdocs icons include logs lib man manual modules [root@www1 apache2]# bin/apachectl start [root@www1 apache2]# ss -tnl #查看80端口出现,表示成功启动

编译安装软件包时,如果是安装在系统默认的安装位置/usr/local则不需要配置软件(但这样不方便以后彻底删除),如果是安装在自定义的路径下,则需要进行以下后续的配置,方便软件(像rpm/yum安装那样)使用;后续配置如下

[root@www1 apache2]# vim /etc/profile.d/apache2.sh #配置系统的软件启动方式 export PATH=/usr/local/apache2/bin:$PATH

[root@www1 apache2]# . /etc/profile.d/apache2.sh [root@www1 apache2]# echo $PATH /usr/local/apache2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

[root@www1 apache2]# apachectl stop [root@www1 apache2]# ss -tnl #80端口关闭,表示配置apachectl命令成功,以后不需要用绝对路径启动,停止。 [root@www1 ~]# vim /etc/ld.so.conf.d/apache2.conf #导出库文件路径 /usr/local/apache2/lib [root@www1 ~]# ldconfig -v #重新生成库文件缓存

[root@www1 ~]# ln -s /usr/loacl/apache2/include /usr/include/ #导出头文件

[root@www1 ~]# vim /etc/man_db.conf #centos 7 ( centos6为/etc/man.conf) MANDATORY_MANPATH /usr/local/apache2/man #导出man手册

一些常用参数说明: --prefix=: #默认安装位置 --sysconfdir=: #配置文件安装位置 System types:

				--disable-FEATURE                 #禁用某功能
				--enable-FEATURE[=ARG]      #开启某功能
			
				--with-PACKAGE[=ARG]          #依赖某包
				--without-PACKAGE                 #忽略某依赖包

其它的源码软件包类似这样编译,主要查看软件包的INSTALL或README及编译时的./configure帮助