<< 点击显示目录 >> 主页 exOS使用助手 > exOS Automation Help > Development > exOS build-chain in Automation Studio > Installing Linux packages |
exOS 提供将文件安装到 B&R/Debian Linux 目标机系统的内置功能,这些文件可以是软件包(.deb)的形式。
关于软件包的安装和移除命令,需要在 .exoscomponents / .exospkg 文件 中手动输入 。关于.exospkg 和 .exoscomponents 之间的关系 , 请参阅 exOS软件包, 关于具体部署设置的更多信息,请参阅配置元素 。
在 B&R/Debian Linux 中直接安装 .deb 软件包时,如果不使用 apt 这样的工具(它会处理和解决软件包之间的依赖关系),还需要知道一些额外的事情。不用说,在互联网上可以找到更多的信息,但为了简单起见,以下是一些基本信息:
1.Debian
Debian 系统是基于软件包构建的。Debian 中有超过 50,000 个软件包可供使用。换句话说:大多数 Linux 软件工具和驱动程序都以软件包的形式提供。
2.依赖关系
每个发行版都有特定版本的软件包,而软件包可能依赖于其他系统。
oapt
...是 Debian 最常用的软件包检索工具,它可以连接到远程软件仓库并安装软件包(使用一个常用的软件包名称而不是软件包文件名称),同时解决所有依赖关系,即下载并安装所需的其他软件包。这需要连接到远程软件源(即互联网连接,除非在网络上托管了本地镜像)。例如
sudo apt-get install libmongoc-1.0.0
... 将安装
libbson-1.0-0_1.14.0-1_amd64.deb
libsnappy1v5_1.1.7-1_amd64.deb
libmongoc-1.0-0_1.14.0-1_amd64.deb
......,可能还有系统中尚未安装的其他软件包文件
odpkg
...需要互联网连接。它会安装 exOS 软件包提供的软件包(在 .exospkg 文件中定义 ),并解决这些 .deb 软件包之间的依赖关系,也就是说,它会确保按 "正确 "顺序安装软件包,但不能安装任何可能丢失的其他软件包。例如
sudo dpkg -i libmongoc-1.0-0_1.14.0-1_amd64.deb
...将无法安装,除非 libmongoc 依赖的软件包已经存在于系统中。
为了安装 libmongoc所需的 软件包,exOS 组件应提供附加文件:
libbson-1.0-0_1.14.0-1_amd64.deb
libsnappy1v5_1.1.7-1_amd64.deb
在这种情况下,安装命令可以简单为
sudo dpkg -i *.deb
这样 ,dpkg就能 处理这三个文件中的依赖关系。
ogdebi
如果存在未满足的依赖关系 ,dpkg无法 从远程软件源中获取其他软件包。工具 gdebi 可以做到这一点,但它需要在安装软件包时连接到远程软件仓库,例如
sudo gdebi libmongoc-1.0-0_1.14.0-1_amd64.deb
.. 将安装
libbson-1.0-0_1.14.0-1_amd64.deb
libsnappy1v5_1.1.7-1_amd64.deb
libmongoc-1.0-0_1.14.0-1_amd64.deb
......可能还有其他尚未安装到系统中的软件包文件
要找出特定目标系统所需的 pacakges,一个简单的方法是使用 apt-get 服务的缓存文件 。
在 Linux 中 使用 apt-get install..(注意:不是 apt install..)时,所需的 .deb pacakges 保存在 Linux 文件系统的/var/cache/apt/archives中 。在安装所需软件包之前,将其内容移至临时文件夹,就能找到所需的 .deb 软件包。
例如
sudo mkdir /var/cache/apt/archives/tmp
为文件创建一个临时目录
sudo mv /var/cache/apt/archives/* /var/cache/apt/archives/tmp
... 将所有 .deb 文件移至 tmp,并有一个小警告(不能将文件夹复制到自身)
ls /var/cache/apt/archives
现在应该可以看到: tmp
sudo apt-get install libmongoc-1.0.0
安装 MongoDB C 驱动程序(作为示例)
ls /var/cache/apt/archives
......现在应该能得到类似
libbson-1.0-0_1.14.0-1_amd64.deb
libsnappy1v5_1.1.7-1_amd64.deb
libmongoc-1.0-0_1.14.0-1_amd64.deb
->这些是当前系统中安装 libmongoc-1.0.0所需的软件包
这里需要考虑的是,进行此练习的系统是 exOS 服务运行的目标系统的代表。例如,如果软件包安装在开发环境中,那么该环境中预装的软件包很可能多于生产环境。因此,生产映像需要像软件的其他部分一样进行了解和版本控制,如果在生产系统上使用了新发布的 B&R/Debian Linux,exOS 软件包也需要更新,因为在许多情况下,新发布的 B&R/Debian Linux 会附带新版本的底层软件包,这可能需要更新版本的软件包,例如 MongoDB C 驱动程序。
也就是说,安装已安装的软件包会被直接忽略,所以多安装几个软件包是个不错的策略。
由于这些额外的 Debian "系统 "软件包最好不要在移除组件时移除(它们可能已经存在于系统中并被其他组件使用),因此 exOS 组件中不应该有移除 "系统 "软件包的命令。
如果需要移除未使用的 Debian "系统 "软件包(在 Debian 中称为 "孤儿 "软件包),可使用以下命令
sudo apt-get autoremove
将删除 Debian 上所有未使用的软件包。如果这看起来是件大事, 在 实际操作 之前 , 可以使用 --dry-run来 检查哪些软件包 会 被移除
sudo apt-get autoremove --dry-run
如果 exOS 运行的目标系统在安装或更新软件包时已知有互联网连接(或本地镜像连接),exOS 组件可以使用 apt 或 gdebi 服务指定安装命令 , 而不是以文件形式提供所有需要的 .deb 软件包。这种方法的最大优点是,依赖关系会自动解决,而且 exOS 软件包既不会依赖当前的系统配置,也不会像使用 .deb 文件那样依赖底层 Linux 发行版。
这可以通过 在.exospkg 文件 中 配置 安装 服务 ,或直接在 .exoscomponents 配置元素 中设置相应选项 来实现 。 例如,要在安装某个 exOS 组件(该组件依赖于 MongoDB C 驱动程序库)之前安装 MongoDB C 驱动程序,应在 exospkg 文件中 包含以下命令 :
<服务类型="安装" 命令="apt-get install libmongoc-1.0.0 -y"/>
所有安装命令都会被记录并在 AR 中的ExDeploy Logger 中显示。
exOS provides built-in functionality to install files to a B&R/Debian Linux target system that can come in the form of packages (.deb).
When it comes to the installation and removal commands of the packages, the commands need to be entered manually in the .exoscomponents / .exospkg file. See the exOS Package for the relation between .exospkg and .exoscomponents, and Configuration Elements for more information on the specific deployment settings.
When it comes to installing .deb packages directly in B&R/Debian Linux without the usage of a tool like apt (that will handle and resolve dependencies between packages), a few additional things need to be known. Needless to say, a lot more information can be found on the Internet, but for the sake of simplicity, here are some basics:
1.Debian
A Debian system is built on the basis of packages. More than 50,000 packages are available to be used in Debian. In other words: most Linux software tools and drivers are available as packages
2.Dependencies
Every distribution is created with a certain version of packages, and packages can have dependencies to other systems.
oapt
.. is the most commonly used package retrieval tool for Debian, which connects to a remote repository and installs a package (using a commonly known package name rather than the name of a package file) resolving all dependencies, i.e. downloads and installs any additional packages that are required. This requires a connection to a remote repository (i.e. Internet connection - unless a local mirror is hosted on the network). For example,
sudo apt-get install libmongoc-1.0.0
.. will install
libbson-1.0-0_1.14.0-1_amd64.deb
libsnappy1v5_1.1.7-1_amd64.deb
libmongoc-1.0-0_1.14.0-1_amd64.deb
.. and possibly other package files that were no yet on your system
odpkg
.. does require expect an Internet connection. It installs the packages that are provided with the exOS Package (defined in the .exospkg file), and resolvesthe dependencies in between those .deb packages, i.e. it will make sure to install the packages in the "right" order between themselves, but cannot install any additional packages that might be missing. For example,
sudo dpkg -i libmongoc-1.0-0_1.14.0-1_amd64.deb
.. will not install unless packages that libmongoc depends upon, are already present on the system
In order to install the needed packages for libmongoc, the additional files should be provided with the exOS component:
libbson-1.0-0_1.14.0-1_amd64.deb
libsnappy1v5_1.1.7-1_amd64.deb
In this case, the installation command can simply be
sudo dpkg -i *.deb
Which lets dpkg take care of the dependencies within the three files.
ogdebi
dpkg is not able to retrieve additional packages from a remote repository if there are unmet dependencies. The tool gdebi can do this, however it requires a connection to a remote repository when installing the package, for example
sudo gdebi libmongoc-1.0-0_1.14.0-1_amd64.deb
.. will install
libbson-1.0-0_1.14.0-1_amd64.deb
libsnappy1v5_1.1.7-1_amd64.deb
libmongoc-1.0-0_1.14.0-1_amd64.deb
.. and possibly other package files that were not yet on your system
Figuring out the dpkg dependencies
A simple way to figure out the needed pacakges for a given target system is to use the cached files of the apt-get service.
When using apt-get install .. in Linux (note: not apt install ..), the required .deb pacakges are stored in the /var/cache/apt/archives of the Linux filesystem. By moving the contents to a temporary folder before installing a required package, the needed .deb packages can be identified.
For example:
sudo mkdir /var/cache/apt/archives/tmp
.. creates a temp directory for your files
sudo mv /var/cache/apt/archives/* /var/cache/apt/archives/tmp
.. moves out all .deb files to tmp, with a small warning (cannot copy folder to itself)
ls /var/cache/apt/archives
.. should now give you: tmp
sudo apt-get install libmongoc-1.0.0
.. installs the MongoDB C Driver (as an example)
ls /var/cache/apt/archives
.. should now give you something like
libbson-1.0-0_1.14.0-1_amd64.deb
libsnappy1v5_1.1.7-1_amd64.deb
libmongoc-1.0-0_1.14.0-1_amd64.deb
-> these are the packages needed in the current system to install libmongoc-1.0.0
What needs to be considered here is that the system on which this exercise is carried out on, is representative of the target system where the exOS service runs on. For example, if the package is installed in a development environment, it is very likely that this environment has more packages preinstalled than a production environment. Therefore, the production image needs to be known and version controlled like other parts of the software, and if a new release of for example B&R/Debian Linux is used on the production system, the exOS packages need to be updated as well, as in many cases, the new B&R/Debian Linux release come with new versions of underlying packages, which could require newer versions of - for example - the MongoDB C driver.
That being said, installing an already installed package will simply be ignored, so having a few extra packages is a good strategy.
As these additional Debian "system" packages should preferably not be removed when removing the component (they could already be present on the system and used by other components), there should not be a removal command for the "system" packages in the exOS component.
If there is a need to remove Debian "system" packages which are unused (this is called "orphaned" packages in debian), the command
sudo apt-get autoremove
will remove all unused packaged on debian. If this might seem like a big thing, the --dry-run can be used to check which packages would be removed, before actually doing it
sudo apt-get autoremove --dry-run
Systems with Internet connection (at commissioning)
If the target system that exOS runs on, is known to have an Internet connection (or connection to a local mirror) at the time when packages are installed or updated, the exOS component can specify installation commands using the apt or gdebi services, rather than providing all needed .deb packages as files. This alternative has the big advantage that dependencies are resolved automatically, and the exOS package would neither dependent on the current system configuration, nor on the underlying Linux distribution as when using .deb files.
This can be accomplished by configuring an Installation service in the .exospkg file, or setting the corresponding option directly in the .exoscomponents configuration element. For example, to install the MongoDB C driver before installing a certain exOS component (which is dependent on the MongoDB C driver library), the following command should be included in the exospkg file:
<Service Type="Install" Command="apt-get install libmongoc-1.0.0 -y"/>
Checking the installation status
All installation commands are logged and become visible in the ExDeploy Logger in Automation Runtime.