第三章 Ubuntu包管理工具介绍及本地源配置

    不论是在学习还是在做Linux运维的过程中都需要安装各种软件包以及使用包管理工具,但由于很多内网环境几乎不允许生产环境的服务器连接互联网,这样就造成内网服务器无法使用网上的各种源,而且如果使用来回拷贝软件包安装还得解决依赖问题,所以就需要搭建个本地源。

    下面先来介绍Ubuntu两款包管理工具然后再来介绍本地源的配置。

一、包管理工具介绍

1 dpkg包管理器

dpkg 即 package manager for Debian ,是 Debian 和基于 Debian 的系统中一个主要的包管理工具,可以用来管理 deb 格式的软件包。。它可以安装、删除和构建包,但与其他包管理系统不同,它不能自动下载和安装包或者安装包的依赖项。

使用语法:

 dpkg (选项) (参数)

选项介绍:

       -i:安装软件包;

       -r:删除软件包;

       -P:删除软件包的同时删除其配置文件;

      -L package: 显示于软件包关联的文件;

     -l package:显示已经安装包的版本

       -l:显示已安装软件包列表;

     -S keyword : 搜索所属的包内容

      -unpack:解开软件包;

      -c:显示软件包内文件列表;

     –confiugre:配置软件包。

参数:

       Deb软件包:指定要操作的.deb软件包。

2 dpkg命令使用示例

2.1 列出已安装软件包列表

列出系统包数据库中已安装的所有包,从终端提示符类型:

2.2 查看是否安装了特定的包

根据系统上的包数量,这可能会生成大量输出。通过grep输出管道来查看是否安装了特定的包:

sudo dpkg - l | grep apache2

2.3 查询软件包关联的文件

要列出一个包所安装的文件,在本例中是ufw包,输入:

arshou@arshou-ser:~$ dpkg -L ufw

/.

/etc

/etc/default

/etc/default/ufw

/etc/init.d

/etc/init.d/ufw

/etc/logrotate.d

/etc/logrotate.d/ufw

/etc/rsyslog.d

/etc/rsyslog.d/20-ufw.conf

/etc/ufw

/etc/ufw/applications.d

/etc/ufw/sysctl.conf

/lib

/lib/systemd

/lib/systemd/system

/lib/systemd/system/ufw.service

/lib/ufw

/lib/ufw/ufw-init

/lib/ufw/ufw-init-functions

/usr

/usr/lib

/usr/lib/python3

/usr/lib/python3/dist-packages

/usr/lib/python3/dist-packages/ufw

/usr/lib/python3/dist-packages/ufw/__init__.py

/usr/lib/python3/dist-packages/ufw/applications.py

/usr/lib/python3/dist-packages/ufw/backend.py

/usr/lib/python3/dist-packages/ufw/backend_iptables.py

/usr/lib/python3/dist-packages/ufw/common.py

/usr/lib/python3/dist-packages/ufw/frontend.py

/usr/lib/python3/dist-packages/ufw/parser.py

/usr/lib/python3/dist-packages/ufw/util.py

/usr/lib/python3/dist-packages/ufw-0.36.1.egg-info

/usr/sbin

/usr/sbin/ufw

/usr/share

/usr/share/bash-completion

/usr/share/bash-completion/completions

/usr/share/bash-completion/completions/ufw

/usr/share/doc

/usr/share/doc/ufw

/usr/share/doc/ufw/README.Debian

/usr/share/doc/ufw/README.gz

/usr/share/doc/ufw/changelog.Debian.gz

/usr/share/doc/ufw/copyright

/usr/share/doc/ufw/examples

/usr/share/doc/ufw/examples/skel-ui.example

/usr/share/lintian

/usr/share/lintian/overrides

/usr/share/lintian/overrides/ufw

/usr/share/man

/usr/share/man/man8

/usr/share/man/man8/ufw-framework.8.gz

/usr/share/man/man8/ufw.8.gz

/usr/share/ufw

/usr/share/ufw/after.init

/usr/share/ufw/after.rules.md5sum

/usr/share/ufw/after6.rules.md5sum

/usr/share/ufw/before.init

/usr/share/ufw/before.rules.md5sum

