首页 > 系统相关 >Linux软件包管理

Linux软件包管理

时间:2023-01-03 19:24:40浏览次数:34  
标签:Linux mirrors 管理 yum lnh aliyun 软件包 com

软件包管理

1.常见的安装软件方式

Linux下面的软件包格式:rpm格式(红帽系列系统,Centos,麒麟系统)或deb格式(Debian,Ubuntu)

安装软件方式 说明 应用场景
yum/apt方式 通过网络下载软件包,替我们安装,如果有以来自动下载依赖并安装,自动 大部分场景,没有网络可以自建yum软件仓库,内网使用
rpm/dpkg 手动下载rpm包,手动安装rpm包,缺少依赖需要自己解决 没有网路,误删除软件包,依赖较少
编译安装方式 可以自定义安装,比较漫长,缺少依赖自己解决 软件进行自定义,增加功能
二进制安装方式 类似于绿色软件,解压即用,可能需要准备环境 如果有可以选用,优先选择yum,没有就选择二进制方式
#编译安装
1) 自定义。
2) yum安不上,rpm没有包。

编译本质:源代码(c语言)-->命令

编译安装三部曲: 配置-->编译-->编译安装


#0.上传软件包并安装依赖
#上传压缩包
E:\lnh\笔记\老师笔记\软件包\cmatrix-1.2a.tar.gz
#解压压缩包
[root@lnh tools]# tar xf cmatrix-1.2a.tar.gz
#进入压缩包
[root@lnh tools]# cd cmatrix-1.2a/
#安装依赖
[root@lnh cmatrix-1.2a]# yum install -y ncurses-devel

1. ./configure 配置,安装到哪个目录(默认是/usr/local/下面),开启或关闭功能。
需要在代码目录下面执行 ls -l ./configure 否则失败
[root@lnh cmatrix-1.2a]# ./configure
	屏幕输出一堆内容
[root@lnh cmatrix-1.2a]# echo $? #如果结果是0(屏幕输出),表示成功了。(这个命令表示上一个命令执行的是否正确)
	如果不是0,则可能出错了。

2.  进行编译
[root@lnh cmatrix-1.2a]# make    #运行这个命令即可
[root@lnh cmatrix-1.2a]# echo $? #查看结果如果0则对了。如果不是0,则查看报错,可能要安装依赖,安装完成依赖,需要从0)下面的b步骤开始。 

3.  安装
[root@lnh cmatrix-1.2a]# make install    
[root@lnh cmatrix-1.2a]# echo $?
4.  运行cmatrix命令,检查结果。

5.  清理战场,清理掉软件包,解压目录

2.rpm 安装方式

rpm命令 选项及含义
增加-安装 -vih
查看-检查 -qa (query all) 查看软件包是否安装
-ql 查看软件包内容
-qf 文件或命令绝对路径,文件或命令所归属的软件包
修改 -Uvh 升级软件包(如果软件包不存在,相当于ivh安装)
删除 -e 删除软件包

2.1 增加 - 安装rpm包

-vih

-i install

-v 显示过程

-h 人类可读显示过程

#下载软件包
wget  --no-check-certificate -P /server/tools/ https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/7/x86_64/zabbix-agent2-6.0.0-1.el7.x86_64.rpm

wget 下载指定内容,默认下载到当前目录
-P   下载到指定目录,目录不存在会创建
-no-check-certificate 下载地址https,加上这个选项,下载失败。

#安装依赖,后面yum部分可以解决软件包依赖和查找依赖
[root@lnh ~]# yum install  -y pcre2

#安装软件包
[root@lnh ~]# rpm -ivh /server/tools/zabbix-agent2-6.0.0-1.el7.x86_64.rpm

如果不安装依赖,则会提示缺少依赖而安装失败

2.2 查询

#检查软件包是否是否安装成功
[root@lnh ~]# rpm -qa |grep zabbix
zabbix-agent2-6.0.0-1.el7.x86_64
[root@lnh ~]# rpm -qa zabbix-agent2
zabbix-agent2-6.0.0-1.el7.x86_64

#检查软件包的内容
[root@lnh ~]# rpm -ql zabbix-agent2 
/etc/logrotate.d/zabbix-agent2
/etc/zabbix/zabbix_agent2.conf
/etc/zabbix/zabbix_agent2.d
/etc/zabbix/zabbix_agent2.d/plugins.d/ceph.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/docker.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/memcached.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/modbus.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/mongodb.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/mqtt.conf
/etc/zabbix/zabbix_agent2.d/plugins.d/mysql.conf

#查询某个命令或文件属于哪个软件包
[root@lnh ~]# rpm -qf /usr/bin/tree
tree-1.6.0-10.el7.x86_64


2.3 修改

