Linux——(3)應用安裝的幾種方式

軟件的安裝方式:html

  • 編譯安裝
  • RPM包安裝
  • yum安裝

 

1、編譯安裝java

1.下載一個源碼安裝包:tengine-2.3.0.tar.gz。這是淘寶二次開發過的nginx。將其解壓。linux

tar xf tengine-2.3.0.tar.gz

2.查看解壓後的目錄:nginx

[root@centos-clone1 tengine-2.3.0]# ll
total 820
-rw-rw-r--  1 root root    889 Mar 25  2019 AUTHORS.te
drwxrwxr-x  6 root root   4096 Mar 25  2019 auto
-rw-rw-r--  1 root root 295057 Mar 25  2019 CHANGES
-rw-rw-r--  1 root root  23830 Mar 25  2019 CHANGES.cn
-rw-rw-r--  1 root root 450114 Mar 25  2019 CHANGES.ru
-rw-rw-r--  1 root root  30541 Mar 25  2019 CHANGES.te
drwxrwxr-x  2 root root   4096 Mar 25  2019 conf
-rwxrwxr-x  1 root root   2502 Mar 25  2019 configure
drwxrwxr-x  4 root root    103 Mar 25  2019 contrib
drwxrwxr-x  3 root root     51 Mar 25  2019 docs
drwxrwxr-x  2 root root     38 Mar 25  2019 html
-rw-rw-r--  1 root root   1715 Mar 25  2019 LICENSE
drwxrwxr-x  2 root root     20 Mar 25  2019 man
drwxrwxr-x 22 root root   4096 Mar 25  2019 modules
drwxrwxr-x  3 root root     19 Mar 25  2019 packages
-rw-rw-r--  1 root root   3421 Mar 25  2019 README.markdown
drwxrwxr-x 10 root root     95 Mar 25  2019 src
drwxrwxr-x  4 root root     41 Mar 25  2019 tests
-rw-rw-r--  1 root root     43 Mar 25  2019 THANKS.te

3.咱們能夠看到其中有READNME文本,閱讀內容,其中有一個Installation章節,裏面告訴咱們若是對源碼進行編譯安裝:git

Installation
============

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:
//github.com/alibaba/tengine)

To install Tengine, just follow these three steps:

    $ ./configure
    $ make
    # make install

4../configure操做:github

咱們要使用make命令進行編譯,必須有一個MakeFile,而configure腳本就是用來檢查依賴和生成Makefile文件的。express

查看configure腳本的參數:windows

