So sánh lệnh yum va rpm trong linux

Bài viết này sẽ giới thiệu với các bạn về cách sử dụng lệnh RPM trên hệ điều hành Linux. Trong bài viết này chúng ta sẽ tìm hiểu về RPM cũng như các ví dụ về nó từ đây giúp cho chúng ta có thể tự học và tự tìm hiểu Linux cơ bản.

1. Giới thiệu về RPM

RPM(Red Hat Package Manager) là một công cụ dùng để quản lý gói mặc định và mã nguồn mở mặc định cho các hệ thống dựa trên Red Hat (RHEL, CentOS và Fedora). Công cụ này giúp cho phép chúng ta có thể cài đặt, cập nhật, gỡ cài đặt, truy vấn, xác minh và quản lý các gói phần mềm trên hệ thống. RPM trước đây được gọi là tệp

[root@localhost ~]# rpm -qa | grep python
python-libs-2.7.5-86.el7.x86_64
libselinux-python-2.5-14.1.el7.x86_64
python-schedutils-0.4-6.el7.x86_64
newt-python-0.52.15-4.el7.x86_64
rpm-python-4.11.3-40.el7.x86_64
...

8 gồm các chương trình và thư viện phần mềm được biên dịch cần thiết cho các gói. Tiện ích này chỉ hoạt động với các gói được xây dựng trên định dạng

[root@localhost ~]# rpm -qa | grep python
python-libs-2.7.5-86.el7.x86_64
libselinux-python-2.5-14.1.el7.x86_64
python-schedutils-0.4-6.el7.x86_64
newt-python-0.52.15-4.el7.x86_64
rpm-python-4.11.3-40.el7.x86_64
...

8.

Chức năng cơ bản lệnh RPM:

  • [root@localhost ~]# rpm -q wget wget-1.19.5-7.el8_0.1.x86_64

    0: Sử dụng để cài đặt bất kỳ gói

    [root@localhost ~]# rpm -q wget wget-1.19.5-7.el8_0.1.x86_64

    1.
  • [root@localhost ~]# rpm -q wget wget-1.19.5-7.el8_0.1.x86_64

    2: Sử dụng để xóa hoặc hủy cài đặt bất kỳ gói

    [root@localhost ~]# rpm -q wget wget-1.19.5-7.el8_0.1.x86_64

    1.
  • [root@localhost ~]# rpm -q wget wget-1.19.5-7.el8_0.1.x86_64

    4: Sử dụng để cập nhật gói

    [root@localhost ~]# rpm -q wget wget-1.19.5-7.el8_0.1.x86_64

    1 hiện có.
  • [root@localhost ~]# rpm -q wget wget-1.19.5-7.el8_0.1.x86_64

    6: Sử dụng để truy vấn bất kỳ gói

    [root@localhost ~]# rpm -q wget wget-1.19.5-7.el8_0.1.x86_64

    1.
  • [root@localhost ~]# rpm -q wget wget-1.19.5-7.el8_0.1.x86_64

    8: Sử dụng để xác minh các gói

    [root@localhost ~]# rpm -q wget wget-1.19.5-7.el8_0.1.x86_64

    1.

Với quyền

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

0 chúng ta có thể sử dụng lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 với các tùy chọn phù hợp để quản lý các gói phần mềm RPM.

[root@localhost ~]# rpm -q wget
wget-1.19.5-7.el8_0.1.x86_64

1 là công cụ miễn phí và được phát hành theo GPL (General Public License).

[root@localhost ~]# rpm -q wget
wget-1.19.5-7.el8_0.1.x86_64

1 sẽ lưu giữ thông tin của tất cả các gói đã cài đặt trong

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

4.

[root@localhost ~]# rpm -q wget
wget-1.19.5-7.el8_0.1.x86_64

1 xử lý các tệp

[root@localhost ~]# rpm -qa | grep python
python-libs-2.7.5-86.el7.x86_64
libselinux-python-2.5-14.1.el7.x86_64
python-schedutils-0.4-6.el7.x86_64
newt-python-0.52.15-4.el7.x86_64
rpm-python-4.11.3-40.el7.x86_64
...

8 chứa thông tin về các gói như: nó là gì, từ đâu đến, thông tin phụ thuộc, thông tin phiên bản...

Chúng ta có thể tìm gói RPM tại các trang web sau đây:

  • https://rpmfind.net/
  • https://www.redhat.com/en
  • https://freshrpms.net/
  • http://rpm.pbone.net/

2. Sử dụng RPM

2.1. Các ví dụ cơ bản với lệnh PRM

👉 Ví dụ 1: Cài đặt gói RPM

Tên của tệp

[root@localhost ~]# rpm -q wget
wget-1.19.5-7.el8_0.1.x86_64

1 gồm có các thành phần là: tên gói, phiên bản, phát hành và kiến ​​trúc.

Khi chúng ta thực hiện cài đặt

[root@localhost ~]# rpm -q wget
wget-1.19.5-7.el8_0.1.x86_64

1 thì nó sẽ kiểm tra xem hệ thống có phù hợp với phần mềm mà gói

[root@localhost ~]# rpm -q wget
wget-1.19.5-7.el8_0.1.x86_64

1 chứa hay không, tìm ra nơi cài đặt các tệp và cài đặt chúng trên hệ thống và thêm phần mềm đó vào cơ sở dữ liệu gói

[root@localhost ~]# rpm -q wget
wget-1.19.5-7.el8_0.1.x86_64

1 đã được cài đặt.

Chúng ta chạy lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 với tùy chọn

