linux查看已启用的服务

什么是仓库?

在Linux系统中,仓库(Repository)是一个用于存储软件包的地方,它通常包含了一系列软件包及其元数据,如版本号、依赖关系等,用户可以通过访问仓库来获取所需的软件包,或者将自己的软件包上传到仓库以供他人使用,在Linux中,有许多知名的仓库,如Ubuntu的APT仓库、Fedora的DNF仓库等。

如何查看已启用或激活的仓库?

在Linux系统中,有多种方法可以查看已启用或激活的仓库,以下是一些常用的方法:

linux查看已启用的服务

1、使用cat命令查看/etc/apt/sources.list文件

对于基于Debian的系统(如Ubuntu),可以使用以下命令查看已启用的仓库:

cat /etc/apt/sources.list

对于基于Red Hat的系统(如Fedora),可以使用以下命令查看已启用的仓库:

cat /etc/yum.repos.d/*.repo

2、使用dpkgrpm命令查看已安装的软件包

这两个命令可以分别用于基于Debian和Red Hat的系统,它们会列出已安装的软件包及其来源仓库的信息,对于基于Debian的系统,可以使用以下命令:

dpkg --get-selections | grep -E '^ii' | awk '{print $2}' | tr ':' '
' | sort | uniq -c | sort -nr

对于基于Red Hat的系统,可以使用以下命令:

linux查看已启用的服务

rpm -qa --whatprovides $(rpm -qa --queryformat '%{NAME}
') | sort | uniq -c | sort -nr

3、使用yum repolistdnf repolist命令查看已启用的仓库

这两个命令可以分别用于基于Debian和Red Hat的系统,它们会列出已启用的仓库及其状态,对于基于Debian的系统,可以使用以下命令:

yum repolist all

对于基于Red Hat的系统,可以使用以下命令:

dnf repolist all

如何在新系统中添加仓库?

在Linux系统中,添加新的仓库非常简单,只需编辑相应的配置文件(如/etc/apt/sources.list/etc/yum.repos.d/*.repo),然后添加新的仓库地址即可,以下是一些示例:

1、添加一个新的Debian仓库(以Ubuntu为例):

打开终端并输入以下命令以编辑/etc/apt/sources.list文件:

linux查看已启用的服务

sudo nano /etc/apt/sources.list

在文件末尾添加以下内容:

deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse

保存并退出文件,接下来,运行以下命令以更新软件包列表:

sudo apt-get update

2、添加一个新的Red Hat仓库(以Fedora为例):

打开终端并输入以下命令以编辑/etc/yum.repos.d/CentOS-Base.repo文件:

sudo vi /etc/yum.repos.d/CentOS-Base.repo

在文件末尾添加以下内容:

[base]            Base repository from which other packages can be installed on top of it (not a dependency)     comment out the next line if you do not want to install extra packages when doing yum updates      [base]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               url=http://mirror.centos.org/centos$releasever/os/$basearch/       enabled=1       gpgcheck=0       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               [epel]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             Extra Packages that comes with EPEL repository                                                                                                                                              The first entry can be commented out if you do not want to install EPEL packages                                                                                        [epel]                                                                                                                                                                                                                                                                                                       url=http://download.fedoraproject.org/pub/epel/\$releasever/$basearch/\$arch       enabled=1       gpgcheck=0       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7                                                                                   [extras]                                                                                                                  Extra Packages that comes with EPEL repository                                                                                                                                                  The first entry can be commented out if you do not want to install EPEL packages                                                                                    [extras]                                                                                                                                                                                                                                       url=http://mirror.centos.org/centos$releasever/extras/\$basearch/\$arch       enabled=0       gpgcheck=0       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7                                                                               [updates]                                                                                                                  Additional Packages that comes with updates for base and extras                                                                               The first entry can be commented out if you do not want to install updates for extras                                                                                       [updates]                                                                                                                                                                       url=http://mirror.centos.org/centos$releasever/updates/\$basearch/\$arch       enabled=0       gpgcheck=0       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7                                                                               [fastestmirror]                                                                                                                      Use fastest mirror server                                                                                     You should use this option if you are using UDP traffic                              instead of TCP                                                                                   [fastestmirror]                                                                                                                                                                       url=http://mirror.centos.org/centos$releasever/\$basearch/\$arch       enabled=1       gpgcheck=0       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-\$releasever                                                                                               [centosplus]                                                                                                                                                                               Extra Packages that comes with centosplus repository                                                                                                                                                  The first entry can be commented out if you do not want to install centosplus packages                                                                                    [centosplus]                                                                                                                                                                       url=https://centosplus.org/\$releasever/\$basearch/\$arch       enabled=0       gpgcheck=0       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-\$releasever                                                                                               [remi]                                                                                                                                                                               Extra Packages that comes with remi repository                                                                                                                                                  The first entry can be commented out if you do not want to install remi packages                                                                                    [remi]                                                                                                                                                                       url=http://remirepo.net/\$releasever/\$basearch/\$arch       enabled=0       gpgcheck=0       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-\$releasever                                                                                               [testing]                                                                                                                                                                               Extra Packages that comes with testing repository                                                                                                                                                  The first entry can be commented out if you do not want to install testing packages                                                                                    [testing]                                                                                                                                                                       url=http://people.centos.org/tru/testing/\$releasever/\$basearch/\$arch       enabled=0       gpgcheck=0       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-\$releasever                                                                                               [tools]                                                                                                                                                                                             Extra Packages that comes with tools repository                                                                                                                                                  The first entry can be commented out if you do not want to install tools packages                                                                                    [tools]                                                                                                                                                                       url=http://mirror.centos.org/\$releasever/$basearch/\$arch       enabled=1       gpgcheck=0       gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-\$releasever                                                                                               [updatesextra]                                                                                                                                                                               Additional Packages that comes with updates for base and extras                                                                                   The first entry can be commented out if you do not want to install updates for extras                                                                                       [updatesextra]                                                                                                                                                                       url=http://mirror.centos.org/\$releasever/\$basearch/\$arch       enabled=0                                                                                                                         gpgcheck=0                                                                                                                         gpgkey=file:///etc//

原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/138038.html

Like (0)
Donate 微信扫一扫 微信扫一扫
K-seo的头像K-seoSEO优化员
Previous 2023-12-17 21:21
Next 2023-12-17 21:24

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

免备案 高防CDN 无视CC/DDOS攻击 限时秒杀,10元即可体验  (专业解决各类攻击)>>点击进入