どうやら実稼働サーバー上で何らかの問題が発生し、誰かが/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
。そのため、この問題を解決するためにどう進めたらよいか分からないループに陥ってしまいました。
答え1
以下を参考にします記事そしてDebian Wiki の投稿私の答えは。
まず、Raspbianシステム上でdebootstrap
環境を作成します。Debian ウィキ以下の手順を完了するだけで済みます。
mkdir /debootstrap
debootstrap stable /debootstrap http://deb.debian.org/debian/
Raspbianを使用しているので、正しいgpgキーを追加する必要があるかもしれません。ここで指摘されているように、そしてRaspbian Debミラーを参照します。次のようになりますhttp://archive.raspbian.org/raspbian
。リンクRaspberry Pi ではなく amd64 システムでこれを実行する場合は、クロスプラットフォーム ビルド ガイドを参照してください。
grub
重要な注意: プロンプトが表示された場合は、 MBR にインストールしないでください。既存のインストールが壊れる可能性があります。
次に、壊れたシステムで、インストールされているすべてのプログラムのリストを取得します。 最初は を使用することを提案しましたdpkg --get-selections
が、ユーザー AB が指摘したように、これは失敗します。 は動作するためにdpkg
さまざまな/var
ディレクトリを参照しますが、 が/var
欠落しているため、これは当然失敗します。 ユーザー AB は、 および関連するシンボリック リンクの内容を参照できることを指摘しています/usr/share/doc/
。まず、何が利用可能かを確認し、installed.txt
その結果を使用して を構築してみます。
cd /usr/share/doc && for i in *; do echo $i install >> /home/user/installed.txt; done
この結果をinstalled.txt
期待したものと比較してください。 をチェックするもう 1 つの場所は です/usr/share/man
。このディレクトリには manpages がありますが、manpages をインストールするパッケージに対してのみ正確です。比較対象として動作することがわかっている Raspberry Pi がある場合は、壊れたRaspberry Piと同じ構成ですinstalled.txt
、 Raspberry Pi の出力を使用してビルドできますdpkg --get-selections
。
installed.txt
欠落した/var
ホストから修復ホストにコピーします/var
。scp
または はrysnc
ここでは機能しますが、この時点では、ssh
破損したホストと修復を行っているホスト間の構成が機能していることを確認する必要があります。ssh
これら 2 つのホスト間で構成が機能していないと、 をコピーすることはできません/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 ... packageN
chroot で実行して、/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
。すべてのサービスを有効にする必要はありません。ここでも、動作中のサーバーと比較することをお勧めします。現在実行されていないが実行する必要があるサービスを再起動してみてください。すべての権限が正しく、関連するユーザー データ (ある場合) が復元されていれば、サービスは正常に起動するはずです。そうでない場合は、 で systemd のステータスystemctl status <service-name>
、 で systemd のログjournalctl -xe
、 でサービスのログ ファイルをチェックします/var/log
。これらにより、残っている問題を追跡するのに十分な情報が得られるはずです。
幸運にも 2 つ目のホストが動作している場合は、環境と壊れたホストを比較することに時間をかけることを強くお勧めしますdebootstrap
。すべての権限が正しく、サービスが適切に実行されていることを確認する必要があります。これを実行した後でのみ、ホストを再起動してすべてが元に戻ったことを確認します。
コマンドを試す前に、私が提供したすべてのリンクをよくお読みください。私の投稿に間違い、誤解、問題がある場合はお知らせください。修正に努めます。
幸運を祈ります!