[root@localhost ~]# rpm -qdf /usr/bin/python2.7
/usr/share/doc/python2/README
/usr/share/man/man1/python.1.gz
/usr/share/man/man1/python2.1.gz
/usr/share/man/man1/python2.7.1.gz

2,

[root@localhost ~]# rpm -qdf /usr/bin/python2.7
/usr/share/doc/python2/README
/usr/share/man/man1/python.1.gz
/usr/share/man/man1/python2.1.gz
/usr/share/man/man1/python2.7.1.gz

3,

[root@localhost ~]# rpm -qdf /usr/bin/python2.7
/usr/share/doc/python2/README
/usr/share/man/man1/python.1.gz
/usr/share/man/man1/python2.1.gz
/usr/share/man/man1/python2.7.1.gz

4 để cài đặt gói RPM

[root@localhost ~]# rpm -qdf /usr/bin/python2.7
/usr/share/doc/python2/README
/usr/share/man/man1/python.1.gz
/usr/share/man/man1/python2.1.gz
/usr/share/man/man1/python2.7.1.gz

5 như bên dưới:

[root@localhost ~]# rpm -ivh wget-1.19.5-7.el8_0.1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:wget                   ########################################### [100%]

Trong đó các tùy chọn có ý nghĩa như sau:

  • [root@localhost ~]# rpm -qdf /usr/bin/python2.7 /usr/share/doc/python2/README /usr/share/man/man1/python.1.gz /usr/share/man/man1/python2.1.gz /usr/share/man/man1/python2.7.1.gz

    2: Cài đặt một gói.
  • [root@localhost ~]# rpm -qdf /usr/bin/python2.7 /usr/share/doc/python2/README /usr/share/man/man1/python.1.gz /usr/share/man/man1/python2.1.gz /usr/share/man/man1/python2.7.1.gz

    3: Hiển thị đầy đủ.
  • [root@localhost ~]# rpm -qdf /usr/bin/python2.7 /usr/share/doc/python2/README /usr/share/man/man1/python.1.gz /usr/share/man/man1/python2.1.gz /usr/share/man/man1/python2.7.1.gz

    4: Hiển thị dấu băm khi gói được giải nén.

👉 Ví dụ 2: Truy vấn tất cả các gói RPM

Chúng ta có thể truy vấn tất cả các gói RPM đã dược cài đặt bằng cách sử dụng lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 cùng với các tùy chọn

[root@localhost ~]# rpm -qi python
Name        : python
Version     : 2.7.5
Release     : 86.el7
Architecture: x86_64
Install Date: Tue 01 Oct 2019 07:37:48 PM +07
Group       : Development/Languages
Size        : 80907
License     : Python
Signature   : RSA/SHA256, Fri 23 Aug 2019 04:40:03 AM +07, Key ID 24c6a8a7f4a80eb5
Source RPM  : python-2.7.5-86.el7.src.rpm
Build Date  : Wed 07 Aug 2019 08:15:38 AM +07
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem 
Vendor      : CentOS
URL         : http://www.python.org/
Summary     : An interpreted, interactive, object-oriented programming language
Description :
Python is an interpreted, interactive, object-oriented programming
language often compared to Tcl, Perl, Scheme or Java. Python includes
modules, classes, exceptions, very high level dynamic data types and
dynamic typing. Python supports interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac and MFC).
Programmers can write new built-in modules for Python in C or C++.
Python can be used as an extension language for applications that need
a programmable interface.
Note that documentation for Python is provided in the python-docs
package.
This package provides the "python" executable; most of the actual
implementation is within the "python-libs" package.

0 và

[root@localhost ~]# rpm -qi python
Name        : python
Version     : 2.7.5
Release     : 86.el7
Architecture: x86_64
Install Date: Tue 01 Oct 2019 07:37:48 PM +07
Group       : Development/Languages
Size        : 80907
License     : Python
Signature   : RSA/SHA256, Fri 23 Aug 2019 04:40:03 AM +07, Key ID 24c6a8a7f4a80eb5
Source RPM  : python-2.7.5-86.el7.src.rpm
Build Date  : Wed 07 Aug 2019 08:15:38 AM +07
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem 
Vendor      : CentOS
URL         : http://www.python.org/
Summary     : An interpreted, interactive, object-oriented programming language
Description :
Python is an interpreted, interactive, object-oriented programming
language often compared to Tcl, Perl, Scheme or Java. Python includes
modules, classes, exceptions, very high level dynamic data types and
dynamic typing. Python supports interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac and MFC).
Programmers can write new built-in modules for Python in C or C++.
Python can be used as an extension language for applications that need
a programmable interface.
Note that documentation for Python is provided in the python-docs
package.
This package provides the "python" executable; most of the actual
implementation is within the "python-libs" package.

1:

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

