/var 콘텐츠가 제거되거나 손상된 Raspbian의 apt 문제

/var 콘텐츠가 제거되거나 손상된 Raspbian의 apt 문제

프로덕션 서버에 문제가 발생하여 누군가 /var폴더 내용을 삭제한 것 같습니다.

이로 인해 웹 서버와 같은 다양한 서비스를 사용하여 해결해온 몇 가지 오류가 발생했습니다.

내가 겪고 있는 문제 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. 그래서 이 문제를 해결하기 위해 진행하는 방법을 모르는 루프에 들어갔습니다.

답변1

다음을 참고하겠습니다.기사그리고데비안 위키 게시물내 대답을 위해.

먼저 작동 중인 Raspbian 시스템에서 debootstrap환경을 만듭니다. 의 지시에 따라데비안 위키다음 사항만 완료하면 됩니다.

mkdir /debootstrap
debootstrap stable /debootstrap http://deb.debian.org/debian/

이제 Raspbian을 사용하고 있으므로 올바른 gpg-key를 추가해야 할 수도 있습니다.여기서 지적한 대로, Raspbian Deb Mirror를 참조하세요. 이 같은: http://archive.raspbian.org/raspbian. 나는 포함할 예정이다링크Raspberry Pi 대신 amd64 시스템에서 이 작업을 수행하는 경우 크로스 플랫폼 빌드 가이드를 참조하세요.

중요 참고 사항: 메시지가 표시되면 grubMBR에 설치하지 마십시오! 이로 인해 기존 설치가 중단될 수 있습니다!

다음으로, 손상된 시스템에서 설치된 모든 프로그램 목록을 가져옵니다. 처음에는 사용을 제안했지만 dpkg --get-selections사용자 AB가 지적했듯이 이것이 실패할 것입니다. 작업을 위해 dpkg다양한 디렉토리를 참조하며 누락되면 당연히 실패합니다. 사용자 AB는 해당 심볼릭 링크의 내용 과 관련 심볼릭 링크를 참조할 수 있음을 지적합니다. 나는 사용 가능한 것이 무엇인지 확인하고 결과를 바탕으로 구축해 보겠습니다 ./var/var/usr/share/doc/installed.txt

cd /usr/share/doc && for i in *; do echo $i install >> /home/user/installed.txt; done

이 결과를 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 내에 동일한 소프트웨어를 모두 설치할 준비를 합니다.

cp installed.txt /debootstrap/
chroot /bootstrap/
mount -t proc none /proc
dpkg --set-selections < installed.txt

필요한 경우 sources.list일치하는지 확인하세요. debootstrap기본적으로 main.

apt update
apt install dselect
dselect update
apt-get dselect-upgrade

좋은 건물을 짓지 못했다면installed.txt

chroot 에 필요한 모든 패키지를 수동으로 설치해야 할 수도 있습니다 debootstrap. 여기에서 좋은 설정 문서나 코드형 인프라가 유용합니다. apt install package1 package2 package3 ... packageNchroot에서 실행하여 /var원본과 최대한 일치하도록 빌드하세요 /var. 설치하는 대신 dselect다음 단계를 따라야 합니다.

chroot /bootstrap/
mount -t proc none /proc
apt update
apt install package1 package2 package3 ... packageN

이 시점에서 귀하의 debootstrap환경은 대상인 손상된 호스트의 환경과 일치해야 합니다. 여기에서 rsync복사를 사용해야 합니다 /var. rsync -A충분해야합니다. 내에서 지적했듯이링크PermitRootLogin without-password, 작동 하려면 을 sshd_config허용 해야 할 수도 있습니다 rsync.

또한 Alephnull.uk의 Pete Donnell이 실행해야 했던 마지막 단계와 고려 사항을 직접 인용하겠습니다.

mariadb-server... 깨진 서버에 패키지를 다시 설치해야 했습니다 apt-get install --reinstall mariadb-server mariadb-server-10.1 mariadb-server-core-10.1.

다음 단계는 사용자 데이터를 복원하는 것입니다. 이는 사용하는 구조에 따라 다르므로 이에 대한 지침은 드릴 수 없습니다. 그런 다음 작업 서버(또는 부트스트랩)에 /var/lib있는 파일의 권한을 확인하여 /var/log올바른지 확인하세요. 시스템 계정의 사용자 ID는 서버와 부트스트랩 환경에서 다를 가능성이 높습니다.

이제 를 사용하여 설치된 다양한 서비스를 확인해야 합니다 service --status-all. 모든 서비스를 반드시 활성화해야 하는 것은 아닙니다. 다시 한 번 작동 중인 서버와 비교하는 것이 좋습니다. 현재 실행되고 있지 않지만 실행되어야 하는 서비스를 다시 시작해 보세요. 모든 권한이 올바르고 관련 사용자 데이터(있는 경우)가 복원된 경우 서비스가 성공적으로 시작됩니다. 그렇지 않은 경우 s 로 systemd 상태를 확인하고 ystemctl status <service-name>systemd는 로 로그하며 journalctl -xe서비스의 로그 파일은 /var/log. 이를 통해 남은 문제를 추적할 수 있는 충분한 정보를 얻을 수 있습니다.

debootstrap운이 좋게 작동하는 두 번째 호스트가 있는 경우 환경과 손상된 호스트를 비교하는 데 시간을 할애하는 것이 좋습니다 . 모든 권한이 올바르고 서비스가 제대로 실행되고 있는지 확인하고 싶습니다. 이 작업을 완료한 후에만 호스트를 재부팅하고 모든 것이 다시 돌아왔는지 확인합니다.

명령을 시도하기 전에 제가 제공한 모든 링크를 자세히 읽어보시기 바랍니다. 제 글에 오류나 오해, 문제가 있는 경우 알려주시면 수정하도록 노력하겠습니다.

행운을 빌어 요!

관련 정보