[root@lnh ~]# rpm -Uvh zabbix-agent2-6.0.7-1.el7.x86_64.rpm

2.4 删除

[root@lnh ~]# rpm -e zabbix-agent2

3.yum安装方式

yum是红帽系列系统中默认的软件包管理器。替我们下载指定的rpm包,替我们安装,安装过程中有依赖,下载安装依赖

#推荐安装 命令补全增强工具
[root@lnh ~]# yum -y install bash-completion bash-completion-extras
安装后重新登录Linux,可以对yum选项进行tab补全

3.1 yum软件安装全流程

  1. 运行yum -install -y 软件包 命令
  2. 解析软件包是否有依赖
  3. yum根据本地配置的yum源的地址,进行请求软件包及依赖软件包
  4. 如果yum源存在软件,则会通知yum进行下载,rpm包被下载到yum缓存目录中
  5. 软件包和依赖都下载了,就开始安装
  6. 安装后删除刚刚下载的rpm包(默认)

image

  • yum命令:下载与安装软件包,配置文件/etc/yum.conf
  • yum仓库/源:存放软件包的地方,配置目录/etc/yum.repos.d/*.repo

3.2yum 源配置 必会

3.2.1 为什么要配置

  1. 为了下载更快
  2. 系统默认的yum源无法满足要求(需要的软件yum源没有),需要增加其他的yum源

3.2.2 一键配置为阿里云的yum源

查看系统正在使用的yum源列表

[root@lnh ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
 repo id (源标识)          repo name (源名称)                        status(状态)
base/7/x86_64     CentOS-7 - Base - mirrors.aliyun.com               10,072
epel/x86_64       Extra Packages for Enterprise Linux 7 - x86_64     13,747
extras/7/x86_64   CentOS-7 - Extras - mirrors.aliyun.com                515
updates/7/x86_64  CentOS-7 - Updates - mirrors.aliyun.com            4,425      
repolist: 28,759

目前只有base,extras,updates,epel 4个源

base,extras,updates是系统默认的yum源

epel 是额外的源

设置系统的yum源为阿里云

https://mirrors.aliyun.com/进入网站

#1.备份已有的yum源
[root@lnh ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
#2.配置系统默认的源,改为阿里云的
#使用wget或curl 下载阿里云的yum源的配置文件到/etc/yum.repos.d目录下
#wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
#- O 下载并改名,存放到指定目录中
[root@lnh ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

#3.修改了base,extras,updates是系统默认的yum源,改为了阿里云。

增加epel源

#1.备份
#第一次备份会提示文件不存在
[root@lnh ~]# mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
[root@lnh ~]# mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup

#2.增加系统的epel(企业级Linux的额外的软件包,yum仓库)
[root@lnh ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

#3.检查
[root@lnh ~]# yum -y install sl

3.2.3 yum源配置文件详解

存放在/yum.repos.d/目录下面,都是以.repo结尾,

image

[root@lnh ~]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

文件的名称 说明
[base] yum源的名字
name 说明信息
baseurl yum源地址,打开后会看到repodata目录
enaabled=1 是否 开启这个yum源
gpgcheck 开启软件包检查,自建yum仓库的话可以关系
gpgkey 检查的密钥

3.3 yum命令配置文件

[root@lnh ~]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
文件名称 说明
keepcache 0:关闭缓存,软件下载安装后自动删除rpm包
1:开启缓存,软件下载安装后保留rpm包
cachedir yum下载软件包的缓存目录,/var/cache/yum/$basearch/$releasever
logfile yum命令的记录,/var/log/yum.log

生产应用的建议keepcashe,未来没有网络的环境,可以找个有公网的主机,开启keepcache,下载各种服务软件,保留缓存,通过缓存的rpm包进行安装

3.4 yum命令详解 必会

命令 说明
yum install -y 软件包
yum provides 内容
yum search all 内容
yum repolist 查看源列表
删除 yum remove 删除软件包及依赖
yum clean all 清空缓存
yum update/upgrade

3.4.1 安装软件

[root@lnh ~]# yum -y install tree
#-y 表示提示是否安装,是否确认的时候默认选择yes

#使用较少,重新安装软件包
[root@lnh ~]# yum reinstall -y tree

3.4.2 检查软件/搜索软件

#查询某个命令属于哪个软件包,查询某个依赖属于哪个软件包
[root@lnh ~]# yum provides ifconfig
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
Repo        : @base
Matched from:
Filename    : /usr/sbin/ifconfig

[root@lnh ~]# yum search all ifconfig
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
==================================================================== Matched: ifconfig =====================================================================
python36-ifcfg.noarch : Python cross-platform network interface discovery (ifconfig/ipconfig/ip)
moreutils.x86_64 : Additional unix utilities
net-tools.x86_64 : Basic networking tools
python2-psutil.x86_64 : A process and system utilities module for Python
python34-psutil.x86_64 : A process and system utilities module for Python

#查看yum源信息 必会
[root@lnh ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
 repo id (源标识)          repo name (源名称)                        status(状态)
base/7/x86_64     CentOS-7 - Base - mirrors.aliyun.com               10,072
epel/x86_64       Extra Packages for Enterprise Linux 7 - x86_64     13,747
extras/7/x86_64   CentOS-7 - Extras - mirrors.aliyun.com                515
updates/7/x86_64  CentOS-7 - Updates - mirrors.aliyun.com            4,425      
repolist: 28,759
#显示所有yum仓库中的所有的软件,未来用于根据软件包名字查找
[root@lnh ~]# yum list |grep tree
tree.x86_64                              1.6.0-10.el7                  @base    
cherrytree.noarch                        0.38.5-5.el7                  epel     
ebtree.x86_64                            6.0.8-4.el7                   epel     

3.4.3 卸载软件

尽量不要使用yum命令删除软件,删除的时候可能会把依赖删除掉

推荐使用rpm -e

删除/清空 本地缓存

[root@lnh ~]# yum clean all
#自建yum仓库需要使用,使用公有的yum源,一般不用

3.4.4 升级软件

yum update 或yum upgrade ,软件或命令有bug或漏洞,需要更新

3.4.5安装rpm包

yum localinstall 安装本地的rpm包并解决依赖(手动下载的rpm包,rpm还有依赖)

4.Ubuntu系统软件包管理

4.1 配置源

vim /etc/apt/sources.lis
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

#编辑完成一定要运行
apt update  #用于生成本地apt缓存,如果不做,无法安装软件

4.2 安装软件

#安装软件并测试
apt install -y cmatrix 

4.3 检查软件

功能 debian(ubuntu) 红帽(Centos,麒麟)
检查是否安装 dpkg -l rpm -qa
安装 dpkg -i rpm -ivh
检查软件包内容 dpkg -L rpm -ql
删除 dpkg -r rpm -e

标签:Linux,mirrors,管理,yum,lnh,aliyun,软件包,com
From: https://www.cnblogs.com/world-of-yuan/p/17013569.html

相关文章

  • Linux三剑客日志处理系列
    三剑客日志处理系列一、特殊符号1.引号系列必会引号含义单引号所见即所得,单引号里的内容会原封不动输出双引号和单引号类似,对双引号里面的特殊符号进......
  • Linux磁盘管理
    磁盘管理1、磁盘基础1.1概述内存:临时存放,断电后丢失磁盘:永久保存1.2分类运行方式与原理详细信息机械硬盘(HDD)电机带动磁盘高速旋转,读取数据,速度可以达......
  • Linux服务管理
    服务管理1.管理命令systemctl管理服务开机自启动管理正在运行的服务旧版本的系统:Centos5.x6.x需要使用service命令#检查sshd远程连接服务状态[root@lnh~]#s......
  • Linux读取U盘内容
    查找设备sudofdisk-l创建挂载点sudomkdir/mnt/usb将存储设备进行挂载sudomount/dev/sda1/mnt/usb访问U盘内容cd/mnt/usb卸载U盘sudoumount/mnt/usb......
  • Linux切换python版本
    【前提条件】linux已经安装好多个版本的python如2.7&3.6linux为Debian系查看是否有关于Python的候选项​​update-alternatives--displaypython​​,输出​​update-a......
  • 数据管理
    oracle数据管道 CREATEORREPLACEPACKAGEpkg_tableAS TYPEnumset_tISTABLEoft_gk_test%rowtype; --定义返回类型  FUNCTIONget_gk_test(xvarchar2......
  • 阿里云 ACK One 多集群管理再升级:GitOps 多集群持续集成,统一报警管理
    作者:宇汇、壮怀ACKOne概述ACKOne是阿里云面向混合云、多集群、分布式计算等场景推出的分布式云容器平台,能够统一管理阿里云上、边缘、部署在客户数据中心以及其他云......
  • Linux中fork和exec是什么?有何区别?
    在学习任何技术的时候,很多人经常会因为搞不懂专业术语而犯愁,甚至也经常因为两个相似的专业术语摸不着头脑,比如:Linux中fork和exec。fork和exec都是和进程相关的调用,而且......
  • linux学习笔记003
    安装jdk下载地址https://www.oracle.com/java/technologies/downloads/archive/安装命令rpm-ivhjdk-8u202-linux-x64.rpm检查安装java-version卸载命令//先检......
  • C# 获取设备管理器中设备信息
    需要引用System.Management//硬件Win32_Processor,//CPU处理器Win32_PhysicalMemory,//物理内存条Win32_Keyboard,//键盘Win32_PointingDevice,//点输入设备,包......