编译安装软件包

7案例7:编译安装软件包

7.1问题

本例要求掌握常规代码应用的安装过程,通过编译的方式安装inotify-tools软件工具,完成下列任务:

  1. 释放inotify-tools-3.13.tar.gz源码包
  2. 配置./configure
  3. 编译make、安装make install
  4. 测试inotifywait监控工具的用法及用途

7.2方案

对于标准源码发布C/C++软件包,编译安装一般包括以下过程:

  1. 解包:使用tar命令,将下载的源代码释放至指定目录
  2. 配置:执行源码目录内的./configure脚本,指定安装目录/功能模块等选项
  3. 编译:在源码下执行make操作,根据配置情单Makefile生成可执行的二进制程序文件
  4. 安装:在源码目录下执行make install 操作,将编译好的程序及文件复制到安装目录

7.3步骤

实现此案例需要按照如下步骤进行。

步骤一:确认已配置好编译环境

[root@svr7 ~]# yum  -y  install  gcc  gcc-c++  make
.. ..
[root@svr7 ~]# gcc  --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

步骤二:编译安装inotify-tools软件包

1)解包inotify-tools-3.13.tar.gz文件

[root@svr7 ~]# ls  inotify-tools-3.13.tar.gz 
inotify-tools-3.13.tar.gz
[root@svr7 ~]# tar  xf  inotify-tools-3.13.tar.gz  -C /usr/src/ 

2)配置./configure,安装目录默认(/usr/local/*/)

[root@svr7 ~]# cd  /usr/src/inotify-tools-3.13/          //进入源码目录
[root@svr7 inotify-tools-3.13]# ./configure              //配置操作
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
.. ..
configure: creating ./config.status
config.status: creating Makefile
.. ..
[root@svr7 inotify-tools-3.13]# ls  Makefile              //检查配置结果
Makefile

3)编译make

[root@svr7 inotify-tools-3.13]# make
.. ..
Making all in src
make[2]: Entering directory `/usr/src/inotify-tools-3.13/src'
make[3]: Entering directory `/usr/src/inotify-tools-3.13'
make[3]: Leaving directory `/usr/src/inotify-tools-3.13'
.. ..

4)安装 make install

[root@svr7 inotify-tools-3.13]# make  install
.. ..
/usr/bin/install -c .libs/inotifywait /usr/local/bin/inotifywait
  /bin/sh ../libtool --mode=install /usr/bin/install -c 'inotifywatch' '/usr/local/bin/inotifywatch'
.. ..
[root@svr7 inotify-tools-3.13]# find  /usr/local/  -name  "inotify*"
/usr/local/bin/inotifywait                              //确认安装结果
/usr/local/bin/inotifywatch
/usr/local/include/inotifytools
/usr/local/include/inotifytools/inotifytools.h

步骤三:测试inotify-tools软件程序

 软件包inotify-tools提供了一个主要程序inotifywait,可以用来监控指定目录或文档的变化,并及时给出通知。

1)开启/opt目录的事件监控

[root@svr7 ~]# inotifywait  -mrq  /opt &                  //开启监控
[1] 15568

2)修改/opt/目录内容,观察屏幕输出信息

[root@svr7 ~]# touch  /opt/a.txt                          //新建文件a.txt
/opt/ CREATE a.txt
/opt/ OPEN a.txt
/opt/ ATTRIB a.txt
/opt/ CLOSE_WRITE,CLOSE a.txt
[root@svr7 ~]# mv  /opt/a.txt  /opt/b.txt                  //将文件改名
/opt/ MOVED_FROM a.txt
/opt/ MOVED_TO b.txt

3)结束inotifywait监控

杀死当前用户的第一个后台任务:

[root@svr7 ~]# kill  -9  %1
[1]+  Killed                  inotifywait -mrq /opt

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值