Linux-軟件包管理

第13章 Linux系統管理-軟件包管理

 
 
 
xxxxxxxxxx
 
 
 
 
與windows安裝各類應用程序類似,在linux下也能夠安裝各類須要的應用程序,一般稱爲軟件包。
 

1. Rpm安裝軟件包

1. 什麼是Rpm

 
 
 
xxxxxxxxxx
 
 
 
 
RPM 是Red-Hat Package Manager(RPM軟件包管理器)的縮寫,這一文件格式名稱雖然打上了RedHat的標誌,可是
其原始設計理念是開放式的是由紅帽公司開發用於軟件包的安裝、升級、卸載、查詢等操做。在主流的linux系統上,多數
軟件的安裝、升級、移除以及維護工做都是使用RPM軟件包管理程序來完成的。
 

2. Rpm包介紹

 
 
 
xxxxxxxxxx
 
 
 
 
zip-3.0-11.el7.x86_64.rpm#el7
zip-3.0-1.el6.x86_64.rpm#el6
yum-utils-1.1.31-50.el7.noarch.rpm#noarch,noarch是no architecture的縮寫,說明這個包能夠在各個不一樣的cpu上使用。
QQ_v8.9.exe#Windows
 

img

3. Linux系統安裝軟件方式

分類 安裝 版本
rpm包 預先編譯打包,安裝簡單 軟件版本偏低
源碼包 手動編譯打包,安裝繁瑣 軟件版本隨意
二進制包 解壓便可使用, 安裝簡單 不能修改源代碼

4. Rpm包獲取

 
 
 
xxxxxxxxxx
 
 
 
 
1.本地的ISO鏡像光盤(軟件包可能存在版本偏低狀況)/mnt --掛載-->/dev/cdrom
2.自行聯網下載rpm包進行安裝
3.倉庫聯網獲取rpm包      #yum的時候
 

5. Rpm實戰

1.安裝html

 
 
 
xxxxxxxxxx
 
 
 
 
-i#安裝軟件包
-v#顯示安裝的過程
-h#顯示安裝的進度條
--test#模擬演練
--force#強制安裝
 
        
[root@qls ~]# rpm -ivh /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
1:tree-1.6.0-10.el7                  ################################# [100%]
 

2.安裝過程當中出現了依賴的狀況前端

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# rpm -ivh /mnt/Packages/samba-4.8.3-4.el7.x86_64.rpm 
error: Failed dependencies:
libxattr-tdb-samba4.so()(64bit) is needed by samba-0:4.8.3-4.el7.x86_64
libxattr-tdb-samba4.so(SAMBA_4.8.3)(64bit) is needed by samba-0:4.8.3-4.el7.x86_64
samba-common-tools = 4.8.3-4.el7 is needed by samba-0:4.8.3-4.el7.x86_64
samba-libs = 4.8.3-4.el7 is needed by samba-0:4.8.3-4.el7.x86_64
 
 
 
 
x
 
 
 
 
1.嘗試安裝依賴包samba-common-tools
[root@qls ~]# rpm -ivh /mnt/Packages/samba-common-tools-4.8.3-4.el7.x86_64.rpm 
error: Failed dependencies:
samba-libs = 4.8.3-4.el7 is needed by samba-common-tools-0:4.8.3-4.el7.x86_64
2.嘗試安裝依賴包samba-libs
[root@qls ~]# rpm -ivh /mnt/Packages/pytalloc-2.1.13-1.el7.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:pytalloc-2.1.13-1.el7            ################################# [100%]
3.安裝samba-libs
[root@qls ~]# rpm -ivh /mnt/Packages/samba-libs-4.8.3-4.el7.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:samba-libs-0:4.8.3-4.el7         ################################# [100%]
4.安裝samba-common-tools
[root@qls ~]# rpm -ivh /mnt/Packages/samba-common-tools-4.8.3-4.el7.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:samba-common-tools-0:4.8.3-4.el7 ################################# [100%]
5.安裝samba
[root@qls ~]# rpm -ivh /mnt/Packages/samba-4.8.3-4.el7.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:samba-0:4.8.3-4.el7              ################################# [100%]
------------------------------------rpm軟件包依賴太強了......一般使用yum來解決
 

3.如何使用rpm安裝互聯網上面的軟件包(沒有依賴)node

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm
 

4.卸載mysql

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# rpm -e tree
[root@qls ~]# rpm -qa zabbix-agent
zabbix-agent-4.0.0-2.el7.x86_64
[root@qls ~]# rpm -e zabbix-agent-4.0.0-2.el7.x86_64
[root@qls ~]# rpm -qa zabbix-agent
 