Trong đó ý nghĩa các tùy chọn như sau:

  • [root@localhost ~]# rpm -qi python Name : python Version : 2.7.5 Release : 86.el7 Architecture: x86_64 Install Date: Tue 01 Oct 2019 07:37:48 PM +07 Group : Development/Languages Size : 80907 License : Python Signature : RSA/SHA256, Fri 23 Aug 2019 04:40:03 AM +07, Key ID 24c6a8a7f4a80eb5 Source RPM : python-2.7.5-86.el7.src.rpm Build Date : Wed 07 Aug 2019 08:15:38 AM +07 Build Host : x86-01.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem Vendor : CentOS URL : http://www.python.org/ Summary : An interpreted, interactive, object-oriented programming language Description : Python is an interpreted, interactive, object-oriented programming language often compared to Tcl, Perl, Scheme or Java. Python includes modules, classes, exceptions, very high level dynamic data types and dynamic typing. Python supports interfaces to many system calls and libraries, as well as to various windowing systems (X11, Motif, Tk, Mac and MFC). Programmers can write new built-in modules for Python in C or C++. Python can be used as an extension language for applications that need a programmable interface. Note that documentation for Python is provided in the python-docs package. This package provides the "python" executable; most of the actual implementation is within the "python-libs" package.

    2: Dùng để truy vấn.
  • [root@localhost ~]# rpm -qi python Name : python Version : 2.7.5 Release : 86.el7 Architecture: x86_64 Install Date: Tue 01 Oct 2019 07:37:48 PM +07 Group : Development/Languages Size : 80907 License : Python Signature : RSA/SHA256, Fri 23 Aug 2019 04:40:03 AM +07, Key ID 24c6a8a7f4a80eb5 Source RPM : python-2.7.5-86.el7.src.rpm Build Date : Wed 07 Aug 2019 08:15:38 AM +07 Build Host : x86-01.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem Vendor : CentOS URL : http://www.python.org/ Summary : An interpreted, interactive, object-oriented programming language Description : Python is an interpreted, interactive, object-oriented programming language often compared to Tcl, Perl, Scheme or Java. Python includes modules, classes, exceptions, very high level dynamic data types and dynamic typing. Python supports interfaces to many system calls and libraries, as well as to various windowing systems (X11, Motif, Tk, Mac and MFC). Programmers can write new built-in modules for Python in C or C++. Python can be used as an extension language for applications that need a programmable interface. Note that documentation for Python is provided in the python-docs package. This package provides the "python" executable; most of the actual implementation is within the "python-libs" package.

    3: Dùng để hiển thi tất cả các gói đã cài đặt.

Khi chúng ta muốm tìm kiếm xem một gối PRM có được cài đặt trên hệ thống hay không thì chúng ta có thể kết hợp lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 và lệnh grep để tìm kiếm. Ví dụ sau đây chúng ta sẽ xem gói

[root@localhost ~]# rpm -qi python
Name        : python
Version     : 2.7.5
Release     : 86.el7
Architecture: x86_64
Install Date: Tue 01 Oct 2019 07:37:48 PM +07
Group       : Development/Languages
Size        : 80907
License     : Python
Signature   : RSA/SHA256, Fri 23 Aug 2019 04:40:03 AM +07, Key ID 24c6a8a7f4a80eb5
Source RPM  : python-2.7.5-86.el7.src.rpm
Build Date  : Wed 07 Aug 2019 08:15:38 AM +07
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem 
Vendor      : CentOS
URL         : http://www.python.org/
Summary     : An interpreted, interactive, object-oriented programming language
Description :
Python is an interpreted, interactive, object-oriented programming
language often compared to Tcl, Perl, Scheme or Java. Python includes
modules, classes, exceptions, very high level dynamic data types and
dynamic typing. Python supports interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac and MFC).
Programmers can write new built-in modules for Python in C or C++.
Python can be used as an extension language for applications that need
a programmable interface.
Note that documentation for Python is provided in the python-docs
package.
This package provides the "python" executable; most of the actual
implementation is within the "python-libs" package.

5 có được cài đặt trên hệ thống không.

[root@localhost ~]# rpm -qa | grep python
python-libs-2.7.5-86.el7.x86_64
libselinux-python-2.5-14.1.el7.x86_64
python-schedutils-0.4-6.el7.x86_64
newt-python-0.52.15-4.el7.x86_64
rpm-python-4.11.3-40.el7.x86_64
...

Qua đây chúng ta sẽ thấy các gói RPM liên qua tới

[root@localhost ~]# rpm -qi python
Name        : python
Version     : 2.7.5
Release     : 86.el7
Architecture: x86_64
Install Date: Tue 01 Oct 2019 07:37:48 PM +07
Group       : Development/Languages
Size        : 80907
License     : Python
Signature   : RSA/SHA256, Fri 23 Aug 2019 04:40:03 AM +07, Key ID 24c6a8a7f4a80eb5
Source RPM  : python-2.7.5-86.el7.src.rpm
Build Date  : Wed 07 Aug 2019 08:15:38 AM +07
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem 
Vendor      : CentOS
URL         : http://www.python.org/
Summary     : An interpreted, interactive, object-oriented programming language
Description :
Python is an interpreted, interactive, object-oriented programming
language often compared to Tcl, Perl, Scheme or Java. Python includes
modules, classes, exceptions, very high level dynamic data types and
dynamic typing. Python supports interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac and MFC).
Programmers can write new built-in modules for Python in C or C++.
Python can be used as an extension language for applications that need
a programmable interface.
Note that documentation for Python is provided in the python-docs
package.
This package provides the "python" executable; most of the actual
implementation is within the "python-libs" package.

5 đã cài đặt sẽ hiển thị.

👉 Ví dụ 3: Truy vấn 1 gói RPM cụ thể

Chúng ta có thể truy vấn một gói cụ thể và xác minh chúng đã được cài đặt chưa bằng việc kết hợp

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 với tùy chọn