/usr/share/ufw/before6.rules.md5sum

/usr/share/ufw/check-requirements

/usr/share/ufw/iptables

/usr/share/ufw/iptables/after.rules

/usr/share/ufw/iptables/after6.rules

/usr/share/ufw/iptables/before.rules

/usr/share/ufw/iptables/before6.rules

/usr/share/ufw/iptables/user.rules

/usr/share/ufw/iptables/user6.rules

/usr/share/ufw/messages

/usr/share/ufw/messages/ar.mo

/usr/share/ufw/messages/ast.mo

/usr/share/ufw/messages/bg.mo

/usr/share/ufw/messages/bs.mo

/usr/share/ufw/messages/ca.mo

/usr/share/ufw/messages/ce.mo

/usr/share/ufw/messages/cs.mo

/usr/share/ufw/messages/da.mo

/usr/share/ufw/messages/de.mo

/usr/share/ufw/messages/el.mo

/usr/share/ufw/messages/en_AU.mo

/usr/share/ufw/messages/en_GB.mo

/usr/share/ufw/messages/es.mo

/usr/share/ufw/messages/et.mo

/usr/share/ufw/messages/fi.mo

/usr/share/ufw/messages/fr.mo

/usr/share/ufw/messages/he.mo

/usr/share/ufw/messages/hu.mo

/usr/share/ufw/messages/id.mo

/usr/share/ufw/messages/it.mo

/usr/share/ufw/messages/ja.mo

/usr/share/ufw/messages/ko.mo

/usr/share/ufw/messages/lv.mo

/usr/share/ufw/messages/nb.mo

/usr/share/ufw/messages/nl.mo

/usr/share/ufw/messages/pl.mo

/usr/share/ufw/messages/pt.mo

/usr/share/ufw/messages/pt_BR.mo

/usr/share/ufw/messages/ru.mo

/usr/share/ufw/messages/se.mo

/usr/share/ufw/messages/sk.mo

/usr/share/ufw/messages/sl.mo

/usr/share/ufw/messages/sr.mo

/usr/share/ufw/messages/sv.mo

/usr/share/ufw/messages/tl.mo

/usr/share/ufw/messages/tr.mo

/usr/share/ufw/messages/uk.mo

/usr/share/ufw/messages/ur.mo

/usr/share/ufw/messages/zh_CN.mo

/usr/share/ufw/messages/zh_TW.mo

/usr/share/ufw/ufw.conf

/usr/share/ufw/user.rules.md5sum

/usr/share/ufw/user6.rules.md5sum

/usr/share/ufw/after.rules

/usr/share/ufw/after6.rules

/usr/share/ufw/before.rules

/usr/share/ufw/before6.rules

/usr/share/ufw/user.rules

/usr/share/ufw/user6.rules

arshou@arshou-ser:~$

2.4  查询软件包的版本

列出一个包所安装的版本,执行dpkg -l 包名,示例如下:

使用 dpkg -l 命令列出当前系统中已经安装的软件以及软件包的状态有如下:

命令输出的第一行为期望状态,期望状态有以下几种:

  • u:即 unknown,软件包未安装且用户未请求安装
  • i:即 install,用户请求安装该软件包
  • r:即 remove,用户请求卸载该软件包
  • p:即 purge,用户请求卸载该软件包并清理配置文件
  • h:即 hold,用户请求保持续当前软件包版本

命令输出的第二行为当前状态有以下几种:

  • n:即 not-installed,软件包未安装
  • i:即 installed,软件包已安装并完成配置
  • c:即 config-files,软件包已经被卸载,但是其配置文件未清理
  • u:即 unpacked,软件包已经被解压缩,但还未配置
  • f:即 half-configured,配置软件包时出现错误
  • w:即 triggers-awaited,触发器等待
  • t:即 triggers-pending,触发器未决

命令输出的第三行为错误状态,有以下几种:

  • h:软件包被强制保持
  • r:即 reinstall-required,需要卸载并重新安装
  • x:软件包被破坏

因此 ii 表示该软件需要安装且已经安装,没有出现错误; iu 表示已经安装该软件,但未正确配置; rc 表示该软件已经被删除,但配置文件未清理。

