显然在生产服务器上出现了一些问题,有人删除了该/var
文件夹的内容。
这导致了一些错误,我一直在使用各种服务作为 Web 服务器来解决这些错误。
我遇到的apt
问题,不允许我更新、删除或安装软件包的问题。
例如我想重新安装数据库服务器mariadb-server
,但它告诉我系统中没有安装包(这是错误的,我个人安装了它):
root# apt remove mariadb-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'mariadb-server' is not installed, so not removed
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
chkconfig : Depends: perl but it is not going to be installed
Recommends: insserv but it is not going to be installed
libboost-chrono1.50.0 : Depends: libgcc1 (>= 1:4.4.0) but it is not going to be installed
Depends: libstdc++6 (>= 4.4.0) but it is not going to be installed
libboost-system1.50.0 : Depends: libgcc1 (>= 1:4.4.0) but it is not going to be installed
Depends: libstdc++6 (>= 4.4.0) but it is not going to be installed
libboost-thread1.50.0 : Depends: libgcc1 (>= 1:4.4.0) but it is not going to be installed
Depends: libstdc++6 (>= 4.6) but it is not going to be installed
libc6 : Depends: libgcc1 but it is not going to be installed
libprotobuf-lite7 : Depends: libgcc1 (>= 1:4.4.0) but it is not going to be installed
Depends: libstdc++6 (>= 4.4.0) but it is not going to be installed
Depends: zlib1g (>= 1:1.1.4) but it is not going to be installed
oracle-java8-jdk : Depends: libasound2 (>= 1.0.16)
Depends: libgcc1 (>= 1:4.4.0) but it is not going to be installed
Depends: libx11-6 but it is not going to be installed
Depends: libxext6 but it is not going to be installed
Depends: libxi6 but it is not going to be installed
Depends: libxrender1 but it is not going to be installed
Depends: libxtst6 but it is not going to be installed
Recommends: netbase but it is not going to be installed
redis-server : Depends: init-system-helpers (>= 1.18~) but it is not going to be installed
Depends: libjemalloc1 (>= 2.1.1) but it is not going to be installed
Depends: adduser but it is not going to be installed
redis-tools : Depends: libjemalloc1 (>= 2.1.1) but it is not going to be installed
watchdog : Depends: debconf (>= 0.5) but it is not going to be installed or
debconf-2.0
Depends: init-system-helpers (>= 1.18~) but it is not going to be installed
Depends: makedev (>= 2.3.1-24) but it is not going to be installed or
udev but it is not going to be installed
Depends: lsb-base (>= 3.2-14) but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
如果我启动告诉我解决未满足的依赖项的命令:
root# apt-get -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following extra packages will be installed:
adduser apt apt-utils base-passwd ca-certificates coreutils debconf debconf-i18n debianutils dpkg e2fslibs e2fsprogs gnupg gnupg-curl gpgv ifupdown init-system-helpers initscripts insserv iproute2 isc-dhcp-client isc-dhcp-common
krb5-locales libacl1 libalgorithm-c3-perl libapt-inst1.5 libapt-pkg4.12 libarchive-extract-perl libasound2 libasound2-data libatm1 libattr1 libaudit-common libaudit1 libblkid1 libbz2-1.0 libcgi-fast-perl libcgi-pm-perl
libclass-c3-perl libclass-c3-xs-perl libcomerr2 libcpan-meta-perl libcurl3-gnutls libdata-optlist-perl libdata-section-perl libdb5.3 libdebconfclient0 libdns-export100 libfcgi-perl libffi6 libgcc1 libgcrypt20 libgdbm3 libgmp10
libgnutls-deb0-28 libgpg-error0 libgpm2 libgssapi-krb5-2 libhogweed2 libidn11 libirs-export91 libisc-export95 libisccfg-export90 libjemalloc1 libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0 libldap-2.4-2 liblocale-gettext-perl
liblog-message-perl liblog-message-simple-perl liblzma5 libmodule-build-perl libmodule-pluggable-perl libmodule-signature-perl libmount1 libmro-compat-perl libncurses5 libnettle4 libp11-kit0 libpackage-constants-perl libpam-modules
libpam-modules-bin libpam0g libparams-util-perl libpcre3 libpng12-0 libpod-latex-perl libpod-readme-perl libreadline6 libregexp-common-perl librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libselinux1 libsemanage-common
libsemanage1 libsepol1 libslang2 libsmartcols1 libsoftware-license-perl libss2 libssh2-1 libssl1.0.0 libstdc++6 libsub-exporter-perl libsub-install-perl libsystemd0 libtasn1-6 libterm-ui-perl libtext-charwidth-perl libtext-iconv-perl
libtext-soundex-perl libtext-template-perl libtext-wrapi18n-perl libtinfo5 libusb-0.1-4 libustr-1.0-1 libuuid1 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxi6 libxrender1 libxtables10 libxtst6 lsb-base makedev netbase
openssl passwd perl perl-base perl-modules psmisc raspbian-archive-keyring readline-common redis-server redis-tools rename sensible-utils startpar sysv-rc sysvinit-utils tar tzdata util-linux uuid-runtime x11-common zlib1g
Suggested packages:
aptitude synaptic wajig dpkg-dev apt-doc python-apt debconf-doc debconf-utils whiptail dialog gnome-utils libterm-readline-gnu-perl libgtk2-perl libnet-ldap-perl libqtgui4-perl libqtcore4-perl gpart parted fuse2fs e2fsck-static
gnupg-doc libpcsclite1 parcimonie xloadimage imagemagick eog ppp rdnssd net-tools bootchart2 iproute2-doc resolvconf avahi-autoipd libasound2-plugins alsa-utils rng-tools gnutls-bin gpm krb5-doc krb5-user libpam-doc
libsasl2-modules-otp libsasl2-modules-ldap libsasl2-modules-sql libsasl2-modules-gssapi-mit libsasl2-modules-gssapi-heimdal perl-doc make libb-lint-perl libcpanplus-dist-build-perl libcpanplus-perl libfile-checktree-perl
libobject-accessor-perl readline-doc bum bootlogd sash bzip2 ncompress xz-utils tar-scripts dosfstools kbd console-tools util-linux-locales
Recommended packages:
libarchive-tar-perl
The following NEW packages will be installed:
adduser apt apt-utils base-passwd ca-certificates coreutils debconf debconf-i18n debianutils dpkg e2fslibs e2fsprogs gnupg gnupg-curl gpgv ifupdown init-system-helpers initscripts insserv iproute2 isc-dhcp-client isc-dhcp-common
krb5-locales libacl1 libalgorithm-c3-perl libapt-inst1.5 libapt-pkg4.12 libarchive-extract-perl libasound2 libasound2-data libatm1 libattr1 libaudit-common libaudit1 libblkid1 libbz2-1.0 libcgi-fast-perl libcgi-pm-perl
libclass-c3-perl libclass-c3-xs-perl libcomerr2 libcpan-meta-perl libcurl3-gnutls libdata-optlist-perl libdata-section-perl libdb5.3 libdebconfclient0 libdns-export100 libfcgi-perl libffi6 libgcc1 libgcrypt20 libgdbm3 libgmp10
libgnutls-deb0-28 libgpg-error0 libgpm2 libgssapi-krb5-2 libhogweed2 libidn11 libirs-export91 libisc-export95 libisccfg-export90 libjemalloc1 libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0 libldap-2.4-2 liblocale-gettext-perl
liblog-message-perl liblog-message-simple-perl liblzma5 libmodule-build-perl libmodule-pluggable-perl libmodule-signature-perl libmount1 libmro-compat-perl libncurses5 libnettle4 libp11-kit0 libpackage-constants-perl libpam-modules
libpam-modules-bin libpam0g libparams-util-perl libpcre3 libpng12-0 libpod-latex-perl libpod-readme-perl libreadline6 libregexp-common-perl librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libselinux1 libsemanage-common
libsemanage1 libsepol1 libslang2 libsmartcols1 libsoftware-license-perl libss2 libssh2-1 libssl1.0.0 libstdc++6 libsub-exporter-perl libsub-install-perl libsystemd0 libtasn1-6 libterm-ui-perl libtext-charwidth-perl libtext-iconv-perl
libtext-soundex-perl libtext-template-perl libtext-wrapi18n-perl libtinfo5 libusb-0.1-4 libustr-1.0-1 libuuid1 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxi6 libxrender1 libxtables10 libxtst6 lsb-base makedev netbase
openssl passwd perl perl-base perl-modules psmisc raspbian-archive-keyring readline-common rename sensible-utils startpar sysv-rc sysvinit-utils tar tzdata util-linux uuid-runtime x11-common zlib1g
The following packages will be upgraded:
redis-server redis-tools
2 upgraded, 153 newly installed, 0 to remove and 3 not upgraded.
11 not fully installed or removed.
Need to get 37.1 MB of archives.
After this operation, 120 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://archive.raspberrypi.org/debian/ jessie/main libasound2-data all 1.0.28-1+rpi3 [65.3 kB]
Get:2 http://archive.raspberrypi.org/debian/ jessie/main libasound2 armhf 1.0.28-1+rpi3 [320 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main libgcc1 armhf 1:4.9.2-10+deb8u2 [39.5 kB]
Get:4 http://archive.raspberrypi.org/debian/ jessie/main x11-common all 1:7.7+16 [251 kB]
[...]
Get:152 http://mirrordirector.raspbian.org/raspbian/ jessie/main libterm-ui-perl all 0.42-1 [19.1 kB]
Get:153 http://mirrordirector.raspbian.org/raspbian/ jessie/main libtext-soundex-perl armhf 3.4-1+b2 [13.3 kB]
Get:154 http://mirrordirector.raspbian.org/raspbian/ jessie/main psmisc armhf 22.21-2 [117 kB]
Get:155 http://mirrordirector.raspbian.org/raspbian/ jessie/main rename all 0.20-3 [12.4 kB]
Fetched 37.1 MB in 2min 29s (249 kB/s)
Reading changelogs... Done
E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 19%E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 38%E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 58%E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 77%E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 96%E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 100%
dpkg: regarding .../libgcc1_1%3a4.9.2-10+deb8u2_armhf.deb containing libgcc1:armhf, pre-dependency problem:
libgcc1 pre-depends on multiarch-support
multiarch-support is unpacked, but has never been configured.
dpkg: error processing archive /var/cache/apt/archives/libgcc1_1%3a4.9.2-10+deb8u2_armhf.deb (--unpack):
pre-dependency problem - not installing libgcc1:armhf
Errors were encountered while processing:
/var/cache/apt/archives/libgcc1_1%3a4.9.2-10+deb8u2_armhf.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
这是mariadb-server已安装的证明(错误是由于删除了/var,所以我想重新安装它):
root# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111 "Connection refused")
如您所见,两者都会在目录中丢失内容apt
并mariadb-server
抛出错误。/var
所以我进入了一个循环,我不知道如何继续解决这个问题。
我将参考以下文章和Debian Wiki 帖子来回答我的问题。
首先,在一个正常工作的 Raspbian 系统上,创建一个
debootstrap
环境。按照Debian Wiki的说明,您只需完成以下操作:现在,您正在使用 Raspbian,因此您可能需要添加正确的 gpg-key,如此处所指出的,并参考 Raspbian Deb Mirror。像这样的东西:
http://archive.raspbian.org/raspbian
。我将包含一个跨平台构建指南的链接,以说明您在 amd64 系统而不是 Raspberry Pi 上执行此操作。接下来,在损坏的系统上获取所有已安装程序的列表。最初我建议使用
dpkg --get-selections
,但是正如用户 AB 指出的那样,这将失败。dpkg
引用各种/var
目录来工作,如果您/var
丢失,这当然会失败。用户 AB 指出,您可以参考/usr/share/doc/
相关符号链接的内容。我会先看看有什么可用的,然后尝试installed.txt
用你的结果构建一个。将此结果
installed.txt
与您的预期进行比较。另一个要检查的地方是/usr/share/man
. 这个目录有手册页,但只对安装手册页的包是准确的。如果您有一个已知的工作 Raspberry Pi 也可以与之比较,并且它的配置与损坏的 Raspberry Pi 相同installed.txt
,您可以使用该 Raspberry Pi 的输出进行构建dpkg --get-selections
。installed.txt
从丢失的主机复制/var
到修复/var
主机。scp
或rysnc
将在这里工作,但此时您确实需要确认您ssh
在损坏的主机和进行修复的主机之间有一个工作配置。如果这两个主机之间没有有效的ssh
配置,您将无法复制/var
. 在继续之前,任何ssh
问题都需要解决。现在,将这个文件移动到
/deboostrap
环境中,并准备在这个 chroot 中安装所有相同的软件。如果需要,请确保您的
sources.list
匹配。debootstrap
默认情况下仅包括main
.如果你无法建立一个好的
installed.txt
您可能需要简单地在
debootstrap
chroot 中手动安装所有必需的软件包。这就是良好的设置文档或基础设施代码派上用场的地方。在 chroot 中运行apt install package1 package2 package3 ... packageN
以构建/var
尽可能接近原始的/var
.dselect
您应该按照以下步骤操作,而不是安装:此时,您的
debootstrap
环境应该与您的目标(损坏的主机)相匹配。这是您需要用来rsync
复制/var
的地方。rsync -A
应该足够了。正如我在链接中指出的那样,您可能需要允许PermitRootLogin without-password
您的sshd_config
forrsync
工作。我还将直接引用 Alephnull.uk 的 Pete Donnell 必须运行的最后步骤和注意事项:
debootstrap
如果您有幸拥有第二台工作主机,我强烈建议您花时间比较环境和损坏的主机。您要确认所有权限均正确且服务运行正常。只有在您完成此操作后,我才会重新启动主机并确认一切都恢复了。在尝试任何命令之前,请仔细阅读我提供的每个链接。如果我的帖子有任何错误、误解或问题,请告诉我,我会努力纠正它们。
祝你好运!