[root@localhost ~]# rpm -qi python
Name        : python
Version     : 2.7.5
Release     : 86.el7
Architecture: x86_64
Install Date: Tue 01 Oct 2019 07:37:48 PM +07
Group       : Development/Languages
Size        : 80907
License     : Python
Signature   : RSA/SHA256, Fri 23 Aug 2019 04:40:03 AM +07, Key ID 24c6a8a7f4a80eb5
Source RPM  : python-2.7.5-86.el7.src.rpm
Build Date  : Wed 07 Aug 2019 08:15:38 AM +07
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem 
Vendor      : CentOS
URL         : http://www.python.org/
Summary     : An interpreted, interactive, object-oriented programming language
Description :
Python is an interpreted, interactive, object-oriented programming
language often compared to Tcl, Perl, Scheme or Java. Python includes
modules, classes, exceptions, very high level dynamic data types and
dynamic typing. Python supports interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac and MFC).
Programmers can write new built-in modules for Python in C or C++.
Python can be used as an extension language for applications that need
a programmable interface.
Note that documentation for Python is provided in the python-docs
package.
This package provides the "python" executable; most of the actual
implementation is within the "python-libs" package.

0 sau đó là tên của gói cần sác minh như bên dưới:

[root@localhost ~]# rpm -q wget
wget-1.19.5-7.el8_0.1.x86_64

Lưu ý: Để có thể truy vấn một gói, chúng ta cần sác định tên gói một cách chính xác. Nếu tên gói không chính xác, thì lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n' NetworkManager-1.14.0-14.el8 9797209 geolite2-city-20180605-1.el8 56549434 policycoreutils-2.8-16.1.el8 668198 pkgconf-m4-1.4.2-1.el8 14187 selinux-policy-targeted-3.14.1-61.el8_0.2 51822907 dnf-data-4.0.9.2-5.el8 34196 ...

1 sẽ báo cáo rằng gói không được cài đặt.

👉 Ví dụ 4: Truy vấn các gói RPM theo một định dạng khác nhau

Lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 cung cấp cho chúng ta tùy chọn

[root@localhost ~]# rpm -qf /usr/bin/python2.7
python2-2.7.15-24.module_el8.0.0+193+7850e68f.x86_64

1, cho phép chúng ta có thể đặt tên thẻ tiêu đề, để liệt kê các gói. Đính kèm thẻ tiêu đề trong

[root@localhost ~]# rpm -qf /usr/bin/python2.7
python2-2.7.15-24.module_el8.0.0+193+7850e68f.x86_64

2.

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

👉 Ví dụ 5: Xác định vị trí của gói thuộc các tệp

Lệnh sau, cung cấp vị trí của tất cả các tệp liên quan đến gói

[root@localhost ~]# rpm -qf /usr/bin/python2.7
python2-2.7.15-24.module_el8.0.0+193+7850e68f.x86_64

3.

[root@localhost ~]# rpm -qdf /usr/bin/python2.7
/usr/share/doc/python2/README
/usr/share/man/man1/python.1.gz
/usr/share/man/man1/python2.1.gz
/usr/share/man/man1/python2.7.1.gz

Trong đó tùy chọn

[root@localhost ~]# rpm -qf /usr/bin/python2.7
python2-2.7.15-24.module_el8.0.0+193+7850e68f.x86_64

4 giúp chúng ta đề cập tới tệp liên quan tới gói.

👉 Ví dụ 6: Hiển thị thông tin về gói RPM

Lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 giúp cho chúng ta có thể hiển thị rất nhiều thông tin về một pacakge bằng việc kết hợp lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 với tùy chọn

[root@localhost ~]# rpm -qi python
Name        : python
Version     : 2.7.5
Release     : 86.el7
Architecture: x86_64
Install Date: Tue 01 Oct 2019 07:37:48 PM +07
Group       : Development/Languages
Size        : 80907
License     : Python
Signature   : RSA/SHA256, Fri 23 Aug 2019 04:40:03 AM +07, Key ID 24c6a8a7f4a80eb5
Source RPM  : python-2.7.5-86.el7.src.rpm
Build Date  : Wed 07 Aug 2019 08:15:38 AM +07
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem 
Vendor      : CentOS
URL         : http://www.python.org/
Summary     : An interpreted, interactive, object-oriented programming language
Description :
Python is an interpreted, interactive, object-oriented programming
language often compared to Tcl, Perl, Scheme or Java. Python includes
modules, classes, exceptions, very high level dynamic data types and
dynamic typing. Python supports interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac and MFC).
Programmers can write new built-in modules for Python in C or C++.
Python can be used as an extension language for applications that need
a programmable interface.
Note that documentation for Python is provided in the python-docs
package.
This package provides the "python" executable; most of the actual
implementation is within the "python-libs" package.

2 và tùy chọn

[root@localhost ~]# rpm -qf /usr/bin/python2.7
python2-2.7.15-24.module_el8.0.0+193+7850e68f.x86_64

8 được cài đặt trên hệ thống:

[root@localhost ~]# rpm -qi python
Name        : python
Version     : 2.7.5
Release     : 86.el7
Architecture: x86_64
Install Date: Tue 01 Oct 2019 07:37:48 PM +07
Group       : Development/Languages
Size        : 80907
License     : Python
Signature   : RSA/SHA256, Fri 23 Aug 2019 04:40:03 AM +07, Key ID 24c6a8a7f4a80eb5
Source RPM  : python-2.7.5-86.el7.src.rpm
Build Date  : Wed 07 Aug 2019 08:15:38 AM +07
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem 
Vendor      : CentOS
URL         : http://www.python.org/
Summary     : An interpreted, interactive, object-oriented programming language
Description :
Python is an interpreted, interactive, object-oriented programming
language often compared to Tcl, Perl, Scheme or Java. Python includes
modules, classes, exceptions, very high level dynamic data types and
dynamic typing. Python supports interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac and MFC).
Programmers can write new built-in modules for Python in C or C++.
Python can be used as an extension language for applications that need
a programmable interface.
Note that documentation for Python is provided in the python-docs
package.
This package provides the "python" executable; most of the actual
implementation is within the "python-libs" package.