2.4.1 筛选查找模式匹配的软件包

使用命令格式:dpkg -l <package_name_pattern>

arshou@ub-client:~$ sudo dpkg -l "apache*"

Desired=Unknown/Install/Remove/Purge/Hold

| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend

|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)

||/ Name                            Version           Architecture Description

+++-===============================-=================-============-==============================================>

un  apache2-api-20120211            <none>            <none>       (no description available)

un  apache2-api-20120211-openssl1.1 <none>            <none>       (no description available)

ii  apache2-bin                     2.4.52-1ubuntu4.5 amd64        Apache HTTP Server (modules and other binary f>

ii  apache2-data                    2.4.52-1ubuntu4.5 all          Apache HTTP Server (common files)

un  apache2-doc                     <none>            <none>       (no description available)

un  apache2-suexec-custom           <none>            <none>       (no description available)

un  apache2-suexec-pristine         <none>            <none>       (no description available)

ii  apache2-utils                   2.4.52-1ubuntu4.5 amd64        Apache HTTP Server (utility programs for web s

un 表示此软件包没有安装。

2.5 安装本地软件包

使用dpkg安装本地软件包,本地必须有这个软件包,并且这个包没有其他包的依赖关系,使用dpkg才能安装成功,如果有依赖其他包则安装或报错。

以下安装zip包,执行以下命令:

arshou@arshou-ser:~$ sudo dpkg -i zip_3.0-12build2_amd64.deb

(Reading database ... 110181 files and directories currently installed.)

Preparing to unpack zip_3.0-12build2_amd64.deb ...

Unpacking zip (3.0-12build2) over (3.0-12build2) ...

Setting up zip (3.0-12build2) ...

Processing triggers for man-db (2.10.2-1) ...

arshou@arshou-ser:~$

这里使用dpkg安装有依赖的软件包安装部成功之后会有提示报错,比如安装ansible。

查看安装结果:

 这里iU 表示已经安装该软件,但未正确配置;

这个时候安装其他软件包时会提示有包绝少依赖,其他软件无法安装成功,如下:

解决方法把这个已经安装该软件,但未正确配置的软件包删除,然后再安装其他软件包。

2.6 卸载软件包

使用dpkg卸载软件包时,有两个选项可以使用,使用选项P不保留其配置信息,使用选项r时,有配置文件的软件包会保留配置信息。

列如使用选项r卸载apache2时,因为apache2有配置文件,所以使用选项r卸载时会保留配置信息,出口已经卸载的软件时会显示rc。

卸载和查看示例如下:

再使用选项P卸载时,查看就没有apache2时就没有发现apache2了,如下:

 

3 高级包装工具- APT

apt命令是一个强大的命令行工具,它与Ubuntu的高级打包工具(apt)一起工作。apt中包含的命令提供了安装新软件包、升级现有软件包、更新软件包列表索引,甚至升级整个Ubuntu系统的方法。

在介绍apt工具安装或者删除软件包之前先来介绍修改配置安装源的方法,将安装好系统自带默认源改为国内源,这样安装软件包时会加快安装速度。

下面将安装源修改为国内的阿里云的源:

root@arshou-ser:~# vi /etc/apt/sources.list

deb ubuntu安装包下载_开源镜像站-阿里云 jammy main restricted universe multiverse
deb-src ubuntu安装包下载_开源镜像站-阿里云 jammy main restricted universe multiverse

deb ubuntu安装包下载_开源镜像站-阿里云 jammy-security main restricted universe multiverse
deb-src ubuntu安装包下载_开源镜像站-阿里云 jammy-security main restricted universe multiverse

deb ubuntu安装包下载_开源镜像站-阿里云 jammy-updates main restricted universe multiverse
deb-src ubuntu安装包下载_开源镜像站-阿里云 jammy-updates main restricted universe multiverse

# deb ubuntu安装包下载_开源镜像站-阿里云 jammy-proposed main restricted universe multiverse
# deb-src ubuntu安装包下载_开源镜像站-阿里云 jammy-proposed main restricted universe multiverse

deb ubuntu安装包下载_开源镜像站-阿里云 jammy-backports main restricted universe multiverse
deb-src ubuntu安装包下载_开源镜像站-阿里云 jammy-backports main restricted universe multiverse

 

执行apt update:

root@arshou-ser:~# apt update

Hit:1 ubuntu安装包下载_开源镜像站-阿里云 jammy InRelease

Hit:2 ubuntu安装包下载_开源镜像站-阿里云 jammy-security InRelease             

Hit:3 ubuntu安装包下载_开源镜像站-阿里云 jammy-updates InRelease              

Hit:4 ubuntu安装包下载_开源镜像站-阿里云 jammy-backports InRelease

Reading package lists... Done

Building dependency tree... Done

Reading state information... Done

11 packages can be upgraded. Run 'apt list --upgradable' to see them.

root@arshou-ser:~#

执行apt update报错解决:

执行 apt update报错:

root@arshou-ser:~# apt update

Reading package lists... Done                                                                        

E: Method https has died unexpectedly!

E: Sub-process https received signal 4.

root@arshou-ser:~#

一般可能是安装源有问题,更换安装源重新update就好了,这里要说的是,就算更换了安装源,依然会报这个错的情况

这里需要在设置了环境变量的情况下执行

root@arshou-ser:~# source /etc/profile   

root@arshou-ser:~# source /etc/environment

这个问题应该是CPU的问题引起,当前使用的CPUIntel(R) Xeon(R) Silver 4214 CPU @ 2.20GHz,使用其他cpu的系统是正常的。

补充知识点:

GNUTLS_CPUID_OVERRIDE是一个环境变量,用于指定GnuTLS库使用的CPUID(CPU信息检测)函数的行为。

CPUID是用于检测计算机中央处理器(CPU)的特性和功能的函数。

将GNUTLS_CPUID_OVERRIDE设置为0x1意味着GnuTLS库将忽略CPU的特性检测,并始终使用指定的固定值0x1。

这可能是为了在某些情况下强制使用特定的加密算法或功能,而忽略实际的CPU特性。

然而,设置该环境变量可能会对系统的性能和安全性产生潜在影响。

因为忽略CPU特性检测可能导致在某些情况下使用不合适的加密算法或功能,这可能会降低系统性能或增加安全风险。

因此,在一般情况下,建议不要修改该环境变量,除非您明确知道修改的目的和影响

知识引用站点: <https://www.cnblogs.com/guangdelw/p/17616268.html>

3.1 安装软件包

使用apt安装软件包非常简单。例如,要安装apache2做web服务器,请输入以下命令:

sudo apt install apache2

3.2移除包

删除一个(或多个)包也很简单。要删除前面示例中安装的包,只需输入:

sudo apt remove apache2

这样删除软件包,会保留软件包的配置文件,当使用dpkg -l | grep 软件包名时显示结果会显示rc

有些包卸载不彻底,也会导致各种问题。

debian系的底层包管理程序dpkg可以对于帮助我们找到这些包。

使用dpkg --list可以查看所有包的状态,其中前两位表示状态,第一位为期望的状态,第二位为实际的状态。可以大致理解为:当我们输入安装命令时,第一位置为i(表示install),当命令完成时,第二位置为i。

一个常见的非理想状态是:第一位为r(removed),第二位为c(Cfg-file存在)。

向apt remove添加——purge选项将删除包配置文件。这可能是也可能不是想要的效果,所以要小心使用。

移除软件包是增加--purge参数将会删除软件包已经相关的配置文件,再次查看移除的软件包时就没有rc了

二、配置本地源

1 前言

    由于很多内网环境都是不允许连接互联网,无法使用网上的各种源,而且在安装软件包时由于多数软件包的安装都需要解决依赖关系,使用来回拷贝软件包安装麻也比较麻烦,并且还得解决软件包之间的依赖问题,所以就需要搭建个本地源。

2 系统环境

系统版本

 IP

用途

Ubuntu 22.04.1 LTS

192.168.20.128

软件包源服务器

3 下载软件包

     首先执行下载命令的时候,会系统会默认保存下载的安装包,路径是/var/cache/apt/archives,可以从这里面复制出去安装包,然后就可以拿去制作本地源了。

单纯下载软件包的话,使用以下命令:

如下载时间同步chrony:

root@server:~# apt download chrony

但是更多时候我们需要同时下载一个软件和他的依赖软件,这时候执行如下命令可以一块下载他的依赖,-d参数就是下载模式,不安装,这个的前提是没有安装过这个软件才能下载

root@server:~# apt -d install ansible -y

这样软件包就会下载到/var/cache/apt/archives目录下。

4 安装dpkg-dev工具

需要安装dpkg-dev软件包,才能为本地APT仓库创建软件包元数据。

root@server:~#  apt install -y dpkg-dev

5、配置提供本机使用的源

5.1 创建本地仓库的存储目录

创建/soft/repo目录,用来存放软件包:

root@server:~# mkdir -p /soft/repo

 

将下载好的软件包放置在/soft/repo目录下(这里是下载ansible的安装包和依赖包做源后测试无公网连接来安装ansible):

root@server:~# ll /soft/repo/

total 22380

drwxr-xr-x 2 root root     4096 Jun 13 02:16 ./

drwxr-xr-x 3 root root     4096 Jun 13 02:11 ../

-rw-r--r-- 1 root root 17530700 Jun 13 02:16 ansible_2.10.7+merged+base+2.10.8+dfsg-1_all.deb

-rw-r--r-- 1 root root  1887104 Jun 13 02:16 ieee-data_20210605.1_all.deb

-rw-r--r-- 1 root root    27236 Jun 13 02:16 python3-argcomplete_1.8.1-1.5_all.deb

-rw-r--r-- 1 root root   123058 Jun 13 02:16 python3-dnspython_2.1.0-1ubuntu1_all.deb

-rw-r--r-- 1 root root    21708 Jun 13 02:16 python3-jmespath_0.10.0-1_all.deb

-rw-r--r-- 1 root root    23012 Jun 13 02:16 python3-kerberos_1.1.14-3.1build5_amd64.deb

-rw-r--r-- 1 root root  1554184 Jun 13 02:16 python3-libcloud_3.2.0-2_all.deb

-rw-r--r-- 1 root root    14576 Jun 13 02:16 python3-lockfile_1%3a0.12.2-2.2_all.deb

-rw-r--r-- 1 root root   308658 Jun 13 02:16 python3-netaddr_0.8.0-2_all.deb

-rw-r--r-- 1 root root    20384 Jun 13 02:16 python3-ntlm-auth_1.4.0-1_all.deb

-rw-r--r-- 1 root root    30672 Jun 13 02:16 python3-packaging_21.3-1_all.deb

-rw-r--r-- 1 root root  1026726 Jun 13 02:16 python3-pycryptodome_3.11.0+dfsg1-3build1_amd64.deb

-rw-r--r-- 1 root root    11892 Jun 13 02:16 python3-requests-kerberos_0.12.0-2_all.deb

-rw-r--r-- 1 root root     6160 Jun 13 02:16 python3-requests-ntlm_1.1.0-1.1_all.deb

-rw-r--r-- 1 root root    37984 Jun 13 02:16 python3-requests-toolbelt_0.9.1-1_all.deb

-rw-r--r-- 1 root root   158910 Jun 13 02:16 python3-selinux_3.3-1build2_amd64.deb

-rw-r--r-- 1 root root    54722 Jun 13 02:16 python3-simplejson_3.17.6-1build1_amd64.deb

-rw-r--r-- 1 root root    21660 Jun 13 02:16 python3-winrm_0.3.0-2_all.deb

-rw-r--r-- 1 root root    12608 Jun 13 02:16 python3-xmltodict_0.12.0-2_all.deb

root@server:~#

 

5.2 创建本地软件源的文件

进入/soft/repo目录下:

root@server:~# cd /soft/repo

创建本地软件源的Package.gz和index文件

root@server:/soft/repo# dpkg-scanpackages ./ | gzip -9c > Packages.gz

dpkg-scanpackages: info: Wrote 19 entries to output Packages file.

root@server:/soft/repo#

root@server:/soft/repo# apt-ftparchive packages ./ > Packages

root@server:/soft/repo# apt-ftparchive release ./ > Release

root@server:/soft/repo#

 

5.3 更改安装源为本地源

root@server:/soft/repo# mv /etc/apt/sources.list /etc/apt/sources.list.old

root@server:/soft/repo#

root@server:/soft/repo# vi /etc/apt/sources.list

输入以下内容并保存:

deb [trusted=yes] file:///soft/repo/ ./

更新源

root@server:/soft/repo# apt update

Get:1 file:/soft/repo ./ InRelease

Ign:1 file:/soft/repo ./ InRelease

Get:2 file:/soft/repo ./ Release [1,204 B]

Get:2 file:/soft/repo ./ Release [1,204 B]

Get:3 file:/soft/repo ./ Release.gpg

Ign:3 file:/soft/repo ./ Release.gpg

Get:4 file:/soft/repo ./ Packages [8,635 B]

Reading package lists... Done

Building dependency tree... Done

Reading state information... Done

All packages are up to date.

root@server:/soft/repo#

执行更新源命令后,源就只有本地源可以使用了。

5.4 安装软件

前面是下载ansible和其依赖包来做包的安装源,那么我们就安装ansible:

 

先验证是否已经安装有ansible:

 

验证结果没有安装ansible软件,下面进行安装。

root@server:~# apt install -y ansible

Reading package lists... Done

Building dependency tree... Done

Reading state information... Done

The following additional packages will be installed:

  ieee-data python3-argcomplete python3-dnspython python3-jmespath python3-kerberos python3-libcloud python3-lockfile python3-netaddr

  python3-ntlm-auth python3-packaging python3-pycryptodome python3-requests-kerberos python3-requests-ntlm python3-requests-toolbelt

  python3-selinux python3-simplejson python3-winrm python3-xmltodict

Suggested packages:

  cowsay sshpass python3-sniffio python3-trio python-lockfile-doc ipython3 python-netaddr-docs

The following NEW packages will be installed:

  ansible ieee-data python3-argcomplete python3-dnspython python3-jmespath python3-kerberos python3-libcloud python3-lockfile python3-netaddr

  python3-ntlm-auth python3-packaging python3-pycryptodome python3-requests-kerberos python3-requests-ntlm python3-requests-toolbelt

  python3-selinux python3-simplejson python3-winrm python3-xmltodict

0 upgraded, 19 newly installed, 0 to remove and 0 not upgraded.

Need to get 0 B/22.9 MB of archives.

After this operation, 243 MB of additional disk space will be used.

Get:1 file:/soft/repo ./ python3-packaging 21.3-1 [30.7 kB]

Get:2 file:/soft/repo ./ python3-pycryptodome 3.11.0+dfsg1-3build1 [1,027 kB]

Get:3 file:/soft/repo ./ python3-dnspython 2.1.0-1ubuntu1 [123 kB]

Get:4 file:/soft/repo ./ ieee-data 20210605.1 [1,887 kB]

Get:5 file:/soft/repo ./ python3-netaddr 0.8.0-2 [309 kB]

Get:6 file:/soft/repo ./ ansible 2.10.7+merged+base+2.10.8+dfsg-1 [17.5 MB]

Get:7 file:/soft/repo ./ python3-argcomplete 1.8.1-1.5 [27.2 kB]

Get:8 file:/soft/repo ./ python3-jmespath 0.10.0-1 [21.7 kB]

Get:9 file:/soft/repo ./ python3-kerberos 1.1.14-3.1build5 [23.0 kB]

Get:10 file:/soft/repo ./ python3-lockfile 1:0.12.2-2.2 [14.6 kB]

Get:11 file:/soft/repo ./ python3-simplejson 3.17.6-1build1 [54.7 kB]

Get:12 file:/soft/repo ./ python3-libcloud 3.2.0-2 [1,554 kB]

Get:13 file:/soft/repo ./ python3-ntlm-auth 1.4.0-1 [20.4 kB]

Get:14 file:/soft/repo ./ python3-requests-kerberos 0.12.0-2 [11.9 kB]

Get:15 file:/soft/repo ./ python3-requests-ntlm 1.1.0-1.1 [6,160 B]

Get:16 file:/soft/repo ./ python3-requests-toolbelt 0.9.1-1 [38.0 kB]

Get:17 file:/soft/repo ./ python3-selinux 3.3-1build2 [159 kB]

Get:18 file:/soft/repo ./ python3-xmltodict 0.12.0-2 [12.6 kB]

Get:19 file:/soft/repo ./ python3-winrm 0.3.0-2 [21.7 kB]

Selecting previously unselected package python3-packaging.

…………………………………………………………………………………………………………………..

Processing triggers for man-db (2.10.2-1) ...

Scanning processes...                                                                                                                          

Scanning linux images...                                                                                                                       

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

root@server:~#

5.5 编写一个脚本来更新Package.gz和索引文件

创建一个脚本文件以扫描更新Packages.gz文件,因为可能会不时的在本地APT仓库中添加新的deb软件包。因此,每次在repo目录中添加新的deb软件包之后,都需要更新Packages.gz文件和索引文件。

root@server:~# vim /bin/update-debs.sh

#!/bin/bash
cd
/soft/repo
dpkg
-scanpackages ./ /dev/null|gzip -9c >Packages.gz

apt-ftparchive packages ./ > Packages
apt-ftparchive release ./ > Release

给update-debs脚本文件添加可执行权限:

root@server:~# chmod +x /bin/update-debs.sh

现在执行此脚本以创建Packages.gz文件:

root@server:~#  /bin/update-debs.sh

 

 

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
Baremaps 是一个用于生成自定义 OpenStreetMap 数据库的工具,它可以用于构建自己的路网、建筑物和其他地图数据。在 Ubuntu配置 Baremaps 的步骤如下: 1. 安装 Java 运行环境 Baremaps 是用 Java 编写的,因此需要安装 Java 运行环境。在终端中输入以下命令安装 OpenJDK: ``` sudo apt update sudo apt install default-jdk ``` 2. 安装 Postgres 数据库 Baremaps 使用 Postgres 数据库存储地图数据。在终端中输入以下命令安装 Postgres: ``` sudo apt install postgresql postgresql-contrib ``` 3. 创建数据库 创建一个 Baremaps 数据库和用户。在终端中输入以下命令: ``` sudo -u postgres createuser baremaps sudo -u postgres createdb baremaps sudo -u postgres psql -c "alter user baremaps with encrypted password 'password';" sudo -u postgres psql -c "grant all privileges on database baremaps to baremaps;" ``` 其中,将 'password' 替换为自己想要设置的密码。 4. 下载 Baremaps 在终端中输入以下命令下载 Baremaps: ``` wget https://github.com/baremaps/baremaps/releases/download/v2.8.0/baremaps-2.8.0.tar.gz ``` 5. 解压 Baremaps 在终端中输入以下命令将 Baremaps 解压到当前目录: ``` tar -xvf baremaps-2.8.0.tar.gz ``` 6. 配置 Baremaps 在终端中进入 Baremaps 目录: ``` cd baremaps-2.8.0 ``` 编辑 application.yml 文件: ``` nano config/application.yml ``` 修改以下配置: ``` spring: datasource: url: jdbc:postgresql://localhost:5432/baremaps username: baremaps password: password server: port: 8080 ``` 将 'password' 替换为第 3 步中设置的密码。 7. 运行 Baremaps 在终端中输入以下命令运行 Baremaps: ``` ./baremaps.sh import --config config/import.yml ``` 该命令将下载并导入 OpenStreetMap 数据。导入完成后,可以在浏览器中访问 http://localhost:8080 查看地图。 8. 可选:使用 Docker 运行 Baremaps 如果不想在本地安装 Baremaps 的依赖项,可以使用 Docker 运行 Baremaps。在终端中输入以下命令: ``` docker run -it --rm -p 8080:8080 baremaps/baremaps:v2.8.0 import --config https://raw.githubusercontent.com/baremaps/baremaps/master/configs/osm2pgsql/osm2pgsql-import-web.yml ``` 该命令将下载并导入 OpenStreetMap 数据,并在本地的 8080 端口运行 Baremaps。可以在浏览器中访问 http://localhost:8080 查看地图。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yjun89

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值