5.升級linux

 
 
 
xxxxxxxxxx
 
 
 
 
wget  https://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/zabbix-agent-3.0.9-1.el7.x86_64.rpm
wget  https://mirrors.aliyun.com/zabbix/zabbix/4.2/rhel/7/x86_64/zabbix-agent-4.2.0-1.el7.x86_64.rpm
1.先安裝低版本
[root@qls ~]# rpm -ivh zabbix-agent-3.0.9-1.el7.x86_64.rpm
2.嘗試安裝高版本(會出現錯誤)
[root@qls ~]# rpm -ivh zabbix-agent-4.2.0-1.el7.x86_64.rpm
3.使用升級的方式,完美解決替換
[root@qls ~]# rpm -Uvh zabbix-agent-4.2.0-1.el7.x86_64.rpm
warning: /var/tmp/rpm-tmp.saqeVO: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-agent-4.2.0-1.el7         ################################# [ 50%]
Cleaning up / removing...
   2:zabbix-agent-3.0.9-1.el7         ################################# [100%]
 

6.查看軟件安裝的路徑,或者其餘nginx

 
 
 
xxxxxxxxxx
 
 
 
 
#選項描述
rpm -q#查看指定軟件包是否安裝
[root@qls ~]# rpm -q vsftpd**
package vsftpd is not installed
rpm -qa#查看系統中已安裝的全部RPM軟件包列表
[root@qls ~]# rpm -qa|grep "samba"#列出全部的rpm包,而後篩選名稱是samba的相關包****
samba-common-tools-4.8.3-4.el7.x86_64
samba-common-libs-4.8.3-4.el7.x86_64
samba-common-4.8.3-4.el7.noarch
samba-libs-4.8.3-4.el7.x86_64
samba-client-libs-4.8.3-4.el7.x86_64
samba-4.8.3-4.el7.x86_64
[root@qls ~]# rpm -qa samba#明確知道軟件包的名稱,在進行查找
samba-4.8.3-4.el7.x86_64
rpm -ql#查詢指定軟件包所安裝的目錄、文件列表,存放的位置*****
rpm -qc#查詢指定軟件包的全部配置文件*****
rpm -qf#查詢文件或目錄屬於哪一個RPM軟件***(只能查詢已存在的命令或已存在的文件路徑)
[root@qls ~]# rpm -qf /bin/cd
bash-4.2.46-31.el7.x86_64
[root@qls ~]# rpm -qf /bin/cp
coreutils-8.22-23.el7.x86_64
[root@qls ~]# yum provides mkpasswd#更好的解決方案
rpm -qi#查看指定軟件的詳細信息*
[root@qls ~]# rpm -qi samba
 

6. Rpm包總結

 
 
 
xxxxxxxxxx
 
 
 
 
#安裝:rpm -ivh <RPM包名全稱>
#卸載:rpm -e <RPM包名>
#升級:rpm -Uvh <RPM包名>
#查詢:rpm [參數] <RPM包名>
經常使用參數:rpm -qa   #查詢系統中安裝的全部RPM軟件包
            rpm -q <RPM包名>     #查詢指定軟件包是否已安裝
            rpm -qi <RPM包名>     #查詢系統中已安裝包的描述信息
            rpm -ql <RPM包名>     #查詢系統中已安裝包裏所包含的文件
            
            rpm -qc<RPM包名>   #查詢指定軟件包的全部配置文件
            rpm -qf <RPM包名>     #查詢系統中指定文件所屬的軟件包
            rpm -qa | grep php       #檢索系統中已經安裝有關php的軟件包
5.驗證:rpm -V [參數]
 

2. Yum安裝軟件包

1. Yum介紹

 
 
 
xxxxxxxxxx
 
 
 
 
Yum(全稱爲 Yellow dog Updater, Modified)是一個在Fedora和RedHat以及CentOS中的Shell前端軟件包管理器。基於RPM包管理,可以從指定的服務器自動下載RPM包而且安裝,能夠自動處理依賴性關係,而且一次安裝全部依賴的軟件包,無須繁瑣地一次次下載、安裝。
 

2. Yum源(Yum倉庫)

 
 
 
xxxxxxxxxx
 
 
 
 
要使用yum前,須要準備一個yum源(咱們也稱爲yum倉庫),  這個能夠是一個互聯網上的倉庫,也能夠是本地本身搭建的倉庫.
 
        
倉庫裏面有什麼呢?裏面所有都是.rpm的軟件包.
 
        
一臺linux,能夠添加N多個yum源,  能搜索的軟件包數量就是N個yum源之和.
 

3. 系統中經常使用的Yum源

 
 
 
xxxxxxxxxx
 
 
 
 
1.base基礎源
2.epel擴展源       
3.與服務相關的源(官網)    
 

4. Yum實戰