[root@centos-clone1 tengine-2.3.0]# ./configure --help

  --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

  --user=USER                        set non-privileged user for
                                     worker processes
  --group=GROUP                      set non-privileged group for
                                     worker processes

  --build=NAME                       set build name
  --builddir=DIR                     set build directory

  --with-select_module               enable select module
  --without-select_module            disable select module
  --with-poll_module                 enable poll module
  --without-poll_module              disable poll module

  --without-procs                    disable procs module

  --with-threads                     enable thread pool support

  --with-file-aio                    enable file AIO support

  --with-http_ssl_module             enable ngx_http_ssl_module
  --with-http_v2_module              enable ngx_http_v2_module
  --with-http_realip_module          enable ngx_http_realip_module
  --with-http_addition_module        enable ngx_http_addition_module
  --with-http_xslt_module            enable ngx_http_xslt_module
  --with-http_xslt_module=dynamic    enable dynamic ngx_http_xslt_module
  --with-http_image_filter_module    enable ngx_http_image_filter_module
  --with-http_image_filter_module=dynamic
                                     enable dynamic ngx_http_image_filter_module
  --with-http_geoip_module           enable ngx_http_geoip_module
  --with-http_geoip_module=dynamic   enable dynamic ngx_http_geoip_module
  --with-http_sub_module             enable ngx_http_sub_module
  --with-http_dav_module             enable ngx_http_dav_module
  --with-http_flv_module             enable ngx_http_flv_module
  --with-http_mp4_module             enable ngx_http_mp4_module
  --with-http_gunzip_module          enable ngx_http_gunzip_module
  --with-http_gzip_static_module     enable ngx_http_gzip_static_module
  --with-http_auth_request_module    enable ngx_http_auth_request_module
  --with-http_random_index_module    enable ngx_http_random_index_module
  --with-http_secure_link_module     enable ngx_http_secure_link_module
  --with-http_degradation_module     enable ngx_http_degradation_module
  --with-http_slice_module           enable ngx_http_slice_module
  --with-http_stub_status_module     enable ngx_http_stub_status_module

  --without-http_charset_module      disable ngx_http_charset_module
  --without-http_gzip_module         disable ngx_http_gzip_module
  --without-http_ssi_module          disable ngx_http_ssi_module
  --without-http_ssl_module          disable ngx_http_ssl_module
  --without-http_userid_module       disable ngx_http_userid_module
  --without-http_access_module       disable ngx_http_access_module
  --without-http_auth_basic_module   disable ngx_http_auth_basic_module
  --without-http_mirror_module       disable ngx_http_mirror_module
  --without-http_autoindex_module    disable ngx_http_autoindex_module
  --without-http_geo_module          disable ngx_http_geo_module
  --without-http_map_module          disable ngx_http_map_module
  --without-http_split_clients_module disable ngx_http_split_clients_module
  --without-http_referer_module      disable ngx_http_referer_module
  --without-http_rewrite_module      disable ngx_http_rewrite_module
  --without-http_proxy_module        disable ngx_http_proxy_module
  --without-http_fastcgi_module      disable ngx_http_fastcgi_module
  --without-http_uwsgi_module        disable ngx_http_uwsgi_module
  --without-http_scgi_module         disable ngx_http_scgi_module
  --without-http_grpc_module         disable ngx_http_grpc_module
  --without-http_memcached_module    disable ngx_http_memcached_module
  --without-http_limit_conn_module   disable ngx_http_limit_conn_module
  --without-http_limit_req_module    disable ngx_http_limit_req_module
  --without-http_empty_gif_module    disable ngx_http_empty_gif_module
  --without-http_browser_module      disable ngx_http_browser_module
  --without-http_stub_status_module  disable ngx_http_stub_status_module
  --without-http_upstream_hash_module
                                     disable ngx_http_upstream_hash_module
  --without-http_upstream_ip_hash_module
                                     disable ngx_http_upstream_ip_hash_module
  --without-http_upstream_least_conn_module
                                     disable ngx_http_upstream_least_conn_module
  --without-http_upstream_random_module
                                     disable ngx_http_upstream_random_module
  --without-http_upstream_keepalive_module
                                     disable ngx_http_upstream_keepalive_module
  --without-http_upstream_zone_module
                                     disable ngx_http_upstream_zone_module

  --with-http_perl_module            enable ngx_http_perl_module
  --with-http_perl_module=dynamic    enable dynamic ngx_http_perl_module
  --with-perl_modules_path=PATH      set Perl modules path
  --with-perl=PATH                   set perl binary pathname

  --without-http-upstream-rbtree     disable using rbtree for upstream lookup

  --with-http_lua_module             enable ngx_http_lua_module (will also enable --with-md5 and --with-sha1)
  --with-luajit-inc=PATH             set LuaJIT headers path (where lua.h/lauxlib.h/... are located)
  --with-luajit-lib=PATH             set LuaJIT library path (where libluajit-5.1.{a,so} are located)
  --with-lua-inc=PATH                set Lua headers path (where lua.h/lauxlib.h/... are located)
  --with-lua-lib=PATH                set Lua library path (where liblua.{a,so} are located, only support Lua-5.1.x)
  --http-log-path=PATH               set http access log pathname
  --http-client-body-temp-path=PATH  set path to store
                                     http client request body temporary files
  --http-proxy-temp-path=PATH        set path to store
                                     http proxy temporary files
  --http-fastcgi-temp-path=PATH      set path to store
                                     http fastcgi temporary files
  --http-uwsgi-temp-path=PATH        set path to store
                                     http uwsgi temporary files
  --http-scgi-temp-path=PATH         set path to store
                                     http scgi temporary files

  --without-http                     disable HTTP server
  --without-http-cache               disable HTTP cache

  --with-mail                        enable POP3/IMAP4/SMTP proxy module
  --with-mail=dynamic                enable dynamic POP3/IMAP4/SMTP proxy module
  --with-mail_ssl_module             enable ngx_mail_ssl_module
  --without-mail_pop3_module         disable ngx_mail_pop3_module
  --without-mail_imap_module         disable ngx_mail_imap_module
  --without-mail_smtp_module         disable ngx_mail_smtp_module

  --with-stream                      enable TCP/UDP proxy module
  --with-stream=dynamic              enable dynamic TCP/UDP proxy module
  --with-stream_ssl_module           enable ngx_stream_ssl_module
  --with-stream_realip_module        enable ngx_stream_realip_module
  --with-stream_geoip_module         enable ngx_stream_geoip_module
  --with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module
  --with-stream_ssl_preread_module   enable ngx_stream_ssl_preread_module
  --with-stream_sni                  enable dynamic server block
  --without-stream_limit_conn_module disable ngx_stream_limit_conn_module
  --without-stream_access_module     disable ngx_stream_access_module
  --without-stream_geo_module        disable ngx_stream_geo_module
  --without-stream_map_module        disable ngx_stream_map_module
  --without-stream_split_clients_module
                                     disable ngx_stream_split_clients_module
  --without-stream_return_module     disable ngx_stream_return_module
  --without-stream_upstream_hash_module
                                     disable ngx_stream_upstream_hash_module
  --without-stream_upstream_least_conn_module
                                     disable ngx_stream_upstream_least_conn_module
  --without-stream_upstream_random_module
                                     disable ngx_stream_upstream_random_module
  --without-stream_upstream_zone_module
                                     disable ngx_stream_upstream_zone_module

  --with-google_perftools_module     enable ngx_google_perftools_module
  --with-cpp_test_module             enable ngx_cpp_test_module

  --add-module=PATH                  enable external module
  --add-dynamic-module=PATH          enable dynamic external module

  --with-compat                      dynamic modules compatibility

  --with-cc=PATH                     set C compiler pathname
  --with-cpp=PATH                    set C preprocessor pathname
  --with-cc-opt=OPTIONS              set additional C compiler options
  --with-ld-opt=OPTIONS              set additional linker options
  --with-cpu-opt=CPU                 build for the specified CPU, valid values:
                                     pentium, pentiumpro, pentium3, pentium4,
                                     athlon, opteron, sparc32, sparc64, ppc64

  --without-pcre                     disable PCRE library usage
  --with-pcre                        force PCRE library usage
  --with-pcre=DIR                    set path to PCRE library sources
  --with-pcre-opt=OPTIONS            set additional build options for PCRE
  --with-pcre-jit                    build PCRE with JIT compilation support

  --with-zlib=DIR                    set path to zlib library sources
  --with-zlib-opt=OPTIONS            set additional build options for zlib
  --with-zlib-asm=CPU                use zlib assembler sources optimized
                                     for the specified CPU, valid values:
                                     pentium, pentiumpro

  --with-libatomic                   force libatomic_ops library usage
  --with-libatomic=DIR               set path to libatomic_ops library sources

  --with-jemalloc                    force jemalloc library usage
  --with-jemalloc=DIR                set path to jemalloc library files

  --with-openssl=DIR                 set path to OpenSSL library sources
  --with-openssl-opt=OPTIONS         set additional build options for OpenSSL

  --with-debug                       enable debug logging

