Open106

Linux学習

tenryutenryu

pwd:カレントディレクトリを表示

[node1] (local) root@10.0.168.4 ~
$ pwd
/root

前のカレントディレクトリに戻る

cd -
tenryutenryu

mkdirのオプション

-m 権限も同時に設定(mode)

[node1] (local) root@10.0.168.4 ~
$ mkdir -m 777 testdir2
[node1] (local) root@10.0.168.4 ~
$ ls -la | grep testdir
drwxr-xr-x    2 root     root             6 Mar 27 23:39 testdir
drwxrwxrwx    2 root     root             6 Mar 27 23:40 testdir2

-p 親ディレクトリも同時に作成(parent)

$ mkdir -p /test/testdir
tenryutenryu

rmdirコマンドは空のディレクトリの削除コマンド。ファイルがある場合は削除不可。
その場合はrm -rfコマンドを使用して強制的に削除する。

[node1] (local) root@10.0.168.4 ~
$ ls
dir       testdir   testdir2
[node1] (local) root@10.0.168.4 ~
$ cd dir
[node1] (local) root@10.0.168.4 ~/dir
$ touch test.html
[node1] (local) root@10.0.168.4 ~/dir
$ cd -
/root
[node1] (local) root@10.0.168.4 ~
$ rmdir dir
rmdir: 'dir': Directory not empty
[node1] (local) root@10.0.168.4 ~
$ rm -rf dir
[node1] (local) root@10.0.168.4 ~
$ ls
testdir   testdir2
tenryutenryu

echoコマンドでファイルを作成

[node1] (local) root@10.0.168.4 ~/home/user2
$ echo "test" > test1.txt
[node1] (local) root@10.0.168.4 ~/home/user2
$ cat test1.txt
test

">"(だいなり記号)をリダイレクト演算子といって、出力をファイルに書き込むために使われる。
上書きされるので注意。

>>二重大なり記号でファイルの末尾に追加

$ echo Hello3 >> file.txt
[node1] (local) root@10.0.168.4 ~/home/user2
$ cat file.txt
Hello2
Hello3
Hello3
tenryutenryu

ls コマンドのオプション

オプション 説明
-a 「.」から始まるファイルを表示する(隠しファイルの表示)
-A 「.」から始まるファイルを表示するが、カレントディレクトリと親ディレクトリは表示しない
-d ディレクトリ自身の情報を表示する
-F ファイルの種類も表示
-i iノード番号を表示する
-l ファイルの詳細な情報を表示する
-t 日付順に表示する
-h 単位付きで表示する

全ファイルの詳細情報を表示し日付順に並び替え

$ ls -lat
total 16
-rw-r--r--    1 root     root            21 Mar 28 00:01 file.txt
drwxr-xr-x    2 root     root            73 Mar 28 00:01 .
-rw-r--r--    1 root     root            14 Mar 27 23:58 test2.txt
-rw-r--r--    1 root     root             5 Mar 27 23:55 test1.txt
-rw-r--r--    1 root     root             6 Mar 27 23:53 ifle.text
drwxr-xr-x    4 root     root            32 Mar 27 23:48 ..

指定したファイル名の情報だけ表示

$ ls -lat | grep test
-rw-r--r--    1 root     root            14 Mar 27 23:58 test2.txt
-rw-r--r--    1 root     root             5 Mar 27 23:55 test1.txt

ファイルのサイズを読みやすい形で表示

KとかMで単位をつけてくれる

root@08740c625075:/workspace# ls -lh
total 412K
drwxr-xr-x 11 root root  352 Feb 28 08:39 app
-rw-r--r--  1 root root 1.7K Feb  6 00:31 artisan
drwxr-xr-x  4 root root  128 Feb  6 00:31 bootstrap
-rw-r--r--  1 root root 2.1K Mar 14 02:18 composer.json

ファイルの種類も表示

ディレクトリだと末尾に/がつく

oot@08740c625075:/workspace# ls -lF
total 412
drwxr-xr-x 11 root root    352 Feb 28 08:39 app/
-rw-r--r--  1 root root   1686 Feb  6 00:31 artisan

カレントディレクトリの情報表示

root@08740c625075:/workspace# ls -ld
drwxr-xr-x 43 root root 1376 Mar 27 04:40 .
tenryutenryu

rmコマンドのオプション

オプション 説明
-i ファイルの削除前に確認する
-r ディレクトリを再帰的に削除する
-v 削除の詳細を表示
tenryutenryu

権限について

$ ls -l /etc
total 216
-rw-r--r--    1 root     root             7 Sep 28 11:17 alpine-release
drwxr-xr-x    1 root     root            19 Oct 19 23:22 apk
drwxr-xr-x    2 root     root            46 Oct 19 23:22 bash
drwxr-xr-x    2 root     root            20 Oct 19 23:22 bash_completion.d

r: Read(読み込み権限)
w: Write(書き込み権限)
x: Execute(実行権限)
-: 権限なし

一番の- or dになっているところはファイルの種類
d: ディレクトリ
l: リンク
-: ファイル

  • rwx r-x r-x
    種類はファイルで、rwxは所有者(ユーザー)、r-xは所有グループ、r-xは所有グループに属していないユーザーの権限を表す
-rw-r--r--    1 root     root             7 Sep 28 11:17 alpine-release

ファイルの所有者:root
ファイルの所有グループ:root
で、権限が
rootユーザーに読み込みと書き込みの権限があり、実行権限なし
rootグループには読み込み権限のみあり、書き込みと実行権限なし
rootグループに所属していないユーザーには読み込み権限のみあり、書き込みと実行権限なし

tenryutenryu

権限の変更

chmodコマンド

[node1] (local) root@10.0.216.4 ~
$ ls
[node1] (local) root@10.0.216.4 ~
$ mkdir test
[node1] (local) root@10.0.216.4 ~
$ ls
test
[node1] (local) root@10.0.216.4 ~
$ ls -l
total 0
drwxr-xr-x    2 root     root             6 Mar 28 23:19 test
[node1] (local) root@10.0.216.4 ~
$ chmod 660 test
[node1] (local) root@10.0.216.4 ~
$ ls -l
total 0
drw-rw----    2 root     root             6 Mar 28 23:19 test
[node1] (local) root@10.0.216.4 ~
$ chmod 760 test
[node1] (local) root@10.0.216.4 ~
$ ls -l
total 0
drwxrw----    2 root     root             6 Mar 28 23:19 test

r(読み込み権限): 4
w(書き込み権限): 2
x(実行権限): 1

chmodで設定する際、

  • 読み込みと書き込みと実行権限を与えたければ、4+2+1で7を設定(rwx)
  • 読み込みと書き込み権限を与えたければ、4+2で6を設定(rw-)
  • 読み込みと実行権限を与えたければ、4+1で5を設定(r-x)
  • 読み込み権限を与えたければ、4を設定(r--)
[node1] (local) root@10.0.216.4 ~
$ chmod 764 test
[node1] (local) root@10.0.216.4 ~
$ ls -l
total 0
drwxrw-r--    2 root     root             6 Mar 28 23:19 test

記号による権限設定

[node1] (local) root@10.0.216.4 ~
$ chmod 764 test
[node1] (local) root@10.0.216.4 ~
$ ls -l
total 0
drwxrw-r--    2 root     root             6 Mar 28 23:19 test
[node1] (local) root@10.0.216.4 ~
$ chmod ug+x test
[node1] (local) root@10.0.216.4 ~
$ ls -l
total 0
drwxrwxr--    2 root     root             6 Mar 28 23:19 test

u: 所有者
g: グループ
o: その他のユーザー
a: 全てのユーザー(u,g,oの全て)

数字ではなく記号でも指定できる。
記号で権限を変更する場合は、[対象][操作][権限の種類]の3つを指定

上の例だとユーザーと所属するグループへ読み込み権限を追加
操作は以下が可能
+: 権限を追加
–: 権限を削除
=: 権限を指定

イコールだと一括で指定可能

[node1] (local) root@10.0.216.4 ~
$ chmod u=w test
[node1] (local) root@10.0.216.4 ~
$ ls -l
total 0
d-w-rwxr--    2 root     root             

権限の種類
r : 読み取り権限
w : 書き込み権限
x : 実行権限
s : SUIDもしくはSGID
t : スティッキービット

tenryutenryu

ユーザーとグループの変更(chown)

ユーザーとグループを変更する

まずユーザーとグループの追加

[node1] (local) root@10.0.216.4 ~
$ adduser user
Changing password for user
New password: 
Bad password: too short
Retype password: 
Passwords don't match
passwd: password for user is unchanged
[node1] (local) root@10.0.216.4 ~
$ addgroup test

ファイルの作成と権限の変更

$ touch file.txt
[node1] (local) root@10.0.216.4 ~
$ ls -l | grep .txt
-rw-r--r--    1 root     root             0 Mar 28 23:36 file.txt
[node1] (local) root@10.0.216.4 ~
$ chown user:test file.txt
[node1] (local) root@10.0.216.4 ~
$ ls -l | grep .txt
-rw-r--r--    1 user     test             0 Mar 28 23:36 file.txt

ユーザーのみ変更する場合

chown user file.txt

グループのみ変更する場合、先頭に:をつける

chown :test file.txt
tenryutenryu

演習

/homeディレクトリに”file.txt”というファイルを作成
ファイルの所有者に全ての権限を与えて、それ以外のユーザーには読み込み権限のみを与える

$ touch /home/file.txt
[node1] (local) root@10.0.216.4 ~
$ ls -l /home/file.txt
-rw-r--r--    1 root     root             0 Mar 28 23:39 /home/file.txt
[node1] (local) root@10.0.216.4 ~
$ chmod u+rwx /home/file.txt
[node1] (local) root@10.0.216.4 ~
$ ls -l /home/file.txt
-rwxr--r--    1 root     root             0 Mar 28 23:39 /home/file.txt
[node1] (local) root@10.0.216.4 ~
$ chmod go=r /home/file.txt
[node1] (local) root@10.0.216.4 ~
$ ls -l /home/file.txt
-rwxr--r--    1 root     root             0 Mar 28 23:39 /home/file.txt
tenryutenryu

SUID

通常ファイルを実行した場合、実行したユーザーの権限で実行される。
SUIDを設定したファイルはファイルの所有者の権限で実行される

ユーザーのパスワードを変更する場合、passwdコマンドを実行する。
その際パスワードは/etc/passwdに保存される。
権限を確認してみる。

$ ls -l /etc/passwd
-rw-r--r--    1 root     root          1289 Mar 28 23:34 /etc/passwd

rootユーザーのみ書き込み権限がある。
そのため、追加したユーザーなどが/etc/passwdにパスワードを書き込むことができない。

testユーザーを追加し、パスワード変更コマンドを実行。エラーになる。

$ adduser test
Changing password for test
New password: 
Bad password: too short
Retype password: 
passwd: password for test changed by root
[node2] (local) root@10.0.216.5 ~
$ login test
Password: 
###############################################################
#                                                             #
#                    Welcome to InfraAcademy !!!!             #
#                                                             #
###############################################################
node2:~$ whoami  // ログインユーザーの確認
test
node2:~$ passwd test  // パスワード変更コマンド
passwd: must be suid to work properly

suidの設定はchmod 4755のように頭に4をつける

SGID

SGIDビットをセットすると、そのファイルを実行したユーザーの所属するグループの権限で実行される

sgidの設定はchmod 4755のように頭に2をつける

tenryutenryu

スティッキービット

ディレクトリのファイルを保護するために使用される。
ディレクトリに設定した場合にファイルを削除できるのは

  • ファイルの所有者
  • ディレクトリの所有者
  • 特権を持つユーザー

1をつける

のみになる

root@6c320b6e0130:/# chmod 1777 file
root@6c320b6e0130:/# ls -l file
-rwxrwxrwt 1 root root 0 Apr 11 11:12 file
root@6c320b6e0130:/# chmod 777 file
root@6c320b6e0130:/# ls -l file
-rwxrwxrwx 1 root root 0 Apr 11 11:12 file
tenryutenryu

Vim

今までiしか使ってこなかったけど、aやoで文字を追加できるらしい。
a: 現在のカーソル位置の右側に文字を追加
i: 現在のカーソル位置の左側に文字を追加
o: 現在のカーソル位置の下の行に文字を追加
shift + r: 文字の上書き
x: コマンドモード(一番下に--INSERT--とか表示されていない状態)でカーソルを合わせてxで1文字切り取り
dd: コマンドモードで一行切り取り。2ddで二行切り取り
shift + d: 文末まで削除
yy: 一行コピー
p: 貼り付け
行番号 shift g: 指定行へ移動
/文字列: 現在のカーソル位置から下を検索 エンターを押した後にnで次にジャンプ
?文字列: 現在のカーソル位置から上を検索 エンターを押した後にnで次にジャンプ
:set number: 行番号を表示

::

tenryutenryu

ユーザーID(UID)

rootユーザーはuid=0

node1:~$ id root
uid=0(root) gid=0(root) groups=0(root),0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)

グループID(GID)

ユーザーが属するグループのこと。複数のグループに属することができる。
作成したtestuserがどのグループに属しているかを確認。左から4番目のGIDが1000のグループに属している。

testuser:x:1000:1000:Linux User,,,:/home/testuser:/bin/bash
node1:~$ cat /etc/group
()
testuser:x:1000:

一番楽なのはidコマンド

node1:~$ id testuser
uid=1000(testuser) gid=1000(testuser) groups=1000(testuser)

uid指定でユーザー作成

adduser -u 2010 user10
tenryutenryu

ユーザー情報の変更コマンド(usermod)

usermodコマンドの追加

