勉強日記

チラ裏

LPIC あずき本v5.0 ch2 Linuxのインストールとパッケージ管理

www.shoeisha.co.jp


ハードディスクのレイアウト設計

Linuxインストールに必要なパーティション

cat /proc/swaps
Filename             Type        Size    Used    Priority
/swapfile                               file        2097148 0   -2

普通、パーティションを切って割り当てるディレクトリ群

  • 柔軟なシステム管理
  • ディスク障害時の
    • 被害の低減
    • スムーズな復旧作業
  • man 7 hierで各ディレクトリの意図するところを閲覧できる

/home

/home  On  machines   with  home directories for users,
       these  are  usually  beneath  this   directory,
       directly  or not.  The structure of this direc‐
       tory depends on local administration  decisions
       (optional).

/var

/var   This   directory contains files which may change
       in size, such as spool and log files.
  • VARiable
  • 更新頻度の高いファイル
    • ログ
    • スプール
  • ルートファイルシステムにあるとやばいのは明白
    • ログであふれたときシステム全体に影響

/usr

/usr   This directory is usually mounted from a   sepa‐
       rate partition.  It should hold only shareable,
       read-only data, so that it can  be  mounted  by
       various machines running Linux.
  • 由来は諸説ある
    • User Services and Routines
    • Unix System Routines
    • Universal System Resources
  • "It should hold only shareable, read-only data"
    • プログラム
    • ライブラリ
    • ドキュメント
  • "~, so that it can be mounted by various machines running Linux."
    • NFS: Network File Systemを使ってコマンドやプログラムを共有することが想定されている
    • 読み込み専用でマウントする

/boot

/boot  Contains   static  files  for  the  boot loader.
       This directory holds only the files  which  are
       needed  during  the  boot process.  The map in‐
       staller and configuration files  should  go  to
       /sbin  and  /etc.   The operating system kernel
       (initrd for example) must be located in  either
       / or /boot.
  • ディスクの先頭数100MB程度を割り当てたほうがよいこともある
    • RAID使用時、内蔵ハードディスク内に/bootを掘る

スワップ領域

  • 仮想メモリ領域
  • cat /proc/swapsによると
    • 今使っているマシンでは/swapfileという名前のよう
    • 2GB
      • 搭載メモリの1-2倍くらいが目安とされる
      • cat /proc/meminfoしたら8GB搭載されてたんだが

/

パーティションのレイアウト設計

  • 勘案事項
    • システムの用途
      • 何人で使う
      • なんのサーバ
    • ディスクの容量
    • バックアップの方法

20GBのハードディスク、512MBメモリ

  • 分け方
  • 分けるほどないよ、ってことかな

200GBのハードディスク、1GBメモリ、ユーザー100人のファイルサーバー

  • 分け方
    • スワップ: 1GB
    • /boot: 100MB
    • /usr: 10GB
    • /var: 10GB
    • /: 1GB
    • /home: 残り(役180GB)
  • 考えること
    • スワップ: 物理メモリと同程度
    • /boot: 先頭数100MB程度
    • /: なるべく小さく
    • /home: ユーザー数の多いファイルサーバーなので一番多く

100GBのハードディスク、4GBのメモリ、Webサーバー(Apache)

  • 分け方
    • スワップ: 4GB
    • /boot: 100MB
    • /usr: 10GB
    • /var: 20GB
    • /var/log: 50GB
    • /: 15GB
  • 考えること
    • スワップ: 物理メモリと同程度
    • /boot: 先頭数百MB
    • /var/log: ログファイルが容量かなり食うので多くとる

COLUMN -- LVM: Logical Volume Manager(論理ボリューム管理)

  • 物理ボリュームを束ねて仮想ディスクをつくる
    • ボリュームグループ
  • ボリュームグループ上に仮想的なパーティションを切る
    • 論理ボリューム

ESP: EFI System Partition

ブートローダのインストール

  • (広義の)BIOSから呼び出され、カーネルを呼び出す人
  • GRUB: GRand Unified Bootloader が代表的
  • 古いのと新しいのがある
    • 設定ファイルの設定法が異なる
    • パーティションの数え方が異なる
      • (hd<ディスク番号>,<パーティション番号>)
GRUB Legacy GRUB 2
version 0.9x 1.9x
ディスク番号 0から 0から
パーティション番号 0から 1から

GRUBのインストール

sudo grub-install /dev/sda
Installing for x86_64-efi platform.
Installation finished. No error reported.
grub-install -V
# または
# grub-install --version
grub-install (GRUB) 2.02-2ubuntu8.12
  • GRUB2ですね

GRUB Legacyの設定

  • /boot/grub/menu.lstまたは/boot/grub/grub.confで設定
    • 手元のubuntuはGRUB2なので、なかった
  • (hd0,0)とか出てくる
    • 両方0始まり
    • /dev/sda1に相当
      • aが0, 1が0に対応
    • /boot/grub/device.mapで対応表を閲覧できるらしい

GRUB 2の設定

cat /boot/grub/grub.cfg
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  • 「触るな」
  • 自動生成する
    1. /etc/default/grub触る
    2. grub2-mkconfigまたはgrub-mkconfig叩く
      • update-grubというのも
  • /etc/default/grub
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
  • 生成
