您的位置:首页 > 运维架构 > Linux

带快照的Linux软件包管理

2020-08-20 23:44 901 查看

A big part of administrating Linux machines - especially remote machines - is managing and installing software.

管理Linux机器(尤其是远程机器)的很大一部分是管理和安装软件。

When something goes wrong with a local application or when something on the file system breaks and needs fixing, you're often going to want to push updates without having to travel many miles to sit down in front of a physical screen.

当本地应用程序出现问题时,或者文件系统上的某些文件损坏并且需要修复时,您通常会希望推送更新,而不必走很多路才坐在物理屏幕前。

A lot of problems can be solved through Bash scripts, of course, but there are still plenty of use-cases where there's no alternative to a good old fashioned binary.

当然,通过Bash脚本可以解决很多问题,但是仍然有很多用例,没有什么可以替代传统的老式二进制文件了。

Imagine that some of your remote systems need new applications installed so the team members using those computers will be able to perform some business function. Being able to leverage the integration and automation of one of the major Linux repository systems - like Debian or RPM - can make your administration tasks a whole lot easier.

想象一下,您的某些远程系统需要安装新的应用程序,因此使用这些计算机的团队成员将能够执行某些业务功能。 能够利用Debian或RPM等主要Linux存储库系统之一的集成和自动化,可以使您的管理任务变得更加容易。

In this article we'll explore a relatively new standalone package management system: Snap.

在本文中,我们将探讨一个相对较新的独立程序包管理系统:Snap。

As Linus Torvalds never tires of reminding us, the problem with many Linux software managements systems is that there are too many Linux software management systems.

正如Linus Torvalds永不厌倦地提醒我们的那样,许多Linux软件管理系统的问题在于Linux软件管理系统太多。

App development and even Linux adoption have, over the years, become more complicated. All the time and work you invest in preparing your software for, say, Debian repos, won't help you if you want to get them into RPM systems. And neither will help for SUSE's zypper manager.

多年来,应用程序开发甚至Linux的采用都变得更加复杂。 如果您想将软件投入RPM系统,那么您花费大量的时间和精力来为Debian repos准备软件,将无济于事。 两者都不会对SUSE的zypper管理器有所帮助。

As I show in my Pluralsight course: Linux System Maintenance and Troubleshooting, one promising solution to the software silo problem is to distribute applications with their own self-contained environments that'll work on any Linux distribution.

正如我在Pluralsight课程:Linux系统维护和故障排除课程中所展示的那样,一种解决软件孤岛问题的有前途的解决方案是,使用可以在任何Linux发行版上运行的自包含环境来分发应用程序。

The two big standards in this young and growing field are AppImage and snap. We'll start with snaps.

这个新兴且不断发展的领域中的两个主要标准是AppImage和snap。 我们将从快照开始。

使用快照 (Working with Snaps)

The snap system - under the guidance of Canonical, the company that sponsors Ubuntu - installs each individual application on your system within its own virtual partition. All those loop partitions sure make a royal mess of the output of the df command, but they also represent a rational approach to distributing a single version of software across any and all Linux installations.

快照系统-在赞助Ubuntu的公司Canonical的指导下-将每个单独的应用程序安装在系统中自己的虚拟分区中。 所有这些循环分区肯定会使df命令的输出混乱不堪,但是它们也代表了一种合理的方法,可以在所有Linux安装中分发单个版本的软件。