$ apk update
fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
v3.18.6-122-gf17e19e260e [https://dl-cdn.alpinelinux.org/alpine/v3.18/main]
v3.18.6-122-gf17e19e260e [https://dl-cdn.alpinelinux.org/alpine/v3.18/community]
OK: 20102 distinct packages available
[node1] (local) root@10.0.218.4 ~
$ apk add shadow
(1/1) Installing shadow (4.13-r4)
Executing busybox-1.36.1-r2.trigger
OK: 469 MiB in 163 packages

グループの変更

プライマリグループの変更は-gオプション、サブグループは-G
まずグループ追加する

$ addgroup test2
[node1] (local) root@10.0.218.4 ~
$ cat /etc/group
()
test2:x:1001:

GID: 1001のtest2グループを追加

グループ変更

$ usermod -g test2 testuser
[node1] (local) root@10.0.218.4 ~
$ id testuser
uid=1000(testuser) gid=1001(test2) groups=1001(test2)
tenryutenryu

ネットワーク

LAN(Local area network)

限られた範囲のネットワーク。家の中や会社のオフィスなど。

WAN(Wide area network)

広い範囲のネットワークで誰でもアクセス可能。インターネット。地理的に離れたネットワークを接続可能。
WANは通信事業者(プロバイダー)が構築する。

tenryutenryu

IPアドレスの確認

$ ifconfig
()
eth0     ()
          inet addr:xxx.xxx.xxx.xxx

eth0やeth1はネットワークインターフェースを識別するためのラベル。
ネットワークインターフェースとは、インターネットやほかのデバイスと通信するための口のこと。
「LANケーブルを差し込む部分」や「Wifi」が該当するらしい。
※LANケーブルを差し込む部分が物理的なもので、Wifiのように論理的なものもある?

LANケーブルを差し込む機器のことをNICという

loはlocalhost、wifiはwlan

eth

ethはEthernetの略。Ethernetは優先ネットワーク技術の一つで優先ケーブルでデータ通信を行うためのプロトコル。

tenryutenryu

ping

$ ping 10.0.218.4
PING 10.0.218.4 (10.0.218.4): 56 data bytes
64 bytes from 10.0.218.4: seq=0 ttl=127 time=0.605 ms
64 bytes from 10.0.218.4: seq=1 ttl=127 time=0.076 ms
64 bytes from 10.0.218.4: seq=2 ttl=127 time=0.080 ms
64 bytes from 10.0.218.4: seq=3 ttl=127 time=0.074 ms
^C
--- 10.0.218.4 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.074/0.208/0.605 ms

ICMP(Internet Control Message Protocol)を使って接続確認する。

tenryutenryu

IPアドレス

ネットワーク部とホスト部で構成される。
ネットワーク:どこのネットワークに所属しているか
ホスト:ネットワーク内で割り当てられた番号

サブネットマスク

どこまでがネットワーク部、どこからがホスト部なのかを識別するためのもの
255.255.255.0のように表す。
IPアドレスが192.168.1.2の場合、
192.168.1までがネットワーク、2がホストという意味

ただこの書き方だと冗長なのでCIDR表記で書くのが一般的
255.255.255.0をCIDRで書くと/24
255を2進数で表すと11111111と1が8つで表される。それが3つだから3*8で24という意味。
192.168.1.2/24のように書くのが一般的

tenryutenryu

IPアドレスの確認

$ ip address
2307: eth0@if2308: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1450 qdisc noqueue state UP 
    link/ether 02:42:0a:00:db:04 brd ff:ff:ff:ff:ff:ff
    inet 10.0.219.4/24 brd 10.0.219.255 scope global eth0
       valid_lft forever preferred_lft forever

IPアドレス追加と削除

$ ip address add 10.0.31.100 dev eth0
$ ip address
2307: eth0@if2308: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1450 qdisc noqueue state UP 
    link/ether 02:42:0a:00:db:04 brd ff:ff:ff:ff:ff:ff
    inet 10.0.219.4/24 brd 10.0.219.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 10.0.31.100/32 scope global eth0
       valid_lft forever preferred_lft forever
$ ip address del 10.0.31.100 dev eth0
[node1] (local) root@10.0.219.4 ~
$ ip address
2307: eth0@if2308: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1450 qdisc noqueue state UP 
    link/ether 02:42:0a:00:db:04 brd ff:ff:ff:ff:ff:ff
    inet 10.0.219.4/24 brd 10.0.219.255 scope global eth0
       valid_lft forever preferred_lft forever
tenryutenryu

デフォルトゲートウェイとルーティング

インターネット上のサーバーなど、どこにあるかわからない場所へ通信する際に一番最初に送る先。
異なるネットワーク同士の通信を行う際に設定が必要。

設定コマンド

ip route add default via 192.168.1.254

ルーティング情報の確認

$ ip route
default via 172.18.0.1 dev eth1 
10.0.219.0/24 dev eth0 scope link  src 10.0.219.4 
172.17.0.0/16 dev docker0 scope link  src 172.17.0.1 
172.18.0.0/16 dev eth1 scope link  src 172.18.0.3 

シミュレータだと172.18.0.1がデフォルトになっている

ルーティングの追加

172.16.0.0/16のネットワークをゲートウェイの172.18.0.1に送りたい場合
手動で設定したルートを静的ルート(スタティックルート)という

$ ip route
default via 172.18.0.1 dev eth1 
10.0.219.0/24 dev eth0 scope link  src 10.0.219.4 
172.17.0.0/16 dev docker0 scope link  src 172.17.0.1 
172.18.0.0/16 dev eth1 scope link  src 172.18.0.3 
[node1] (local) root@10.0.219.4 ~
$ ip route add 172.16.0.0/16 via 172.18.0.1 dev eth1
[node1] (local) root@10.0.219.4 ~
$ i@route
bash: i@route: command not found
[node1] (local) root@10.0.219.4 ~
$ ip route
default via 172.18.0.1 dev eth1 
10.0.219.0/24 dev eth0 scope link  src 10.0.219.4 
172.16.0.0/16 via 172.18.0.1 dev eth1 
172.17.0.0/16 dev docker0 scope link  src 172.17.0.1 
172.18.0.0/16 dev eth1 scope link  src 172.18.0.3 
tenryutenryu

シェル

ユーザーが入力したコマンドを受け付け、必要なプログラムを実行させるもの。ユーザーとOSの間にある。
LinuxではデフォルトがBash

環境変数

$ env
DOCKER_VERSION=24.0.6
CHARSET=UTF-8
などなど

ユーザーがログインした際の情報

$ set | head
BASH=/bin/bash
()

環境変数の設定と削除

$ export MY_VAR=Hello
[node1] (local) root@10.0.223.4 ~
$ echo $MY_VAR
Hello
$ unset MY_VAR
[node1] (local) root@10.0.223.4 ~
$ echo $MY_VAR
tenryutenryu

コマンド

コマンドとは、コンパイルされたプログラムの実行ファイル

$ which ls
/bin/ls
ディレクトリ 説明 コマンド例
/bin 基本的なシステムコマンドが配置される。一般ユーザーでも実行可能なコマンドです。 ls, cp, mv
/sbin 管理者向けのシステムコマンドが配置される。 ifconfig, shutdown
/usr/bin 一般ユーザー向けのアプリケーションやコマンドが配置される。 firefox, gedit
/usr/sbin 管理者向けのアプリケーションやコマンドが配置される。 networkd, httpd
/usr/local/bin システムディストリビューションに含まれていないソフトウェアが配置される。 /usr/local/bin/myapp
/usr/local/sbin /usr/local/bin と同様、管理者向けのアプリケーションやコマンドが配置される。 /usr/local/sbin/mytool

lsは/bin/ls -laでも実行可能。パスを指定しなくていいのは$PATHに定義されているから

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/go/bin

aliasで短縮コマンドを登録

alias ll = "ls -la"
tenryutenryu

正規表現検索

grepと合わせた正規表現検索
testを含む行を取得
-Eで正規表現、マッチした部分だけ抜き出す場合は-oオプション
-rでディレクトリを指定して検索

$ echo test1234 > file.txt
[node1] (local) root@10.0.223.4 /bin
$ echo abcd1234 >> file.txt
[node1] (local) root@10.0.223.4 /bin
$ cat file.txt
test1234
abcd1234
[node1] (local) root@10.0.223.4 /bin
$ grep test file.txt
test1234
$ grep -E [1-9] file.txt
test1234
abcd1234
$ grep -o -E [1-9] file.txt
1
2
3
4
1
2
3
4
$ mkdir testdir
[node1] (local) root@10.0.223.4 /bin
$ echo test1234 > testdir/file1.txt
[node1] (local) root@10.0.223.4 /bin
$ echo test1234 > testdir/file2.txt
[node1] (local) root@10.0.223.4 /bin
$ grep -r test testdir
testdir/file1.txt:test1234
testdir/file2.txt:test1234
オプション 説明
-i 大文字小文字を無視して検索する
-v パターンに一致しない行を表示する
-c パターンに一致する行の数を表示する
-l パターンに一致する行を含むファイル名を表示する
-n パターンに一致する行の行番号を表示する
-r, -R サブディレクトリ内のファイルも再帰的に検索する
-w パターンと完全に一致する単語を検索する
-A <N> パターンに一致した行の後に<N>行を表示する
-B <N> パターンに一致した行の前に<N>行を表示する
-C <N> パターンに一致した行の前後に<N>行を表示する
-E 拡張正規表現を使用する (GNU grep)
-F パターンを固定文字列として解釈する
-P Perl互換の正規表現を使用する (GNU grep)
-o パターンに一致する部分のみを表示する
–exclude 特定のパターンを持つファイルを検索から除外する
–include 特定のパターンを持つファイルだけを検索対象にする
–exclude-dir 特定のディレクトリを検索から除外する
–color パターンに一致した部分を色付けして表示する
tenryutenryu

コマンドの連続実行

セミコロン;

前のコマンドの成功、失敗に関わらず実行される

echo Hello ; date; ls -l

アンパサント&&

前のコマンドが失敗したら後続のコマンドは実行されない

$ ls hogehoge && echo hoge
ls: hogehoge: No such file or directory

パイプ|

前のコマンドの実行結果を後続に渡す

$ ls -l /etc | grep init
drwxr-xr-x    1 root     root            18 Oct 19 23:22 init.d
-rw-r--r--    1 root     root           570 May  9  2023 inittab

パイプ2つだと前のコマンドが失敗した場合のみ実行される

$ ls hogehoge || echo DirectoryNotFound
ls: hogehoge: No such file or directory
DirectoryNotFound
tenryutenryu

カーネル

OSの中核を成すシステム

カーネルの機能

  • プロセス(処理)管理
    • プロセスの生成、割り当て、実行停止、スケジューリングなど
  • メモリ管理
    • システムが正常に動作するために必要なメモリの最適化
  • ファイルシステム
    • アプリケーションがファイルを読み書きできるよう管理

カーネルのバージョン確認(uname)

$ uname -r
6.1.55-75.123.amzn2023.x86_64
[node1] (local) root@10.1.20.4 ~
$ uname -m
x86_64
[node1] (local) root@10.1.20.4 ~
$ uname -n
node1
[node1] (local) root@10.1.20.4 ~
$ uname -p
unknown
[node1] (local) root@10.1.20.4 ~
$ uname -s
Linux
[node1] (local) root@10.1.20.4 ~
$ uname -v
#1 SMP PREEMPT_DYNAMIC Tue Sep 26 20:06:16 UTC 2023
[node1] (local) root@10.1.20.4 ~
$ uname -a
Linux node1 6.1.55-75.123.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Sep 26 20:06:16 UTC 2023 x86_64 Linux

/proc/versionでも確認できる

$ cat /proc/version
Linux version 6.1.55-75.123.amzn2023.x86_64 (mockbuild@ip-10-0-62-35) (gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2), GNU ld version 2.39-6.amzn2023.0.9) #1 SMP PREEMPT_DYNAMIC Tue Sep 26 20:06:16 UTC 2023

カーネルモジュール

カーネル機能の一部を切り出したもの。容量が小さく起動時間が短くなるなどメリットがある。
メモリ管理やスケジューラなどの重要な部分は切り出し不可。

カーネルモジュールの確認

$ lsmod
Module                  Size  Used by    Not tainted
tls                   110592  0 
iptable_nat            16384  7 
iptable_filter         16384  7 
bpfilter               16384  0 
xt_nat                 16384 68 
veth                   36864  0 
vxlan                 110592  0 
ip6_udp_tunnel         16384  1 vxlan
udp_tunnel             28672  1 vxlan
xt_policy              16384  0 
xt_mark                16384  0 
xt_bpf                 20480  0 
xt_conntrack           16384 11 
nft_chain_nat          16384 35 
xt_MASQUERADE          20480 15 
nf_nat                 57344  4 iptable_nat,xt_nat,nft_chain_nat,xt_MASQUERADE
nf_conntrack_netlink    57344  0 
nf_conntrack          184320  5 xt_nat,xt_conntrack,xt_MASQUERADE,nf_nat,nf_conntrack_netlink
nf_defrag_ipv6         24576  1 nf_conntrack
nf_defrag_ipv4         16384  1 nf_conntrack
xfrm_user              57344  8 
xfrm_algo              16384  1 xfrm_user
xt_addrtype            16384 16 
nft_compat             20480 82 
nf_tables             303104 862 nft_chain_nat,nft_compat
nfnetlink              20480 11 nf_conntrack_netlink,nft_compat,nf_tables
br_netfilter           36864  0 
bridge                307200  1 br_netfilter
stp                    16384  1 bridge
llc                    16384  2 bridge,stp
overlay               167936 10 
sunrpc                696320  1 
nls_ascii              16384  1 
nls_cp437              20480  1 
vfat                   24576  1 
fat                    86016  1 vfat
ghash_clmulni_intel    16384  0 
aesni_intel           393216  0 
ena                   159744  0 
crypto_simd            16384  1 aesni_intel
cryptd                 28672  2 ghash_clmulni_intel,crypto_simd
button                 24576  0 
drm                   602112  0 
sch_fq_codel           20480  3 
i2c_core              106496  1 drm
dm_mod                188416  0 
fuse                  163840  1 
drm_panel_orientation_quirks    28672  1 drm
backlight              24576  1 drm
loop                   32768  0 
dax                    45056  1 dm_mod
configfs               57344  1 
dmi_sysfs              20480  0 
crc32_pclmul           16384  0 
crc32c_intel           24576  0 
efivarfs               24576  1

BIOS/UEFI

BIOS(Basic Input Output System)とUEFI(Unified Extensible Firmware Interface)はPCが起動した際に最初に実行され、ハードウェアとソフトウェアが適切に通信できるようにしてくれるもの。
UEFIはより高度な機能やセキュリティを備えたもので、広義の意味でBIOSと呼ばれる。
https://www.nec-lavie.jp/products/contents/bios.html#anc1

ブートローダー

カーネルを読み込むためのプログラム。ハードディスクやCD、USBなどに入っている。ブートローダーが入っているデバイスをブートデバイスという。BIOSにはブートデバイス情報が設定されていて、該当するデバイスを認識する。

ブートローダーを読み込み、Linuxの元となるカーネルを起動させる。カーネルは初期プロセスの起動などを行う。

GRUB(グラブ)

Linuxの代表的なブートローダーをGRUB(グラブ)という。
GRUBのバージョンが0.9x系のものを「GRUB Legacy」、1.9以降のものを「GRUB2」と呼ぶ。

tenryutenryu

ディストリビューション

ディストリビューションとは、Linuxカーネルをベースとして構築されたOSのバージョンやバリエーションのこと。

Ubuntu, Debian, CentOSとかはよくみる

$ cat /etc/issue
Welcome to Alpine Linux 3.18
Kernel \r on an \m (\l)

シミュレータはAlpine Linuxが使われているらしい。

ディストリビューション 特徴
Ubuntu ユーザーフレンドリーなデスクトップディストリビューション。コミュニティ版(Ubuntu)と企業版(Ubuntu LTS)が提供されています。
Debian 安定性とセキュリティを重視したディストリビューション。多くの派生ディストリビューションの基盤となっています。
Fedora 最新のソフトウェアとテクノロジーを提供するディストリビューション。コミュニティによって開発されています。
CentOS Red Hat Enterprise Linux(RHEL)のオープンソース版で、安定性とサポートを提供。
Arch Linux ロールインストールとカスタマイズが得意なディストリビューション。ユーザーに高い自由度を提供。
openSUSE オープンソースのディストリビューションで、幅広い用途に適しています。openSUSE LeapとTumbleweedが提供されています。
Kali Linux セキュリティテストとペネトレーションテストのためのディストリビューション。セキュリティ専門のツールが含まれています。

パッケージ管理コマンド

それぞれのディストリビューションでパッケージ管理の方針が異なるため、いろいろ使われているらしい

コマンド Linuxの種類
apt Debian,Ubunts
apk Alpine
dpkg Debian,Ubunts
yum CentOS,RHEL
rpm CentOS,RHEL
pacman Arch Linux
tenryutenryu

aptコマンド

dockerを使ってDebianを動かす

docker run -it debian /bin/bash
Unable to find image 'debian:latest' locally
latest: Pulling from library/debian
71215d55680c: Pull complete 
Digest: sha256:e97ee92bf1e11a2de654e9f3da827d8dce32b54e0490ac83bfc65c8706568116
Status: Downloaded newer image for debian:latest
root@211173b52161:/# cat /etc/issue
Debian GNU/Linux 12 \n \l

パッケージを検索

apt-cache search apache

パッケージの詳細情報を取得

root@211173b52161:/# apt-cache show apache2
Package: apache2
Version: 2.4.57-2
Installed-Size: 566
Maintainer: Debian Apache Maintainers <debian-apache@lists.debian.org>
Architecture: amd64
Provides: httpd, httpd-cgi
Depends: apache2-bin (= 2.4.57-2), apache2-data (= 2.4.57-2), apache2-utils (= 2.4.57-2), lsb-base, media-types, perl:any, procps
Pre-Depends: init-system-helpers (>= 1.54~)
Recommends: ssl-cert
Suggests: apache2-doc, apache2-suexec-pristine | apache2-suexec-custom, www-browser
Description: Apache HTTP Server
Description-md5: d02426bc360345e5acd45367716dc35c
Homepage: https://httpd.apache.org/
Tag: role::metapackage, suite::apache
Section: httpd
Priority: optional
Filename: pool/main/a/apache2/apache2_2.4.57-2_amd64.deb
Size: 214864
MD5sum: 3e510937d7323527502133b230614002
SHA256: 5857cb3cfd29597c3b4898b788b048b2c0bcf092012773c330459dc9abfbb63f
tenryutenryu

yumコマンド

最新のパッケージ情報を取得

yum update

パッケージの検索

yum search http

パッケージの詳細情報取得

yum info httpd
tenryutenryu

ファイルの圧縮

gzipとxzを使用。
xzの方が圧縮効率が高くファイルを小さくすることができるが、時間がかかる。

gzip

$ gzip file.txt
[node1] (local) root@10.1.20.4 ~
$ ls
file.txt.gz
[node1] (local) root@10.1.20.4 ~
$ ls -l
total 4
-rw-r--r--    1 root     root            20 Mar 31 03:58 file.txt.gz

ファイルの解凍

-dオプションはdecompress(解凍の意味)

$ gzip -d file.txt.gz
[node1] (local) root@10.1.20.4 ~
$ ls -l
total 0
-rw-r--r--    1 root     root             0 Mar 31 03:59 file.txt

-kオプションで圧縮するファイルを残したままにする
keepの意味

$ gzip file.txt -k
[node1] (local) root@10.1.20.4 ~
$ ls -l
total 4
-rw-r--r--    1 root     root             0 Mar 31 03:59 file.txt
-rw-r--r--    1 root     root            20 Mar 31 03:59 file.txt.gz

-fはforceで強制、
gunzip file.txt.gzでも解凍可能

xz

$ xz file.txt
[node1] (local) root@10.1.20.4 ~
$ ls -l
total 4
-rw-r--r--    1 root     root            32 Mar 31 03:59 file.txt.xz
[node1] (local) root@10.1.20.4 ~
$ xz -d file.txt.xz
[node1] (local) root@10.1.20.4 ~
$ ls -l
total 0
-rw-r--r--    1 root     root             0 Mar 31 03:59 file.txt

解凍はunxzコマンドでも可能

tenryutenryu

アーカイブ

ファイルの圧縮は一つのファイルにしかできない。複数のファイルを圧縮するにはアーカイブを行なって圧縮を行う。

アーカイブは複数のファイルやフォルダを一つのファイルにまとめたもの。
圧縮だけではなく、転送やバックアップの際にも使用される。

$ touch file1
touch file2
touch file3
[node1] (local) root@10.1.20.4 ~
$ ls -l
total 0
-rw-r--r--    1 root     root             0 Mar 31 03:59 file.txt
-rw-r--r--    1 root     root             0 Mar 31 04:05 file1
-rw-r--r--    1 root     root             0 Mar 31 04:05 file2
-rw-r--r--    1 root     root             0 Mar 31 04:05 file3
[node1] (local) root@10.1.20.4 ~
$ tar cvf archive file1 file2 file3
file1
file2
file3
[node1] (local) root@10.1.20.4 ~
$ ls -l
total 4
-rw-r--r--    1 root     root          2560 Mar 31 04:05 archive
-rw-r--r--    1 root     root             0 Mar 31 03:59 file.txt
-rw-r--r--    1 root     root             0 Mar 31 04:05 file1
-rw-r--r--    1 root     root             0 Mar 31 04:05 file2
-rw-r--r--    1 root     root             0 Mar 31 04:05 file3
オプション 説明
-c ファイルをアーカイブに追加するために新しいアーカイブを作成する createの略
-r アーカイブにファイルを追加する
-u アーカイブに、ファイルの更新日時がアーカイブより新しい場合にファイルを追加する
-x アーカイブを展開する extract(抽出)の意味
-t アーカイブに含まれるファイルのリストを表示する
-f <ファイル名> アーカイブファイルの名前を指定する
-v アーカイブに含まれるファイルの詳細を表示する
-z アーカイブをgzipで圧縮する
-j アーカイブをbzip2で圧縮する
-C <ディレクトリ> アーカイブを展開するディレクトリを指定する
tenryutenryu

リンク

https://4thsight.xyz/45975

ハードリンクはファイルの中身を直接参照し、シンボリックリンクはリンク元のファイルを参照する。

ハードリンク(ln)

同じファイルに対して複数の名前をつけることができるリンクの一種。同じファイルに対して複数のプログラムでアクセスする場合に便利。

file.txtのhogehogeがhardlink.txtで参照できる

$ echo hogehoge > file.txt
[node1] (local) root@10.1.31.4 ~
$ ls -l
total 4
-rw-r--r--    1 root     root             9 Mar 31 06:58 file.txt
[node1] (local) root@10.1.31.4 ~
$ cat file.txt
hogehoge
[node1] (local) root@10.1.31.4 ~
$ ln file.txt hardlink.txt
[node1] (local) root@10.1.31.4 ~
$ ls -l
total 8
-rw-r--r--    2 root     root             9 Mar 31 06:58 file.txt
-rw-r--r--    2 root     root             9 Mar 31 06:58 hardlink.txt
[node1] (local) root@10.1.31.4 ~
$ cat hardlink.txt
hogehoge

解除

$ unlink hardlink.txt
[node1] (local) root@10.1.31.4 ~
$ cat hardlink.txt
cat: can't open 'hardlink.txt': No such file or directory

シンボリックリンク(ln -s)

-sオプションをつけるとシンボリックリンク
ls -lコマンドでも確認できる。

$ ln -s file.txt synlink.txt
$ cat synlink.txt
hogehoge
$ ls -l
total 4
-rw-r--r--    1 root     root             9 Mar 31 06:58 file.txt
lrwxrwxrwx    1 root     root             8 Mar 31 07:06 synlink.txt -> file.txt
tenryutenryu

CPU

演算や処理を行うPCの頭脳

CPUの確認

cat /proc/cpuinfo でも確認可能

$ lscpu
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         46 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  2
  On-line CPU(s) list:   0,1
Vendor ID:               GenuineIntel
  BIOS Vendor ID:        Intel(R) Corporation
  Model name:            Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
    BIOS Model name:     Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz  CPU @ 2.5GHz
    BIOS CPU family:     179
    CPU family:          6
    Model:               85
    Thread(s) per core:  2
    Core(s) per socket:  1
    Socket(s):           1
    Stepping:            7
    BogoMIPS:            4999.99
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht s
                         yscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pcl
                         mulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand
                          hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms inv
                         pcid mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xget
                         bv1 xsaves ida arat pku ospke
Virtualization features: 
  Hypervisor vendor:     KVM
  Virtualization type:   full
Caches (sum of all):     
  L1d:                   32 KiB (1 instance)
  L1i:                   32 KiB (1 instance)
  L2:                    1 MiB (1 instance)
  L3:                    35.8 MiB (1 instance)
NUMA:                    
  NUMA node(s):          1
  NUMA node0 CPU(s):     0,1
Vulnerabilities:         
  Gather data sampling:  Unknown: Dependent on hypervisor status
  Itlb multihit:         KVM: Mitigation: VMX unsupported
  L1tf:                  Mitigation; PTE Inversion
  Mds:                   Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
  Meltdown:              Mitigation; PTI
  Mmio stale data:       Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
  Retbleed:              Vulnerable
  Spec rstack overflow:  Not affected
  Spec store bypass:     Vulnerable
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; Retpolines, STIBP disabled, RSB filling, PBRSB-eIBRS Not affected
  Srbds:                 Not affected
  Tsx async abort:       Not affected
項目 説明
Architecture x86_64 システムのアーキテクチャです。インテルおよびAMDなどのプロセッサメーカーによって開発された一連のプロセッサアーキテクチャの総称です。
CPU op-mode(s) 32-bit, 64-bit サポートされているCPUの動作モードです。32ビットと64ビットが使用できます。
Address sizes 46 bits physical, 48 bits virtual 物理アドレスと仮想アドレスのサイズです。
CPU(s) 2 システムに存在するCPUコア数です。コアの数が多いほど、CPUは複数のタスクを同時に実行できます。
On-line CPU(s) list 0, 1 オンライン状態のCPUコアのリスト
Vendor ID GenuineIntel CPUのベンダー情報(Intel)
Model name Intel Xeon Platinum 8259CL CPU @ 2.50GHz CPUのモデル名
CPU family 6 CPUファミリー
Thread(s) per core 2 各プロセッサコアが同時に実行できるスレッドの数を表します。
tenryutenryu

メモリ(主記憶装置)

コンピュータが実行中のプログラムやデータを一時的に保存するために使用される。

メモリの確認(top)

Mem: 2532904K used, 1386564K free, 14432K shrd, 1660K buff, 1651816K cached
CPU:   0% usr   0% sys   0% nic  97% idle   0% io   0% irq   0% sirq
Load average: 0.08 0.07 0.06 2/516 191
  PID  PPID USER     STAT   VSZ %VSZ CPU %CPU COMMAND
   39    13 root     S     732m  19%   0   0% containerd --config /var/run/docker/containerd/containerd.toml --log-level debug
   13     1 root     S    1489m  39%   0   0% dockerd
   32     1 root     S     6400   0%   0   0% sshd: /usr/sbin/sshd -o PermitRootLogin=yes -o PrintMotd=no [listener] 0 of 10-100 s
   16    14 root     S     4912   0%   1   0% /bin/bash -l
    1     0 root     S     1608   0%   0   0% /bin/sh -c cat /etc/hosts >/etc/hosts.bak &&     sed 's/^::1.*//' /etc/hosts.bak > /
  191    16 root     R     1600   0%   0   0% top
   14     1 root     S      848   0%   1   0% script -q -c /bin/bash -l /dev/null

メモリの確認(free)

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           3.7G      736.8M        1.3G       14.1M        1.7G        2.7G
Swap:       1020.0K           0     1020.0K

Swap(仮想メモリ)

メモリの容量が足りなくなった際に、ストレージ(HDなど)の容量をメモリとして扱う
当然、本来想定されている用途(データの保存など)とは異なるため、パフォーマンスは悪くなる。

補助記憶装置

ハードディスクとかUSBメモリとか

tenryutenryu

シェルスクリプト

#!/bin/bashは「シバン(shebang)」と呼ばれ、スクリプトを実行する際にどのシェルを使用するかをシステムに伝える

#!/bin/bash
echo "Hello World"

実行する場合はパスを付ける。ファイル名だけで実行する場合はパスを通す必要がある。

$ ./script.sh
Hello world
$ source script.sh
Hello world
[node1] (local) root@10.1.31.4 ~
$ bash script.sh
Hello world
[node1] (local) root@10.1.31.4 ~
$ . script.sh
Hello world

sourceコマンド(.だけでも同じ)で実行する場合は実行権限は不要

$ vi script1.sh
[node1] (local) root@10.1.31.4 ~
$ source script1.sh
test

変数

#!/bin/bash

MY_VAR="Hello World!"
echo $MY_VAR

実行結果を変数に格納する場合は以下のように変数=$(コマンド)を使用する

#!/bin/bash

MY_VAR=$(date)
echo $MY_VAR

引数

#!/bin/bash

echo "arg1: $1"
echo "arg2: $2"

$ . script3.sh arg1 arg2
arg1: arg1
arg2: arg2
特殊記号 説明
$0 スクリプト自体の名前を示します。
$1, $2, $3, … スクリプトに渡された位置引数を示します。$1 は最初の引数、$2 は2番目の引数、といった具体的な値を持ちます。
$# 引数の総数を示します。
$* すべての引数を一つの文字列として示します。
$@ 引数を個別の引用符で区切って示します。
$? 直前に実行されたコマンドの終了ステータスを示します。通常、0は成功を示し、非ゼロはエラーを示します。
$$ スクリプト自体のプロセスID(PID)を示します。

ユーザーに入力させる(read)

#!/bin/bash

echo "Enter your name:"
read name
echo "Hello! $name"

$ . script4.sh
Enter your name:
ssss
Hello! ssss

条件分岐

#!/bin/bash

echo "How old are you?:"
read age

if [ $age -ge 18 ]; then
 echo True
else
 echo False
fi
casein
"ケース1")
  #ケース1の条件 ;;
"ケース2")
  #ケース2の条件 ;;
"ケース3")
  #ケース3の条件 ;;
*)
  #ケースに当てはまらない場合の条件 ;;
esac

#!/bin/bash

fruit="apple"

case $fruit in
"apple")
echo "apple was chosen";;

"banana")
echo "banana was chosen";;

"cherry")
echo "cherry was chosen";;

*)
echo "nothing"
;;

esac

ループ

#!/bin/bash
for i in 1 2 3 4 5 
do
 echo "Number $i"
done
#!/bin/bash
for i in {1..100}
do
 echo "Number $i" 
done
#!/bin/bash
for i in $(seq 1 100)
do
 echo "Number $i"
done

ファイルやディレクトリのループ

mkdir /testdir
touch /testdir/file{1..5}

#!/bin/bash

for file in /testdir/*
do
 echo "File: $file"
done

while

#!/bin/bash

count=1
while [ $count -le 5 ]
do
 echo "Count: $count"
 count=$((count + 1))
done

比較演算子

演算子 意味
-eq 等しい(equal)
-ne 等しくない(not equal)
-lt より小さい(less than)
-le 以下(less than or equal)
-gt より大きい(greater than)
-ge 以上(greater than or equal)

文字列比較

演算子 意味
= 等しい
!= 等しくない
-z 文字列が空(zero)

ファイルテスト演算子

演算子 意味
-f ファイルが存在し、通常のファイルである
-d ディレクトリが存在する
-e ファイル/ディレクトリが存在する
-s ファイルが存在し、サイズが0より大きい
-r ファイルが読み取り可能である
-w ファイルが書き込み可能である
-x ファイルが実行可能である

複数条件組み合わせ

#!/bin/bash

if [ -e file1.txt ] && [ ! -e file2.txt ]; then
 echo "make file3.txt"
fi
tenryutenryu

DNS

FQDN(Fully Qualified Domain Name:完全修飾ドメイン名)

ホスト名とドメイン名をつなげて表示したもの
www.google.comやhost1.test.com
www, host1がホスト名、google.comやtest.comがドメイン名

名前解決

$ nslookup www.google.com
Server:         127.0.0.11
Address:        127.0.0.11:53

Non-authoritative answer:
Name:   www.google.com
Address: 142.251.42.164

Non-authoritative answer:
Name:   www.google.com
Address: 2404:6800:4004:823::2004

Address: 142.251.42.164がIPアドレス

tenryutenryu

bind9

DNSサーバー構築のためのOSS

apt-get update
apt-get install bind9 vim dnsutils

dnsutilsはnslookupコマンドを実行するためインストール

root@73d2944cc40e:/# dpkg -l bind9
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-=================================
ii  bind9          1:9.18.24-1  amd64        Internet Domain Name Server

iiで正常にインストールできている

ゾーン

DNSサーバーが管理するドメインの範囲のこと
test.comのドメインを管理する場合はゾーンがtest.comになる

レコード

名前解決をするために登録した情報
IPアドレスや名前のことで、ゾーンごとに格納される
レコードが保存されたファイルのことをゾーンファイルと呼ぶ

ゾーン情報の設定ファイル

/etc/bind/named.conf.default-zones
vimで見てみる

zone "test.com" {
 type master;
 file "/etc/bind/db.test.com";
};

ゾーンファイルの作成

/etc/bindにあるdb.localをコピーして使う

root@73d2944cc40e:/# cd /etc/bind
root@73d2944cc40e:/etc/bind# cp db.local db.test.com
root@73d2944cc40e:/etc/bind# vi db.test.com

@ IN SOA www.test.com. root.test.com. (
  2 ; Serial
  604800 ; Refresh
  86400 ; Retry
  2419200 ; Expire
  604800 ) ; Negative Cache TTL
;

@ IN NS www.test.com.
www IN A 10.0.6.4

IPアドレスはシミュレータのものを設定

nslookupコマンド

nslookup www.test.com 127.0.0.1

www.test.com: 問い合わせ内容
127.0.0.1 問い合わせ先
localhostにwww.test.comのIPアドレスを問い合わせてる

tenryutenryu

DNSレコードの種類

FQDNからIPアドレスを取得する正引きはAレコードを登録することで名前解決が可能

レコード 説明
Aレコード ホスト名に対応するIPアドレス
AAAAレコード ホスト名に対応するIPv6アドレス
PTRレコード IPアドレスに対応するホスト名
NSレコード ゾーンを管理するDNSサーバー
SOAレコード 管理情報を記述
CNAME ホスト名の別名
MX メールサーバー

Aレコード

FQDNからIPアドレスを名前解決するために登録
ゾーンファイルへは以下の書式で設定

[ホスト名] IN A [IPアドレス]

/etc/bind/db.test.comに以下を追加

host1  IN   A   192.168.1.1
www2   IN   A   172.16.1.1

再起動

/etc/init.d/named restart
root@512e4a56fe27:/etc/bind# nslookup host1.test.com 127.0.0.1
Server:         127.0.0.1
Address:        127.0.0.1#53

Name:   host1.test.com
Address: 192.168.1.1

root@512e4a56fe27:/etc/bind# nslookup www2 127.0.0.1
Server:         127.0.0.1
Address:        127.0.0.1#53

** server can't find www2: NXDOMAIN

root@512e4a56fe27:/etc/bind# nslookup www2.a 127.0.0.1
Server:         127.0.0.1
Address:        127.0.0.1#53

** server can't find www2.a: NXDOMAIN

root@512e4a56fe27:/etc/bind# nslookup www2.test.com
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
Name:   www2.test.com
Address: 69.167.164.199

ドメインが誤っているとエラーになる

SOAレコード

@       IN      SOA     www.test.com. root.test.com. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;

@: ドメイン名(@はzone-default.comで定義されたドメイン名)
SOA: レコードの種類
www.test.som. : DNSサーバーのドメイン名
root.test.com. : 管理者名(なんでもいいらしい)
Serial:シリアル番号
Refresh: 更新チェックの間隔
Retry: リトライ感覚
Expire:問い合わせの期限
Negative Cache TTL: ネガティブキャッシュの時間

SOAレコードの確認

root@512e4a56fe27:/etc/bind# nslookup -type=SOA google.com
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
google.com
        origin = ns1.google.com
        mail addr = dns-admin.google.com
        serial = 621114726
        refresh = 900
        retry = 900
        expire = 1800
        minimum = 60

Authoritative answers can be found from:

root@512e4a56fe27:/etc/bind# nslookup -type=SOA www.test.com
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
www.test.com    canonical name = h186602-geo.txproxy.com.

Authoritative answers can be found from:
txproxy.com
        origin = ns-495.awsdns-61.com
        mail addr = awsdns-hostmaster.amazon.com
        serial = 1
        refresh = 7200
        retry = 900
        expire = 1209600
        minimum = 86400

root@512e4a56fe27:/etc/bind#

NSレコード

ドメインの名前解決をする
NSはネームサーバーの略

@       IN      NS      www.test.com.

@は/etc/bind/named.conf.default-zonesファイルで定義したドメイン名を省略したもの

root@512e4a56fe27:/etc/bind# nslookup -type=ns google.com
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
google.com      nameserver = ns2.google.com.
google.com      nameserver = ns4.google.com.
google.com      nameserver = ns1.google.com.
google.com      nameserver = ns3.google.com.

Authoritative answers can be found from:

複数のネームサーバーが登録されている

ちなみに、NSレコードの終わりは.(ドット)で終わっています。
ゾーンファイルには、.(ドット)をつけないと自動でドメイン名を補完する機能があります。

CNAME

ホスト名の別名

alias IN CNAME www.test.com.
root@512e4a56fe27:/etc/bind# nslookup alias.test.com 127.0.0.1
Server:         127.0.0.1
Address:        127.0.0.1#53

alias.test.com  canonical name = www.test.com.
Name:   www.test.com
Address: 10.2.56.4
tenryutenryu

DNSサーバーの指定

nslookupコマンドで毎回127.0.0.1を指定するのは面倒
問い合わせ先のDNSサーバーを指定する

/etc/resolv.confのnameserverを編集

search ap-northeast-1.compute.internal
options ndots:0

nameserver 127.0.0.1
nameserver 8.8.4.4

127.0.0.1を指定しなくても問い合わせることができる

root@512e4a56fe27:/etc/bind# nslookup www.test.com
Server:         127.0.0.1
Address:        127.0.0.1#53

Name:   www.test.com
Address: 10.2.56.4
tenryutenryu

Webサーバーの構築

Apache2のインストール

Debianのコンテナ立ち上げる

docker run -it -p 80:80 debian /bin/bash

apt-get install apache2

Apacheサーバーの起動

service apache2 start
#もしくは
/etc/init.d/apache2 start

ドキュメントルート

ドキュメントルートの設定は/etc/apache2/sites-enabled/000-default.confを確認する

root@da4654436ef5:/# cat /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

ドキュメントルートの変更

/etc/apache2/apache2.conf

root@da4654436ef5:/# cat /etc/apache2/apache2.conf
# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.4/ for detailed information about
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
# hints.
#
#
# Summary of how the Apache 2 configuration works in Debian:
# The Apache 2 web server configuration in Debian is quite different to
# upstream's suggested way to configure the web server. This is because Debian's
# default Apache2 installation attempts to make adding and removing modules,
# virtual hosts, and extra configuration directives as flexible as possible, in
# order to make automating the changes and administering the server as easy as
# possible.

# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
#       /etc/apache2/
#       |-- apache2.conf
#       |       `--  ports.conf
#       |-- mods-enabled
#       |       |-- *.load
#       |       `-- *.conf
#       |-- conf-enabled
#       |       `-- *.conf
#       `-- sites-enabled
#               `-- *.conf
#
#
# * apache2.conf is the main configuration file (this file). It puts the pieces
#   together by including all remaining configuration files when starting up the
#   web server.
#
# * ports.conf is always included from the main configuration file. It is
#   supposed to determine listening ports for incoming connections which can be
#   customized anytime.
#
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
#   directories contain particular configuration snippets which manage modules,
#   global configuration fragments, or virtual host configurations,
#   respectively.
#
#   They are activated by symlinking available configuration files from their
#   respective *-available/ counterparts. These should be managed by using our
#   helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
#   their respective man pages for detailed information.
#
# * The binary is called apache2. Due to the use of environment variables, in
#   the default configuration, apache2 needs to be started/stopped with
#   /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
#   work with the default configuration.


# Global configuration
#

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the Mutex documentation (available
# at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"

#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
#Mutex file:${APACHE_LOCK_DIR} default

#
# The directory where shm and other runtime files will be stored.
#

DefaultRuntimeDir ${APACHE_RUN_DIR}

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5


# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log

#
# LogLevel: Control the severity of messages logged to the error_log.
# Available values: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the log level for particular modules, e.g.
# "LogLevel info ssl:warn"
#
LogLevel warn

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf


# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

#<Directory /srv/>
#       Options Indexes FollowSymLinks
#       AllowOverride None
#       Require all granted
#</Directory>




# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#
AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>


#
# The following directives define some format nicknames for use with
# a CustomLog directive.
#
# These deviate from the Common Log Format definitions in that they use %O
# (the actual bytes sent including headers) instead of %b (the size of the
# requested file), because the latter makes it impossible to detect partial
# requests.
#
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

設定ファイル

グローバルなサーバー設定

  • /etc/apache2/apache2.conf(Ubuntu / Debian系)
  • /etc/httpd/conf/httpd.conf(CentOS / RHEL系)

sites-enabledディレクトリ

Apache2では仮想ホスト(VirtualHost)を使用して複数のドメインやウェブサイトを同じサーバー上でホスティングできる。

  • etc/apache2/sites-available/(Ubuntu / Debian系)
  • /etc/httpd/conf.d/(CentOS / RHEL系)
    ディレクトリが作成され、デフォルトの設定として000-default.confファイルが作成される

IPアドレスの制限をかける

/etc/apache2/apache2.conf
<Directory>のとこ
ディレクトリ単位で設定する
/var/wwwディレクトリにWebアクセスを許可したい場合

<Directory /var/www/>
  Require all granted
</Directory>

/var/wwwディレクトリにWebアクセスを拒否したい場合

<Directory /var/www/>
  Require all denied
</Directory>

Directory / よりもDirectory /var/www/のような具体的な指定の方が優先される

特定のIPアドレスからのアクセスを許可したい場合

<Directory [設定するディレクトリ]>
  Require ip [IPアドレス]
</Directory>

特定のIPアドレスからのアクセスを拒否したい場合
全てのアクセスを許可するけど、特定のIPアドレスのみ拒否

<Directory [設定するディレクトリ]>
  Require all granted
  Require not ip [IPアドレス]
</Directory>

## Basic認証
Basic認証はパスワードをそのままサーバーに送るためセキュリティリスクが高い
/etc/apache2/apache2.config
```bash
<Directory /var/www/html>
  AuthUserfile /etc/apache2/.htpasswd
  AuthName "basic"
  AuthType Basic
  Require valid-user
</Directory>

ユーザーの登録

htpasswd -c /etc/apache2/.htpasswd user

/etc/apache2/.htpasswdに保存される

Digest認証

パスワードをハッシュ化して送る

ログ

apache2のアクセスログは、/var/log/apache2/access.logに保存されている

tenryutenryu

プロキシサーバー

Squidで構築
今回は以下の構成

  • クライアント(node3)
  • プロキシサーバー(node1)
  • webサーバー(node2)

Squid

設定は/etc/squid/squid.conf
アクセスを許可する。デフォルトでは特定場所からのアクセスのみ許可されている

http_access deny all

以下のようにすべてのアクセスを許可するよう変更

http_access allow all

再起動

service squid restart
Restarting Squid HTTP Proxy: squid2024/04/04 23:15:39| WARNING: BCP 177 violation. Detected non-functional IPv6 loopback.
squid[3930]: Squid Parent: will start 1 kids

apacheの時もだったけどserviceコマンドだとコケる

/etc/init.d/squid restart
tenryutenryu

プロキシサーバー経由でのアクセス

curlのxオプションをつける

$ curl http://10.2.151.5 -x http://10.2.151.4:3128
node2 web page

http://10.2.151.4:3128がプロキシサーバー

tenryutenryu

Squidのアクセス制限

2つの設定が必要
1.条件を定義する

acl [acl名] [aclタイプ] []

2.定義した条件を許可するか拒否するのかを設定する

http_access [deny もしくは allow] [acl名]

10.0.0.0/16のクライアントのみアクセス

acl mynet src 10.0.0.0/16
http_access allow mynet
http_access deny all
tenryutenryu

PacketTracer

CISCOが開発するネットワークシミュレーター

IPアドレス復習

192.168.1.1と192.168.1.2は同じネットワーク192.168.1に属している

ネットワークアドレス

192.168.1.0/24のようにホスト部が0のIPアドレスで、そのネットワーク自体を表す
192.168.1.1/24のPCが所属するネットワークは、192.168.1.0/24

ブロードキャストアドレス

192.168.1.255/24のようにホスト部が255のIPアドレスで、ネットワークに接続されている全ての機器へ通信するためのアドレス

ルーター

違うネットワークで通信する場合はルーターが必要

ルーターで設定するにはコンフィグレーションモードに移行する必要がある

Router> enable
Router# conf t
Router(config)# interface gi 0/0/0
Router(config-if)# ip address 192.168.1.254 255.255.255.0
Router(config-if)# no shutdown
tenryutenryu

CISCOのコマンドモードについて

  • ユーザーモード
  • 特権モード(イネーブルモード)
  • コンフィグレーションモード

IPアドレスの設定はコンフィグレーションモードで可能

ユーザーモード

Router>

特権モードに移行する場合はenableコマンド

Router> enable

特権モード

Router# show run

特権モードからユーザーモードに移行する場合はdisable

Router# disable
↓
Router>

コンフィグレーションモード

特権モードからconfigure terminalコマンドを実行して移行

Router# conf t
↓
Router(conf)#

特権モードに戻る

Router(conf)# exit
↓
Router#

インターフェースコンフィグレーションモード

インターフェースの設定を行う場合は、コンフィグレーションモードからさらにインターフェースコンフィグレーションモードに移行

Router(conf)# int gi 0/0/1
↓
Router(conf-if)#
tenryutenryu

ルーター

異なるネットワークで通信する場合に設定する。
192.168.1.1と192.168.2.1のような異なるネットワークで接続する場合、192.168.1.254と192.168.2.254の設定を行うことで通信可能

インターフェースの設定
まずインターフェースモードへ移行

Router(config)# interface gi 0/0/0

IPアドレスを設定する。

Router(config-if)# ip address 192.168.1.254 255.255.255.0
Router(config)# interface gi 0/0/1
Router(config-if)# ip address 192.168.2.254 255.255.255.0

その後にPCのデフォルトゲートウェイで192.168.1.254と192.168.2.254を設定することで通信可能

tenryutenryu

ルーティング

ルーターのコンフィグレーションモードで以下を設定する

Router1(config)# ip route 172.16.1.0 255.255.255.0 10.0.0.2

Router1は172.16.1.0のネットワークへのアクセスは、10.0.0.2のネットワーク(ルーター2)へ送る

ルーティング設定はルーティングテーブルで確認
特権モードで実行

Router1# show ip route
()
S 172.16.1.0/24 [1/0] via 10.0.0.2

viaは経由という意味

tenryutenryu

スイッチ

複数のネットワークデバイスを接続し、データの転送を制御する装置
スイッチの制御にはMACアドレスが使用される

MACアドレス

機器固有で世界で唯一のアドレス
MACアドレステーブルはMACアドレスがどこのポートに接続されているかを記載した表

特権モードでswitchを確認

Switch>enable
Switch#show mac-address-table
Switch>enable
Switch#show mac-address-table
          Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----

Switch#

最初は空になっていて、通信した後に登録される

Switch#show mac-address-table
          Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----

   1    0007.ec0d.816b    DYNAMIC     Fa0/1
   1    00e0.f997.e9a7    DYNAMIC     Fa0/2
tenryutenryu

NAT

IPアドレスを変換する
グローバルIPとローカルIPの変換に使用される

ローカルIP

LAN内で使用されるIPアドレス

グローバルIP

インターネット(WAN)で使用するIPアドレス
プロバイダによって割り当てられる

tenryutenryu

ハードウェア

https://mirumanoblog.com/memory-cpu/

メモリ

処理を行う場所。よく例えられるのが作業机。広ければ広いほど効率よく処理できる

CPU

作業を行う「人」の役割。同じメモリ(作業机)で作業を行う場合でも、優秀な人の方が効率よく処理できる。

メモリをハイスペックにする方が処理としてはよくなるらしい。

tenryutenryu

デバイスファイル

ハードウェアへのアクセスを簡単にするためにつかわれる
キーボードやプリンタを使えるようにするにはデバイスドライバをインストールする必要がある
デバイスドライバはデバイスを動かすためのもの

ls /dev
$ ls /dev
autofs           loop6            stdin            tty24            tty42            tty60            vcs5
btrfs-control    loop7            stdout           tty25            tty43            tty61            vcs6
console          mapper           tty              tty26

デバイスファイルを作成する際のルールは以下のディレクトリのファイルを確認する

ls /lib/udev/rules.d

/proc

Linuxが認識しているデバイス情報

tenryutenryu

コンピュータ起動時の初期プロセス

init(イニット)ともいう
SysVinit, Upstart, systemdなどがある

SysVinit

Unix系の起動プロセス

initプロセスの開始
initが/etc/inittabのファイルに書かれたプロセスの実行
initが/etc/rc.sysinitスクリプトを読み込む
initが/etc/rcスクリプトを実行
/etc/rcスクリプトが、/etc/rc〇〇.dディレクトリ以下のスクリプトを実行する

$ cat /etc/inittab
# デフォルトランレベル(ランレベル3を指定)
id:3:initdefault:# ブート時の処理(/etc/rc.d/rc.sysinitを実行)
si::sysinit:/etc/rc.d/rc.sysinit# ランレベルごとの処理(各ランレベル用のrcスクリプトを実行し、その終了を待つ)
l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6

# 1度だけ実行される処理(/sbin/updateを実行)
ud::once:/sbin/update

# [Ctrl]+[Alt]+[Delete]キーを押したときの処理
ca::ctrlaltdel:/sbin/shutdown -t3 -r now

# 電源オフ時の処理
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"

# 電源オン時の処理
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"

# 端末制御(ランレベル2~5で/sbin/mingettyを実行。終了されると再実行)
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

# ランレベル5時のログイン処理(/etc/X11/prefdmを実行。終了されると再実行)
x:5:respawn:/etc/X11/prefdm -nodaemon

各設定の書式は、以下のようになっています。

id:ユニークな文字列(1~4文字)
runlevel:ランレベルを指定(後ほど解説)
action:プロセスの起動あるいは終了時の動作
process:起動するプログラムを指定

Upstart

プロセスを並行で起動するため短時間で起動可能。
イベント駆動を採用している。

systemd

多くのLinuxディストリビューションで採用されている
初期プロセスの代わりにsystemdプロセスが起動する
systemdではUnitという単位で処理を管理する

Webサービスを起動するユニットは、「httpd.service」

systemctl

webサービスを起動するユニットhttpd.serviceを起動

systemctl start httpd.service

停止

systemctl stop httpd.service

再起動

systemctl restart httpd.service
tenryutenryu

シェルの操作

キーバインド 操作
Ctrl + a 行の先頭に移動
Ctrl + e 行の末尾に移動
Ctrl + ← (左矢印キー) 前の単語に移動
Ctrl + → (右矢印キー) 次の単語に移動
Ctrl + h 一文字削除 (バックスペース)
Ctrl + d 一文字削除 (デリート)
Ctrl + w 一単語削除 (前方)
Alt + d 一単語削除 (後方)
Ctrl + t カーソルを一文字挿入 (挿入モードへ切り替え)
Ctrl + p コマンド履歴の前方向スクロール
Ctrl + n コマンド履歴の後方向スクロール
Ctrl + l コマンドラインをクリア
Ctrl + c コマンドの中断
Ctrl + z コマンドの一時停止

Macで試したら行の先頭末尾への移動はctrlでよかったけど前後の単語への移動はスタート(option)じゃないとダメだった

tenryutenryu

コマンド

コマンド 説明
history 最近実行したコマンドの履歴を表示します。
man マニュアルページを表示します。コマンドの使い方やオプションなどの詳細な情報が得られます。
ls カレントディレクトリ内のファイルとディレクトリをリスト表示します。
cp ファイルをコピーします。
mv ファイルやディレクトリを移動したり、名前を変更したりします。
mkdir 新しいディレクトリを作成します。
rm ファイルを削除します。
rmdir 空のディレクトリを削除します。
touch 新しい空のファイルを作成します。または、既存のファイルの最終アクセスおよび変更時刻を更新します。
file ファイルの種類や形式を判定します。
tenryutenryu

manコマンド

コマンドの説明を表示してくれる

Debianのコンテナ実行してパッケージを検索

root@cff74f02ddc1:/# apt-cache search manpages
erlang-manpages - Erlang/OTP manual pages
freebsd-manpages - Manual pages for a GNU/kFreeBSD system
libfreefem-dev - Development library, header files and manpages
go-md2man - utility to create manpages from markdown
golang-github-cpuguy83-go-md2man-v2-dev - utility to create manpages from markdown (source)
golang-github-containers-image - Configuration files and manpages for github.com/containers repositories
isc-dhcp-common - common manpages relevant to all of the isc-dhcp packages
manpages - Manual pages about using a GNU/Linux system
manpages-dev - Manual pages about using GNU/Linux for development
manpages-ja - Japanese version of the manual pages (for users)
manpages-ja-dev - Japanese version of the manual pages (for developers)

-jaとか日本版もあったりいろんな国のものがあるらしい

manなくてもhelpオプションでも解説してくれる

root@cff74f02ddc1:/# pwd --help
pwd: pwd [-LP]
    Print the name of the current working directory.
    
    Options:
      -L	print the value of $PWD if it names the current working
    		directory
      -P	print the physical directory, without any symbolic links
    
    By default, `pwd' behaves as if `-L' were specified.
    
    Exit Status:
    Returns 0 unless an invalid option is given or the current directory
    cannot be read.
tenryutenryu

cpコマンド

オプション 説明
-a ファイルの属性を保持したままコピー
-b バックアップを作成してからコピー
-i 上書きの確認を求める
-n 同名のファイルが存在する場合はスキップ
-r / -R ディレクトリを再帰的にコピー
-u コピー先が古い場合のみコピー
-v 詳細な操作を表示
--backup[=CONTROL] バックアップの方法を指定
root@cff74f02ddc1:/# mkdir testdir2
root@cff74f02ddc1:/# ls -l | grep testdir
drwxr-xr-x   2 root root 4096 Apr 10 00:05 testdir
drwxr-xr-x   2 root root 4096 Apr 10 00:06 testdir2
root@cff74f02ddc1:/# cp testdir testdir2
cp: -r not specified; omitting directory 'testdir'
root@cff74f02ddc1:/# cp -r testdir testdir2
root@cff74f02ddc1:/# ls -l testdir2
total 4
drwxr-xr-x 2 root root 4096 Apr 10 00:07 testdir

-iオプションで上書きの確認を求められる

tenryutenryu

メタキャラクタ

アスタリスク*

*(アスタリスク)は0個以上の文字と一致

$ ls /etc/*.conf
/etc/ca-certificates.conf  /etc/resolv.conf
/etc/e2scrub.conf          /etc/sysctl.conf
/etc/krb5.conf             /etc/udhcpd.conf
/etc/mke2fs.conf           /etc/xtables.conf
/etc/nsswitch.conf
root@cff74f02ddc1:/# touch 1.js 2.js 3.js
root@cff74f02ddc1:/# ls *.js 
1.js  2.js  3.js

クエスチョン?

root@cff74f02ddc1:/# touch file1 file2 test1
root@cff74f02ddc1:/# ls file?
file1  file2

[]

root@cff74f02ddc1:/# touch file3
root@cff74f02ddc1:/# ls file[12]
file1  file2
root@cff74f02ddc1:/# ls -l | grep js
-rw-r--r--   1 root root    0 Apr 10 00:26 1.js
-rw-r--r--   1 root root    0 Apr 10 00:26 2.js
-rw-r--r--   1 root root    0 Apr 10 00:26 3.js
root@cff74f02ddc1:/# ls [12].js
1.js  2.js
root@cff74f02ddc1:/# ls file[!12]
file3

{}

root@cff74f02ddc1:/# touch file{1..10}
root@cff74f02ddc1:/# ls -l file?
-rw-r--r-- 1 root root 0 Apr 10 00:30 file1
-rw-r--r-- 1 root root 0 Apr 10 00:30 file2
-rw-r--r-- 1 root root 0 Apr 10 00:30 file3
-rw-r--r-- 1 root root 0 Apr 10 00:30 file4
-rw-r--r-- 1 root root 0 Apr 10 00:30 file5
-rw-r--r-- 1 root root 0 Apr 10 00:30 file6
-rw-r--r-- 1 root root 0 Apr 10 00:30 file7
-rw-r--r-- 1 root root 0 Apr 10 00:30 file8
-rw-r--r-- 1 root root 0 Apr 10 00:30 file9
tenryutenryu

リダイレクト演算子

$ cat hogehoge 2> err.txt
[node1] (local) root@10.0.52.4 ~
$ cat err.txt
cat: can't open 'hogehoge': No such file or directory

通常の大なり一つだとただエラーが表示されるだけだが、2>とするとエラーの内容をファイルに書き込むことができる

echoやcatコマンドなどのプログラムの表示結果を標準出力といい、プログラムの正常動作とは関係ないエラーの出力を標準エラー出力と言う

標準出力のリダイレクトは、>を使い、標準エラー出力のリダイレクトは、2>を使う

標準出力(&1)と標準エラー出力(2)を同時に保存したい場合は以下
“2>&1″は、標準エラー出力 (2) を標準出力 (&1) にリダイレクトするという意味

echo test > file.txt 2>&1
tenryutenryu

catコマンド

Head Head
-n 行番号を表示する。
-b 空白行を除いて行番号を表示する。
-s 連続する空白行を一つにまとめて表示する。
-E 各行の末尾に$を表示する。
-T タブ文字を^Iとして表示する。
$ cat -nb file.txt
     1  cat: can't open 'hogehoge': No such file or director
     2  y

     3  a




     4  d
tenryutenryu

nlコマンド

$ nl file.txt
     1  cat: can't open 'hogehoge': No such file or director
     2  y
       
     3  a
       
       
       
       
     4  d

catの-nbとほぼ一緒?

tenryutenryu

odコマンド

octal dump
ファイルの内容を8進数や16進数で表示する

$ od -b /etc/passwd
0000000 162 157 157 164 072 170 072 060 072 060 072 162 157 157 164 072
0000020 057 162 157 157 164 072 057 142 151 156 057 142 141 163 150 012
tenryutenryu

headコマンド

ファイルの先頭部分を表示する

$ head -20 /etc/group
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
sys:x:3:root,bin,adm
adm:x:4:root,adm,daemon
tty:x:5:
disk:x:6:root,adm
lp:x:7:lp
mem:x:8:
kmem:x:9:
wheel:x:10:root
floppy:x:11:root
mail:x:12:mail
news:x:13:news
uucp:x:14:uucp
man:x:15:man
cron:x:16:cron
console:x:17:
audio:x:18:
cdrom:x:19:
tenryutenryu

tailコマンド

ファイルの末尾を表示する
head <=> tail
tail -fでファイルの更新を監視していたけど本来の用途を知らなかった

$ tail /etc/group
nofiles:x:200:
smmsp:x:209:smmsp
locate:x:245:
abuild:x:300:
utmp:x:406:
ping:x:999:
nogroup:x:65533:
nobody:x:65534:
docker:x:2375:
dockremap:x:101:dockremap

headと同様に行数指定も可能

$ tail -n 7 -f /etc/group
abuild:x:300:
utmp:x:406:
ping:x:999:
nogroup:x:65533:
nobody:x:65534:
docker:x:2375:
dockremap:x:101:dockremap
tenryutenryu

cutコマンド

$ cut -c1-5 /etc/passwd
root:
bin:x
daemo

-dでデリミタを指定することができる
:で区切って7番目のフィールドを取得

$ cut -d: -f 7 /etc/passwd
/bin/bash
/sbin/nologin
/sbin/nologin
tenryutenryu

joinコマンド

ファイルを共通のキーで結合する
file1.txt

1 tanaka
2 sato
3 suzuki

file2.txt

1 25
2 30
3 40
$ join -1 1 -2 1 file1.txt file2.txt
1 tanaka 25
2 sato 30
3 suzuki 40
tenryutenryu

pasteコマンド

複数のファイルを行ごとに結合する

paste file1.txt file2.txt

-dでデリミタを使用できる

$ paste -d: file1.txt file2.txt
1 tanaka:1 25
2 sato:2 30
3 suzuki:3 40
tenryutenryu

trコマンド

標準入力で読み込まれた文字列を変換、削除する

$ echo hello | tr l L
heLLo
$ echo hello | tr -d l
heo

重複した文字列を一つにまとめる

$ echo helllllllllllllllo | tr -s l
helo
tenryutenryu

sortコマンド

fileの内容をsortして出力することができる
ファイルの中身

b
c
a
f
d
e
1
3
4

sortする

$ sort file.txt
1
3
4
a
b
c
d
e
f

降順とかもできる

$ sort -r file.txt
f
e
d
c
b
a
4
3
1
tenryutenryu

splitコマンド

/etc/passwdファイルを10行ごとに分割

split [オプション] [入力ファイル] [出力ファイルの先頭]
$ split -l 10 /etc/passwd split.
[node1] (local) root@10.0.90.4 ~
$ ls
file.txt  split.aa  split.ab  split.ac
[node1] (local) root@10.0.90.4 ~
$ cat split.aa
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/mail:/sbin/nologin
news:x:9:13:news:/usr/lib/news:/sbin/nologin

-lは行単位で分割、-bはバイト単位で分割

tenryutenryu

prコマンド

印刷用に整形したりテキストの整形や列の配置を行う

pr -l 30 +1:1 /etc/services

2023-09-27 06:14                  /etc/services                   Page 1


# Network services, Internet style
#
# Updated from https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml .
#
# New ports will be added on request if they have been officially assigned
# by IANA and used in the real-world or are needed by a debian package.
# If you need a huge list of used numbers please install the nmap package.

tcpmux          1/tcp                           # TCP port service multiplexer
echo            7/tcp
echo            7/udp
discard         9/tcp           sink null
discard         9/udp           sink null
systat          11/tcp          users
daytime         13/tcp
daytime         13/udp
netstat         15/tcp
qotd            17/tcp          quote
chargen         19/tcp          ttytst source
chargen         19/udp          ttytst source
tenryutenryu

fmtコマンド

-wが行の最大幅

$ fmt -w 1 test.txt
I
am
linux
$ fmt -w 5 test.txt
I am
linux
tenryutenryu

expandコマンド

タブをスペースへ変換

expand test.txt

unexpandコマンド

先頭の空白をタブへ変換

unexpand test.txt
tenryutenryu

wcコマンド

word count
テキストファイル内の単語、行数、文字数をカウントする

行数、単語数、文字数

$ wc /etc/passwd
  28   31 1237 /etc/passwd
tenryutenryu

正規表現

$ cat  sample.txt
test1
sample
abc 2

文字列の検索

$ grep -E test sample.txt
test1
$ grep -E a.c sample.txt
abc 2
$ grep -E ^sa sample.txt
sample
$ grep -E e$ file.txt
e

マッチした部分だけ抜き出す

root@6c320b6e0130:/# cat file.txt
test1234
abcd1234
root@6c320b6e0130:/# grep -o -E [1-9] file.txt
1
2
3
4
1
2
3
4

ディレクトリの下層まで検索

root@6c320b6e0130:/# echo test1234 > testdir/file1.txt
root@6c320b6e0130:/# echo test1234 > testdir/file2.txt
root@6c320b6e0130:/# grep -r test testdir
testdir/file2.txt:test1234
testdir/file1.txt:test1234
tenryutenryu

shutdownコマンド

システムの再起動やシャットダウンが可能
shutdown -h now
がデフォルトで、-hはhalt(止める)の意味
-rだと再起動、-tでタイマーの設定が可能

tenryutenryu

dmesgコマンド

システム起動時にカーネルがどのような処理を行ったかを表示する
display message

headで最初の

$ dmesg | head
[    0.000000] Linux version 6.1.55-75.123.amzn2023.x86_64 (mockbuild@ip-10-0-62-35) (gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2), GNU ld version 2.39-6.amzn2023.0.9) #1 SMP PREEMPT_DYNAMIC Tue Sep 26 20:06:16 UTC 2023
[    0.000000] Command line: BOOT_IMAGE=(hd0,gpt1)/boot/vmlinuz-6.1.55-75.123.amzn2023.x86_64 root=UUID=db2477a6-ca5d-4f37-a4d1-d16dd2369669 ro console=tty0 console=ttyS0,115200n8 nvme_core.io_timeout=4294967295 rd.emergency=poweroff rd.shell=0 selinux=1 security=selinux quiet
[    0.000000] KASLR enabled
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000bbccdfff] usable
[    0.000000] BIOS-e820: [mem 0x00000000bbcce000-0x00000000bbf4dfff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000bbf4e000-0x00000000bbf5dfff] ACPI data
[    0.000000] BIOS-e820: [mem 0x00000000bbf5e000-0x00000000bbfddfff] ACPI NVS
[    0.000000] BIOS-e820: [mem 0x00000000bbfde000-0x00000000bff7bfff] usable

tenryutenryu

modprobeコマンド

mod probe(探る、調査する)
カーネルモジュールを自動で読み込んだり、依存解決をしたりする
カーネルモジュールをロードする

modprobe usb-storage
tenryutenryu

trコマンド

root@edcf271b9daf:/# tr 'a-z' 'A-Z'
hello
HELLO
こんにちは
こんにちは
^C
tenryutenryu

fgrepコマンド

入力された文字列をただの文字列として検索する
.a[^b]とかで検索しても、正規表現ではなくこの文字列が検索される

grepコマンドで-fオプションつけても同じ

tenryutenryu

psコマンド

# apt install procps
# ps
  PID TTY          TIME CMD
    1 pts/0    00:00:00 bash
  361 pts/0    00:00:00 bash
  366 pts/0    00:00:00 ps
tenryutenryu

ジョブ

コマンドライン一行で実行された処理単位のこと

バッググラウンドジョブ

裏側で実行され、次のコマンド入力ができる
&アンパサンドを末尾につけるとバックグラウンドジョブになる

フォアグラウンドジョブ

実行中のジョブに関する操作入力はできるが、次のコマンドは入力できない

tenryutenryu

nohupコマンド

ログアウトしてもコマンドを実行したい場合に使用したい
no hung upの略

nohup コマンド &
ログアウトしてもバックグラウンドで実行

tenryutenryu

FHS(FIlesystem Fierarchy Standard)

ディレクトリ構造の標準を定めた仕様書。多くのLinuxディストリビューションでも準拠されている。

tenryutenryu

niceコマンド

プロセスの優先度を指定するコマンド。
-20から19までを指定することができ、-20が最も優先度が高い

nice -n -20 ps -l

reniceコマンド

実行中のプロセスの優先度を変更

tenryutenryu

システム管理コマンド

top

プロセスやCPU、メモリなどの状況を表示

Mem: 1854580K used, 2064896K free, 13948K shrd, 24K buff, 1265812K cached
CPU:   0% usr   0% sys   0% nic  99% idle   0% io   0% irq   0% sirq
Load average: 0.00 0.00 0.00 2/340 283
  PID  PPID USER     STAT   VSZ %VSZ CPU %CPU COMMAND
   13     1 root     S    1925m  50%   0   0% dockerd
   38    13 root     S    1236m  32%   1   0% containerd --config /var/run/docker/containerd/containerd.toml --log-level debug
   36     1 root     S     6480   0%   1   0% sshd: /usr/sbin/sshd -o PermitRootLogin=yes -o PrintMotd=no [listener] 0 of 10-100 s
   15    14 root     S     5048   0%   0   0% /bin/bash -l
    1     0 root     S     1632   0%   1   0% /bin/sh -c cat /etc/hosts >/etc/hosts.bak &&     sed 's/^::1.*//' /etc/hosts.bak > /
  283    15 root     R     1624   0%   0   0% top
   14     1 root     S      864   0%   1   0% script -q -c /bin/bash -l /dev/null

freeコマンド

メモリの状況を表示する

$ free
              total        used        free      shared  buff/cache   available
Mem:        3919476      489972     2060612       13948     1368892     3159980
Swap:             0           0           0

uptimeコマンド

システムの稼働状況や負荷状況などを表示する

$ uptime
 02:35:22 up 6 days, 15:45,  0 users,  load average: 0.13, 0.03, 0.00
tenryutenryu

ハードディスクの接続形態

SATA(サタ)

シリアルATA
ハードディスクとマザーボードを接続する、一般的なPCで使用されるインターフェース

SAS(サス)

複数のデバイスを接続し品質が高い通信品質と冗長性がある
データセンターなどで使用される。SATAより高品質で価格が高い

SCSI(スカジー)

こっちもハードディスクなどの接続で使用される

USB

みんな知ってるやつ

tenryutenryu

ファイルシステム

ディスク上のデータをファイルとして取り扱うための仕組み。

ハードディスクはセクタと呼ばれる区画がある
ファイルシステムがあるおかげでcp file.txt dirのようなコマンドで操作することができるが、ない場合は84387セクタのデータを読み取る、といった形で操作しなければならない

現在のlinuxで最も使われているのはext4と呼ばれるファイルシステム

tenryutenryu

パーティション

ハードディスクなどのストレージデバイスを論理的に分割した区画のこと
物理的なディスクを複数の論理的なセクションに分け、それぞれ独立して利用できるようになる
パーティションを作ることでバックアップの管理が容易になったりする

パーティションには基本パーティション、拡張パーティション、論理パーティションの3つの種類がある

tenryutenryu

mkfsコマンド

make filesystem
パーティションにファイルシステムを作成する

mkfs -t ext4 /dev/nvme0n1p127

mke2fsコマンド

make ext2 filesystemの略で、もともとファイルシステムext2を作成するためのコマンドだったが、のちのバージョンでext3とext4に対応した

-jでext3、-tでext4を作成する

tenryutenryu

lsblkコマンド

linuxで利用可能なブロックデバイス(HD, SSD USBドライブなど)を一覧で表示する

$ lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
nvme0n1       259:0    0  80G  0 disk 
├─nvme0n1p1   259:1    0  80G  0 part /var/lib/docker
│                                     /etc/hosts
│                                     /etc/hostname
│                                     /etc/resolv.conf
├─nvme0n1p127 259:2    0   1M  0 part 
└─nvme0n1p128 259:3    0  10M  0 part 
$ lsblk -f /dev/nvme0n1p127
NAME        FSTYPE FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
nvme0n1p127 ext4               b8bb14ea-6ca9-4f1c-b787-a39c1c9d5902  
tenryutenryu

mkswapコマンド

スワップ領域を作成するために使用される

mkswap /dev/nvme0n1p127

swap領域として使用するにはswaponコマンドを使用する

swapon /dev/nvme0n1p127
tenryutenryu

dfコマンド

disk free
ファイルシステムやパーティションの使用容量や空き容量を表示する

$ df -h
Filesystem                Size      Used Available Use% Mounted on
overlay                  79.9G     10.2G     69.8G  13% /
tmpfs                    64.0M         0     64.0M   0% /dev
shm                      64.0M         0     64.0M   0% /dev/shm
/dev/nvme0n1p1           79.9G     10.2G     69.8G  13% /etc/resolv.conf
/dev/nvme0n1p1           79.9G     10.2G     69.8G  13% /etc/hostname
/dev/nvme0n1p1           79.9G     10.2G     69.8G  13% /etc/hosts
/dev/nvme0n1p1           79.9G     10.2G     69.8G  13% /var/lib/docker
tenryutenryu

duコマンド

ディスク使用状況を表示
-d で何階層分表示するかを指定
-hはいつものhuman readable

$ du -d 1 -h
2.0M    ./bin
0       ./dev
1.6M    ./etc
0       ./home
8.7M    ./lib
0       ./media
0       ./mnt
0       ./opt
0       ./proc
28.0K   ./root
28.0K   ./run
4.4M    ./sbin
0       ./srv
0       ./sys
0       ./tmp
782.7M  ./usr
196.0K  ./var
0       ./certs
799.7M  .
tenryutenryu

