linux 软件_Linux运维教程Linux软件包管理

abde181bc997044b2afae42add04d644.png

Linux软件包管理

  • rpm软件包管理

  • Yum软件包管理

  • Dnf软件包管理

  • 源码编译安装

准备工作

挂载iso镜像

80990dfc21d2c24d9d2961e92ecc986b.png

a650edb42f3ff4128beab4b1710e2990.png

将光驱挂载到系统中

[root@myserver dev]# mount /dev/sr0 /mnt/mount: /mnt: WARNING: device write-protected, mounted read-only.[root@myserver dev]# df -hFilesystem                    Size  Used Avail Use% Mounted ondevtmpfs                      884M     0  884M   0% /devtmpfs                         901M     0  901M   0% /dev/shmtmpfs                         901M  9.8M  891M   2% /runtmpfs                         901M     0  901M   0% /sys/fs/cgroup/dev/mapper/cl_myserver-root   17G  5.2G   12G  31% //dev/sdb1                     5.0G   68M  5.0G   2% /data/sdb1/dev/sda1                     976M  194M  716M  22% /boottmpfs                         181M   16K  181M   1% /run/user/0tmpfs                         181M  1.2M  179M   1% /run/user/42/dev/sr0                      6.7G  6.7G     0 100% /mnt

Rpm软件包管理

windows :exe  ;mac OS :dmg ;Linux:rpm

当我们的应用可以直接安装的时候建议使用rpm直接安装。但是当我们的应用需要依赖于其他的包的时候rpm就会变得很难受。

rpm 命令使用方法

rpm -qa | grep xz :查看所有已经安装的包

rpm -ivh xxx.rpm  : 安装xxx.rpm

rpm -e xxx : 卸载 xxx

rpm -Uvh xxx.rpm  :  更新xxx.rpm

cd /mnt/BaseOS/Packages## 查找包是否已经安装[root@myserver Packages]# rpm -qa  | grep xzxz-libs-5.2.4-3.el8.x86_64xz-5.2.4-3.el8.x86_64## 获取相关的RPM包[root@myserver Packages]# ls | grep xzxz-5.2.4-3.el8.x86_64.rpmxz-devel-5.2.4-3.el8.i686.rpmxz-devel-5.2.4-3.el8.x86_64.rpmxz-libs-5.2.4-3.el8.i686.rpmxz-libs-5.2.4-3.el8.x86_64.rpm## 开始安装[root@myserver Packages]# rpm -ivh xz-devel-5.2.4-3.el8.x86_64.rpmVerifying...                          ################################# [100%]Preparing...                          ################################# [100%]Updating / installing...   1:xz-devel-5.2.4-3.el8             ################################# [100%]## 验证是否安装成功[root@myserver Packages]# rpm -qa  | grep xzxz-libs-5.2.4-3.el8.x86_64xz-5.2.4-3.el8.x86_64xz-devel-5.2.4-3.el8.x86_64## 卸载[root@myserver Packages]# rpm -e xz-devel-5.2.4-3.el8.x86_64[root@myserver Packages]# rpm -qa  | grep xzxz-libs-5.2.4-3.el8.x86_64xz-5.2.4-3.el8.x86_64

Yum软件包管理工具

yum仓库概念=== yum源

源配置需要的是一个xxx.repo文件, /etc/yum.repos.d/

yum remove xz-devel: 卸载xz-devel

yum -y install xz-devel : 安装xz-devel  -y不用交互方式。

yum update xz-devel:更新xz-devel

yum clean all :清理缓存

操作前准备: 备份初始源

[root@myserver yum.repos.d]# mkdir bak[root@myserver yum.repos.d]# lsbak                     CentOS-Debuginfo.repo  CentOS-Media.repoCentOS-AppStream.repo   CentOS-Devel.repo      CentOS-PowerTools.repoCentOS-Base.repo        CentOS-Extras.repo     CentOS-Sources.repoCentOS-centosplus.repo  CentOS-fasttrack.repo  CentOS-Vault.repoCentOS-CR.repo          CentOS-HA.repo[root@myserver yum.repos.d]# mv *.repo bak/[root@myserver yum.repos.d]# lsbak