1.如何經過倉庫進行查找軟件包,好比模糊匹配web

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# yum list #查看全部的rpm包,建議配合less
[root@qls ~]# yum list | grep ftp#模糊匹配的方式
[root@qls ~]# yum info vsftpd#查看vsftpd軟件的詳情(無關緊要)
 

2.yum經過公網倉庫搜索進行安裝sql

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# yum install vsftpd#交互,麻煩
[root@qls ~]# yum install vsftpd -y#非交互
 

3.yum直接安裝公網的rpm包, 會自動查找當前系統上已有的倉庫解決依賴關係shell

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# yum install https://mirrors.aliyun.com/centos/7.6.1810/os/x86_64/Packages/samba-4.8.3-4.el7.x86_64.rpm
 

4.Yum直接安裝本地的rpm包,會自動查找當前系統上已有的倉庫解決依賴關係

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# yum localinstall samba-4.8.3-4.el7.x86_64.rpm
 

5.若是誤刪除某個軟件的配置文件,可使用reinstall進行重裝

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# yum reinstall vsftpd
 

6.更新全部的軟件包,包括內核(剛裝好系統時進行一次升級)

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# yum update acl -y
[root@qls ~]# yum update -y
 

7.如何去刪除一個軟件包

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# yum remove samba -y
 

8.查看正在使用的倉庫基本信息

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# yum repolist
[root@qls ~]# yum repolist all 查看全部的倉庫
#啓用和禁用倉庫
[root@qls ~]# yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
[root@qls ~]# yum repolist all|grep mysql
[root@qls ~]# yum-config-manager --disable mysql80-community#關閉倉庫
[root@qls ~]# yum-config-manager --enable mysql57-community#啓用倉庫
本質:  都是在修改repo文件中的enable的值   0 不啓用  1 啓用
 

9.查找一個命令或文件所屬的軟件包是什麼?

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# rpm -qf $(which cd)
bash-4.2.46-31.el7.x86_64
PS: rpm須要知道命令的絕對路徑, 若是不存在該命令是沒法查找到該命令所屬的軟件包
[root@qls ~]# yum provides cd
[root@qls ~]# yum provides ifconfig
PS1: yum不須要知道命令的絕對路徑,只須要知道完整的命令便可.
PS2: yum會經過全部已啓用的倉庫進行查找那些軟件包中涵蓋了須要查詢的命令
之後: 查詢命令來自於哪一個軟件,使用yum的方式進行查詢
1.若是查詢不到,檢查命令是否寫錯,若是寫錯,修改便可.
 
        
2.若是修改命令仍是查詢不到,請檢查是否倉庫真的沒有軟件包涵蓋此命令, 建議添加更多yum源(倉庫)
 
       
 

10.組包的安裝與卸載

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# yum groups install Development Tools
[root@qls ~]# yum groups remove -y Base
 

11.如何使用Yum緩存已經安裝過了的軟件包

 
 
 
xxxxxxxxxx
 
 
 
 
#緩存rpm包方式1、修改yum全局配置文件
[root@qls ~]# vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1     #啓動緩存
#緩存rpm包方式二,只下載不安裝
[root@qls ~]# yum install httpd -y --downloadonly --downloaddir=/tmp
#1.先清空
[root@qls ~]# yum clean packages
#當你的yum出現問題,進行了一次替換後,你須要執行 yum clean all 
#2.開啓緩存,而後再下載軟件包
 

12.Yum的歷史記錄

 
 
 
xxxxxxxxxx
 
 
 
 
#1.查看歷史執行yum命令
[root@qls ~]# yum history
#2.查詢歷史執行yum命令ID詳細信息
[root@qls ~]# yum history info ID
#3.撤銷歷史執行過的yum命令
[root@qls ~]# yum history undo ID
 

5. Yum總結

 
 
 
xxxxxxxxxx
 
 
 
 
yum是管理rpm包的工具,可以自動解決依賴,同時能實現聯網下載,極其方便.
經常使用選項說明:
#安裝yum install httpd httpd-tools
#卸載yum remove httpd httpd-tools
#重裝yum reinstall httpd   #不當心刪除了配置文件的時
#更新   yum check-update #檢查能更新的軟件包    
 yum update -y  #更新全部軟件包,包括內核
 
        
 yum update httpd -y #更新某個軟件包
 
        
#查看   yum list #列出可用倉庫中全部的軟件包
 yum provides command/file   #聯網查詢命令所屬的軟件包
 
        
#倉庫yum repolist all #查看全部倉庫,包括已啓用或禁用的
#緩存vim /etc/yum.conf   #keepcache=1 便可開啓緩存
 

3. Yum搭建本地倉庫

1. Yum搭建本地倉庫-單臺

1.掛載cd光盤,由於裏面不少的軟件包

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# mount /dev/cdrom /mnt
 

