软件的安装方式:

  • 编译安装
  • RPM包安装
  • yum安装

一、编译安装

1.下载一个源码安装包:tengine-2.3.0.tar.gz。这是淘宝二次开发过的nginx。将其解压。

  1. tar xf tengine-2.3..tar.gz

2.查看解压后的目录:

  1. [root@centos-clone1 tengine-2.3.]# ll
  2. total
  3. -rw-rw-r-- root root Mar AUTHORS.te
  4. drwxrwxr-x root root Mar auto
  5. -rw-rw-r-- root root Mar CHANGES
  6. -rw-rw-r-- root root Mar CHANGES.cn
  7. -rw-rw-r-- root root Mar CHANGES.ru
  8. -rw-rw-r-- root root Mar CHANGES.te
  9. drwxrwxr-x root root Mar conf
  10. -rwxrwxr-x root root Mar configure
  11. drwxrwxr-x root root Mar contrib
  12. drwxrwxr-x root root Mar docs
  13. drwxrwxr-x root root Mar html
  14. -rw-rw-r-- root root Mar LICENSE
  15. drwxrwxr-x root root Mar man
  16. drwxrwxr-x root root Mar modules
  17. drwxrwxr-x root root Mar packages
  18. -rw-rw-r-- root root Mar README.markdown
  19. drwxrwxr-x root root Mar src
  20. drwxrwxr-x root root Mar tests
  21. -rw-rw-r-- root root Mar THANKS.te