yum源文件格式

[BaseOS]    ## 仓库名称name=CentOS-$releasever - Base   ## 仓库描述baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/  ## 源地址 【在线HTTP|FILE本地文件】gpgcheck=1   ## 证书验证enabled=1   ## 是否启动gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
配置本地YUM
[myrepo]name=My first repo test.baseurl=file:///mnt/BaseOS/gpgcheck=0enabled=1
[root@myserver ~]# cd /etc/yum.repos.d/[root@myserver yum.repos.d]# lsbak[root@myserver yum.repos.d]# vim myrepo.repo[root@myserver yum.repos.d]# lsbak  myrepo.repo
[root@myserver ~]# yum repolistrepo id                             repo namemyrepo                              My first repo test.
[root@myserver ~]# rpm -qa  | grep xzxz-libs-5.2.4-3.el8.x86_64xz-5.2.4-3.el8.x86_64[root@myserver ~]# yum install xz*My first repo test.                                 24 MB/s | 2.2 MB     00:00    Last metadata expiration check: 0:00:01 ago on Sun 21 Jun 2020 10:00:03 PM EDT.Package xz-5.2.4-3.el8.x86_64 is already installed.Package xz-libs-5.2.4-3.el8.x86_64 is already installed.Dependencies resolved.=================================================================================== Package            Architecture     Version                Repository        Size===================================================================================Installing: xz-devel           x86_64           5.2.4-3.el8            myrepo            62 kTransaction Summary===================================================================================Install  1 PackageTotal size: 62 kInstalled size: 202 kIs this ok [y/N]: yDownloading Packages:Running transaction checkTransaction check succeeded.Running transaction testTransaction test succeeded.Running transaction  Preparing        :                                                                        1/1  Installing       : xz-devel-5.2.4-3.el8.x86_64                                            1/1  Running scriptlet: xz-devel-5.2.4-3.el8.x86_64                                            1/1  Verifying        : xz-devel-5.2.4-3.el8.x86_64                                            1/1Installed products updated.Installed:  xz-devel-5.2.4-3.el8.x86_64                                                                  Complete![root@myserver ~]# rpm -qa  | grep xzxz-devel-5.2.4-3.el8.x86_64xz-libs-5.2.4-3.el8.x86_64xz-5.2.4-3.el8.x86_64
[root@myserver ~]# yum remove xz-devel
Dependencies resolved.
================================================================================================
Package Architecture Version Repository Size
================================================================================================
Removing:
xz-devel x86_64 5.2.4-3.el8 @myrepo 202 k
Transaction Summary
================================================================================================
Remove 1 Package
Freed space: 202 k
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Erasing : xz-devel-5.2.4-3.el8.x86_64 1/1
Running scriptlet: xz-devel-5.2.4-3.el8.x86_64 1/1
Verifying : xz-devel-5.2.4-3.el8.x86_64 1/1
Installed products updated.
Removed:
xz-devel-5.2.4-3.el8.x86_64
Complete!
在线YUM源

备份本地yum,创建新的在线yum源