2.建立一個本地的倉庫

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# cd /etc/yum.repos.d/
[root@qls yum.repos.d]# gzip *
[root@qls yum.repos.d]# cat local.repo 
[LocalBase]   #真實的倉庫名稱
name=This is Local Base   #當前倉庫的描述
baseurl=file:///mnt   #倉庫所在的路徑,能夠是 http://   https://   ftp:// file://
enabled=1   #啓用當前的倉庫,默認是啓用的
gpgcheck=0    #校驗安裝的rpm是不是合法的,0表示不校驗 
 
       
 

3.使用當前本地的倉庫

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls yum.repos.d]# yum makecache
[root@qls yum.repos.d]# yum repolist 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                               repo name                                    status
LocalBase                             This is Local Base                            4,021
repolist: 4,021
 

2. 共享給局域網中的全部主機

 
 
 
xxxxxxxxxx
 
 
 
 
環境準備:
10.0.0.99#做爲yum倉庫
 
        
10.0.0.98#做爲使用yum倉庫的客戶端
 
       
 

1.搭建一個Yum倉庫

1.1.初始環境

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# systemctl disable firewalld#關閉開機自動啓動firewalld防火牆
[root@qls ~]# systemctl stop firewalld#如今當即關閉firewalld防火牆
[root@qls ~]# setenforce 0#關閉selinux防火牆
[root@qls ~]# sed -i 's#^SELINUX=.*#SELINUX=disabled#g' /etc/selinux/config#關閉開機自啓動
 

1.2.安裝Ftp服務,並啓動

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# yum install vsftpd -y#安裝ftp服務
[root@qls ~]# systemctl start vsftpd#啓動ftp服務
[root@qls ~]# systemctl status vsftpd#查看ftp服務狀態是不是active Running
 

3.給Ftp共享的目錄準備基礎軟件包

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# mkdir /var/ftp/centos7#建立基礎base倉庫
[root@qls ~]# mount /dev/cdrom /mnt/#掛載磁盤
[root@qls ~]# find /mnt/Packages/ -type f -name "*.rpm" |xargs -I {} cp -rp {} /var/ftp/centos7/
 

1.5.將ftp對應的目錄生成爲Yum的倉庫

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# yum install createrepo -y
[root@qls ~]# createrepo /var/ftp/centos7/
 

1.6.客戶端指向並使用內部的Yum倉庫

 
 
 
xxxxxxxxxx
 
 
 
 
[root@client yum.repos.d]# gzip *
[root@client yum.repos.d]# cat ftp_99.repo 
[FtpRepos]
name = This is Ftp Share Repos
baseurl = ftp://10.0.0.99/centos7/
enabled = 1
gpgcheck = 0
[root@client yum.repos.d]# yum makecache
[root@client yum.repos.d]# yum repolist 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                               repo name                                    status
LocalBase                             This is Local Base                            4,021
repolist: 4,021
 

4. 源碼包管理

1.下載Nginx的源碼包

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# wget http://nginx.org/download/nginx-1.16.0.tar.gz
 

2.解壓源碼包

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls ~]# tar xf nginx-1.16.0.tar.gz
 

3.對軟件進行各類自定義操做

 
 
 
x
 
 
 
 
[root@qls ~]# cd nginx-1.16.0/
[root@qls nginx-1.16.0]# ./configure --prefix=/soft/nginx-1.16.0 --with-http_ssl_module
 

4.生成makfile後,根據makefile的文件進行編譯 使用make命令

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls nginx-1.16.0]# make
 

5.將編譯好的二進制文件和配置文件,拷貝到./configure指定的目錄

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls nginx-1.16.0]# make install
 

6.將程序設定一個軟鏈接,便於後續的升級

 
 
 
xxxxxxxxxx
 
 
 
 
[root@qls soft]# ln -s /soft/nginx-1.16.0/ /soft/nginx
 

7.執行二進制文件,而後在瀏覽器中輸入當前服務器的IP地址,測試是否有welcome to nginx

 
 
 
x
 
 
 
 
[root@qls ~]# /soft/nginx/sbin/nginx
 

注意:如今百分之90,能用上的軟件,都提供了rpm包. --->使用戶可使用yum直接安裝使用.

8.編譯過程當中的報錯解決

 
 
 
xxxxxxxxxx
 
 
[root@qls nginx-1.16.0]# ./configure --prefix=/soft/nginx-1.16.0 --with-http_ssl_module
checking for OS
Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
#解決:
[root@qls yum.repos.d]# yum install gcc
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
#解決:
[root@qls nginx-1.16.0]# yum install pcre-devel pcre -y
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
#解決:
[root@qls nginx-1.16.0]# yum install openssl-devel -y
 
 
#整合:
[root@qls yum.repos.d]# yum install gcc pcre-devel pcre openssl-devel -y
相關文章
相關標籤/搜索