1. 源码包
1.1 源码包是什么?
源码包指的是开发编写好的程序源代码, 但并没有将其编译为一个能正常使用的工具.
1.2 为什么要学习源码包?
1. 部分软件官网仅提供源码包, 需要自行编译并安装.
2. 部分软件在新版本有一些特性还没来得及制作成rpm包时, 可以自行编译软件使用其新特性.
1.3 源码包的优缺点
优点:
1. 可以自行修改源代码
2. 可以定制需要的相关功能
3. 新版软件优先更新源码
缺点:
1. 相对yum安装软件会复杂很多.
2. 标准化实施困难, 自动化就无法落地.
1.3 源码包如何获取?
常见的软件包都可以在官网获取源码包, 比如 apache、nginx、mysql等等
2. 源码包编译步骤
将源码包编译为二进制可执行文件步骤如下, 简称安装三步曲:
PS: 此方法不是百分百通用于所有源码包, 建议拿到源码包解压后, 进入到目录找相关的README帮助文档
3. 源码编译示例
下面通过编译Nginx来深入了解下源码包编译的过程.
# 1.基础环境准备 (下载gcc编译器, make编译器, wget下载工具, ...)
[root@kid ~]# yum install -y gcc make wget zlib-devel gcc-c++ libtool openssl openssl-devel
# 2.下载nginx服务器源码包
[root@kid ~]# wget http://nginx.org/download/nginx-1.15.12.tar.gz
[root@kid ~]# ll
-rw-r--r--. 1 root root 1032347 Apr 16 2019 nginx-1.15.12.tar.gz
...
# 3.解压源码包, 并进入相应目录
[root@kid ~]# tar xf nginx-1.15.12.tar.gz
[root@kid ~]# ll
drwxr-xr-x. 8 1001 1001 158 Apr 16 2019 nginx-1.15.12
..
# 进入nginx目录
[root@kid ~]# cd nginx-1.15.12
# 4.配置相关的选项, 并生成Makefile
[root@kid nginx-1.15.12]# ./configure --help
# 设置安装路径
--prefix=PATH set installation prefix
...
# 指定安装到/usr/local/nginx下, 目录不存在会自动创建
[root@kid nginx-1.15.12]# ./configure --prefix=/usr/local/nginx
# 检查上一个命令是否执行成功
[root@kid nginx-1.15.12]# echo $?
0
# 如果返回值是0,就是执行成功;如果是返回值是0以外的值,就是失败
# 失败一般是基础环境少了什么... 去百度看看别人的第一步是什么复制过来执行
# 5.将Makefile文件编译可执行二进制程序, 此时,/usr/local/nginx可执行文件还不在,
# 需要执行make install 才能copy过去
[root@kid nginx-1.15.12]# make
# 6.将二进制文件拷贝至对应的目录中
[root@kid nginx-1.15.12]# make install
# 7. 建立软连接(以后方便升级)
[root@kid nginx-1.15.12]# ln -s nginx-1.18.0 nginx
# 进入到编译目录的 sbin 目录下,启动 nginx
# 进入 sbin目录下
cd /usr/local/nginx/sbin
# 启动 nginx
./nginx
# 查看 nginx 进程
[root@kid sbin]# ps aux|grep nginx
root 71267 0.0 0.0 20556 612 ? Ss 16:17 0:00 nginx: master process ./nginx
nobody 71268 0.0 0.1 21008 1320 ? S 16:17 0:00 nginx: worker process
root 71270 0.0 0.0 112812 980 pts/1 S+ 16:17 0:00 grep --color=auto nginx
# 关闭防火墙
[root@kid sbin]# systemctl stop firewalld.service
# 查看防火墙的状态
[root@kid sbin]# firewall-cmd --state
not running
# 禁止firewall开机启动
[root@kid sbin]# systemctl disable firewalld.service
# 接下来测试一下,输入你 Linux 服务器的地址, 出现下面这个页面说明安装成功了
nginx 目录介绍
conf: 配置文件
html: 网站文件存放
logs: 日志
sbin: 可执行文件
nginx命令:
nginx 启动
nginx -s reload 重新加载
nginx -s stop 重启
nginx -s stop 停止
4. 源码编译报错信息处理
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
make: *** No rule to make target `build', needed by `default'. Stop.
解决方法: yum install -y gcc make wget zlib-devel gcc-c++ libtool openssl openssl-devel
安装之后再回到第四步, 往下执行...
————————————————
文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
————————————————