[root@myserver ~]# cd /etc/yum.repos.d/
[root@myserver yum.repos.d]# ls
bak myrepo.repo
[root@myserver yum.repos.d]# mv myrepo.repo myrepo.repo~
[root@myserver yum.repos.d]# ls
bak myrepo.repo~
[root@myserver yum.repos.d]# vim myrepo.repo
[myrepo]
name=My first repo test.
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/8/BaseOS/x86_64/os/
gpgcheck=0
enabled=1
[root@myserver yum.repos.d]# yum -y install xz-devel
My first repo test. 537 kB/s | 2.2 MB 00:04
Last metadata expiration check: 0:00:01 ago on Sun 21 Jun 2020 10:09:55 PM EDT.
Dependencies resolved.
================================================================================================
Package Architecture Version Repository Size
================================================================================================
Installing:
xz-devel x86_64 5.2.4-3.el8 myrepo 62 k
Transaction Summary
================================================================================================
Install 1 Package
Total download size: 62 k
Installed size: 202 k
Downloading Packages:
xz-devel-5.2.4-3.el8.x86_64.rpm 105 kB/s | 62 kB 00:00
------------------------------------------------------------------------------------------------
Total 104 kB/s | 62 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : xz-devel-5.2.4-3.el8.x86_64 1/1
Running scriptlet: xz-devel-5.2.4-3.el8.x86_64 1/1
Verifying : xz-devel-5.2.4-3.el8.x86_64 1/1
Installed products updated.
Installed:
xz-devel-5.2.4-3.el8.x86_64
Complete!

FAQ

[root@myserver yum.repos.d]# yum -y install xz-devel
My first repo test. 0.0 B/s | 0 B 00:00
Errors during downloading metadata for repository 'myrepo':
- Curl error (6): Couldn't resolve host name for https://mirrors.tuna.tsinghua.edu.cn/centos/8/BaseOS/x86_64/os/repodata/repomd.xml [Could not resolve host: mirrors.tuna.tsinghua.edu.cn]
Error: Failed to download metadata for repo 'myrepo': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
[root@myserver yum.repos.d]# ping www.baidu.com
ping: www.baidu.com: Name or service not known
## 重新获取地址信息
[root@myserver yum.repos.d]# dhclient
[root@myserver yum.repos.d]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=1 ttl=56 time=4.68 ms
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=2 ttl=56 time=4.92 ms
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 2ms
rtt min/avg/max/mdev = 4.675/4.795/4.916/0.138 ms

Dnf软件包管理工具

DNF是Dandified yum的缩写。DNF也是基于RPM的包管理工具,其首先在Fedora系统中出现,已经成为Fedora系统的默认的包管理工具。

比Yum要简单、消耗更少内容、依赖包解析速度更快

xz-devel

dnf list installed:列出所有已安装的包

dnf search :查找包

dnf install:安装命令

dnf reinstall :重新安装

dnf download :下载包

dnf check-update:检查更新

dnf update :更新

dnf repolist all :查看所有可用的源

dnf remove :卸载软件

dnf clean all :清除缓存


源码编译安装

创建归档

tar cf 归档名称  文件

tar xf 归档名称 -C 指定解包路径

[root@myserver ~]# tar cf mytestfile.tar a.txt b.txt c.txt
[root@myserver ~]# ls
a b.txt Documents Music Pictures test
anaconda-ks.cfg c.txt Downloads mytestfile Public Videos
a.txt Desktop initial-setup-ks.cfg mytest.txt Templates
[root@myserver ~]# file mytestfile.tar
mytestfile: POSIX tar archive (GNU)
[root@myserver ~]# tar xf mytestfile.tar -C /opt/
[root@myserver ~]# ls /opt/
a.txt b.txt c.txt

压缩包 tar.gz

[root@myserver ~]# tar zcf mytestfile.tar.gz a.txt b.txt c.txt
[root@myserver ~]# ls
a c.txt initial-setup-ks.cfg mytest.txt test
anaconda-ks.cfg Desktop Music Pictures Videos
a.txt Documents mytestfile Public
b.txt Downloads mytestfile.tar.gz Templates
[root@myserver ~]# file mytestfile.tar.gz
mytestfile.tar.gz: gzip compressed data, last modified: Mon Jun 22 12:38:35 2020, from Unix, original size 10240
[root@myserver ~]# tar zxf mytestfile.tar.gz -C /mnt/
[root@myserver ~]# ls /mnt/
a.txt b.txt c.txt hgfs

源码编译安装过程

  • 下载应用的源码包

    • wget 下载源码包

  • 解压源码包

    • 默认解压路径 : /usr/local/

    • tar zxf xxxx -C /usr/local

  • 执行配置文件

  • 执行编译

  • 执行编译安装