Trong đó ý nghĩa các tùy chọn như sau:

  • [root@localhost ~]# rpm -qf /usr/bin/python2.7 python2-2.7.15-24.module_el8.0.0+193+7850e68f.x86_64

    8: Hiển thị thông tin của một package.
  • [root@localhost ~]# rpm -qa --last microcode_ctl-2.1-53.3.el7_7.x86_64 Mon 02 Dec 2019 10:54:27 PM +07 python-perf-3.10.0-1062.4.3.el7.x86_64 Mon 02 Dec 2019 10:54:26 PM +07 epel-release-7-12.noarch Mon 02 Dec 2019 10:54:26 PM +07 kernel-3.10.0-1062.4.3.el7.x86_64 Mon 02 Dec 2019 10:54:23 PM +07 kernel-tools-3.10.0-1062.4.3.el7.x86_64 Mon 02 Dec 2019 10:54:16 PM +07 kernel-tools-libs-3.10.0-1062.4.3.el7.x86_64 Mon 02 Dec 2019 10:54:15 PM +07 wget-1.14-18.el7_6.1.x86_64 Mon 02 Dec 2019 10:50:47 PM +07 htop-2.2.0-3.el7.x86_64 Sat 09 Nov 2019 10:41:57 PM +07 gpg-pubkey-352c64e5-52ae6884 Sat 09 Nov 2019 10:41:56 PM +07 ...

    0: Chỉ định một package.

👉 Ví dụ 7: Kiểm tra xem tệp RPM thuộc về gói nào.

Khi chúng ta có danh sách các tệp và chúng ta muốn biết gói nào sở hữu tất cả các tệp này thì lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 có thể giúp chúng ta xác định điều này.

Ví dụ: Khi chúng ta có tệp

[root@localhost ~]# rpm -qa --last
microcode_ctl-2.1-53.3.el7_7.x86_64           Mon 02 Dec 2019 10:54:27 PM +07
python-perf-3.10.0-1062.4.3.el7.x86_64        Mon 02 Dec 2019 10:54:26 PM +07
epel-release-7-12.noarch                      Mon 02 Dec 2019 10:54:26 PM +07
kernel-3.10.0-1062.4.3.el7.x86_64             Mon 02 Dec 2019 10:54:23 PM +07
kernel-tools-3.10.0-1062.4.3.el7.x86_64       Mon 02 Dec 2019 10:54:16 PM +07
kernel-tools-libs-3.10.0-1062.4.3.el7.x86_64  Mon 02 Dec 2019 10:54:15 PM +07
wget-1.14-18.el7_6.1.x86_64                   Mon 02 Dec 2019 10:50:47 PM +07
htop-2.2.0-3.el7.x86_64                       Sat 09 Nov 2019 10:41:57 PM +07
gpg-pubkey-352c64e5-52ae6884                  Sat 09 Nov 2019 10:41:56 PM +07
...

2 để có thể biết gói sở hửu tệp chúng ta thực thi lệnh sau:

[root@localhost ~]# rpm -qf /usr/bin/python2.7
python2-2.7.15-24.module_el8.0.0+193+7850e68f.x86_64

👉 Ví dụ 8: Để có thể liệt kê các gói RPM được cài đặt gần đây chúng ta sử dụng lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 với tùy chọn

[root@localhost ~]# rpm -qa --last
microcode_ctl-2.1-53.3.el7_7.x86_64           Mon 02 Dec 2019 10:54:27 PM +07
python-perf-3.10.0-1062.4.3.el7.x86_64        Mon 02 Dec 2019 10:54:26 PM +07
epel-release-7-12.noarch                      Mon 02 Dec 2019 10:54:26 PM +07
kernel-3.10.0-1062.4.3.el7.x86_64             Mon 02 Dec 2019 10:54:23 PM +07
kernel-tools-3.10.0-1062.4.3.el7.x86_64       Mon 02 Dec 2019 10:54:16 PM +07
kernel-tools-libs-3.10.0-1062.4.3.el7.x86_64  Mon 02 Dec 2019 10:54:15 PM +07
wget-1.14-18.el7_6.1.x86_64                   Mon 02 Dec 2019 10:50:47 PM +07
htop-2.2.0-3.el7.x86_64                       Sat 09 Nov 2019 10:41:57 PM +07
gpg-pubkey-352c64e5-52ae6884                  Sat 09 Nov 2019 10:41:56 PM +07
...

4 dùng để truy vấn tất cả ), sẽ giúp chúng ta liệt kê tất cả các gói

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 được cài đặt gần đây như bên dưới:

[root@localhost ~]# rpm -qa --last
microcode_ctl-2.1-53.3.el7_7.x86_64           Mon 02 Dec 2019 10:54:27 PM +07
python-perf-3.10.0-1062.4.3.el7.x86_64        Mon 02 Dec 2019 10:54:26 PM +07
epel-release-7-12.noarch                      Mon 02 Dec 2019 10:54:26 PM +07
kernel-3.10.0-1062.4.3.el7.x86_64             Mon 02 Dec 2019 10:54:23 PM +07
kernel-tools-3.10.0-1062.4.3.el7.x86_64       Mon 02 Dec 2019 10:54:16 PM +07
kernel-tools-libs-3.10.0-1062.4.3.el7.x86_64  Mon 02 Dec 2019 10:54:15 PM +07
wget-1.14-18.el7_6.1.x86_64                   Mon 02 Dec 2019 10:50:47 PM +07
htop-2.2.0-3.el7.x86_64                       Sat 09 Nov 2019 10:41:57 PM +07
gpg-pubkey-352c64e5-52ae6884                  Sat 09 Nov 2019 10:41:56 PM +07
...