咱們能夠從幫助中看出,能夠指定安裝的位置,甚至各個不一樣文件有不一樣的安裝位置。後端

後面的with和without控制編譯的模塊(軟件是模塊化開發的)。centos

 

咱們通常採用默認安裝,或者指定 --prefix:

[root@centos-clone1 tengine-2.3.0]# ./configure 
checking for OS
 + Linux 3.10.0-1062.1.2.el7.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

在運行configure腳本的時候,報錯,說缺乏C compiler,即系統沒有安裝gcc編譯器,從這裏咱們能夠看出該軟件是由C語言編寫的。

使用yum安裝gcc:

yum install gcc -y

再次運行configure,提示缺乏pcre和openssl。

咱們使用如下命令在yum倉庫中查找相應的安裝包:

yum search pcre
[root@centos-clone1 tengine-2.3.0]# yum search pcre
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: hkg.mirror.rackspace.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
============================================================================================================ N/S matched: pcre =============================================================================================================
ghc-pcre-light-devel.x86_64 : Haskell pcre-light library development files
mingw32-pcre.noarch : MinGW Windows pcre library
mingw32-pcre-static.noarch : Static version of the mingw32-pcre library
mingw64-pcre.noarch : MinGW Windows pcre library
mingw64-pcre-static.noarch : Static version of the mingw64-pcre library
ocaml-pcre.x86_64 : Perl compatibility regular expressions (PCRE) for OCaml
ocaml-pcre-devel.x86_64 : Development files for ocaml-pcre
pcre-devel.i686 : Development files for pcre
pcre-devel.x86_64 : Development files for pcre
pcre-static.i686 : Static library for pcre
pcre-static.x86_64 : Static library for pcre
pcre-tools.x86_64 : Auxiliary utilities for pcre
pcre2-devel.i686 : Development files for pcre2
pcre2-devel.x86_64 : Development files for pcre2
pcre2-static.i686 : Static library for pcre2
pcre2-static.x86_64 : Static library for pcre2
pcre2-tools.x86_64 : Auxiliary utilities for pcre2
pcre2-utf16.i686 : UTF-16 variant of PCRE2
pcre2-utf16.x86_64 : UTF-16 variant of PCRE2
pcre2-utf32.i686 : UTF-32 variant of PCRE2
pcre2-utf32.x86_64 : UTF-32 variant of PCRE2
ghc-pcre-light.x86_64 : Perl5 compatible regular expression library
opensips-regex.x86_64 : RegExp via PCRE library
pcre.i686 : Perl-compatible regular expression library
pcre.x86_64 : Perl-compatible regular expression library
pcre2.i686 : Perl-compatible regular expression library
pcre2.x86_64 : Perl-compatible regular expression library