$ df
Filesystem     1K-blocks      Used Available Use% Mounted on
udev             7101884         0   7101884   0% /dev
tmpfs            1432092      3936   1428156   1% /run
/dev/sda2      479152840 183520724 271222724  41% /
tmpfs            7160452    329336   6831116   5% /dev/shm
tmpfs               5120         4      5116   1% /run/lock
tmpfs            7160452         0   7160452   0% /sys/fs/cgroup
/dev/loop2           384       384         0 100% /snap/gnome-characters/539
/dev/loop4         56320     56320         0 100% /snap/core18/1705
/dev/loop5         56320     56320         0 100% /snap/core18/1754
/dev/loop3        145664    145664         0 100% /snap/slack/23
/dev/loop0          2560      2560         0 100% /snap/gnome-calculator/730
/dev/loop6         15360     15360         0 100% /snap/aws-cli/130
[...]
/dev/loop21       521216    521216         0 100% /snap/onlyoffice-desktopeditors/38
/dev/loop22       145664    145664         0 100% /snap/slack/22
/dev/loop23       185472    185472         0 100% /snap/spotify/36
/dev/loop25        96128     96128         0 100% /snap/core/8935
/dev/loop26       319104    319104         0 100% /snap/onlyoffice-desktopeditors/43
/dev/loop27         1152      1152         0 100% /snap/drawing/16
/dev/loop24        56192     56192         0 100% /snap/gtk-common-themes/1502
/dev/loop31         2560      2560         0 100% /snap/gnome-calculator/748
/dev/sda1         523248      6152    517096   2% /boot/efi
tmpfs            1432088        12   1432076   1% /run/user/121
tmpfs                100         0       100   0% /var/lib/lxd/shmounts
tmpfs                100         0       100   0% /var/lib/lxd/devlxd
tmpfs            1432088        68   1432020   1% /run/user/1000

In this demo, I'm going to show you how to package a GitHub-based application as a snap. With such a package, you would theoretically be able to submit it to the official snap store where, if accepted, it would be freely available to anyone on earth.

在此演示中,我将向您展示如何打包基于GitHub的应用程序。 有了这样的软件包,从理论上讲,您可以将其提交给官方的快照商店,如果被接受,那么它将对地球上的任何人免费提供。

Now, I could pretend that I worked tirelessly to figure out the very best way to get all this done from the command line - but that wouldn't be completely honest. Actually, it wouldn't be honest at all.

现在,我可以假装自己不知疲倦地工作,以找出从命令行完成所有这些工作的最佳方法-但这并不是完全诚实。 实际上,这根本不诚实。

In fact, I simply used the "first snap" tutorial on the snapcraft.io website that lets you select a language and then helpfully guides you through each step of the process. At the very end, it shows you how to submit your snap to the official snap store.

实际上,我只是使用了snapcraft.io网站上的“第一快照”教程, 教程可让您选择一种语言,然后有帮助地指导您完成该过程的每个步骤。 最后,它显示了如何将快照提交到官方快照存储。

I'm going to take you through the process from the command line but, if you're doing this for yourself, it would probably make sense to check out the website to make sure nothing has changed.

我将通过命令行引导您完成该过程,但是,如果您自己进行操作,那么检查网站以确保未发生任何更改可能很有意义。

So let's begin. You'll first need to make sure that the virtual machine manager Multipass is properly installed, since that's what snap uses to create the VMs where the images will be build. Naturally, Multipass itself is available as a snap.

因此,让我们开始吧。 首先,您需要确保正确安装了虚拟机管理器Multipass,因为那是snap用于创建将在其中构建映像的VM的工具。 当然,Multipass本身也可以轻松获得。

Likewise, you'll need the snapcraft package. After installing snapcraft, you should follow it up with "hash -r" to refresh the list of places your shell will look for known programs.

同样,您将需要snapcraft软件包。 安装snapcraft之后,应在其后添加“ hash -r”以刷新shell查找已知程序的位置列表。

$ sudo snap install multipass --classic
$ sudo snap install snapcraft --classic
$ hash -r

As I went with Python for my language, the tutorial provided me with a link to the GitHub site of an open source Python email backup project called OfflineIMAP. Don't feel you're restricted to Python, for that matter. And, obviously, you can substitute your own project for the example.

当我使用Python编写语言时,该教程为我提供了指向名为OfflineIMAP的开源Python电子邮件备份项目的GitHub站点的链接。 就此而言,不要觉得您仅限于Python。 而且,显然,您可以用自己的项目代替该示例。

When I've cloned the project locally, I'll cd into the new offlineimap directory. Next, I'll use wget to download the special Python-specific version of the YAML configuration file.

在本地克隆项目后,我将进入新的offlineimap目录。 接下来,我将使用wget下载YAML配置文件的特定于Python的特殊版本。

Since there's already a file with that name in the directory, this one will get an alternative name, so I'll just overwrite the old copy by changing the name of the new one. We'll then open the file and edit the three places where the word "name" appears in curly braces. I need to replace those with the name I'd actually like to use.

