Linux软件安装之源码与Tarball

一、执行文件

1.执行文件说明

linux下的可执行文件,首先可执行文件必须有执行的权限(x),可执行文件再linux系统下都是二进制文件。script shell可以执行是利用shell这个程序的功能进行判别,最终执行shell提供的功能,或者调用一些编译好的二进制程序进行执行。

2.执行文件判断方法

通过file命令来判断文件是否是二进制文件

# 使用系统提供的/bin/bash进行测试,第一段(ELF 64-bit LSB executable)信息表示是可执行类
[root@localhost objs]# file /bin/bash
/bin/bash: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

# 查看python编写的脚本,显示信息表示一个使用python编写的可执行脚本
[root@localhost python_demo]# file demo001.py 
demo001.py: a /usr/bin/python script text executable

二、软件安装

通过源码进行软件安装时,首先需要一个编译器,将源码编译成可执行文件,以gcc编译器进行编译为例。

1、检测用户的操作环境

检查项:

  • 是否有适合的编译程序可以编辑本软件的程序代码
  • 是否已经存在本软件所需要的函数库或其他需要的相关软件
  • 操作系统平台是否适合本软件,包括Linux的内核版本
  • 内核的头定义文件是否存在
2、通过源码安装软件
  1. 下载源码的打包文件,源码文件压缩后缀名一般为:*.tar.gz或者简写为*.tgz或者*.tar.bz2等。包中包含文件一般有源码文件、检测程序文件(config或configure)、软件的简易说明与安装说明(INSTALL和README)
  2. 解压文件,切换到解压后的文件下
  3. 软件使用./configure检测程序找到所需函数库、编译器及其他资料,并主动来生成MakeFile(or makefile)
  4. make命令根据MakeFile的定义,调用源代码、函数库、编译器来编译
  5. make install将编译完成的文件生成可执行文件放到指定的安装目录中
3、nginx安装示例
  1. 下载文件压缩包
[root@localhost test]# curl -O http://nginx.org/download/nginx-1.17.7.tar.gz
# 或者去http://nginx.org/en/download.htm 网站上下载需要的版本并上传到服务器
  1. 解压缩文件
[root@localhost tools]# tar -zxvf nginx-1.17.7.tar.gz
  1. 切换目录,并查看内容
[root@localhost tools]# cd nginx-1.17.7
[root@localhost nginx-1.17.7]# ll
	total 784
	drwxr-xr-x 6 1001 1001   4096 Jan 10 13:43 auto
	-rw-r--r-- 1 1001 1001 301572 Dec 24 23:00 CHANGES
	-rw-r--r-- 1 1001 1001 460207 Dec 24 23:00 CHANGES.ru
	drwxr-xr-x 2 1001 1001   4096 Jan 10 13:43 conf
	-rwxr-xr-x 1 1001 1001   2502 Dec 24 23:00 configure #自动检查系统环境,并生成MakeFile
	drwxr-xr-x 4 1001 1001   4096 Jan 10 13:43 contrib
	drwxr-xr-x 2 1001 1001   4096 Jan 10 13:43 html
	-rw-r--r-- 1 1001 1001   1397 Dec 24 23:00 LICENSE
	drwxr-xr-x 2 1001 1001   4096 Jan 10 13:43 man
	-rw-r--r-- 1 1001 1001     49 Dec 24 23:00 README
	drwxr-xr-x 9 1001 1001   4096 Jan 10 13:43 src
  1. 检查系统环境,并生成makefile文件,./configure命令的输出见下
[root@localhost nginx-1.17.7]# ./configure --prefix=/home/tools/nginx
	creating objs/Makefile #生成Makefile操作
	
	Configuration summary
	  + using system PCRE library
	  + OpenSSL library is not used
	  + using system zlib library
	
	  nginx path prefix: "/home/tools/nginx"
	  nginx binary file: "/home/tools/nginx/sbin/nginx"
	  nginx modules path: "/home/tools/nginx/modules"
	  nginx configuration prefix: "/home/tools/nginx/conf"
	  nginx configuration file: "/home/tools/nginx/conf/nginx.conf"
	  nginx pid file: "/home/tools/nginx/logs/nginx.pid"
	  nginx error log file: "/home/tools/nginx/logs/error.log"
	  nginx http access log file: "/home/tools/nginx/logs/access.log"
	  nginx http client request body temporary files: "client_body_temp"
	  nginx http proxy temporary files: "proxy_temp"
	  nginx http fastcgi temporary files: "fastcgi_temp"
	  nginx http uwsgi temporary files: "uwsgi_temp"
	  nginx http scgi temporary files: "scgi_temp"
  1. 查看MakeFile文件内容
[root@localhost nginx-1.17.7]# vim Makefile
		
default:	build

clean:
	rm -rf Makefile objs

build:
	$(MAKE) -f objs/Makefile

install:
	$(MAKE) -f objs/Makefile install

modules:
	$(MAKE) -f objs/Makefile modules

upgrade:
	/home/tools/nginx/sbin/nginx -t

	kill -USR2 `cat /home/tools/nginx/logs/nginx.pid`
	sleep 1
	test -f /home/tools/nginx/logs/nginx.pid.oldbin

	kill -QUIT `cat /home/tools/nginx/logs/nginx.pid.oldbin`
  1. make clean清空上次编译过的信息,需要执行make命令时,需要重新调用./configure命令
[root@localhost nginx-1.17.7]# make clean
rm -rf Makefile objs
  1. make按照Makefile中的命令进行编译工作,最终生成可执行的nginx(./objs/nginx)
[root@localhost nginx-1.17.7]# make
make -f objs/Makefile
make[1]: Entering directory `/home/tools/nginx-1.17.7'
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
		-o objs/src/core/nginx.o \
......
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
		-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
		-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
		-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
		< man/nginx.8 > objs/nginx.8  #替换目录
make[1]: Leaving directory `/home/tools/nginx-1.17.7'
  1. make install 将编译好的二进制文件复制到安装目录
[root@localhost nginx-1.17.7]# make install
make -f objs/Makefile install

參考資料:《鸟哥的Linux私房菜》

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值