前言
生产过程中业务大部分都是在jre镜像中运行,有时候我们需要到服务里面排查问题但是苦于没有很多命令。最简单的方法就是用apt安装下
配置apt源
默认情况下jre镜像的apt源为国外当我们执行apt install会到国外去请求,是无法正常下载的,也会比较慢
apt-get install net-tools
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
net-tools
0 upgraded, 1 newly installed, 0 to remove and 42 not upgraded.
Need to get 248 kB of archives.
After this operation, 1002 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian buster/main amd64 net-tools amd64 1.60+git20180626.aebd88e-1 [248 kB]
61% [1 net-tools 190 kB/248 kB 77%] 3723 B/s 15s
所以我们需要将apt源修改为国内的
备份源文件
cp /etc/apt/sources.list /etc/apt/sources.list.bak
修改apt源文件(这里使用的阿里云源)
cat >/etc/apt/sources.list <<EOF
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multivers
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
EOF
更新源
apt-get update
···
e public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
E: The repository 'http://mirrors.aliyun.com/ubuntu bionic-backports InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
E: The repository 'http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
这里可能会包这个错误原因是缺少公钥
解决方案
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5
Executing: /tmp/apt-key-gpghome.3CPxCTYb74/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5
gpg: key 40976EAF437D05B5: public key "Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>" imported
gpg: Total number processed: 1
gpg: imported: 1
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
Executing: /tmp/apt-key-gpghome.D6x3xpJKO1/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
gpg: key 3B4FE6ACC0B21F32: public key "Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com>" imported
gpg: Total number processed: 1
gpg: imported: 1
再次执行update
apt-get update
Get:1 http://mirrors.aliyun.com/ubuntu bionic InRelease [242 kB]
Get:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease [88.7 kB]
Get:3 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease [83.3 kB]
Get:5 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease [242 kB]
Get:6 http://mirrors.aliyun.com/ubuntu bionic/multiverse Sources [181 kB]
Get:7 http://mirrors.aliyun.com/ubuntu bionic/restricted Sources [5324 B]
Get:8 http://mirrors.aliyun.com/ubuntu bionic/main Sources [829 kB]
Get:9 http://mirrors.aliyun.com/ubuntu bionic/universe Sources [9051 kB]
Get:10 http://mirrors.aliyun.com/ubuntu bionic/main amd64 Packages [1019 kB]
Get:11 http://mirrors.aliyun.com/ubuntu bionic/universe amd64 Packages [8570 kB]
Get:12 http://mirrors.aliyun.com/ubuntu bionic/restricted amd64 Packages [9184 B]
Get:13 http://mirrors.aliyun.com/ubuntu bionic/multiverse amd64 Packages [151 kB]
Get:14 http://mirrors.aliyun.com/ubuntu bionic-security/multiverse Sources [10.6 kB]
再次执行安装就很快了