由于目录中已经存在一个具有该名称的文件,因此该文件将获得一个替代名称,因此我将通过更改新文件的名称来覆盖旧副本。 然后,我们将打开文件并编辑在大括号中出现“名称”一词的三个位置。 我需要将它们替换为我实际想要使用的名称。

$ git clone https://github.com/snapcraft-docs/offlineimap
$ cd offlineimap
$ wget https://snapcraft.io/first-snap/python/snapcraft.yaml

From here, running "snapcraft" will take care of the packaging process. This can be a long process, especially if there's software you need - like Multipass - that's not yet installed and set up. You may see some errors, but the odds are that the install script with automatically fix them on the fly.

从这里开始,运行“ snapcraft”将负责打包过程。 这可能是一个漫长的过程,尤其是如果您需要的软件(如Multipass)尚未安装和设置。 您可能会看到一些错误,但是很有可能安装脚本会自动修复它们。

When that's all died down, you can install the snap locally using the regular "snap install" command, but you'll need to add --devmode and --dangerous because this isn't an official, supported snap so, technically, no one knows what might happen when you start it up.

当这些全部消失后,您可以使用常规的“快照安装”命令在本地安装快照,但是您需要添加--devmode和--dangerous,因为这不是官方支持的快照,因此从技术上讲,没有人们知道启动时会发生什么。

You can prove it's installed by running "snap list" and then confirm that everything worked by running the test-offlineimap-mysnap command with -h to get the help screen.

您可以通过运行“快照列表”来证明它已安装,然后通过使用-h运行test-offlineimap-mysnap命令以获取帮助屏幕来确认一切正常。

Enjoy the software - I know that this kind of email backup is something I've been meaning to get to for years.

享受软件的乐趣-我知道这种电子邮件备份是我多年来一直想要实现的目标。

$ snapcraft
$ sudo snap install --devmode --dangerous *.snap
$ snap list
$ test-offlineimap-mysnap -h

If you're interested in learning how to manage snaps within your Linux environment, you might also enjoy my "How to manage Ubuntu Snaps: the stuff no one tells you" and "snapd Makes Administering Nextcloud a Snap" articles.

如果您有兴趣学习如何在Linux环境中管理快照,则还可以阅读我的“ 如何管理Ubuntu Snaps:没有人告诉您的东西 ”和“ snapd使管理Nextcloud成为快照 ”一文。

与其他包裹经理一起工作 (Working with other package managers)

We just got a pretty good look at snaps. But perhaps now is the perfect time to admit that I've left out some other big players in the alternative package manager world, in particular Flatpak and AppImages.

我们对快照非常满意。 但是现在也许是个绝佳的时机,我承认我已经排除了替代软件包管理器领域的其他一些大公司,特别是FlatpakAppImages

I discuss AppImages in some depth here, but a quick word or two about Flatpak wouldn't be out of place here.

我将在这里深入讨论AppImages,但是在这里不会对Flatpak简短地说两句话。

Flatpak's primary goal is to let developers build their applications into a single package and then distribute them to any Linux distribution. As an end-user, you would install the Flatpak system using your regular software manager - like Apt on Ubuntu or Yum on CentOS. Flatpak is installed by default on Fedora. From there, it's pretty much smooth sailing. Solves all the right problems, doesn't it?

Flatpak的主要目标是让开发人员将其应用程序构建到一个软件包中,然后将其分发到任何Linux发行版。 作为最终用户,您可以使用常规软件管理器(例如Ubuntu上的Apt或CentOS上的Yum)安装Flatpak系统。 Flatpak默认安装在Fedora上。 从那里开始,航行非常顺畅。 解决所有正确的问题,不是吗?

Perhaps. There's been some recent criticism over possible (and significant) security weaknesses in the fundamental design of Flatpak. I'll let you decide for yourself.

也许。 最近有人对Flatpak的基本设计中可能的(和重大的)安全性弱点提出批评 。 我让你自己决定。

There's much more administration goodness in the form of books, courses, and articles available at my bootstrap-it.com.

我的bootstrap-it.com上提供了书籍,课程和文章形式的管理优势。

翻译自: https://www.freecodecamp.org/news/linux-package-management-with-snaps/

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: