LPIC201/202 あずき本 ch7 システムメンテナンス

LPIC201勉強メモ資格勉強

出典: 

7.1 ソースからのソフトウェアインストール

7.1.1 ソースの展開

  • gzip/gunzip, bzip/bunzip, xz/unxz等で伸張
  • tarでtarボール展開
  • patchでソースコードバージョンアップ

7.1.2 Makefileの作成

./configure

7.1.3 コンパイルとインストール

いつもの流れ

make
sudo make install

このinstallは「ターゲット」という

make --help
Usage: make [options] [target] ...
...
  • all

    • コンパイルを行う(デフォルト)
  • install

    • ソフトウェアをインストール
    • /usr/local/bin//usr/local/sbin/などに配置される
  • uninstall

    • アンインストール
  • clean

    • コンパイル時に生成された一時ファイルを削除

7.2 バックアップ

7.2.1 バックアップの種類

  • 完全バックアップ(フルバックアップ)

    • ぜんぶ
    • 単体で復元できる
  • 差分バックアップ

    • 前回のフルバックアップ以降のぜんぶ
    • 最新のフルバックアップ + 最新の差分で復元できる
  • 増分バックアップ

    • 前回のバックアップ以降のぜんぶ
    • 最新のフルバックアップ(+最新の差分バックアップ)+全ての増分バックアップで復元できる

7.2.2 バックアップデバイス

  • CD-R/RW、リムーバブルハードディスク
  • DVD-R/RW
  • BD-R/RE
  • 磁気テープ

    • 大容量。ものによっては800GBとか
    • 摩耗しないうちに新しいメディアに取り替える必要あり
  • ネットワーク

7.2.3 ローカルでのバックアップ

tar

よく使うやつ

  • c/x: compress/extract
  • t: アーカイブ内容表示
  • f: アーカイブファイル名指定。-でstdin/stdout
  • z/j/J: gzip/bzip/xz
  • v: verbose
  • p: preserve-permission
  • C: 処理開始前に指定のディレクトリに移動

cpio

initramfsなどで使われているやつ

ls -l /boot/initramfs-$(uname -r).img
-rw-------. 1 root root 13663227 Nov 10 18:11 /boot/initramfs-3.10.0-1127.19.1.el7.x86_64.img

実体はイメージのcpioアーカイブgzip圧縮したもの

mkdir ~/initramfs
cd ~/initramfs

sudo gzip -d -c /boot/initramfs-$(uname -r).img | cpio -id
cpio: dev/null: Cannot mknod: Operation not permitted
cpio: dev/kmsg: Cannot mknod: Operation not permitted
cpio: dev/console: Cannot mknod: Operation not permitted
53676 blocks
ls
bin  etc   lib	  proc	run   shutdown	sysroot  usr
dev  init  lib64  root	sbin  sys	tmp	 var
  • -i: アーカイブからファイル抽出

    • アーカイブはstdinで与える
  • -o: アーカイブ作成・stdout
  • -d: directory作成
  • -t: 中身を見るだけ

    • tarと同じ
sudo gzip -d -c /boot/initramfs-$(uname -r).img | cpio -t | head -n 10
.
usr
usr/bin
usr/bin/bash
usr/bin/sh
usr/bin/setfont
usr/bin/loadkeys
usr/bin/kbd_mode
usr/bin/stty
usr/bin/gzip

dd

ループバックデバイスを作る時に散々使ったやつ

dd if=/dev/zero of=~/fs/loop0 bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.18218 s, 576 MB/s
  • if: input file
  • of: output file
  • bs: block size
  • count: block count

if/ofは省略するとstdin/stdoutになる

cat /dev/zero | dd bs=1M count=100 > ~/fs/loop1

なんかwarn出てっけど

dd: warning: partial read (131072 bytes); suggest iflag=fullblock
57+43 records in
57+43 records out
82313216 bytes (82 MB) copied, 0.201954 s, 408 MB/s

デバイス間でのディスク内容コピーなどに用いる

dump/restore

ext2/ext3/ext4ファイルシステムのバックアップ

mt

テープドライブ操作

7.2.4 ネットワーク経由でのバックアップ

rsync

ホスト間でやりとりする場合はrsyncdとして起動

cat /etc/rsyncd.conf

アクセスコントロールとか書ける

# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# [ftp]
#        path = /home/ftp
#        comment = ftp export area

ホスト内sync

ls -l dir/
total 0
-rw-r--r--. 1 wand wand 0 Dec 21 15:45 bar
-rw-------. 1 wand wand 0 Dec 21 15:45 baz
-rwxr-xr-x. 1 wand wand 0 Dec 21 15:45 foo

source側末尾に/があるかないかで挙動が変わる

  • /なし: そのディレクトリをdestにコピー
rsync -auv --delete dir backup
sending incremental file list
dir/
dir/bar
dir/baz
dir/foo

sent 253 bytes  received 77 bytes  660.00 bytes/sec
total size is 0  speedup is 0.00
ls -l backup
total 0
drwxrwxr-x. 2 wand wand 39 Dec 21 15:45 dir
  • /あり: そのディレクトリの中身をdestにコピー
rsync -auv --delete dir/ backup
sending incremental file list
deleting dir/foo
deleting dir/baz
deleting dir/bar
deleting dir/
./
bar
baz
foo

sent 240 bytes  received 117 bytes  714.00 bytes/sec
total size is 0  speedup is 0.00
ls -l backup
total 0
-rw-r--r--. 1 wand wand 0 Dec 21 15:45 bar
-rw-------. 1 wand wand 0 Dec 21 15:45 baz
-rwxr-xr-x. 1 wand wand 0 Dec 21 15:45 foo

tar + ssh

単純なコピーならこれでもいける

tar czpf - dir | ssh dest tar -xzpf - -C /backup
  • tar czpf - dir

    • c: compress
    • z: gzip圧縮
    • p: permissionをpreserve
    • f -: アーカイブファイル名指定 stdout
    • dir: 送信元ホストのカレントディレクトリにあるdirディレクトリをアーカイブ
  • ssh dest tar -xzpf - -C /backup

    • dest: 送信先ホスト
    • x: extract
    • z: gzip伸張
    • p: permissionをpreserve
    • f -: stdin
    • -C /backup: current directoryを/backupに移動して実行

要するに、送信元のdirを送信先ホストdest/backupディレクトリにin-transit暗号化・gzip圧縮でコピーする。

7.3 ユーザーへのシステム管理情報の通知

7.3.1 ログイン前後のメッセージ

  • /etc/issue: ログイン前のメッセージ表示
  • /etc/motd: ログイン後のメッセージ表示

今日のお知らせ

cat /etc/motd
(空)

/etc/motdを設定してみる

sudo tee /etc/motd <<EOT
> ====================
> oshirase
> ====================
> EOT
====================
oshirase
====================

ログイン

Last login: Mon Dec 21 15:13:46 2020 from xxx
====================
oshirase
====================

ホームディレクトリに.hushloginを配置すると Last login:のくだりと/etc/motdのお知らせは表示されなくなる

システム情報の表示

通常のログインは/etc/issue

cat /etc/issue
\S
Kernel \r on an \m

telnet越しは/etc/issue.net

cat /etc/issue.net
\S
Kernel \r on an \m

ssh越しは/etc/ssh/sshd_configで設定する

sudo cat /etc/ssh/sshd_config
...
# no default banner path
#Banner none
...

テキストファイルのパスを記述

7.3.2 ログイン中ユーザーへの通知

sudo wall "The system will shut down soon."
Broadcast message from root@lpic2-study-1 (pts/0) (Mon Dec 21 15:22:55 2020):

The system will shut down soon.

ログイン中の全ユーザの端末にブロードキャストされる

shutdown -kでも同じ機能を使える

  • シャットアウトdry-run