sudo grub-mkconfig -o /boot/grub/grub.cfg 
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Linux イメージを見つけました: /boot/vmlinuz-4.15.0-45-generic
Found initrd image: /boot/initrd.img-4.15.0-45-generic
Linux イメージを見つけました: /boot/vmlinuz-4.13.0-46-generic
Found initrd image: /boot/initrd.img-4.13.0-46-generic
Adding boot menu entry for EFI firmware configuration
完了

ブートオプションの設定

  • カーネルパラメータとか別名いっぱい
  • GRUBのブートオプションの起動の仕方がわからず、試せなかった
  • 書籍的にはE押下
  • シングルユーザーモードで起動したければこう
grub append> ro root=/dev/VolGroup00/LoVol00 rhgb quiet single
  • 起動時に指定されたカーネルパラメータ見る
cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-4.15.0-45-generic root=UUID=bbddb2bb-7fde-4777-88b4-d762aadc173d ro quiet splash vt.handoff=1
  • root=デバイス名(/dev/hda1とか)
  • init=プログラム
    • initの代わりに実行するやつ
  • quiet
    • メッセージ出力抑制
  • debug
    • メッセージ出力を冗長に
  • vt.handoff=値
    • 仮想ターミナルを指定した値に切り替える
  • s, single
  • splash
    • スプラッシュ画面を表示する
  • text
    • テキストモードで起動する
  • 数字(1-5)
  • nousb

共有ライブラリ管理

  • ライブラリ
    • よく使われる機能をまとめ、再利用できるようにするやつ
  • 分類
    • 静的ライブラリ
      • static linkするやつ
    • 共有ライブラリ

スタティックリンクとダイナミックリンク

  • C言語などでは、演算・制御等の基本機能以外はライブラリを使う
  • リンク: プログラム本体からライブラリを利用できるようにすること
    • スタティックリンク
      • コンパイル時に実行ファイルに埋め込むやつ
      • 呼び出されるやつ: 静的ライブラリ
    • ダイナミックリンク
      • 埋め込んでおかず、実行時に呼び出すやつ
      • 呼び出されるやつ: 共有ライブラリ
      • lib~.so~という感じの名前
        • so: Shared Object file
        • libreadline.so.5とか
        • /lib,/usr/libとかにある
tree -L 1 /usr/lib | grep so
tree -L 1 /usr/lib | grep so
├── libau.so -> libau.so.2
├── libau.so.2 -> libau.so.2.10
├── libau.so.2.10
├── libgjs.so.0 -> libgjs.so.0.0.0
├── libgjs.so.0.0.0
├── libkeybinder.so.0 -> libkeybinder.so.0.1.0
...

必要な共有ライブラリの確認

  • lddコマンドで調べられる
    • list dynamic dependencies の意味かな
  • ldd自身は共有ライブラリを使っていない模様
ldd /usr/bin/ldd
 動的実行ファイルではありません
  • catechoは同じものを使ってるみたい
/bin/cat:
    linux-vdso.so.1 (0x00007ffc209f0000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f64ec777000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f64ecd71000)
/bin/echo:
    linux-vdso.so.1 (0x00007ffdb83be000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc3af11e000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fc3af718000)
  • ld.soリンカが動的リンクしている
  • *.soを探す場所は/etc/ld.so.confで定義されている
  • /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf
tree /etc/ld.so.conf.d/
/etc/ld.so.conf.d/
├── fakeroot-x86_64-linux-gnu.conf
├── libc.conf
└── x86_64-linux-gnu.conf
  • 上記ファイル群の中身は...
cd /etc/ld.so.conf.d/
cat $(ls /etc/ld.so.conf.d/ | grep .conf)
/usr/lib/x86_64-linux-gnu/libfakeroot
# libc default configuration
/usr/local/lib
# Multiarch support
/usr/local/lib/x86_64-linux-gnu
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu
  • 追加したい場合は*.confファイルを増やす
  • プログラムを実行するたびに上記ファイルを読んで*.soを検索している?...否
  • バイナリのld.so.cacheが参照される
  • ldconfig ... ld.so.cacheの更新
sudo ldconfig
  • 環境変数LD_LIBRARY_PATH
    • 他のディレクトリも検索対象にしたいときに追加する
    • ld.so.confを書き足したりld.so.conf.d*.confを追加するよりも検索の優先度高
echo ${LD_LIBRARY_PATH}
  • 設定されてなかった



  • 設定するときはこんなかんじ
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/student/mylib
  • 優先度
    1. LD_LIBRARY_PATH
    2. /etc/ld.so.cache
    3. デフォルトのパス
      • /lib
      • /usr/lib

Debianパッケージの管理

パッケージ管理とは

  • パッケージのインストール・アンインストール・アップデート作業が容易に
    • パッケージがどこにインストールされているか管理
    • パッケージの依存関係や競合関係を損なうインストールやアンインストールに警告を発する
      • パッケージの依存関係
        • パッケージAのファイルをパッケージBが使用する
      • パッケージ間の競合関係
        • パッケージCによってインストールされるファイルDが
          パッケージAですでにインストールされているファイルDと競合する
  • パッケージ管理形式
Debian形式(deb形式) RPM形式
ディストリ Debian Red Hat
パッケージ管理作業 ・dpkgコマンド
・APTツール
rpmコマンド
YUMツール

