linux學習筆記——yum安裝軟體、搭建倉庫、rpm命令
#############如何安裝軟體####################
yum #全稱Yellow dog Updater Moddified,能夠從指定的伺服器自動下載RPM包並安裝
yum list all ##列出所有安裝包
yum list installed ##列出已經安裝的
yum list available ##列出沒有安裝的
yum remove package ##解除安裝軟體(package是軟體包)
yum install package ##安裝軟體
yum reinstall package ##重新安裝軟體
yum localinstall 本地軟體 ##安裝本地軟體並解決依賴關係
yum search 關鍵字 ##搜尋與關鍵字相關的軟體
yum whatprovides 檔案 ##搜尋包含此檔案的包
yum info ##顯示軟體資訊
yum groups list ##列出軟體組
yum groups install ##安裝組
yum groups remove ##解除安裝組
yum groups info ##檢視組資訊
yum update ##全部更新
yum update package ##更新指定軟體包
yum clean packages ##清除快取目錄下的軟體包
yum repolist ##檢視yum資源庫資訊
eg:
yum install package -y ##安裝軟體,-y表示安裝過程提示全部為yes
yum whatprovides */lftp ##搜尋包含此檔案的包
##############軟體倉庫的建立##############
1.先建立一個軟體倉庫
1)需要一個與本機匹配的安裝映象,rhel-server-7.0-x86_64-dvd.iso,這個檔案從官方網站下載得到
2)mount rhel-server-7.0-x86_64-dvd.iso /yum ##掛在到/yum,/yum目錄是新建出來的
3)mv /etc/yum.repos.d/* /mnt ##把原來的檔案移到/mnt下
4)vim /etc/yum.repos.d/yum.repo ##檔案格式要以.repo結尾
[redhatpackage] ##倉庫名稱
name=localpackage ##倉庫描述
baseurl=file:///yum ##倉庫地址
gpgcheck=0 ##是否檢測軟體的gpgkey,0為不檢測,1為檢測
5)yum clean all ##重新整理倉庫配置
6)yum repolist ##檢視yum資源庫資訊
注:df命令 ##檢視第2步掛載情況
2./etc/fstab ##fstab檔案包含了系統在啟動時,掛載檔案系統和儲存裝置的詳細資訊
格式:
/絕對路徑/rhel-server-7.0-x86_64-dvd.iso /xxx iso9660 ro,relatime 0 0
映象檔案位置 掛在點 型別 掛載引數 不備份 不檢測
eg:
vim /etc/fstab
寫入/etc/fstab,使系統能夠開機讀取rhel-server-7.0-x86_64-dvd.iso中的內容
mount -a ##檢查/etc/fstab內容,並把所寫內容進行掛載
3.編寫軟體倉庫的指定檔案
/etc/yum.repos.d ##倉庫指向檔案儲存目錄
vim /etc/yum.repos.d/test.repo ##倉庫指向檔案
[redhatpackage] ##倉庫名稱
name=localpackage ##倉庫描述
baseurl=file:///yumsource ##倉庫地址
gpgcheck=1 ##是否檢測軟體的gpgkey
enabled=1 ##此倉庫在系統中生效(0為在系統中不生效)
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release ##本機gpgkey檔案
eg:
vim /etc/yum.repos.d/test.repo(/etc/yum.repos.d/中只留下test.repo)
[test]
name=test
baseurl=file:///source(那臺機子的倉庫位置)
gpgcheck=0
enabled=0
4.網路軟體倉庫的配置
(物理機搭建網路yum源,虛擬機器可以訪問使用物理機yum源)
1)yum install httpd -y ##物理機要有httpd服務
2)systemctl start httpd ##啟動httpd
3)systemctl enable httpd ##開機啟動httpd
4)systemctl stop firewalld ##關閉物理機的防火牆
5)mkdir -p /var/www/html/yum ##在/var/www/html/下建立yum目錄
6)mount /iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/yum ##掛載映象
7)vim /etc/fstab ##寫在/etc/fstab可以記錄下來,下次開機即可啟動
/iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/yum iso9660 ro,relatime 0 0
(小技巧:vim編輯時ctrl+z打入後臺,複製rhel-server-7.0-x86_64-dvd.iso,fg調出來,貼上,繼續編輯)
8)mount -a ##檢查/etc/fstab內容,並把所寫內容進行掛載
瀏覽器訪問:http://物理機ip/yum ##可以檢視到倉庫內容
5.第三方軟體倉庫的搭建
1)mkdir /software ##新建/software
2)mv .rpm包 /software ##把所有rpm包放到指定目錄中
3)createrepo -v /software ##建立repodata
4)vim /etc/yum.repos.d/test.repo ##倉庫指向檔案
[software]
name=software
baseurl=file:///software
gpgcheck=0
5)yum clean all ##重新整理配置
6)yum repolist ##檢視software庫資訊
6.以ftp服務的方式搭建
1)yum install vsftp -y ##安裝vsftp服務
2)systemctl start vsftpd ##開啟服務
3)firewall-cmd --permanent --add-service=ftp
4)保證/var/ftp/下的內容有可讀許可權
(訪問:ftp://ip地址/pub/可以看到內容)
5)可以使用lftp ip 訪問了
############rpm命令##########
rpm ###Red Hat Package Manager,軟體包管理工具,類似windows裡面的“新增/刪除”程式
-a ###所有的安裝包
-i ###install
-v ###顯示資訊
-h ###指定包的解密方式為hash
-q ###查詢
-p ###指定軟體包本身
-l ###列出軟體中檔案的名字
-f ###查詢某個檔案屬於那個安裝包
-a ###所有
-e ###解除安裝
--force ###強制
--nodeps ###忽略依賴性
--scripts ##檢視軟體安裝和解除安裝過程中所執行的動作常用組合:
1)對已安裝的軟體的查詢
rpm -qa |grep 關鍵字 ##在已經安裝的軟體包中查詢關鍵字軟體
rpm -qf 檔名 ##查詢已安裝的檔案屬於哪個包,檔名的絕對路徑要寫出來
rpm -qR 軟體名 ##檢視軟體的依賴性
rpm -qd 軟體名 ##查詢軟體的文件安裝位置
2)對為安裝的軟體包的檢視
rpm -qpi file.rpm ##查詢此file.rpm件包的用途、版本資訊
rpm -qpl file.rpm ##查詢此軟體包所包含的軟體
rpm -qpd file.rpm ##查詢此軟體包文件位置
rpm -qpR file.rpm ##查詢此軟體包的依賴關係
3)軟體包的安裝、升級、刪除
rpm -ivh file.rpm ##安裝file.rpm
rpm -Uvh file.rpm ##升級file.rpm
rpm -e 軟體包名 ##解除安裝此軟體包
cat
CentOS-Base-aliyun.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-6 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6/os/$basearch/
http://mirrors.aliyuncs.com/centos/6/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-6 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6/updates/$basearch/
http://mirrors.aliyuncs.com/centos/6/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-6 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6/extras/$basearch/
http://mirrors.aliyuncs.com/centos/6/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/6/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-6 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/6/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
163的yum
cat CentOS-Base-163.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-6 - Base - 163.com
baseurl=http://mirrors.163.com/centos/6/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-6 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/6/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-6 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/6/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/6/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-6 - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/6/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6