👉 Ví dụ 9: Nếu chúng ta muốn nâng cấp bất kỳ gói RPM hãy sử dụng tùy chọn

[root@localhost ~]# rpm -qa --last
microcode_ctl-2.1-53.3.el7_7.x86_64           Mon 02 Dec 2019 10:54:27 PM +07
python-perf-3.10.0-1062.4.3.el7.x86_64        Mon 02 Dec 2019 10:54:26 PM +07
epel-release-7-12.noarch                      Mon 02 Dec 2019 10:54:26 PM +07
kernel-3.10.0-1062.4.3.el7.x86_64             Mon 02 Dec 2019 10:54:23 PM +07
kernel-tools-3.10.0-1062.4.3.el7.x86_64       Mon 02 Dec 2019 10:54:16 PM +07
kernel-tools-libs-3.10.0-1062.4.3.el7.x86_64  Mon 02 Dec 2019 10:54:15 PM +07
wget-1.14-18.el7_6.1.x86_64                   Mon 02 Dec 2019 10:50:47 PM +07
htop-2.2.0-3.el7.x86_64                       Sat 09 Nov 2019 10:41:57 PM +07
gpg-pubkey-352c64e5-52ae6884                  Sat 09 Nov 2019 10:41:56 PM +07
...

6. Nó giúp cho chúng ta nâng cấp phiên bản mới nhất của gói và duy trì sao lưu gói cũ hơn để trong trường hợp gói nâng cấp mới hơn không chạy gói đã cài đặt trước đó có thể được sử dụng lại.

[root@localhost ~]# rpm -Uvh wget-1.19.5-7.el8_0.1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:wget                   ########################################### [100%]

👉 Ví dụ 10: Để hủy cài đặt một gói RPM chúng ta sử dụng lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 với tùy chọn

[root@localhost ~]# rpm -qa --last
microcode_ctl-2.1-53.3.el7_7.x86_64           Mon 02 Dec 2019 10:54:27 PM +07
python-perf-3.10.0-1062.4.3.el7.x86_64        Mon 02 Dec 2019 10:54:26 PM +07
epel-release-7-12.noarch                      Mon 02 Dec 2019 10:54:26 PM +07
kernel-3.10.0-1062.4.3.el7.x86_64             Mon 02 Dec 2019 10:54:23 PM +07
kernel-tools-3.10.0-1062.4.3.el7.x86_64       Mon 02 Dec 2019 10:54:16 PM +07
kernel-tools-libs-3.10.0-1062.4.3.el7.x86_64  Mon 02 Dec 2019 10:54:15 PM +07
wget-1.14-18.el7_6.1.x86_64                   Mon 02 Dec 2019 10:50:47 PM +07
htop-2.2.0-3.el7.x86_64                       Sat 09 Nov 2019 10:41:57 PM +07
gpg-pubkey-352c64e5-52ae6884                  Sat 09 Nov 2019 10:41:56 PM +07
...

8 mèm theo đó là tên gói chúng ta cần hủy cài đặt. Giả sử chúng ta muốn hủy cài đặt gói có tên

[root@localhost ~]# rpm -qdf /usr/bin/python2.7
/usr/share/doc/python2/README
/usr/share/man/man1/python.1.gz
/usr/share/man/man1/python2.1.gz
/usr/share/man/man1/python2.7.1.gz

5 thực hiện như sau:

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

0

👉 Ví dụ 11: Cách xóa gói

[root@localhost ~]# rpm -q wget
wget-1.19.5-7.el8_0.1.x86_64

1 không phụ thuộc bằng cách sử dụng tùy chọn

[root@localhost ~]# rpm -Uvh wget-1.19.5-7.el8_0.1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:wget                   ########################################### [100%]

1 không kiểm tra phụ thuộc:

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

1

Lưu ý: Chúng ta cần xác định loại bỏ gói cụ thể nào đó nếu loại bỏ sai có thể ảnh hưởng các ứng dụng làm việc khác.

👉 Ví dụ 12: Khi chúng ta muốn nhập khóa

[root@localhost ~]# rpm -Uvh wget-1.19.5-7.el8_0.1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:wget                   ########################################### [100%]

2 để xác minh các gói

[root@localhost ~]# rpm -Uvh wget-1.19.5-7.el8_0.1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:wget                   ########################################### [100%]

3 chúng ta cần thực hiện như bên dưới lệnh này sẽ nhập

[root@localhost ~]# rpm -Uvh wget-1.19.5-7.el8_0.1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:wget                   ########################################### [100%]

4:

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

2

👉 Ví dụ 13: Sau khi thực hiện thêm

[root@localhost ~]# rpm -Uvh wget-1.19.5-7.el8_0.1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:wget                   ########################################### [100%]

2 chúng ta có thể hiển thị tất cả các

[root@localhost ~]# rpm -Uvh wget-1.19.5-7.el8_0.1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:wget                   ########################################### [100%]

2 đã được nhập trên hệ thống của chúng ta bằng cách thực thi lệnh sau:

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

3