3.我们可以看到其中有READNME文本,阅读内容,其中有一个Installation章节,里面告诉我们如果对源码进行编译安装:

  1. Installation
  2. ============
  3.  
  4. Tengine can be downloaded at [http://tengine.taobao.org/download/tengine.tar.gz](http://tengine.taobao.org/download/tengine.tar.gz). You can also checkout the latest source code from GitHub at [https://github.com/alibaba/tengine](https:
  5. //github.com/alibaba/tengine)
  6.  
  7. To install Tengine, just follow these three steps:
  8.  
  9. $ ./configure
  10. $ make
  11. # make install

4../configure操作:

我们要使用make命令进行编译,必须有一个MakeFile,而configure脚本就是用来检查依赖和生成Makefile文件的。

查看configure脚本的参数:

  1. [root@centos-clone1 tengine-2.3.]# ./configure --help
  2.  
  3. --help print this message
  4.  
  5. --prefix=PATH set installation prefix
  6. --sbin-path=PATH set nginx binary pathname
  7. --modules-path=PATH set modules path
  8. --conf-path=PATH set nginx.conf pathname
  9. --error-log-path=PATH set error log pathname
  10. --pid-path=PATH set nginx.pid pathname
  11. --lock-path=PATH set nginx.lock pathname
  12.  
  13. --user=USER set non-privileged user for
  14. worker processes
  15. --group=GROUP set non-privileged group for
  16. worker processes
  17.  
  18. --build=NAME set build name
  19. --builddir=DIR set build directory
  20.  
  21. --with-select_module enable select module
  22. --without-select_module disable select module
  23. --with-poll_module enable poll module
  24. --without-poll_module disable poll module
  25.  
  26. --without-procs disable procs module
  27.  
  28. --with-threads enable thread pool support
  29.  
  30. --with-file-aio enable file AIO support
  31.  
  32. --with-http_ssl_module enable ngx_http_ssl_module
  33. --with-http_v2_module enable ngx_http_v2_module
  34. --with-http_realip_module enable ngx_http_realip_module
  35. --with-http_addition_module enable ngx_http_addition_module
  36. --with-http_xslt_module enable ngx_http_xslt_module
  37. --with-http_xslt_module=dynamic enable dynamic ngx_http_xslt_module
  38. --with-http_image_filter_module enable ngx_http_image_filter_module
  39. --with-http_image_filter_module=dynamic
  40. enable dynamic ngx_http_image_filter_module
  41. --with-http_geoip_module enable ngx_http_geoip_module
  42. --with-http_geoip_module=dynamic enable dynamic ngx_http_geoip_module
  43. --with-http_sub_module enable ngx_http_sub_module
  44. --with-http_dav_module enable ngx_http_dav_module
  45. --with-http_flv_module enable ngx_http_flv_module
  46. --with-http_mp4_module enable ngx_http_mp4_module
  47. --with-http_gunzip_module enable ngx_http_gunzip_module
  48. --with-http_gzip_static_module enable ngx_http_gzip_static_module
  49. --with-http_auth_request_module enable ngx_http_auth_request_module
  50. --with-http_random_index_module enable ngx_http_random_index_module
  51. --with-http_secure_link_module enable ngx_http_secure_link_module
  52. --with-http_degradation_module enable ngx_http_degradation_module
  53. --with-http_slice_module enable ngx_http_slice_module
  54. --with-http_stub_status_module enable ngx_http_stub_status_module
  55.  
  56. --without-http_charset_module disable ngx_http_charset_module
  57. --without-http_gzip_module disable ngx_http_gzip_module
  58. --without-http_ssi_module disable ngx_http_ssi_module
  59. --without-http_ssl_module disable ngx_http_ssl_module
  60. --without-http_userid_module disable ngx_http_userid_module
  61. --without-http_access_module disable ngx_http_access_module
  62. --without-http_auth_basic_module disable ngx_http_auth_basic_module
  63. --without-http_mirror_module disable ngx_http_mirror_module
  64. --without-http_autoindex_module disable ngx_http_autoindex_module
  65. --without-http_geo_module disable ngx_http_geo_module
  66. --without-http_map_module disable ngx_http_map_module
  67. --without-http_split_clients_module disable ngx_http_split_clients_module
  68. --without-http_referer_module disable ngx_http_referer_module
  69. --without-http_rewrite_module disable ngx_http_rewrite_module
  70. --without-http_proxy_module disable ngx_http_proxy_module
  71. --without-http_fastcgi_module disable ngx_http_fastcgi_module
  72. --without-http_uwsgi_module disable ngx_http_uwsgi_module
  73. --without-http_scgi_module disable ngx_http_scgi_module
  74. --without-http_grpc_module disable ngx_http_grpc_module
  75. --without-http_memcached_module disable ngx_http_memcached_module
  76. --without-http_limit_conn_module disable ngx_http_limit_conn_module
  77. --without-http_limit_req_module disable ngx_http_limit_req_module
  78. --without-http_empty_gif_module disable ngx_http_empty_gif_module
  79. --without-http_browser_module disable ngx_http_browser_module
  80. --without-http_stub_status_module disable ngx_http_stub_status_module
  81. --without-http_upstream_hash_module
  82. disable ngx_http_upstream_hash_module
  83. --without-http_upstream_ip_hash_module
  84. disable ngx_http_upstream_ip_hash_module
  85. --without-http_upstream_least_conn_module
  86. disable ngx_http_upstream_least_conn_module
  87. --without-http_upstream_random_module
  88. disable ngx_http_upstream_random_module
  89. --without-http_upstream_keepalive_module
  90. disable ngx_http_upstream_keepalive_module
  91. --without-http_upstream_zone_module
  92. disable ngx_http_upstream_zone_module
  93.  
  94. --with-http_perl_module enable ngx_http_perl_module
  95. --with-http_perl_module=dynamic enable dynamic ngx_http_perl_module
  96. --with-perl_modules_path=PATH set Perl modules path
  97. --with-perl=PATH set perl binary pathname
  98.  
  99. --without-http-upstream-rbtree disable using rbtree for upstream lookup
  100.  
  101. --with-http_lua_module enable ngx_http_lua_module (will also enable --with-md5 and --with-sha1)
  102. --with-luajit-inc=PATH set LuaJIT headers path (where lua.h/lauxlib.h/... are located)
  103. --with-luajit-lib=PATH set LuaJIT library path (where libluajit-5.1.{a,so} are located)
  104. --with-lua-inc=PATH set Lua headers path (where lua.h/lauxlib.h/... are located)
  105. --with-lua-lib=PATH set Lua library path (where liblua.{a,so} are located, only support Lua-5.1.x)
  106. --http-log-path=PATH set http access log pathname
  107. --http-client-body-temp-path=PATH set path to store
  108. http client request body temporary files
  109. --http-proxy-temp-path=PATH set path to store
  110. http proxy temporary files
  111. --http-fastcgi-temp-path=PATH set path to store
  112. http fastcgi temporary files
  113. --http-uwsgi-temp-path=PATH set path to store
  114. http uwsgi temporary files
  115. --http-scgi-temp-path=PATH set path to store
  116. http scgi temporary files
  117.  
  118. --without-http disable HTTP server
  119. --without-http-cache disable HTTP cache
  120.  
  121. --with-mail enable POP3/IMAP4/SMTP proxy module
  122. --with-mail=dynamic enable dynamic POP3/IMAP4/SMTP proxy module
  123. --with-mail_ssl_module enable ngx_mail_ssl_module
  124. --without-mail_pop3_module disable ngx_mail_pop3_module
  125. --without-mail_imap_module disable ngx_mail_imap_module
  126. --without-mail_smtp_module disable ngx_mail_smtp_module
  127.  
  128. --with-stream enable TCP/UDP proxy module
  129. --with-stream=dynamic enable dynamic TCP/UDP proxy module
  130. --with-stream_ssl_module enable ngx_stream_ssl_module
  131. --with-stream_realip_module enable ngx_stream_realip_module
  132. --with-stream_geoip_module enable ngx_stream_geoip_module
  133. --with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module
  134. --with-stream_ssl_preread_module enable ngx_stream_ssl_preread_module
  135. --with-stream_sni enable dynamic server block
  136. --without-stream_limit_conn_module disable ngx_stream_limit_conn_module
  137. --without-stream_access_module disable ngx_stream_access_module
  138. --without-stream_geo_module disable ngx_stream_geo_module
  139. --without-stream_map_module disable ngx_stream_map_module
  140. --without-stream_split_clients_module
  141. disable ngx_stream_split_clients_module
  142. --without-stream_return_module disable ngx_stream_return_module
  143. --without-stream_upstream_hash_module
  144. disable ngx_stream_upstream_hash_module
  145. --without-stream_upstream_least_conn_module
  146. disable ngx_stream_upstream_least_conn_module
  147. --without-stream_upstream_random_module
  148. disable ngx_stream_upstream_random_module
  149. --without-stream_upstream_zone_module
  150. disable ngx_stream_upstream_zone_module
  151.  
  152. --with-google_perftools_module enable ngx_google_perftools_module
  153. --with-cpp_test_module enable ngx_cpp_test_module
  154.  
  155. --add-module=PATH enable external module
  156. --add-dynamic-module=PATH enable dynamic external module
  157.  
  158. --with-compat dynamic modules compatibility
  159.  
  160. --with-cc=PATH set C compiler pathname
  161. --with-cpp=PATH set C preprocessor pathname
  162. --with-cc-opt=OPTIONS set additional C compiler options
  163. --with-ld-opt=OPTIONS set additional linker options
  164. --with-cpu-opt=CPU build for the specified CPU, valid values:
  165. pentium, pentiumpro, pentium3, pentium4,
  166. athlon, opteron, sparc32, sparc64, ppc64
  167.  
  168. --without-pcre disable PCRE library usage
  169. --with-pcre force PCRE library usage
  170. --with-pcre=DIR set path to PCRE library sources
  171. --with-pcre-opt=OPTIONS set additional build options for PCRE
  172. --with-pcre-jit build PCRE with JIT compilation support
  173.  
  174. --with-zlib=DIR set path to zlib library sources
  175. --with-zlib-opt=OPTIONS set additional build options for zlib
  176. --with-zlib-asm=CPU use zlib assembler sources optimized
  177. for the specified CPU, valid values:
  178. pentium, pentiumpro
  179.  
  180. --with-libatomic force libatomic_ops library usage
  181. --with-libatomic=DIR set path to libatomic_ops library sources
  182.  
  183. --with-jemalloc force jemalloc library usage
  184. --with-jemalloc=DIR set path to jemalloc library files
  185.  
  186. --with-openssl=DIR set path to OpenSSL library sources
  187. --with-openssl-opt=OPTIONS set additional build options for OpenSSL
  188.  
  189. --with-debug enable debug logging

我们可以从帮助中看出,可以指定安装的位置,甚至各个不同文件有不同的安装位置。

后面的with和without控制编译的模块(软件是模块化开发的)。

我们一般采用默认安装,或者指定 --prefix:

  1. [root@centos-clone1 tengine-2.3.]# ./configure
  2. checking for OS
  3. + Linux 3.10.-1062.1..el7.x86_64 x86_64
  4. checking for C compiler ... not found
  5.  
  6. ./configure: error: C compiler cc is not found

在运行configure脚本的时候,报错,说缺少C compiler,即系统没有安装gcc编译器,从这里我们可以看出该软件是由C语言编写的。

使用yum安装gcc:

  1. yum install gcc -y

再次运行configure,提示缺少pcre和openssl。

我们使用以下命令在yum仓库中查找相应的安装包:

  1. yum search pcre
  1. [root@centos-clone1 tengine-2.3.]# yum search pcre
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.aliyun.com
  5. * epel: hkg.mirror.rackspace.com
  6. * extras: mirrors.aliyun.com
  7. * updates: mirrors.aliyun.com
  8. ============================================================================================================ N/S matched: pcre =============================================================================================================
  9. ghc-pcre-light-devel.x86_64 : Haskell pcre-light library development files
  10. mingw32-pcre.noarch : MinGW Windows pcre library
  11. mingw32-pcre-static.noarch : Static version of the mingw32-pcre library
  12. mingw64-pcre.noarch : MinGW Windows pcre library
  13. mingw64-pcre-static.noarch : Static version of the mingw64-pcre library
  14. ocaml-pcre.x86_64 : Perl compatibility regular expressions (PCRE) for OCaml
  15. ocaml-pcre-devel.x86_64 : Development files for ocaml-pcre
  16. pcre-devel.i686 : Development files for pcre
  17. pcre-devel.x86_64 : Development files for pcre
  18. pcre-static.i686 : Static library for pcre
  19. pcre-static.x86_64 : Static library for pcre
  20. pcre-tools.x86_64 : Auxiliary utilities for pcre
  21. pcre2-devel.i686 : Development files for pcre2
  22. pcre2-devel.x86_64 : Development files for pcre2
  23. pcre2-static.i686 : Static library for pcre2
  24. pcre2-static.x86_64 : Static library for pcre2
  25. pcre2-tools.x86_64 : Auxiliary utilities for pcre2
  26. pcre2-utf16.i686 : UTF- variant of PCRE2
  27. pcre2-utf16.x86_64 : UTF- variant of PCRE2
  28. pcre2-utf32.i686 : UTF- variant of PCRE2
  29. pcre2-utf32.x86_64 : UTF- variant of PCRE2
  30. ghc-pcre-light.x86_64 : Perl5 compatible regular expression library
  31. opensips-regex.x86_64 : RegExp via PCRE library
  32. pcre.i686 : Perl-compatible regular expression library
  33. pcre.x86_64 : Perl-compatible regular expression library
  34. pcre2.i686 : Perl-compatible regular expression library
  35. pcre2.x86_64 : Perl-compatible regular expression library

我们看到有许多版本的pcre可供安装,由于缺少pcre依赖库,我们选择安装pcre-devel开发包,32位还是64位无需我们自己选择,yum会根据硬件信息自动选择:

  1. yum install pcre-devel -y

同理我们安装openssl-devel:

  1. yum install openssl-devel -y

然后再执行./configure就可以成功生成MakeFile了:

  1. Configuration summary
  2. + using system PCRE library
  3. + using system OpenSSL library
  4. + using system zlib library
  5. + jemalloc library is disabled
  6.  
  7. nginx path prefix: "/usr/local/nginx"
  8. nginx binary file: "/usr/local/nginx/sbin/nginx"
  9. nginx modules path: "/usr/local/nginx/modules"
  10. nginx configuration prefix: "/usr/local/nginx/conf"
  11. nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  12. nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  13. nginx error log file: "/usr/local/nginx/logs/error.log"
  14. nginx http access log file: "/usr/local/nginx/logs/access.log"
  15. nginx http client request body temporary files: "client_body_temp"
  16. nginx http proxy temporary files: "proxy_temp"
  17. nginx http fastcgi temporary files: "fastcgi_temp"
  18. nginx http uwsgi temporary files: "uwsgi_temp"
  19. nginx http scgi temporary files: "scgi_temp"

5.查看MakeFile的内容:

  1. [root@centos-clone1 tengine-2.3.]# more Makefile
  2.  
  3. default: build
  4.  
  5. clean:
  6. rm -rf Makefile objs
  7.  
  8. build:
  9. $(MAKE) -f objs/Makefile
  10.  
  11. install:
  12. $(MAKE) -f objs/Makefile install
  13.  
  14. modules:
  15. $(MAKE) -f objs/Makefile modules
  16.  
  17. upgrade:
  18. /usr/local/nginx/sbin/nginx -t
  19.  
  20. kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
  21. sleep
  22. test -f /usr/local/nginx/logs/nginx.pid.oldbin
  23.  
  24. kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`

解释:

1) default、clean、build、install、modules、upgrade这些都是make后面可以带的命令。

2) 在这里,default 指向build,所以直接使用make命令,相当于make build。

3) 在build中,我们看到实际上调用的是objs目录中的Makefile。

4) install中,调用的是make -f objs/Makefile install,所以我们调用make install时,install这个参数是传递到objs/Makefile的。

5) 所以,configure所生成的MakeFile实际上是一个导航文件。

6.查看objs/Makefile文件:

  1. install: build
  2. test -d '$(DESTDIR)/usr/local/nginx' || mkdir -p '$(DESTDIR)/usr/local/nginx'
  3.  
  4. test -d '$(DESTDIR)/usr/local/nginx/sbin' \
  5. || mkdir -p '$(DESTDIR)/usr/local/nginx/sbin'
  6. test ! -f '$(DESTDIR)/usr/local/nginx/sbin/nginx' \
  7. || mv '$(DESTDIR)/usr/local/nginx/sbin/nginx' \
  8. '$(DESTDIR)/usr/local/nginx/sbin/nginx.old'
  9. cp objs/nginx '$(DESTDIR)/usr/local/nginx/sbin/nginx'
  10.  
  11. test -d '$(DESTDIR)/usr/local/nginx/conf' \
  12. || mkdir -p '$(DESTDIR)/usr/local/nginx/conf'
  13.  
  14. cp conf/koi-win '$(DESTDIR)/usr/local/nginx/conf'
  15. cp conf/koi-utf '$(DESTDIR)/usr/local/nginx/conf'
  16. cp conf/win-utf '$(DESTDIR)/usr/local/nginx/conf'
  17.  
  18. test -f '$(DESTDIR)/usr/local/nginx/conf/mime.types' \
  19. || cp conf/mime.types '$(DESTDIR)/usr/local/nginx/conf'
  20. cp conf/mime.types '$(DESTDIR)/usr/local/nginx/conf/mime.types.default'

上述内容是objs/Makefile中的一小部分,install章节,解释如下:

1) 首先判断是否存在/usr/local/nginx 目录,如果不存在则创建该目录,所以我们指定一个目录安装的话,会自动创建目录。

2) install大部分都是文件释放的过程,也就是将编译好的文件拷贝到指定的安装目录下。所以install是很快的,而编译是比较缓慢的。

7.使用make编译

8.使用make install安装

9.进入安装好的目录/usr/local/sbin,运行nginx

  1. cd /usr/local/nginx/sbin
  2. ./nginx

10.打开浏览器,访问192.168.1.121:80

看上以上内容,说明nginx编译安装完成,并正确运行。

二、RPM包安装

1.下载一个JDK 的RPM安装包:

  1. jdk-7u80-linux-x64.rpm

2.使用命令安装JDK:

  1. rpm -i jdk-7u80-linux-x64.rpm

在这里,我们一般可能会使用-ivh选项。-v表示提供更多的详细输出,-h表示打印hash marks,一般vh搭配只用。但是使用-v的话会额外开销IO等。

  1. [root@centos-clone1 ~]# rpm -i jdk-7u80-linux-x64.rpm
  2. Unpacking JAR files...
  3. rt.jar...
  4. jsse.jar...
  5. charsets.jar...
  6. tools.jar...
  7. localedata.jar...
  8. jfxrt.jar...

安装完毕。

3.查询安装的位置

  1. # 查询机器中所有安装的软件(编译安装的不在其列)
    rpm -qa

查询是否安装了JDK:

  1. [root@centos-clone1 ~]# rpm -qa | grep jdk
  2. jdk-1.7.0_80-fcs.x86_64

通过软件的名称来查询安装在什么位置:

  1. [root@centos-clone1 ~]# rpm -ql jdk-1.7.0_80-fcs | more
  2. /etc
  3. /etc/.java
  4. /etc/.java/.systemPrefs
  5. /etc/.java/.systemPrefs/.system.lock
  6. /etc/.java/.systemPrefs/.systemRootModFile
  7. /etc/init.d/jexec
  8. /usr
  9. /usr/java
  10. /usr/java/jdk1..0_80
  11. /usr/java/jdk1..0_80/COPYRIGHT
  12. /usr/java/jdk1..0_80/LICENSE
  13. /usr/java/jdk1..0_80/README.html
  14. /usr/java/jdk1..0_80/THIRDPARTYLICENSEREADME-JAVAFX.txt
  15. /usr/java/jdk1..0_80/THIRDPARTYLICENSEREADME.txt
  16. /usr/java/jdk1..0_80/bin
  17. /usr/java/jdk1..0_80/bin/ControlPanel
  18. /usr/java/jdk1..0_80/bin/appletviewer
    ...
    ...

我们重点关注JDK的JAVA_HOME在 /usr/java/jdk1.7.0_80 这个目录。JDK带的一系列命令在 /usr/java/jdk1.7.0_80/bin 下。

4.设置环境变量

在windows中我们安装JDK后,需要配置一些环境变量,而在linux中通过rpm安装后,运行java:

  1. [root@centos-clone1 ~]# java -version
  2. java version "1.7.0_80"
  3. Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
  4. Java HotSpot(TM) -Bit Server VM (build 24.80-b11, mixed mode)

我们发现,java命令可以直接运行。

我们再尝试运行JDK带的其他命令,例如jps:

  1. [root@centos-clone1 ~]# jps
  2. -bash: jps: command not found

发现jps无法运行,而jps和java命令一样,存在于/usr/java/jdk1.7.0_80/bin下的,是为什么呢?

先查看java命令在哪里:

  1. [root@centos-clone1 ~]# whereis java
  2. java: /usr/bin/java

再去/usr/bin中:

  1. [root@centos-clone1 bin]# ll java
  2. lrwxrwxrwx root root Oct : java -> /usr/java/default/bin/java

我们发现,java是一个软链接,他指向我们安装的目录/usr/java/jdk1.7.0_80/bin中的java命令。

这里的目录是/usr/java/default/bin/java,其中的default我们可以通过在/usr/java中看到:

  1. [root@centos-clone1 java]# ll
  2. total
  3. lrwxrwxrwx root root Oct : default -> /usr/java/latest
  4. drwxr-xr-x root root Oct : jdk1..0_80
  5. lrwxrwxrwx root root Oct : latest -> /usr/java/jdk1..0_80

default指向latest,latest指向JAVA_HOME,所以default就是JAVA_HOME,所以/usr/java/default/bin/java就是JAVA_HOME/bin/java。

在这种情况下java命令肯定可以执行,但是jps在bin下,bin目录尚未加入PATH环境变量,所以系统无法找到jps命令。

我们创建JAVA_HOME并在PATH中添加JAVA_HOME/bin:

  1. vi /etc/profile

在最后添加以下内容:

  1. export JAVA_HOME=/usr/java/jdk1..0_80
  2. export PATH=$PATH:$JAVA_HOME/bin

运行source命令使其重新加载配置文件:

  1. source /etc/profile

此时我们再次运行jps:

  1. [root@centos-clone1 java]# jps
  2. Jps

发现jps成功运行。

5.rpm命令

  1. # 查询已经安装的所有包
  2. rpm -qa
  3. # 查询指定的包是否安装
  4. rpm -q PACKAGE_NAME
  5. # 查询指定包的说明信息
  6. rpm -qi PACKAGE_NAME
  7. # 查询指定包安装后释放的文件列表
  8. rpm -ql PACKAGE_NAME
  9. # 查询指定包安装的配置文件
  10. rpm -qc PACKAGE_NAME
  11. # 查询指定包安装的帮助文件
  12. rpm -qd PACKAGE_NAME
  13. # 查询指定包包含的脚本
  14. rpm -q --scripts PACKAGE_NAME
  15. # 查询文件由哪个rpm包安装生成的
  16. rpm -qf /path/to/somefile
  17. # 在rpm包尚未安装时,查询其说明信息,以及安装以后会生成的文件
  18. rpm -qpi /PATH/TO/PACKAGE_FILE

特别注意rpm -qf命令,该命令可以用来通过某个文件反向查询来自哪个rpm包,非常好的功能。

例如某个命令被误删除了,例如ifconfig:

  1. [root@centos-clone1 java]# type ifconfig
  2. ifconfig is hashed (/usr/sbin/ifconfig)
  1. # 将/sbin/ifconfig移动到tmp
  2. mv /sbin/ifconfig /tmp
  1. # 查看hash缓存
  2. [root@centos-clone1 java]# hash
  3. hits command
  4. /usr/sbin/ifconfig
  5. /usr/java/jdk1..0_80/bin/jps
  6. /usr/bin/mv
  7. # 清除hash缓存
  8. [root@centos-clone1 java]# hash -r
  1. # 再次执行ifconfig发现在/sbin中找不到ifconfig
  2. [root@centos-clone1 java]# ifconfig
  3. -bash: ifconfig: command not found

通过rpm -qf来反向查询安装什么包可以安装ifconfig命令:

  1. [root@centos-clone1 java]# rpm -qf /sbin/ifconfig
  2. net-tools-2.0-0.25.20131004git.el7.x86_64

我们可以看到安装net-tools包就可以恢复ifconfig,我们卸载旧的net-tools,并重新安装:

  1. yum remove net-tools -y
  2. yum install net-tools -y

安装完成后则可正常运行ifconfig:

  1. [root@centos-clone1 tmp]# ifconfig
  2. eth0: flags=<UP,BROADCAST,RUNNING,MULTICAST> mtu
  3. inet 192.168.1.121 netmask 255.255.255.0 broadcast 192.168.1.255
  4. inet6 240e::c4:3b50:20c:29ff:fe27:d31d prefixlen scopeid 0x0<global>
  5. inet6 fe80::20c:29ff:fe27:d31d prefixlen scopeid 0x20<link>
  6. ether :0c:::d3:1d txqueuelen (Ethernet)
  7. RX packets bytes (288.6 MiB)
  8. RX errors dropped overruns frame
  9. TX packets bytes (6.8 MiB)
  10. TX errors dropped overruns carrier collisions
  11.  
  12. lo: flags=<UP,LOOPBACK,RUNNING> mtu
  13. inet 127.0.0.1 netmask 255.0.0.0
  14. inet6 :: prefixlen scopeid 0x10<host>
  15. loop txqueuelen (Local Loopback)
  16. RX packets bytes (336.0 B)
  17. RX errors dropped overruns frame
  18. TX packets bytes (336.0 B)
  19. TX errors dropped overruns carrier collisions

三、从光盘中安装RPM包

1.将光盘放入光驱(虚拟机直接替换CD光盘)

2.挂载光驱

  1. [root@centos-clone1 dev]# mount /dev/cdrom /mnt
  2. mount: /dev/sr0 is write-protected, mounting read-only

3.查看/mnt

  1. [root@centos-clone1 ~]# ll /mnt
  2. total
  3. -r--r--r-- root root Dec CentOS_BuildTag
  4. dr-xr-xr-x root root Dec EFI
  5. -r--r--r-- root root Dec EULA
  6. -r--r--r-- root root Dec GPL
  7. dr-xr-xr-x root root Dec images
  8. dr-xr-xr-x root root Dec isolinux
  9. dr-xr-xr-x root root Dec LiveOS
  10. dr-xr-xr-x root root Dec Packages
  11. dr-xr-xr-x root root Dec repodata
  12. -r--r--r-- root root Dec RPM-GPG-KEY-CentOS-
  13. -r--r--r-- root root Dec RPM-GPG-KEY-CentOS-Testing-
  14. -r--r--r-- root root Dec TRANS.TBL

我们看到有一个文件夹叫Packages,其中全部都是光盘提供的rpm安装包:

  1. [root@centos-clone1 Packages]# ll | wc -l

由于这里是一个mini版的CentOS7的安装镜像,所以其中只包含了337个rpm包,如果DVD版,则有3000多个rpm包。

我们找到需要的rpm包,拷贝到本地就可以进行安装了。

4.rpm包安装的缺点

我们在安装JDK的时候没有发现任何问题。

但是我们在安装其他某些软件时,例如早期Apache提供的httpd安装包,则会出现缺少依赖的问题:

这些缺少的依赖都需要我们手工去进行查找和安装,费时费力,所以催生了yum仓库。

四、yum仓库安装软件

1.yum介绍

yum工具类似C/S架构,但是他的计算部分设计在客户端完成。

也就是说正常C/S架构,客户端的主要功能交互和展现,而计算部分放在Server端进行。

但是yum为了使后端仓库能够多样化,即搭建在不同的架构上,例如http、ftp以及文件系统:

  1. http://
  2. ftp://
  3. file://

安装所需的依赖关系又yum客户端自己计算,然后从仓库请求需要的包。

仓库端存储两类文件:

  1. .所有rpm安装包
  2. .rpm包的元数据描述文件

2.yum安装软件的简要流程

  1. .yum获取仓库提供的元数据描述文件
  2. .计算安装某个软件所需要的所有包清单和版本信息
  3. .直接找仓库要所需的包
  4. .按顺序进行安装

3.仓库在哪?

查看yum配置:

  1. [root@centos-clone1 Packages]# cd /etc/yum.repos.d/
  2. [root@centos-clone1 yum.repos.d]# ll
  3. total
  4. -rw-r--r--. root root Jun CentOS-Base.repo
  5. -rw-r--r-- root root Sep : CentOS-CR.repo
  6. -rw-r--r-- root root Sep : CentOS-Debuginfo.repo
  7. -rw-r--r-- root root Sep : CentOS-fasttrack.repo
  8. -rw-r--r-- root root Sep : CentOS-Media.repo
  9. -rw-r--r-- root root Sep : CentOS-Sources.repo
  10. -rw-r--r-- root root Sep : CentOS-Vault.repo
  11. -rw-r--r-- root root Oct epel.repo
  12. -rw-r--r-- root root Oct epel-testing.repo

所有的repo文件都是源。我们打开CentOS-Base.repo看看:

  1. [base]
  2. name=CentOS-$releasever - Base - mirrors.aliyun.com
  3. failovermethod=priority
  4. baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
  5. http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
  6. http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
  7. gpgcheck=
  8. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  9.  
  10. #released updates
  11. [updates]
  12. name=CentOS-$releasever - Updates - mirrors.aliyun.com
  13. failovermethod=priority
  14. baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
  15. http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
  16. http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
  17. gpgcheck=
  18. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

以上是部分内容。

解释:

1) 方括号中的[base]、[updates]是每一个源的名称,必须唯一,我们可以给其任意取名。

2) name表示描述,可以任意写。

3) baseurl是最关键的,他的值就是仓库的地址,可以是http、ftp、file等各种形式,只要仓库能提供读取功能就可以。如果这些链接的地址都在国外,则可能下载缓慢或不稳定。

4) gpgcheck和gpgkey是安全认证之类的东西,暂时不关心。

4.修改为本地源

我们搞明白repo文件以后,就可以通过修改其中的baseurl来替换源地址。

也可以通过163,阿里云等企业直接提供的repo文件替换原始repo文件:

  1. # 首先备份原始的CentOS-Base.repo
  2. mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  1. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  2. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

5.清理和更新元数据

清理本机上缓存的仓库元数据:

  1. yum clean all

重新下载更新后仓库的元数据:

  1. yum makecache

6.查看目前有哪些库

  1. [root@centos-clone1 yum.repos.d]# yum repolist
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.aliyun.com
  5. * epel: hkg.mirror.rackspace.com
  6. * extras: mirrors.aliyun.com
  7. * updates: mirrors.aliyun.com
  8. repo id repo name status
  9. base//x86_64 CentOS- - Base - mirrors.aliyun.com ,
  10. epel/x86_64 Extra Packages for Enterprise Linux - x86_64 ,
  11. extras//x86_64 CentOS- - Extras - mirrors.aliyun.com
  12. updates//x86_64 CentOS- - Updates - mirrors.aliyun.com
  13. repolist: ,

在上述源中,只有epel是国外源,其他都是国内aliyun的源。

7.将epel源也更新成国内源

删除或备份原本的epel.repo以及epel-testing.repo:

  1. mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
  2. mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup

下载aliyun提供的epel源:

  1. wget -O /etc/yum.repos.d/epel-.repo http://mirrors.aliyun.com/repo/epel-7.repo

清除缓存,并重新下载元数据:

  1. yum clean all
  2. yum makecache

五、创建本地仓库(光盘文件)

1.挂载DVD光盘

  1. mount /dev/cdrom /mnt

2.备份所有repo文件

  1. cd /etc/yum.repos.d
  2. mkdir backup
  3. mv -f *.repo backup

3.新建或拷贝一份repo文件

  1. cp backup/CentOS-Base.repo ./
  2. mv CenOS-Base.repo local.repo

4.修改local.repo内容为如下内容:

  1. [localrepo]
  2. name=local repo
  3. baseurl=file:///mnt
  4. gpgcheck=

重点就是baseurl=file:///mnt

关闭gpgcheck,设置为0

其中file://是协议头,/mnt表示仓库位置

目录只需要写到能看到repodate文件夹的那一层:

  1. [root@centos-clone1 mnt]# ll /mnt
  2. total
  3. -r--r--r-- root root Dec CentOS_BuildTag
  4. dr-xr-xr-x root root Dec EFI
  5. -r--r--r-- root root Dec EULA
  6. -r--r--r-- root root Dec GPL
  7. dr-xr-xr-x root root Dec images
  8. dr-xr-xr-x root root Dec isolinux
  9. dr-xr-xr-x root root Dec LiveOS
  10. dr-xr-xr-x 2 root root 55296 Dec 10 2015 Packages
  11. dr-xr-xr-x 2 root root 4096 Dec 10 2015 repodata
  12. -r--r--r-- root root Dec RPM-GPG-KEY-CentOS-
  13. -r--r--r-- root root Dec RPM-GPG-KEY-CentOS-Testing-
  14. -r--r--r-- root root Dec TRANS.TBL

5.清除缓存,更新元数据:

  1. [root@centos-clone1 yum.repos.d]# yum clean all
  2. dLoaded plugins: fastestmirror
  3. ^HCleaning repos: localrepo
  4. Cleaning up list of fastest mirrors
  5. Other repos take up M of disk space (use --verbose for details)
  6.  
  7. [root@centos-clone1 yum.repos.d]# yum makecache
  8. Loaded plugins: fastestmirror
  9. Determining fastest mirrors
  10. localrepo | 3.6 kB ::
  11. (/): localrepo/group_gz | 3.6 kB ::
  12. (/): localrepo/filelists_db | kB ::
  13. (/): localrepo/primary_db | kB ::
  14. (/): localrepo/other_db | kB ::
  15. Metadata Cache Created

6.查看当前源信息

  1. [root@centos-clone1 ~]# yum repolist
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. repo id repo name status
  5. !localrepo local repo
  6. repolist:

可以看到当前本地源中一共有335个包。

如果不是使用的mini版光盘,而是使用DVD1光盘,则显示有6000多个包,而DVD1中只有3000多个,剩余的部分在DVD2中,所以将DVD1和DVD2都下载下来,然后合并Packages目录。

六、yum命令

1.yum常用命令

  1. # 查看源的信息
  2. yum repolist
  3. # 清楚源数据缓存
  4. yum clean all
  5. # 重新下载元数据
  6. yum makecache
  7.  
  8. # 查询所有已安装的包和可用包
  9. yum list
  10. yum list | grep net-tools
  11. # 查找安装包
  12. yum search net-tools
  13. # 查看包信息
  14. yum info net-tools
  15. # 安装包
  16. yum install net-tools
  17. # 删除已安装软件,后者删除更干净
  18. yum remove | erase

2.yum组命令

  1. # 查看已安装组和可安装组
  2. yum grouplist
  3. # 查看组信息
  4. yum groupinfo
  5. # 安装组
  6. yum groupinstall
  7. # 删除组
  8. yum groupremove
  9. # 升级组
  10. yum groupupdate

3.例如安装中文组件

安装中文支持组件:

  1. yum groupinstall "Chinese Support" -y

修改环境变量LANG:

  1. # 临时修改为中文
  2. echo $LANG
  3. LANG=zh_CN.UTF-

我们可以安装中文版的man:

  1. yum install man man-pages man-pages-zh-CN -y

方便我们学习bash命令。

[Linux系统] (3)应用安装方式详解(编译安装、rpm包安装、yum安装)的更多相关文章

  1. Oracle 11g客户端在Linux系统上的配置步骤详解

    Oracle 11g客户端在Linux系统上的配置步骤详解 2011-07-26 10:47 newhappy2008 CSDN博客 字号:T | T 本文我们主要介绍了Oracle 11g客户端在L ...

  2. linux系统运维常用基本命令详解

      1.ls 文件属性:  -:普通文件  d:目录文件  b:块设备  c:字符设备文件  l:符号连接文件  p:命令管道  s:套接字文件  文件权限: 9位数字,每3位一组  文件硬链接次数  ...

  3. CentOS 下 rpm包与 yum 安装与卸载

    rpm包的安装:      1.安装一个包 # rpm -ivh 2.升级一个包 # rpm -Uvh 3.移走一个包 # rpm -e 4.安装参数 --force 即使覆盖属于其它包的文件也强迫安 ...

  4. rpm包与 yum 安装与卸载

    rpm包的安装:      1.安装一个包 # rpm -ivh 2.升级一个包 # rpm -Uvh 3.移走一个包 # rpm -e 4.安装参数 --force 即使覆盖属于其它包的文件也强迫安 ...

  5. 【夯实Mysql基础】MySQL在Linux系统下配置文件及日志详解

    本文地址 分享提纲: 1. 概述 2. 详解配置文件 3. 详解日志 1.概述 MySQL配置文件在Windows下叫my.ini,在MySQL的安装根目录下:在Linux下叫my.cnf,该文件位于 ...

  6. linux系统初始化——sysinit文件写法详解

    sysinit文件写法详解 sysinit文件是linux初始化文件系统时执行的第一个脚本文件.它主要做在各个运行级别中进行初始化工作,包括: 启动交换分区;检查磁盘;设置主机名;检查并挂载文件系统; ...

  7. Linux系统下DNS主从配置详解

    一.DNS概述DNS(Domain Name System),即域名系统.因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP数串. ...

  8. linux系统中的文件权限详解(转)

    一.在<Linux系统中如何查看文件属性>中介绍了通过ls指令来查看文件的属性,具体如下: [命令] letuknowit@ubuntu:/$ cd /tmp letuknowit@ubu ...

  9. Linux用户态程序计时方式详解

    前言 良好的计时器可帮助程序开发人员确定程序的性能瓶颈,或对不同算法进行性能比较.但要精确测量程序的运行时间并不容易,因为进程切换.中断.共享的多用户.网络流量.高速缓存访问及转移预测等因素都会对程序 ...

随机推荐

  1. 解决Iframe跨域高度自适应,利用window.postMessage()实现跨域消息传递页面高度(JavaScript)

    在iframe跨域引用高度自适应这块写的js方式都试了不管用,最终使用的是window.postMessage() 跨域获取高度 传递信息 1.首先,在主页面上使用iframe引入子页面:也就是A.h ...

  2. Minicom 简单使用

    一. 什么是minicom 1.1. minicom 是linux 下的一个串口调试工具 二. minicom的使用 2.1. 进入设置 sudo minicom -s 2.1.1. 串口设置 i. ...

  3. java中代码块和构造方法以及普通方法的代码执行顺序总结

    说实话,这块真的不好理解啊~都怪jvm  执行顺序搞这么复杂,哼╭(╯^╰)╮ 但是  我们能怎么办,只能研究呗!!! !:首先,毫无置疑的,静态代码块在加载时就执行了,所以肯定是最先执行的.... ...

  4. golang(5):struct & 链表 & 二叉树 & 接口

    struct : 结构体 // 1. 用来自定义复杂数据结构 // 2. struct里面可以包含多个字段(属性) // 3. struct类型可以定义方法,注意和函数的区分 // 4. struct ...

  5. Java APi 之 RMI远程方法调用

    一.什么是RPC RPC全称是remote procedure call,即远程过程调用.它是一种协议,用于从远程计算机上请求服务. 例如有两台服务器A和B,A上的应用想要调用B上应用的方法,但是他们 ...

  6. 北上广Java开发月薪20K往上,该如何做,需要会写什么

    这个问题可能很多人会说这只是大企业或者互联网企业工程师才能拿到.也许是的,小公司或者非互联网企业拿两万的不太可能是码农了,应该已经转管理.还有区域问题,这个不在我的考虑范围内,因为这方面除了北上广深杭 ...

  7. Caffe之prototxt

    1.可视化工具: http://ethereon.github.io/netscope/quickstart.html 2.常用网络模型caffe-model之.prototxt: https://g ...

  8. jq自动触发事件

    $('.btn_fath ').trigger("click");$('.btn_fath ').click();

  9. linux上安装rz和sz

    简介 lrzsz 官网入口:http://freecode.com/projects/lrzsz/ lrzsz是一个unix通信套件提供的X,Y,和ZModem文件传输协议 windows 需要向ce ...

  10. 02:Java基础语法(一)

    Java基础语法 Java的关键字及保留字 关键字(Keyword) 关键字的定义和特点定义:被Java语言赋予了特殊含义的单词特点:关键字中所有字母都为小写注意事项:1)true.false.nul ...