[root@myserver ~]# wget http://zlib.net/zlib-1.2.11.tar.gz
--2020-06-22 08:44:02-- http://zlib.net/zlib-1.2.11.tar.gz
Resolving zlib.net (zlib.net)... 68.66.224.49
Connecting to zlib.net (zlib.net)|68.66.224.49|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 607698 (593K) [application/x-gzip]
Saving to: \u2018zlib-1.2.11.tar.gz\u2019
zlib-1.2.11.tar.gz 100%[=======================>] 593.46K 11.4KB/s in 49s
2020-06-22 08:44:47 (12.2 KB/s) - \u2018zlib-1.2.11.tar.gz\u2019 saved [607698/607698]
[root@myserver ~]# ls
a c.txt initial-setup-ks.cfg mytest.txt test
anaconda-ks.cfg Desktop Music Pictures Videos
a.txt Documents mytestfile Public zlib-1.2.11.tar.gz
b.txt Downloads mytestfile.tar.gz Templates
[root@myserver ~]# tar zxf zlib-1.2.11.tar.gz -C /usr/local/
[root@myserver ~]# ls /usr/local/
bin etc games include lib lib64 libexec sbin share src zlib-1.2.11
[root@myserver ~]# cd /usr/local/zlib-1.2.11/
[root@myserver zlib-1.2.11]# ls
adler32.c examples inflate.c README zlib.3
amiga FAQ inflate.h test zlib.3.pdf
ChangeLog gzclose.c inftrees.c treebuild.xml zlib.h
CMakeLists.txt gzguts.h inftrees.h trees.c zlib.map
compress.c gzlib.c Makefile trees.h zlib.pc.cmakein
configure gzread.c Makefile.in uncompr.c zlib.pc.in
contrib gzwrite.c make_vms.com watcom zutil.c
crc32.c INDEX msdos win32 zutil.h
crc32.h infback.c nintendods zconf.h
deflate.c inffast.c old zconf.h.cmakein
deflate.h inffast.h os400 zconf.h.in
doc inffixed.h qnx zlib2ansi
[root@myserver zlib-1.2.11]#

开始编译  https://www.nginx.cn/install

编译之前首先需要安装gcc gcc-c++ 编译器

yum -y install gcc automake autoconf libtool make
yum install gcc gcc-c++`
[root@myserver zlib-1.2.11]# ./configure
Checking for gcc...
Checking for shared library support...
Building shared library libz.so.1.2.11 with gcc.
Checking for size_t... Yes.
Checking for off64_t... Yes.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.
[root@myserver zlib-1.2.11]# make
[root@myserver zlib-1.2.11]# make install
rm -f /usr/local/lib/libz.a
cp libz.a /usr/local/lib
chmod 644 /usr/local/lib/libz.a
cp libz.so.1.2.11 /usr/local/lib
chmod 755 /usr/local/lib/libz.so.1.2.11
rm -f /usr/local/share/man/man3/zlib.3
cp zlib.3 /usr/local/share/man/man3
chmod 644 /usr/local/share/man/man3/zlib.3
rm -f /usr/local/lib/pkgconfig/zlib.pc
cp zlib.pc /usr/local/lib/pkgconfig
chmod 644 /usr/local/lib/pkgconfig/zlib.pc
rm -f /usr/local/include/zlib.h /usr/local/include/zconf.h
cp zlib.h zconf.h /usr/local/include
chmod 644 /usr/local/include/zlib.h /usr/local/include/zconf.h

更多精彩请关注 DevOps云学堂


2b6393a10dc210b79f626ce9cdc48e80.png

3c6846ef967b9111ccff96541a54a072.png

添加微信小助手devopsvip 回复 "加群",自动加入群聊

点亮 fb2b7ee8820f048d1b80d2301805e70e.png,告诉大家你也在看d1d5f14d5fbb612c89e277714ebe9ccd.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值