👉 Ví dụ 14: Cách kiểm tra gói

[root@localhost ~]# rpm -q wget
wget-1.19.5-7.el8_0.1.x86_64

1 đã cài đặt sử dụng tùy chọn

[root@localhost ~]# rpm -qi python
Name        : python
Version     : 2.7.5
Release     : 86.el7
Architecture: x86_64
Install Date: Tue 01 Oct 2019 07:37:48 PM +07
Group       : Development/Languages
Size        : 80907
License     : Python
Signature   : RSA/SHA256, Fri 23 Aug 2019 04:40:03 AM +07, Key ID 24c6a8a7f4a80eb5
Source RPM  : python-2.7.5-86.el7.src.rpm
Build Date  : Wed 07 Aug 2019 08:15:38 AM +07
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem 
Vendor      : CentOS
URL         : http://www.python.org/
Summary     : An interpreted, interactive, object-oriented programming language
Description :
Python is an interpreted, interactive, object-oriented programming
language often compared to Tcl, Perl, Scheme or Java. Python includes
modules, classes, exceptions, very high level dynamic data types and
dynamic typing. Python supports interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac and MFC).
Programmers can write new built-in modules for Python in C or C++.
Python can be used as an extension language for applications that need
a programmable interface.
Note that documentation for Python is provided in the python-docs
package.
This package provides the "python" executable; most of the actual
implementation is within the "python-libs" package.

0 với tên gói như sau:

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

4

👉 Ví dụ 15: Cách liệt kê tất cả các tệp của gói RPM đã cài đặt sử dụng tùy chọn

[root@localhost ~]# rpm -Uvh wget-1.19.5-7.el8_0.1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:wget                   ########################################### [100%]

9 danh sách truy vấn với lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 như bên dưới:

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

5

👉 Ví dụ 16: Khi chúng ta muốn thực hiện cài dè lệnh gói cũ chúng ta thực hiện như sau. Giả sử chúng ta cần cài đè lên gói

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

01.

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

6

2.2. Xây dựng lại cơ sở dữ liệu RPM bị hỏng trong CentOS 7

Cơ sở dữ liệu

[root@localhost ~]# rpm -q wget
wget-1.19.5-7.el8_0.1.x86_64

1 được tạo thành từ các tệp trong thư mục

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

03 đối với bản phân phối như RHEL, openSUSE, Oracle Linux... Khi cơ sở dữ liệu RPM bị hỏng thì RPM sẽ không hoạt động chính xác, do đó các bản cập nhật không thể được áp dụng cho hệ thống của chúng ta, gặp phải lỗi trong khi cập nhật các gói trên hệ thống thông qua trình quản lý gói yum Hoặc không thể chạy bất kỳ lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 và lệnh

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

05 nào thành công. Trong phần này chúng ta sẽ tìm hiểu cách xây dựng lại cơ sở dữ liệu RPM bị hỏng trong CentOS 7.

Chúng ta sẽ nhận được một số lỗi thường gặp khi cơ sở dữ liệu RPM bị hỏng trong CentOS 7 như sau:

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

7

Hoặc

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

8

Hoặc

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

9

Hoặc

[root@localhost ~]# rpm -qa | grep python
python-libs-2.7.5-86.el7.x86_64
libselinux-python-2.5-14.1.el7.x86_64
python-schedutils-0.4-6.el7.x86_64
newt-python-0.52.15-4.el7.x86_64
rpm-python-4.11.3-40.el7.x86_64
...

0

Trước tiên chúng ta cần bắt đầu bằng cách sao lưu cơ sở dữ liệu RPM hiện tại trước khi tiếp tục vì chúng ta có thể cần nó trong tương lai bằng cách thực thi các lệnh sau:

[root@localhost ~]# rpm -qa | grep python
python-libs-2.7.5-86.el7.x86_64
libselinux-python-2.5-14.1.el7.x86_64
python-schedutils-0.4-6.el7.x86_64
newt-python-0.52.15-4.el7.x86_64
rpm-python-4.11.3-40.el7.x86_64
...

1

Tiếp theo, xác minh tính toàn vẹn của tệp chứ gói chính

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

06 đây là tệp cần xây dựng lại, nhưng trước tiên cần xóa tệp

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

07 để ngăn chặn các khóa cũ:

[root@localhost ~]# rpm -qa | grep python
python-libs-2.7.5-86.el7.x86_64
libselinux-python-2.5-14.1.el7.x86_64
python-schedutils-0.4-6.el7.x86_64
newt-python-0.52.15-4.el7.x86_64
rpm-python-4.11.3-40.el7.x86_64
...

2

Nếu thực hiện các thao tác trên không thành công chúng ta nên tải cơ sở dữ liệu mới. Đồng thời xác minh tính toàn vẹn của gói mới tải:

[root@localhost ~]# rpm -qa | grep python
python-libs-2.7.5-86.el7.x86_64
libselinux-python-2.5-14.1.el7.x86_64
python-schedutils-0.4-6.el7.x86_64
newt-python-0.52.15-4.el7.x86_64
rpm-python-4.11.3-40.el7.x86_64
...

3

Kiểm tra các tiêu đề cơ sở dữ liệu, truy vấn tất cả các gói đã cài đặt bằng cách sử dụng tùy chọn