咱們看到有許多版本的pcre可供安裝,因爲缺乏pcre依賴庫,咱們選擇安裝pcre-devel開發包,32位仍是64位無需咱們本身選擇,yum會根據硬件信息自動選擇:

yum install pcre-devel -y

同理咱們安裝openssl-devel:

yum install openssl-devel -y

而後再執行./configure就能夠成功生成MakeFile了:

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library
  + jemalloc library is disabled

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/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"

5.查看MakeFile的內容:

[root@centos-clone1 tengine-2.3.0]# more 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:
        /usr/local/nginx/sbin/nginx -t

        kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
        sleep 1
        test -f /usr/local/nginx/logs/nginx.pid.oldbin

        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文件:

install:        build 
        test -d '$(DESTDIR)/usr/local/nginx' || mkdir -p '$(DESTDIR)/usr/local/nginx'

        test -d '$(DESTDIR)/usr/local/nginx/sbin' \
                || mkdir -p '$(DESTDIR)/usr/local/nginx/sbin'
        test ! -f '$(DESTDIR)/usr/local/nginx/sbin/nginx' \
                || mv '$(DESTDIR)/usr/local/nginx/sbin/nginx' \
                        '$(DESTDIR)/usr/local/nginx/sbin/nginx.old'
        cp objs/nginx '$(DESTDIR)/usr/local/nginx/sbin/nginx'

        test -d '$(DESTDIR)/usr/local/nginx/conf' \
                || mkdir -p '$(DESTDIR)/usr/local/nginx/conf'

        cp conf/koi-win '$(DESTDIR)/usr/local/nginx/conf'
        cp conf/koi-utf '$(DESTDIR)/usr/local/nginx/conf'
        cp conf/win-utf '$(DESTDIR)/usr/local/nginx/conf'

        test -f '$(DESTDIR)/usr/local/nginx/conf/mime.types' \
                || cp conf/mime.types '$(DESTDIR)/usr/local/nginx/conf'
        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

cd /usr/local/nginx/sbin
./nginx

10.打開瀏覽器,訪問192.168.1.121:80

 

看上以上內容,說明nginx編譯安裝完成,並正確運行。

 

 

2、RPM包安裝

1.下載一個JDK 的RPM安裝包:

jdk-7u80-linux-x64.rpm

2.使用命令安裝JDK:

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

在這裏,咱們通常可能會使用-ivh選項。-v表示提供更多的詳細輸出,-h表示打印hash marks,通常vh搭配只用。可是使用-v的話會額外開銷IO等。

[root@centos-clone1 ~]# rpm -i jdk-7u80-linux-x64.rpm
Unpacking JAR files...
        rt.jar...
        jsse.jar...
        charsets.jar...
        tools.jar...
        localedata.jar...
        jfxrt.jar...

安裝完畢。

3.查詢安裝的位置

# 查詢機器中全部安裝的軟件(編譯安裝的不在其列)
rpm -qa

查詢是否安裝了JDK:

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

經過軟件的名稱來查詢安裝在什麼位置:

[root@centos-clone1 ~]# rpm -ql jdk-1.7.0_80-fcs | more
/etc
/etc/.java
/etc/.java/.systemPrefs
/etc/.java/.systemPrefs/.system.lock
/etc/.java/.systemPrefs/.systemRootModFile
/etc/init.d/jexec
/usr
/usr/java
/usr/java/jdk1.7.0_80
/usr/java/jdk1.7.0_80/COPYRIGHT
/usr/java/jdk1.7.0_80/LICENSE
/usr/java/jdk1.7.0_80/README.html
/usr/java/jdk1.7.0_80/THIRDPARTYLICENSEREADME-JAVAFX.txt
/usr/java/jdk1.7.0_80/THIRDPARTYLICENSEREADME.txt
/usr/java/jdk1.7.0_80/bin
/usr/java/jdk1.7.0_80/bin/ControlPanel
/usr/java/jdk1.7.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:

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

咱們發現,java命令能夠直接運行。

咱們再嘗試運行JDK帶的其餘命令,例如jps:

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

發現jps沒法運行,而jps和java命令同樣,存在於/usr/java/jdk1.7.0_80/bin下的,是爲何呢?

先查看java命令在哪裏:

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

再去/usr/bin中:

[root@centos-clone1 bin]# ll java
lrwxrwxrwx 1 root root 26 Oct 22 14:56 java -> /usr/java/default/bin/java

咱們發現,java是一個軟連接,他指向咱們安裝的目錄/usr/java/jdk1.7.0_80/bin中的java命令。

這裏的目錄是/usr/java/default/bin/java,其中的default咱們能夠經過在/usr/java中看到:

[root@centos-clone1 java]# ll
total 4
lrwxrwxrwx 1 root root   16 Oct 22 14:56 default -> /usr/java/latest
drwxr-xr-x 8 root root 4096 Oct 22 14:55 jdk1.7.0_80
lrwxrwxrwx 1 root root   21 Oct 22 14:56 latest -> /usr/java/jdk1.7.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:

vi /etc/profile

在最後添加如下內容:

export JAVA_HOME=/usr/java/jdk1.7.0_80
export PATH=$PATH:$JAVA_HOME/bin

運行source命令使其從新加載配置文件:

source /etc/profile

此時咱們再次運行jps:

[root@centos-clone1 java]# jps
28430 Jps

發現jps成功運行。

 

5.rpm命令

# 查詢已經安裝的全部包
rpm -qa
# 查詢指定的包是否安裝
rpm -q PACKAGE_NAME
# 查詢指定包的說明信息
rpm -qi PACKAGE_NAME
# 查詢指定包安裝後釋放的文件列表
rpm -ql PACKAGE_NAME
# 查詢指定包安裝的配置文件
rpm -qc PACKAGE_NAME
# 查詢指定包安裝的幫助文件
rpm -qd PACKAGE_NAME
# 查詢指定包包含的腳本
rpm -q --scripts PACKAGE_NAME
# 查詢文件由哪一個rpm包安裝生成的
rpm -qf /path/to/somefile # 在rpm包還沒有安裝時,查詢其說明信息,以及安裝之後會生成的文件
rpm -qpi /PATH/TO/PACKAGE_FILE

特別注意rpm -qf命令,該命令能夠用來經過某個文件反向查詢來自哪一個rpm包,很是好的功能。

例如某個命令被誤刪除了,例如ifconfig:

[root@centos-clone1 java]# type ifconfig
ifconfig is hashed (/usr/sbin/ifconfig)
# 將/sbin/ifconfig移動到tmp
mv /sbin/ifconfig /tmp
# 查看hash緩存
[root@centos-clone1 java]# hash
hits    command
   2    /usr/sbin/ifconfig
   1    /usr/java/jdk1.7.0_80/bin/jps
   1    /usr/bin/mv
# 清除hash緩存
[root@centos-clone1 java]# hash -r
# 再次執行ifconfig發如今/sbin中找不到ifconfig
[root@centos-clone1 java]# ifconfig
-bash: ifconfig: command not found

經過rpm -qf來反向查詢安裝什麼包能夠安裝ifconfig命令:

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

咱們能夠看到安裝net-tools包就能夠恢復ifconfig,咱們卸載舊的net-tools,並從新安裝:

yum remove net-tools -y
yum install net-tools -y

安裝完成後則可正常運行ifconfig:

[root@centos-clone1 tmp]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.121  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 240e:398:c4:3b50:20c:29ff:fe27:d31d  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::20c:29ff:fe27:d31d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:27:d3:1d  txqueuelen 1000  (Ethernet)
        RX packets 852771  bytes 302673365 (288.6 MiB)
        RX errors 0  dropped 611215  overruns 0  frame 0
        TX packets 61176  bytes 7202303 (6.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 4  bytes 336 (336.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 336 (336.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

3、從光盤中安裝RPM包

1.將光盤放入光驅(虛擬機直接替換CD光盤)

2.掛載光驅

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

3.查看/mnt

[root@centos-clone1 ~]# ll /mnt
total 92
-r--r--r-- 1 root root    14 Dec 10  2015 CentOS_BuildTag
dr-xr-xr-x 3 root root  2048 Dec 10  2015 EFI
-r--r--r-- 1 root root   215 Dec 10  2015 EULA
-r--r--r-- 1 root root 18009 Dec 10  2015 GPL
dr-xr-xr-x 3 root root  2048 Dec 10  2015 images
dr-xr-xr-x 2 root root  2048 Dec 10  2015 isolinux
dr-xr-xr-x 2 root root  2048 Dec 10  2015 LiveOS
dr-xr-xr-x 2 root root 55296 Dec 10  2015 Packages
dr-xr-xr-x 2 root root  4096 Dec 10  2015 repodata
-r--r--r-- 1 root root  1690 Dec 10  2015 RPM-GPG-KEY-CentOS-7
-r--r--r-- 1 root root  1690 Dec 10  2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r-- 1 root root  2883 Dec 10  2015 TRANS.TBL

咱們看到有一個文件夾叫Packages,其中所有都是光盤提供的rpm安裝包:

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

因爲這裏是一個mini版的CentOS7的安裝鏡像,因此其中只包含了337個rpm包,若是DVD版,則有3000多個rpm包。

咱們找到須要的rpm包,拷貝到本地就能夠進行安裝了。

4.rpm包安裝的缺點

咱們在安裝JDK的時候沒有發現任何問題。

可是咱們在安裝其餘某些軟件時,例如早期Apache提供的httpd安裝包,則會出現缺乏依賴的問題:

 

這些缺乏的依賴都須要咱們手工去進行查找和安裝,費時費力,因此催生了yum倉庫。

 

4、yum倉庫安裝軟件

1.yum介紹

yum工具相似C/S架構,可是他的計算部分設計在客戶端完成。

也就是說正常C/S架構,客戶端的主要功能交互和展示,而計算部分放在Server端進行。

可是yum爲了使後端倉庫可以多樣化,即搭建在不一樣的架構上,例如http、ftp以及文件系統:

http://
ftp://
file://

安裝所需的依賴關係又yum客戶端本身計算,而後從倉庫請求須要的包。

倉庫端存儲兩類文件:

1.全部rpm安裝包
2.rpm包的元數據描述文件

2.yum安裝軟件的簡要流程

1.yum獲取倉庫提供的元數據描述文件
2.計算安裝某個軟件所須要的全部包清單和版本信息
3.直接找倉庫要所需的包
4.按順序進行安裝

3.倉庫在哪?

查看yum配置:

[root@centos-clone1 Packages]# cd /etc/yum.repos.d/
[root@centos-clone1 yum.repos.d]# ll
total 40
-rw-r--r--. 1 root root 2523 Jun 16  2018 CentOS-Base.repo
-rw-r--r--  1 root root 1309 Sep  5 21:05 CentOS-CR.repo
-rw-r--r--  1 root root  649 Sep  5 21:05 CentOS-Debuginfo.repo
-rw-r--r--  1 root root  314 Sep  5 21:05 CentOS-fasttrack.repo
-rw-r--r--  1 root root  630 Sep  5 21:05 CentOS-Media.repo
-rw-r--r--  1 root root 1331 Sep  5 21:05 CentOS-Sources.repo
-rw-r--r--  1 root root 6639 Sep  5 21:05 CentOS-Vault.repo
-rw-r--r--  1 root root  951 Oct  3  2017 epel.repo
-rw-r--r--  1 root root 1050 Oct  3  2017 epel-testing.repo

全部的repo文件都是源。咱們打開CentOS-Base.repo看看:

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
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文件:

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

5.清理和更新元數據

清理本機上緩存的倉庫元數據:

yum clean all

從新下載更新後倉庫的元數據:

yum makecache

6.查看目前有哪些庫

[root@centos-clone1 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: hkg.mirror.rackspace.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                                                                             repo name                                                                                                                         status
base/7/x86_64                                                                                       CentOS-7 - Base - mirrors.aliyun.com                                                                                              10,097
epel/x86_64                                                                                         Extra Packages for Enterprise Linux 7 - x86_64                                                                                    13,416
extras/7/x86_64                                                                                     CentOS-7 - Extras - mirrors.aliyun.com                                                                                               304
updates/7/x86_64                                                                                    CentOS-7 - Updates - mirrors.aliyun.com                                                                                              611
repolist: 24,428

在上述源中,只有epel是國外源,其餘都是國內aliyun的源。

7.將epel源也更新成國內源

刪除或備份本來的epel.repo以及epel-testing.repo:

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

下載aliyun提供的epel源:

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

清除緩存,並從新下載元數據:

yum clean all
yum makecache

 

5、建立本地倉庫(光盤文件)

1.掛載DVD光盤

mount /dev/cdrom /mnt

2.備份全部repo文件

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

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

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

4.修改local.repo內容爲以下內容:

[localrepo] name=local repo baseurl=file:///mnt
gpgcheck=0

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

關閉gpgcheck,設置爲0

其中file://是協議頭,/mnt表示倉庫位置

目錄只須要寫到能看到repodate文件夾的那一層:

[root@centos-clone1 mnt]# ll /mnt
total 92
-r--r--r-- 1 root root    14 Dec 10  2015 CentOS_BuildTag
dr-xr-xr-x 3 root root  2048 Dec 10  2015 EFI
-r--r--r-- 1 root root   215 Dec 10  2015 EULA
-r--r--r-- 1 root root 18009 Dec 10  2015 GPL
dr-xr-xr-x 3 root root  2048 Dec 10  2015 images
dr-xr-xr-x 2 root root  2048 Dec 10  2015 isolinux
dr-xr-xr-x 2 root root  2048 Dec 10  2015 LiveOS
dr-xr-xr-x 2 root root 55296 Dec 10  2015 Packages
dr-xr-xr-x 2 root root  4096 Dec 10  2015 repodata
-r--r--r-- 1 root root  1690 Dec 10  2015 RPM-GPG-KEY-CentOS-7
-r--r--r-- 1 root root  1690 Dec 10  2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r-- 1 root root  2883 Dec 10  2015 TRANS.TBL

5.清除緩存,更新元數據:

[root@centos-clone1 yum.repos.d]# yum clean all
dLoaded plugins: fastestmirror
^HCleaning repos: localrepo
Cleaning up list of fastest mirrors
Other repos take up 472 M of disk space (use --verbose for details)

[root@centos-clone1 yum.repos.d]# yum makecache Loaded plugins: fastestmirror Determining fastest mirrors localrepo | 3.6 kB 00:00:00 (1/4): localrepo/group_gz | 3.6 kB 00:00:00 (2/4): localrepo/filelists_db | 240 kB 00:00:00 (3/4): localrepo/primary_db | 617 kB 00:00:00 (4/4): localrepo/other_db | 167 kB 00:00:00 Metadata Cache Created

6.查看當前源信息

[root@centos-clone1 ~]# yum repolist
Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile repo
id repo name status !localrepo local repo 335 repolist: 335

能夠看到當前本地源中一共有335個包。

若是不是使用的mini版光盤,而是使用DVD1光盤,則顯示有6000多個包,而DVD1中只有3000多個,剩餘的部分在DVD2中,因此將DVD1和DVD2都下載下來,而後合併Packages目錄。

 

6、yum命令

1.yum經常使用命令

# 查看源的信息
yum repolist
# 清楚源數據緩存
yum clean all
# 從新下載元數據
yum makecache

# 查詢全部已安裝的包和可用包
yum list
yum list | grep net-tools
# 查找安裝包
yum search net-tools
# 查看包信息
yum info net-tools
# 安裝包
yum install net-tools
# 刪除已安裝軟件,後者刪除更乾淨
yum remove | erase

2.yum組命令

# 查看已安裝組和可安裝組
yum grouplist
# 查看組信息
yum groupinfo
# 安裝組
yum groupinstall
# 刪除組
yum groupremove
# 升級組
yum groupupdate

3.例如安裝中文組件

安裝中文支持組件:

yum groupinstall "Chinese Support" -y

修改環境變量LANG:

# 臨時修改成中文
echo $LANG
LANG=zh_CN.UTF-8

咱們能夠安裝中文版的man:

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

方便咱們學習bash命令。

相關文章
相關標籤/搜索