03.源码安装包管理

  1. 1.源码包基本概述

在linux环境下面安装源码包是比较常见的, 早起运维管理工作中,大部分软件都是通过源码安装的。那么安装一个源码包,是需要我们自己把源代码编译成二进制的可执行文件。

源码包的编译用到了linux系统里的编译器,通常源码包都是用C语言开发的,这也是因为C语言为linux上最标准的程序语言。Linux上的C语言编译器叫做gcc,利用它就可以把C语言变成可执行的二进制文件。所以如果你的机器上没有安装gcc就没有办法去编译源码。可以使用yum install -y gcc 来完成安装。

1.使用源码包的好处

1.自定义修改源代码
2.定制需要的相关功能
3.新版软件优先更新源码

  1. 2.源码包如何获取

官方网站, 可以获得最新的软件包Apache官方网站Nginx官方网站

  1. 3.源码包如何安装

编译环境 gcc、make依赖环境pcre、openssl准备对应软件 nginx-1.12.tar.gz

源码安装三步曲(常见)

第一步: ./configure(定制组件)

a.指定安装路径,例如 --prefix=/soft/nginx-1.12
b.启用或禁用某项功能, 例如 --enable-ssl
c.和其它软件关联,例如--with-pcre
d.检查安装环境,例如是否有编译器 gcc,是否满足软件的依赖需求
e.检测通过后生成Makefile文件

第二步: make

1.执行make命令进行编辑, 可以使用-j指定CPU编译
2.按Makefile文件进行编译, 编译成可执行二进制文件
3.生成各类模块和主程序。

第三步: make install

1.执行make install
2.按Makefile定义好的路径拷贝至安装目录中。

上面介绍的源码三部曲不能百分百通用于所有源码包, 也就是说源码包的安装并非存在标准安装步骤。建议:拿到源码包解压后,然后进入到目录找相关的帮助文档,通常会以INSTALL或者README为文件名。

%title插图%num

  1. 4.源码包编译实例

下面通过编译Nginx来深入理解源码包安装

//1.基础环境准备
					
[root@node1 ~]# yum install -y gcc make wget 
						
//2.下载源码包(源码包一定要上官方站点下载,其他站点不安全)
						
[root@node1 ~]# mkdir -p /soft/src
						
[root@node1 src]# cd /soft/src
						
[root@node1 src]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
						
//3.解压源码包,并进入相应目录
					
[root@node1 src]# tar xf nginx-1.12.2.tar.gz
						
[root@node1 src]# cd nginx-1.12.2
						
//4.配置相关的选项,并生成Makefile
						
[root@node1 nginx-1.12.2]# ./configure --help|head 
  --help                             print this message
  --prefix=PATH                      set installation prefix
  --sbin-path=PATH                   set nginx binary pathname
  --modules-path=PATH                set modules path
  --conf-path=PATH                   set nginx.conf pathname
  --error-log-path=PATH              set error log pathname 
  --pid-path=PATH                    set nginx.pid pathname
  --lock-path=PATH                   set nginx.lock pathname
//后面的内容省略了,使用 ./configure --help 命令查看可以使用的选项。
					
//一般常用的有 --prefix=PREFIX 这个选项的意思是定义软件包安装到哪里。
					
//建议,源码包都是安装在/soft/目录下。
					
//5.指定编译参数
						
						
[root@node1 nginx-1.12.2]# ./configure --prefix=/soft/nginx-1.12.2 
//6.验证这一步命令是否成功, 非0d都不算成功
					
[root@node1 nginx-1.12.2]# echo $? 
0
					
//7.编译并安装
					
[root@node1 nginx-1.12.2]# make 
[root@node1 nginx-1.12.2]# make install 
[root@node1 nginx-1.12.2]# echo $? 

源码编译报错信息处理

checking for C compiler ... not found ./configure: error: C compiler cc is not found 
//解决方案
					
# yum -y install gcc gcc-c++ make
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module
					by
					using
					--without-http_rewrite_module
						
option, or
					install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by
					using
					--with-pcre=<path> option.
						
//解决方案
					
# yum install -y pcre-devel
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module
					by
					using
					--without-
						
http_gzip_module option, or
					install the zlib library into the
system, or build the zlib library statically from the source with
				
nginx by
					using
					--with-zlib=<path> option. 
						
//解决方案:
# yum -y install zlib-devel
./configure: error: SSL modules require the OpenSSL library.
You can either do
					not enable the modules, or
					install the OpenSSL 
library into the system, or build the OpenSSL library statically
from the source with nginx by
					using
					--with-openssl=<path> option.
						
//解决方案
					
# yum -y install openssl-devel
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郭亚望

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值