[root@localhost ~]# rpm -qi python
Name        : python
Version     : 2.7.5
Release     : 86.el7
Architecture: x86_64
Install Date: Tue 01 Oct 2019 07:37:48 PM +07
Group       : Development/Languages
Size        : 80907
License     : Python
Signature   : RSA/SHA256, Fri 23 Aug 2019 04:40:03 AM +07, Key ID 24c6a8a7f4a80eb5
Source RPM  : python-2.7.5-86.el7.src.rpm
Build Date  : Wed 07 Aug 2019 08:15:38 AM +07
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem 
Vendor      : CentOS
URL         : http://www.python.org/
Summary     : An interpreted, interactive, object-oriented programming language
Description :
Python is an interpreted, interactive, object-oriented programming
language often compared to Tcl, Perl, Scheme or Java. Python includes
modules, classes, exceptions, very high level dynamic data types and
dynamic typing. Python supports interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac and MFC).
Programmers can write new built-in modules for Python in C or C++.
Python can be used as an extension language for applications that need
a programmable interface.
Note that documentation for Python is provided in the python-docs
package.
This package provides the "python" executable; most of the actual
implementation is within the "python-libs" package.

0 và

[root@localhost ~]# rpm -qi python
Name        : python
Version     : 2.7.5
Release     : 86.el7
Architecture: x86_64
Install Date: Tue 01 Oct 2019 07:37:48 PM +07
Group       : Development/Languages
Size        : 80907
License     : Python
Signature   : RSA/SHA256, Fri 23 Aug 2019 04:40:03 AM +07, Key ID 24c6a8a7f4a80eb5
Source RPM  : python-2.7.5-86.el7.src.rpm
Build Date  : Wed 07 Aug 2019 08:15:38 AM +07
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem 
Vendor      : CentOS
URL         : http://www.python.org/
Summary     : An interpreted, interactive, object-oriented programming language
Description :
Python is an interpreted, interactive, object-oriented programming
language often compared to Tcl, Perl, Scheme or Java. Python includes
modules, classes, exceptions, very high level dynamic data types and
dynamic typing. Python supports interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac and MFC).
Programmers can write new built-in modules for Python in C or C++.
Python can be used as an extension language for applications that need
a programmable interface.
Note that documentation for Python is provided in the python-docs
package.
This package provides the "python" executable; most of the actual
implementation is within the "python-libs" package.

1 quan sát lỗi nào được gửi đến stderror.

[root@localhost ~]# rpm -qa | grep python
python-libs-2.7.5-86.el7.x86_64
libselinux-python-2.5-14.1.el7.x86_64
python-schedutils-0.4-6.el7.x86_64
newt-python-0.52.15-4.el7.x86_64
rpm-python-4.11.3-40.el7.x86_64
...

4

Sau đó chúng ta thực hiện xây dựng lại cơ sở dữ liệu RPM bằng lệnh sau:

[root@localhost ~]# rpm -qa | grep python
python-libs-2.7.5-86.el7.x86_64
libselinux-python-2.5-14.1.el7.x86_64
python-schedutils-0.4-6.el7.x86_64
newt-python-0.52.15-4.el7.x86_64
rpm-python-4.11.3-40.el7.x86_64
...

5

Trong đó tùy chọn

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

10 cho phép hiển thị nhiều thông tin gỡ lỗi.

Ngoài ra chúng ta có thể sử dụng công cụ

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

11 để phát hiện và sửa lỗi cơ sở dữ liệu RPM. Chúng ta có thể tải và thực hiện cài đặt cuúng như sau:

[root@localhost ~]# rpm -qa | grep python
python-libs-2.7.5-86.el7.x86_64
libselinux-python-2.5-14.1.el7.x86_64
python-schedutils-0.4-6.el7.x86_64
newt-python-0.52.15-4.el7.x86_64
rpm-python-4.11.3-40.el7.x86_64
...

6

Khi đã cài đặt

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

11 chúng ta có thể sử dúng nó như sau:

[root@localhost ~]# rpm -qa | grep python
python-libs-2.7.5-86.el7.x86_64
libselinux-python-2.5-14.1.el7.x86_64
python-schedutils-0.4-6.el7.x86_64
newt-python-0.52.15-4.el7.x86_64
rpm-python-4.11.3-40.el7.x86_64
...

7

Sau khi chúng ta xây dựng lại cơ sở dữ liệu RPM bị hỏng trong CentOS 7 chúng ta có thể thực hiện lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 cũng như lệnh

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

05 thành công.

4. Lời kết

Qua bài trên, giúp cho chúng ta hiểu hơn về cách sử dụng lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 trên hệ điều hành Linux. Ngoài ra, bài viết trên còn hổ trợ chúng ta trong việc xây dựng lại cơ sở dữ liệu RPM trên hệ điều hành Linux giúp cho chúng ta có thể khắc phục các sự cố liên quan việc sử dụng lệnh

[root@localhost ~]# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
NetworkManager-1.14.0-14.el8 9797209
geolite2-city-20180605-1.el8 56549434
policycoreutils-2.8-16.1.el8 668198
pkgconf-m4-1.4.2-1.el8 14187
selinux-policy-targeted-3.14.1-61.el8_0.2 51822907
dnf-data-4.0.9.2-5.el8 34196
...

1 cũng như sự cố liên quan đến lệnh

[root@localhost ~]# rpm -qa
libdrm-2.4.97-2.el7.x86_64
device-mapper-event-1.02.158-2.el7_7.2.x86_64
ebtables-2.0.10-16.el7.x86_64
teamd-1.27-9.el7.x86_64
plymouth-0.8.9-0.32.20140113.el7.centos.x86_64
elfutils-libelf-0.176-2.el7.i686
libstdc++-4.8.5-39.el7.i686
...

05 trên hệ thống Linux.