fsckコマンド

ハードディスクなどの障害時にディスクのチェックや修復を行うコマンド
-aオプションで自動で修復してくれ、-nオプションで問題報告だけしてくれる

$ fsck -n /dev/nvme0n1p127
fsck from util-linux 2.39.3
e2fsck 1.47.0 (5-Feb-2023)
/dev/nvme0n1p127: clean, 11/128 files, 58/1024 blocks
[node1] (local) root@10.1.40.4 /
$ fsck -a /dev/nvme0n1p127
fsck from util-linux 2.39.3
/dev/nvme0n1p127: clean, 11/128 files, 58/1024 blocks
tenryutenryu

e2fsckコマンド

ファイルシステムのext2、ext3、またはext4の整合性をチェック

tenryutenryu

マウント

デバイス(ディスクに作成したパーティション)に、ファイルシステムとLinuxのディレクトリを割り当てること

例:/dev/sda1のようなパーティションを、ext4というファイルシステムと/(ルート)に割り当てる
割り当てられたルートのようなディレクトリのことをマウントポイントという

tenryutenryu

/etc/fstabファイル

マウントの情報を確認できる

$ cat /etc/fstab
/dev/cdrom      /media/cdrom    iso9660 noauto,ro 0 0
/dev/usbdisk    /media/usb      vfat    noauto,ro 0 0

/dev/cdromをファイルシステムiso9660で/media/cdromにマウントしている

tenryutenryu

lspciコマンド

PCの部品同士がやりとりするための規格

tenryutenryu

lddコマンド

list dynamic dependencies
実行するコマンドが依存している共有ライブラリを表示する

$ ldd /bin/bash
        /lib/ld-musl-x86_64.so.1 (0x7f8505bec000)
        libreadline.so.8 => /usr/lib/libreadline.so.8 (0x7f8505add000)
        libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f8505bec000)
        libncursesw.so.6 => /usr/lib/libncursesw.so.6 (0x7f8505a89000)
tenryutenryu

mountコマンド

$ mount 
overlay on / type overlay (rw,relatime,seclabel,lowerdir=/var/lib/docker/overlay2/l/6DTRXAVKRZ7LKRMEQNCMBDF63O:/var/lib/docker/overlay2/l/4XFKMJ5NPSMSNDCJ7OUOSGMLFP:/var/lib/docker/overlay2/l/PGCDCBSC4KTLRNZ3KTKAIFOVP7:/var/lib/docker/overlay2/l/YT2ZD6XFKJSGBMB2SH6DHDQ3RX:/var/lib/docker/overlay2/l/RZDEEKVZ7KJWH2WMVTI7QYBUGP:/var/lib/docker/overlay2/l/W7DCWQ2OCMW74TXELCKVMFVW2G:/var/lib/docker/overlay2/l/QMQRON6TH2LQ6C47IB6UP6WGPI:/var/lib/docker/overlay2/l/K6S6ETCGNEVYZLOE363XNDEPEA:/var/lib/docker/overlay2/l/F6YKOUI63CX4XKFK2AACHZCW2U:/var/lib/docker/overlay2/l/QA72NF2EESB7N4UCEJVX7CRGQP:/var/lib/docker/overlay2/l/BSFWSV6HDJYWHT4F6NSGJD6JFF:/var/lib/docker/overlay2/l/6JVRGMUWNAFNGAANZHXMKP4VDB:/var/lib/docker/overlay2/l/5PFM7WZ4HWPOS6PUVI32NN5ZIH:/var/lib/docker/overlay2/l/4DPLP6LGNMWUPPMCXN4SXTB5YL:/var/lib/docker/overlay2/l/QORLBGNDVRLTMJ7OHH5OJUAEVV:/var/lib/docker/overlay2/l/TSNVROHLRUJINRCU5QRGBYQS3Y:/var/lib/docker/overlay2/l/43TLBQB3IBIBKIOZH5Z4272BOS:/var/lib/docker/overlay2/l/3KLV3D7B7ZELDIHWRRBU2EBS2Z:/var/lib/docker/overlay2/l/UHW4CKLUFBNW4CH6N7ZU3TSUO2:/var/lib/docker/overlay2/l/TITPTSF3PWPT6NJGTKEJPP3QHE:/var/lib/docker/overlay2/l/W4IVRSYY3HWPTOBZ3VJEXPI6QJ:/var/lib/docker/overlay2/l/6CA6YFVJLKEL6AKCEXIXILW2C3:/var/lib/docker/overlay2/l/WWQW7BXUJNVZZAVXWX333CI5PI:/var/lib/docker/overlay2/l/Z3SIF7ZVA4ZZ2M7BNQBXWG2YBU:/var/lib/docker/overlay2/l/2BQZ6G2VSPOMHC5BU6SPQXEMCC:/var/lib/docker/overlay2/l/2OZ7VNY4WYRRC5732ZTHDJOE4D:/var/lib/docker/overlay2/l/Q6ZCGCNEXLAIR563CPGFL64KFV,upperdir=/var/lib/docker/overlay2/43154eedce7529bc5942611702be779d221e16f4158da47860acf7aff4f605eb/diff,workdir=/var/lib/docker/overlay2/43154eedce7529bc5942611702be779d221e16f4158da47860acf7aff4f605eb/work)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev type tmpfs (rw,nosuid,seclabel,size=65536k,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=666)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
cgroup on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,seclabel,nsdelegate,memory_recursiveprot)
mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime,seclabel)
shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,seclabel,size=65536k)
/dev/nvme0n1p1 on /etc/resolv.conf type xfs (rw,noatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=1024,swidth=1024,noquota)
/dev/nvme0n1p1 on /etc/hostname type xfs (rw,noatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=1024,swidth=1024,noquota)
/dev/nvme0n1p1 on /etc/hosts type xfs (rw,noatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=1024,swidth=1024,noquota)
/dev/nvme0n1p1 on /var/lib/docker type xfs (rw,noatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=1024,swidth=1024,noquota)
devpts on /dev/console type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=666)
none on /sys/kernel/security type securityfs (rw,relatime)
tenryutenryu

locateコマンド

findのようにファイル名やディレクトリ名を検索するコマンド
locateはlocateデータベースというデータベースファイルを使用して検索するため、findよりも高速になる
データベースファイルを更新しないと使用できない

root@18b612de1381:/# locate query
/var/lib/plocate/plocate.db: No such file or directory  // DBを更新しないと検索できない
root@18b612de1381:/# updatedb
root@18b612de1381:/# locate query
/usr/bin/dpkg-query
/usr/share/man/de/man1/dpkg-query.1.gz
/usr/share/man/fr/man1/dpkg-query.1.gz
/usr/share/man/man1/dpkg-query.1.gz
/usr/share/man/nl/man1/dpkg-query.1.gz
/usr/share/man/pt/man1/dpkg-query.1.gz
/usr/share/man/sv/man1/dpkg-query.1.gz
tenryutenryu

fdiskコマンド

パーティションの一覧を確認、作成、削除する

tenryutenryu

PCIデバイス

PCI (Peripheral Component Interconnect)
パソコンの部品同士がやり取りするための規格で、Peripheralが周辺という意味
https://wa3.i-3-i.info/word12708.html

PCのマザーボードに接続し、機能を追加する拡張カード

tenryutenryu

lsusbコマンド

USBデバイスの情報を表示する

$ lsusb
lsusb: /sys/bus/usb/devices: No such file or directory
tenryutenryu

apt-getコマンド

debian系のパッケージ管理ツール
dpkgも同様

dist-upgrade:現在インストールされているパッケージの最新バージョンをインストールする