CentOS/RHEL內軟件安裝的基本操做-2

本文索引apache

  • yum安裝
    • yum更換國內源
    • 安裝擴展源epel
    • yum下載rpm包
  • 源碼包安裝
    • 問題與解決
  • 源碼包卸載

yum 更換國內源

163倉庫源:http://mirrors.163.com/.help/CentOS7-Base-163.repocentos

獲取倉庫源文件緩存

  1. 切換到倉庫目錄
[root@localhost ~]# cd /etc/yum.repos.d/
  1. 獲取網絡倉庫文件
[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

或在無wget工具的前提下使用curl命令下載
[root@localhost yum.repos.d]# curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
  1. 備份原倉庫Base文件
[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
  1. 清理緩存
[root@localhost yum.repos.d]# yum clean all
  1. 查看倉庫文件列表(生成新緩存)
[root@localhost yum.repos.d]# yum list

查看當前緩存的倉庫列表網絡

[root@localhost yum.repos.d]# yum repolist all
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.163.com
 * epel: mirrors.ustc.edu.cn
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.aliyun.com
repo id                       repo name                     status
C7.0.1406-base/x86_64         CentOS-7.0.1406 - Base        disabled
C7.0.1406-centosplus/x86_64   CentOS-7.0.1406 - CentOSPlus  disabled
C7.0.1406-extras/x86_64       CentOS-7.0.1406 - Extras      disabled
C7.0.1406-fasttrack/x86_64    CentOS-7.0.1406 - CentOSPlus  disabled
C7.0.1406-updates/x86_64      CentOS-7.0.1406 - Updates     disabled
C7.1.1503-base/x86_64         CentOS-7.1.1503 - Base        disabled
C7.1.1503-centosplus/x86_64   CentOS-7.1.1503 - CentOSPlus  disabled
C7.1.1503-extras/x86_64       CentOS-7.1.1503 - Extras      disabled
C7.1.1503-fasttrack/x86_64    CentOS-7.1.1503 - CentOSPlus  disabled
C7.1.1503-updates/x86_64      CentOS-7.1.1503 - Updates     disabled
C7.2.1511-base/x86_64         CentOS-7.2.1511 - Base        disabled
C7.2.1511-centosplus/x86_64   CentOS-7.2.1511 - CentOSPlus  disabled
C7.2.1511-extras/x86_64       CentOS-7.2.1511 - Extras      disabled
C7.2.1511-fasttrack/x86_64    CentOS-7.2.1511 - CentOSPlus  disabled
C7.2.1511-updates/x86_64      CentOS-7.2.1511 - Updates     disabled
base/7/x86_64                 CentOS-7 - Base               enabled:  9591
base-debuginfo/x86_64         CentOS-7 - Debuginfo          disabled
base-source/7                 CentOS-7 - Base Sources       disabled
c7-media                      CentOS-7 - Media              disabled
centosplus/7/x86_64           CentOS-7 - Plus               disabled
centosplus-source/7           CentOS-7 - Plus Sources       disabled
cr/7/x86_64                   CentOS-7 - cr                 disabled
dvd                           dvd                           enabled:  3831
epel/x86_64                   Extra Packages for Enterprise enabled: 12045
epel-debuginfo/x86_64         Extra Packages for Enterprise disabled
epel-source/x86_64            Extra Packages for Enterprise disabled
epel-testing/x86_64           Extra Packages for Enterprise disabled
epel-testing-debuginfo/x86_64 Extra Packages for Enterprise disabled
epel-testing-source/x86_64    Extra Packages for Enterprise disabled
extras/7/x86_64               CentOS-7 - Extras             enabled:   280
extras-source/7               CentOS-7 - Extras Sources     disabled
fasttrack/7/x86_64            CentOS-7 - fasttrack          disabled
updates/7/x86_64              CentOS-7 - Updates            enabled:  1059
updates-source/7              CentOS-7 - Updates Sources    disabled
repolist: 26806

安裝擴展源epel

yum install -y epel-releasecurl

yum下載rpm包

  1. 僅下載不安裝
# 默認的下載存放目錄/var/cache/yum/x86_64/7/倉庫名/packages
[root@localhost ~]# yum install zsh --downloadonly 
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirrors.ustc.edu.cn
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-28.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================
 Package      Arch            Version                 Repository     Size
==========================================================================
Installing:
 zsh          x86_64          5.0.2-28.el7            base          2.4 M

Transaction Summary
==========================================================================
Install  1 Package

Total download size: 2.4 M
Installed size: 5.6 M
Background downloading packages, then exiting:
zsh-5.0.2-28.el7.x86_64.rpm                          | 2.4 MB   00:05     
exiting because "Download Only" specified

[root@localhost ~]# ls -l /var/cache/yum/x86_64/7/base/packages/
total 2436
-rw-r--r--. 1 root root 2494444 Aug 11 04:24 zsh-5.0.2-28.el7.x86_64.rpm
  1. 指定下載軟件所存放的目錄
# --downloaddir指定存放的目錄
[root@localhost ~]# yum install zsh --downloadonly --downloaddir=/tmp/
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirrors.ustc.edu.cn
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-28.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================
 Package      Arch            Version                 Repository     Size
==========================================================================
Installing:
 zsh          x86_64          5.0.2-28.el7            base          2.4 M

Transaction Summary
==========================================================================
Install  1 Package

Total download size: 2.4 M
Installed size: 5.6 M
Background downloading packages, then exiting:
exiting because "Download Only" specified

[root@localhost ~]# ls -l /tmp/zsh-5.0.2-28.el7.x86_64.rpm 
-rw-r--r--. 1 root root 2494444 Aug 11 04:24 /tmp/zsh-5.0.2-28.el7.x86_64.rpm
  1. 上述所下載的包是系統未安裝的,要下載已安裝軟件的軟件包,使用reinstall
# tree已安裝,使用reinstall;
# --downloaddir指定保存目錄,本例中爲當前目錄;
# 不指定,默認保存在/var/cache/yum/x86_64/7/倉庫名/packages
[root@localhost ~]# yum reinstall tree --downloadonly --downloaddir=./
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirrors.ustc.edu.cn
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================
 Package       Arch            Version                Repository     Size
==========================================================================
Reinstalling:
 tree          x86_64          1.6.0-10.el7           base           46 k

Transaction Summary
==========================================================================
Reinstall  1 Package

Total download size: 46 k
Installed size: 87 k
Background downloading packages, then exiting:
tree-1.6.0-10.el7.x86_64.rpm                         |  46 kB   00:01     
exiting because "Download Only" specified

源碼包安裝

約定:源碼包存放目錄 /usr/local/src/工具

這裏介紹的是通用的安裝源碼包的方式。有部分源碼包使用的是cmake安裝,較爲複雜,這裏就不介紹了。url

例:安裝apachedebug

  1. 切換到存放目錄
[root@localhost ~]# cd /usr/local/src/
  1. 獲取源碼包並解壓縮(無wget命令,yum安裝便可)
[root@localhost src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.34.tar.gz
[root@localhost src]# tar -zxvf httpd-2.2.34.tar.gz
  1. 進入軟件安裝包
[root@localhost src]# cd httpd-2.2.34/
  1. 執行配置文件,檢測安裝環境,並生成部分安裝文件
[root@localhost src]# ./configure --prefix=/usr/local/apache2
  1. 編譯
[root@localhost src]# make
  1. 安裝
[root@localhost src]# make install

判斷上一個命令是否執行成功:0成功,其餘不成功code

echo $?索引

問題與解決

  1. 無wget命令:經過yum安裝或使用curl -O命令下載。
  2. 執行./configure報錯,無gcc:安裝gcc;相似的報錯中無哪一種軟件就安裝哪一種軟件,以後再次執行./configure。

源碼包的卸載

只要將安裝軟件時建立的文件、目錄刪除便可!安裝時指定安裝文件在一個目錄,卸載時就直接將該目錄刪除就能徹底卸載掉軟件。

相關文章
相關標籤/搜索