dpkgコマンドを用いたパッケージ管理

パッケージファイル名

tree_1.6.0-1_i386.deb

コンフィグファイル/etc/dpkg/dpkg.cfg

  • /etc/dpkg/dpkg.cfg
# dpkg configuration file
#
# This file can contain default options for dpkg.  All command-line
# options are allowed.  Values can be specified by putting them after
# the option, separated by whitespace and/or an `=' sign.
#

# Do not enable debsig-verify by default; since the distribution is not using
# embedded signatures, debsig-verify would reject all packages.
no-debsig

# Log status changes and actions to a file.
log /var/log/dpkg.log

dpkgコマンド

dpkg --help
使い方: dpkg [<オプション> ...] <コマンド>

...

ユーザ向けパッケージ管理ツールである `apt' または `aptitude' を使いましょう。 
  • オプションアクションがある

主要なオプション

  -E|--skip-same-version     同バージョンがインストール済みのパッケージをスキップする
  -G|--refuse-downgrade      インストール済みパッケージより古いバージョンのパッケージをスキップする
  -i|--install       <.deb file name> ... | -R|--recursive <directory> ...
  --unpack           <.deb file name> ... | -R|--recursive <directory> ...
  -A|--record-avail  <.deb file name> ... | -R|--recursive <directory> ...

主要なアクション

-i, --install
  -i|--install       <.deb file name> ... | -R|--recursive <directory> ...
  • パッケージをインストールする
-r, --remove
  -r|--remove        <package> ... | -a|--pending
  • パッケージをアンインストールする
  • 設定ファイルは残す
  • uninstallとは言わない
-P, --purge
  -P|--purge         <package> ... | -a|--pending
  • パッケージを完全にアンインストールする
  • 設定ファイルも消す
-l, --list
  -l|--list [<pattern> ...]        List packages concisely.
  • インストール済パッケージを検索して表示する
  -S|--search <pattern> ...        Find package(s) owning file(s).
  • 指定したファイルがどのパッケージからインストールされたかを表示する
  • <pattern>にはワイルドカード使用可
-L, --listfiles
  -L|--listfiles <package> ...     List files 'owned' by package(s).
  • 指定パッケージからインストールされたファイルを一覧表示する
-s, --status
  -s|--status <package> ...        Display package status details.
  • パッケージの詳細を表示する
--configure
  --configure        <package> ... | -a|--pending
  • 展開されたパッケージを構成する
--unpack
  --unpack           <.deb file name> ... | -R|--recursive <directory> ...
  • パッケージを展開する
  • インストールはしない
-C, --audit
  -C|--audit [<package> ...]       Check for broken package(s).
  • 壊れたもの=インストールが中断されたもの探す

つかってみる

  • インストール
    • debファイルは自分で探してくる
wget http://archive.ubuntu.com/ubuntu/pool/main/a/apache2/apache2_2.4.29-1ubuntu4.5_amd64.deb

sudo dpkg --install apache2_2.4.29-1ubuntu4.5_amd64.deb
(データベースを読み込んでいます ... 現在 177642 個のファイルとディレクトリがインストールされています。)
apache2_2.4.29-1ubuntu4.5_amd64.deb を展開する準備をしています ...
apache2 (2.4.29-1ubuntu4.5) で (2.4.29-1ubuntu4.5 に) 上書き展開しています ...
dpkg: 依存関係の問題により apache2 の設定ができません:
 apache2 は以下に依存 (depends) します: apache2-utils (= 2.4.29-1ubuntu4.5) ...しかし:
  パッケージ apache2-utils はまだインストールされていません。
 apache2 は以下に依存 (depends) します: apache2-data (= 2.4.29-1ubuntu4.5) ...しかし:
  パッケージ apache2-data はまだインストールされていません。

dpkg: パッケージ apache2 の処理中にエラーが発生しました (--install):
 依存関係の問題 - 設定を見送ります
systemd (237-3ubuntu10.13) のトリガを処理しています ...
ureadahead (0.100.0-20) のトリガを処理しています ...
ufw (0.35-5) のトリガを処理しています ...
man-db (2.8.3-2ubuntu0.1) のトリガを処理しています ...
処理中にエラーが発生しました:
 apache2
  • 依存関係を満足できなかった
  • 大変そうなのでapt-getで入れた
  • インストール済パッケージの検索・表示
dpkg -l apache2*
||/ 名前           バージョン   アーキテクチ 説明
+++-==============-============-============-=================================
ii  apache2        2.4.29-1ubun amd64        Apache HTTP Server
un  apache2-api-20 <なし>       <なし>       (説明 (description) がありません)
un  apache2-api-20 <なし>       <なし>       (説明 (description) がありません)
ii  apache2-bin    2.4.29-1ubun amd64        Apache HTTP Server (modules and o
ii  apache2-data   2.4.29-1ubun all          Apache HTTP Server (common files)
un  apache2-doc    <なし>       <なし>       (説明 (description) がありません)
un  apache2-suexec <なし>       <なし>       (説明 (description) がありません)
un  apache2-suexec <なし>       <なし>       (説明 (description) がありません)
ii  apache2-utils  2.4.29-1ubun amd64        Apache HTTP Server (utility progr
un  apache2.2-bin  <なし>       <なし>       (説明 (description) がありません)
un  apache2.2-comm <なし>       <なし>       (説明 (description) がありません)
  • あらゆる場所のapache2ファイルがどのパッケージからインストールされたか表示
dpkg -S '*/apache2'
apache2, apache2-bin: /var/lib/apache2
apache2, libapache2-mod-dnssd, javascript-common: /etc/apache2
apache2, apache2-data: /usr/share/apache2
apache2: /etc/logrotate.d/apache2
apache2: /var/log/apache2
apache2: /usr/share/bug/apache2
apache2-bin: /usr/sbin/apache2
apache2: /etc/cron.daily/apache2
apache2: /usr/share/doc/apache2
libapache2-mod-dnssd, apache2-bin: /usr/lib/apache2
apache2: /etc/ufw/applications.d/apache2
apache2: /var/cache/apache2
apache2: /usr/share/lintian/overrides/apache2
apache2: /etc/init.d/apache2
  • apache2パッケージからインストールされたファイルを表示
  • ムチャクチャ多いので10個数だけ
dpkg -L apache2 | head -n 10
/.
/etc
/etc/apache2
/etc/apache2/apache2.conf
/etc/apache2/conf-available
/etc/apache2/conf-available/charset.conf
/etc/apache2/conf-available/localized-error-pages.conf
/etc/apache2/conf-available/other-vhosts-access-log.conf
/etc/apache2/conf-available/security.conf
/etc/apache2/conf-available/serve-cgi-bin.conf
  • パッケージの詳細情報表示
dpkg -s apache2
Package: apache2
Status: install ok installed
Priority: optional
Section: httpd
Installed-Size: 521
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Version: 2.4.29-1ubuntu4.5
Replaces: apache2.2-bin, apache2.2-common
Provides: httpd, httpd-cgi
Depends: lsb-base, procps, perl, mime-support, apache2-bin (= 2.4.29-1ubuntu4.5), apache2-utils (= 2.4.29-1ubuntu4.5), apache2-data (= 2.4.29-1ubuntu4.5), perl:any
Pre-Depends: dpkg (>= 1.17.14)
Recommends: ssl-cert
Suggests: www-browser, apache2-doc, apache2-suexec-pristine | apache2-suexec-custom, ufw
Conflicts: apache2.2-bin, apache2.2-common
Conffiles:
...
  • 展開されたパッケージの構成
sudo dpkg --configure apache2
  • 済んでいるのでエラー
dpkg: パッケージ apache2 の処理中にエラーが発生しました (--configure):
 パッケージ apache2 はすでにインストールおよび設定されています
処理中にエラーが発生しました:
 apache2
  • apache2パッケージ削除
sudo dpkg --remove apache2
  • 設定は削除されない
(データベースを読み込んでいます ... 現在 198646 個のファイルとディレクトリがインストールされています。)
apache2 (2.4.29-1ubuntu4.5) を削除しています ...
man-db (2.8.3-2ubuntu0.1) のトリガを処理しています ...
ufw (0.35-5) のトリガを処理しています ...
  • 設定含め完全削除
sudo dpkg --purge apache2
(データベースを読み込んでいます ... 現在 198594 個のファイルとディレクトリがインストールされています。)
apache2 (2.4.29-1ubuntu4.5) の設定ファイルを削除しています ...
systemd (237-3ubuntu10.13) のトリガを処理しています ...
ureadahead (0.100.0-20) のトリガを処理しています ...
ufw (0.35-5) のトリガを処理しています ...

dpkg-reconfigure

  • 既にインストールされたdebパッケージの状態を再設定
    • 設定の初期化
    • --force: 壊れているやつを強制再設定

apt-getコマンド

  • APT: Advanced Packaging Tool
  • apt-getコマンド
    • インターネット経由で最新パッケージ取得してくれる
      • 自分で*.debwgetとかしなくていい
    • 依存解決までできる
      • dpkgでapache2を入れようとしたら依存関係を満足できておらず中断された
  • どこからパッケージ取ってくるの
    • /etc/apt/sources.list
    • /etc/apt/sources.list.d/*
...
deb http://security.ubuntu.com/ubuntu bionic-security main restricted
# deb-src http://security.ubuntu.com/ubuntu artful-security main restricted
deb http://security.ubuntu.com/ubuntu bionic-security universe
# deb-src http://security.ubuntu.com/ubuntu artful-security universe
deb http://security.ubuntu.com/ubuntu bionic-security multiverse
# deb-src http://security.ubuntu.com/ubuntu artful-security multiverse
  • deb
    • パッケージを取得
    • deb-srcの場合、ソースを取得
  • bionic-security, artful-security
    • バージョン
  • main restricted, universe, multiverse
    • main
      • 公式サポート
    • restricted
    • universe
      • コミュニティによってメンテナンスされるソフトウェア
    • multiverse
      • 著作権もしくは法的な問題によって制限されたソフトウェア
    • non-free
      • 利用と改変再配布に制限のあるソフトウェア
    • contrib
      • 依存にnon-freeがいる

【補】aptのリポジトリ登録

  • add-apt-repositoryコマンドでできる
  • docker-ceを入れたいときの例
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) \
  stable"
  • lsb_release -csbionicとかを返す
  -c, --codename     show code name of this distribution
  -s, --short        show requested information in short format
  • 実行結果
  • /etc/apt/sources.list
  deb http://security.ubuntu.com/ubuntu bionic-security multiverse
  # deb-src http://security.ubuntu.com/ubuntu artful-security multiverse
+ deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
+ # deb-src [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable

主なオプション

  • -c, --config-file
    • 設定ファイル指定
    • デフォルト/etc/apt/sources.list

      デフォルト設定ファイルを読んでから、この設定ファイルを読みます。

  • -y, --yes, --assume-yes
    • 全部yes、非対話的に実行
  • -d, --download-only
    • installとともに
    • ダウンロードのみ
  • -s, --simulate
    • システムを変更せず動作をシミュレートする
  • no-install-reommends
    • 必須でない「推奨」パッケージをインストールしない
  • install-suggests
    • 「提案」バッケージをインストールする
  • --reinstall
    • すでに最新版がインストールされていても再インストール

主なサブコマンド

clean

       clean
           clean は、取得したパッケージのローカルリポジトリを掃除しま
           す。/var/cache/apt/archives/ と
           /var/cache/apt/archives/partial/ からロックファイル以外すべ
           て削除します。
ls /var/cache/apt/archives/
firefox-locale-en_66.0.3+build1-0ubuntu0.18.04.1_amd64.deb
firefox-locale-ja_66.0.3+build1-0ubuntu0.18.04.1_amd64.deb
firefox_66.0.3+build1-0ubuntu0.18.04.1_amd64.deb
sudo apt-get clean
  • lockファイル以外消えた
lock  partial

dist-upgrade

  dist-upgrade - ディストリビューションをアップグレードする (apt-get(8) を参照)
sudo apt-get dist-upgrade
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています       
状態情報を読み取っています... 完了
アップグレードパッケージを検出しています... 完了
アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 0 個。

install

  install - 新規パッケージをインストールする (pkg は libc6.deb ではなく libc6 のように指定する)
  • パッケージをインストールまたはアップグレードする
sudo apt-get install apache2

remove

       remove
           remove は、パッケージが削除されることを除き、install と同様
           です。削除されたパッケージの設定ファイルは、システムに残った
           ままになることに注意してください。プラス記号がパッケージ名に
           (間に空白を含まずに) 付加されると、識別されたパッケージ
           を、削除ではなくインストールします。
  • 設定は消さない
sudo apt-get remove apache2

purge

       purge
           パッケージが削除かつ完全削除 (すべての設定ファイルも削除) さ
           れるのを除き、purge は remove と同じです。
  • apt-get remove --purgeとおなじ
sudo apt-get purge apache2
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています       
状態情報を読み取っています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  apache2-data apache2-utils
これを削除するには 'sudo apt autoremove' を利用してください。
以下のパッケージは「削除」されます:
  apache2*
アップグレード: 0 個、新規インストール: 0 個、削除: 1 個、保留: 0 個。
この操作後に追加で 0 B のディスク容量が消費されます。
続行しますか? [Y/n] y
(データベースを読み込んでいます ... 現在 177909 個のファイルとディレクトリがインストールされています。)
apache2 (2.4.29-1ubuntu4.5) の設定ファイルを削除しています ...
ufw (0.35-5) のトリガを処理しています ...
ureadahead (0.100.0-20) のトリガを処理しています ...
systemd (237-3ubuntu10.13) のトリガを処理しています ...

update

       update (apt-get(8))
           update は、設定されたすべての取得元からパッケージ情報をダウ
           ンロードするために使用されます。ほかのコマンドは、このデータ
           を操作します。例えば、パッケージのアップグレードを実行した
           り、中を検索したり、インストール可能なすべてのパッケージに関
           する詳細情報を表示します。
sudo apt-get update
...
取得:22 http://security.ubuntu.com/ubuntu bionic-security/universe DEP-11 48x48 Icons [12.2 kB]
取得:23 http://security.ubuntu.com/ubuntu bionic-security/universe DEP-11 64x64 Icons [50.4 kB]
取得:24 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 DEP-11 Metadata [2,464 B]
取得:25 http://security.ubuntu.com/ubuntu bionic-security/multiverse DEP-11 48x48 Icons [29 B]
4,802 kB を 2秒 で取得しました (2,021 kB/s)
パッケージリストを読み込んでいます... 完了

upgrade

       upgrade (apt-get(8))
           upgrade は、sources.list(5) で設定された取得元からシステムに
           現在インストール済みのすべてのパッケージで利用可能なアップグ
           レードをインストールするために使用されます。依存関係を満たす
           ために必要な場合は新しいパッケージがインストールされます
           が、既存のパッケージが削除されることはありません。パッケージ
           のアップグレードにインストール済みパッケージの削除が必要な場
           合、そのパッケージのアップグレードは行われません。
sudo apt-get upgrade

full-upgrade

  • システムのメジャーバージョンを最新にアップグレードする
  • dist-upgradeと同じっぽい気がする

autoremove

       autoremove (および auto-remove 1.1 以降の別名)
           autoremove は、他のパッケージの依存関係を満たすために自動的
           にインストールされ、もう必要なくなったパッケージを削除するの
           に使用します。

apt-cacheコマンド

apt-cache --help
apt-cache はインストール済みとインストール可能なパッケージの情報を
問い合わせて表示します。例えば apt-get の「更新」コマンドによって
ローカルキャッシュに取得されたデータと排他的に動作します。したがって、
最後の更新が古すぎる場合には、表示される情報は時代遅れかもしれません。
しかし、引き換えに、apt-cache は設定されたソースの可用性とは独立して
動作します (例えばオフライン)。
  • パッケージ情報を照会・検索
    • 未インストールでもいい

主なサブコマンド

  search - 正規表現パターンによってパッケージ一覧を検索する
apt-cache search apache2 | head -n 5
apache2 - Apache HTTP サーバ
apache2-bin - Apache HTTP Server (modules and other binary files)
apache2-data - Apache HTTP Server (common files)
apache2-dbg - Apache debugging symbols
apache2-dev - Apache HTTP Server (development headers)

show

  show - パッケージの情報を表示する
  • 一般的な情報を表示
apt-cache show apache2 | head -n 20
Package: apache2
Architecture: amd64
Version: 2.4.29-1ubuntu4.5
Priority: optional
Section: web
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Apache Maintainers <debian-apache@lists.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 521
Provides: httpd, httpd-cgi
Pre-Depends: dpkg (>= 1.17.14)
Depends: lsb-base, procps, perl, mime-support, apache2-bin (= 2.4.29-1ubuntu4.5), apache2-utils (= 2.4.29-1ubuntu4.5), apache2-data (= 2.4.29-1ubuntu4.5), perl:any
Recommends: ssl-cert
Suggests: www-browser, apache2-doc, apache2-suexec-pristine | apache2-suexec-custom, ufw
Conflicts: apache2.2-bin, apache2.2-common
Replaces: apache2.2-bin, apache2.2-common
Filename: pool/main/a/apache2/apache2_2.4.29-1ubuntu4.5_amd64.deb
Size: 95088
MD5sum: b736ff3435904190fc43ee7d676f97ae

showpkg

  • 詳細な情報を得る
apt-cache showpkg apache2
Package: apache2
Versions: 
2.4.29-1ubuntu4.5 (/var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_bionic-updates_main_binary-amd64_Packages)
 Description Language: 
                 File: /var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_bionic_main_binary-amd64_Packages
                  MD5: d02426bc360345e5acd45367716dc35c
 Description Language: 
                 File: /var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_bionic_main_binary-i386_Packages
                  MD5: d02426bc360345e5acd45367716dc35c
 Description Language: ja
                 File: /var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_bionic_main_i18n_Translation-ja
                  MD5: d02426bc360345e5acd45367716dc35c
 Description Language: en
                 File: /var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_bionic_main_i18n_Translation-en
                  MD5: d02426bc360345e5acd45367716dc35c
 Description Language: 
                 File: /var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_bionic-updates_main_binary-amd64_Packages
                  MD5: d02426bc360345e5acd45367716dc35c
 Description Language: 
                 File: /var/lib/apt/lists/jp.archive.ubuntu.com_ubuntu_dists_bionic-updates_main_binary-i386_Packages
                  MD5: d02426bc360345e5acd45367716dc35c
 Description Language: 
                 File: /var/lib/apt/lists/security.ubuntu.com_ubuntu_dists_bionic-security_main_binary-amd64_Packages
                  MD5: d02426bc360345e5acd45367716dc35c
 Description Language: 
                 File: /var/lib/apt/lists/security.ubuntu.com_ubuntu_dists_bionic-security_main_binary-i386_Packages
                  MD5: d02426bc360345e5acd45367716dc35c

...

depends

  depends - パッケージの生の依存情報を表示する
apt-cache depends apache2
apache2
  先行依存: dpkg
    dpkg:i386
  依存: lsb-base
  依存: procps
    procps:i386
  依存: perl
  依存: mime-support
  依存: apache2-bin
  依存: apache2-utils
    apache2-utils:i386
  依存: apache2-data
  依存: <perl:any>
    perl:i386
    perl
  競合: <apache2.2-bin>
  競合: <apache2.2-common>
  推奨: ssl-cert
  提案: <www-browser>
    dillo
    edbrowse
    hv3
    lynx:i386
    lynx
    chromium-browser
    elinks
    epiphany-browser
    falkon
    firefox
    konqueror
    links
    links:i386
    links2
    links2:i386
    netrik
    sugar-browse-activity
    surf
    w3m:i386
    w3m
    xemacs21-mule
    xemacs21-mule-canna-wnn
    xemacs21-nomule
  提案: apache2-doc
 |提案: apache2-suexec-pristine
  提案: apache2-suexec-custom
  提案: ufw
  置換: <apache2.2-bin>
  置換: <apache2.2-common>

aptitudeコマンド

  • apt-getよりも高機能
  • apt-getとapt-cacheの機能をもつ
    • 使い方は同じ
  • LPIC ver5.0でどっかいった

apt

  • apt-getの後発
  • 「apt-getの設計上のミスを克服している」らしい
    • apt-cacheとかdpkgとか使い分けないといけないのがつらい
      • (例) パッケージ情報の表示に下記いずれかを叩かないといけない
        • dpkg -s パッケージ名
        • apt-cache show パッケージ名
  • 主なオプション
    • apt-getと同じもの使える
    • manもapt-get(8)がリファレンスされてる
  • 主なサブコマンド
    • だいたいapt-getapt-cacheとおなじ
    • list
      • apt-getにもapt-cacheにもないやつ
  • シェルっぽいやつ一覧
apt list *sh
Listing... Done
bash/now 4.4.18-2ubuntu1 amd64 [installed,local]
dash/now 0.5.8-2.10 amd64 [installed,local]
  • インストール済のやつ
apt list --installed
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Listing...
adduser/now 3.116ubuntu1 all [installed,local]
apt/now 1.6.8 amd64 [installed,local]
base-files/now 10.1ubuntu2.4 amd64 [installed,local]
base-passwd/now 3.5.44 amd64 [installed,local]
bash/now 4.4.18-2ubuntu1 amd64 [installed,local]
bsdutils/now 1:2.31.1-0.4ubuntu3.3 amd64 [installed,local]
bzip2/now 1.0.6-8.1 amd64 [installed,local]
coreutils/now 8.28-1ubuntu1 amd64 [installed,local]
dash/now 0.5.8-2.10 amd64 [installed,local]
...
  • upgradeできるやつ一覧
 apt list --upgradable
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

一覧表示...
apport/bionic-updates,bionic-updates 2.20.9-0ubuntu7.6 all [2.20.9-0ubuntu7.5 からアップグレード可]
apport-gtk/bionic-updates,bionic-updates 2.20.9-0ubuntu7.6 all [2.20.9-0ubuntu7.5 からアップグレード可]
apt/bionic-updates 1.6.10 amd64 [1.6.8 からアップグレード可]
apt-transport-https/bionic-updates,bionic-updates 1.6.10 all [1.6.8 からアップグレード可]
apt-utils/bionic-updates 1.6.10 amd64 [1.6.8 からアップグレード可]
console-setup/bionic-updates,bionic-updates 1.178ubuntu2.8 all [1.178ubuntu2.7 からアップグレード可]
console-setup-linux/bionic-updates,bionic-updates 1.178ubuntu2.8 all [1.178ubuntu2.7 からアップグレード可]
containerd.io/bionic 1.2.5-1 amd64 [1.2.2-3 からアップグレード可]
cups/bionic-updates 2.2.7-1ubuntu2.4 amd64 [2.2.7-1ubuntu2.3 からアップグレード可]

主なサブコマンドの比較

apt-get apt-cache apt 対応するdpkg
update o o -
upgrade o o
install o o
remove o o -r, --remove
purge o o -P, --purge
dist-upgrade o o
full-upgrade o o
show o o
showpkg o
list o -l, --list
search o o
depends o o
autoremove o o

RPMパッケージの管理

RPMパッケージ

bash-4.2.46-30.el7.x86_64.rpm
<パッケージ名称>-<バージョン番号>-<リリース番号>.<アーキテクチャ>.<拡張子>

rpmコマンドの利用

  • いくつかのモードがある
    • dpkgのアクション的な

インストール/アップグレードモード

  • 下記を併用するのが一般的
    • -v (verbose)
      • 詳細表示
    • -h, --hash
      • #(hash)で進捗表示
  • -i, --install
    • パッケージをインストール
  • -F, --freshen
    • パッケージがインストールされていればアップグレード
      • 純粋なアップグレード
  • -U, --upgrade
    • パッケージがインストールされていればアップグレード
    • なければインストール

アンインストールモード

  • -e, --erase
    • パッケージをアンインストール

照会モード

  • -q
    • 指定したパッケージがインストールされているか照会
    • オプション
      • -a, --a
        • インストール済全パッケージ表示
      • -i, --info
        • 情報表示
      • -f, --file
        • ファイル->バッケージ
      • -l, --list
        • パッケージ->ファイル群
      • -p
        • パッケージファイル名でパッケージ指定
      • -R, --requires
        • 依存関係調べる
      • --changelog
        • 変更履歴見る
  • bashと名のつくパッケージ探す
rpm -qa | grep bash
bash-4.2.46-31.el7.x86_64
  • bashパッケージの情報取得
rpm -qi bash
Name        : bash
Version     : 4.2.46
Release     : 31.el7
Architecture: x86_64
Install Date: Tue Mar  5 17:34:45 2019
Group       : System Environment/Shells
Size        : 3667773
License     : GPLv3+
Signature   : RSA/SHA256, Mon Nov 12 14:21:49 2018, Key ID 24c6a8a7f4a80eb5
Source RPM  : bash-4.2.46-31.el7.src.rpm
Build Date  : Tue Oct 30 17:09:33 2018
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.gnu.org/software/bash
Summary     : The GNU Bourne Again shell
Description :
The GNU Bourne Again shell (Bash) is a shell or command language
interpreter that is compatible with the Bourne shell (sh). Bash
incorporates useful features from the Korn shell (ksh) and the C shell
(csh). Most sh scripts can be run by bash without modification.
  • bashのバイナリがどのパッケージファイルから入ったか取得
rpm -qf $(which bash)
bash-4.2.46-31.el7.x86_64
  • bashパッケージによりインストールされたファイル一覧を得られるはずのコマンド
    • rpmファイル見つからず
rpm -qlp bash-4.2.46-31.el7.x86_64.rpm
  • 依存調査
rpm -qR bash
/bin/sh
config(bash) = 4.2.46-31.el7
libc.so.6()(64bit)
libc.so.6(GLIBC_2.11)(64bit)
libc.so.6(GLIBC_2.14)(64bit)
libc.so.6(GLIBC_2.15)(64bit)
libc.so.6(GLIBC_2.2.5)(64bit)
libc.so.6(GLIBC_2.3)(64bit)
libc.so.6(GLIBC_2.3.4)(64bit)
libc.so.6(GLIBC_2.4)(64bit)
libc.so.6(GLIBC_2.8)(64bit)
libdl.so.2()(64bit)
libdl.so.2(GLIBC_2.2.5)(64bit)
libtinfo.so.5()(64bit)
rpmlib(BuiltinLuaScripts) <= 4.2.2-1
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rtld(GNU_HASH)
rpmlib(PayloadIsXz) <= 5.2-1

パッケージの署名確認

パッケージの展開

  • rpm2cpioコマンド
    • RPMバッケージをインストールせず、内容を展開
    • cpioコマンドにパイプで流し込む

YUM

  • dpkgに対するAPTツールみたいな
  • rpmに対するYUM: Yellow dog Updater, Modified
  • 設定ファイル
    • /etc/yum.confファイル
    • /etc/yum.repos.d/以下ファイル

/etc/yum.conf

[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
override_install_langs=en_US.utf8
tsflags=nodocs


#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
ls /etc/yum.repos.d/
CentOS-Base.repo       CentOS-Media.repo    CentOS-fasttrack.repo
CentOS-CR.repo         CentOS-Sources.repo
CentOS-Debuginfo.repo  CentOS-Vault.repo
cat /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

アップデート

  • aptと異なり、updateはパッケージのアップデートを意味する
    • cf. aptupdateはパッケージ取得元データベースの更新
  • check-updateサブコマンド
    • アップデートパッケージが存在するパッケージを一覧
  • update [package]サブコマンド
    • 指定のパッケージのアップデート実施
    • package省略時、全パッケージのアップデート実施

インストールとアンインストール

  • installサブコマンド
    • インストール
  • remove
    • アンインストール

パッケージ情報の確認

  • infoサブコマンド
yum info bash
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
Installed Packages
Name        : bash
Arch        : x86_64
Version     : 4.2.46
Release     : 31.el7
Size        : 3.5 M
Repo        : installed
From repo   : CentOS
Summary     : The GNU Bourne Again shell
URL         : http://www.gnu.org/software/bash
License     : GPLv3+
Description : The GNU Bourne Again shell (Bash) is a shell or command language
            : interpreter that is compatible with the Bourne shell (sh). Bash
            : incorporates useful features from the Korn shell (ksh) and the C
            : shell (csh). Most sh scripts can be run by bash without
            : modification.
  • listサブコマンド
    • リポジトリにあるすべてのパッケージ情報と、インストールされているか確認
yum list | grep bash
bash.x86_64                               4.2.46-31.el7                  @CentOS
bash-completion.noarch                    1:2.1-6.el7                    base   
bash-doc.x86_64                           4.2.46-31.el7                  base   
libguestfs-bash-completion.noarch         1:1.38.2-12.el7_6.2            updates
libvirt-bash-completion.x86_64            4.5.0-10.el7_6.6               updates
pcp-pmda-bash.x86_64                      4.1.0-5.el7_6                  updates
  • パッケージ指定
    • 完全一致
yum list bash
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
Installed Packages
bash.x86_64                        4.2.46-31.el7                         @CentOS
  • searchサブコマンド
    • キーワード検索(部分一致)
yum search bash
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
============================== N/S matched: bash ===============================
bash-completion.noarch : Programmable completion for Bash
bash-doc.x86_64 : Documentation files for bash
libguestfs-bash-completion.noarch : Bash tab-completion scripts for libguestfs
                                  : tools
libvirt-bash-completion.x86_64 : Bash completion script
pcp-pmda-bash.x86_64 : Performance Co-Pilot (PCP) metrics for the Bash shell
bash.x86_64 : The GNU Bourne Again shell

  Name and summary matches only, use "search all" for everything.

パッケージグループ単位のインストール

  • RPMバッケージは、いくつかのパッケージグルーブに分類できる
yum groups list
Loaded plugins: fastestmirror, ovl
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done
  • これとかが「グループ」
GNOME Desktop
  • グループインストール
yum groups install "GNOME Desktop"

dnfコマンド

  • 基本的にyumとほぼ同じ

Zypperを使ったパッケージ管理

  • openSUSEではzypperコマンドでパッケージ管理

仮想化のゲストOSとしてのLinux

クラウドサービスとインスタンス

  • インスタンス
    • クラウドサービス上の仮想的なLinuxマシン
    • 物理的なサーバにLinuxをインストールして利用することは減ってきている
    • 素早くインフラを整えられる
    • リソースの拡張が容易
      • CPU
      • メモリ
      • ストレージ
  • XaaS
IaaS PaaS SaaS
アプリケーション o
ミドルウェア(開発環境、ランタイムとか) o o
OS o o o
H/W o o o
ネットワーク o o o

インスタンスの初期化

  • Cloud-init
    • インスタンスごとに異なる値を設定するのに使う
      • ホスト名
      • SSH
      • 一般ユーザー
      • インストールするパッケージ
    • これがないとOSイメージから複製したインスタンスはすべて同一になってしまう
  • D-BusマシンID
cat /etc/machine-id
2277c4be5b694b...