Debian GNU/Linuxをインストールしてみる:あると便利なツールを入れてみよう

本格的にサーバの構築に入る前に、今後サーバを運用していく上で、インストールしてあると便利なツールをいくつかピックアップするので、インストールしてみよう。

Debianアーカイブを追加

これは、ツールではありませんが、Debianアーカイブを追加しておきましょう。
この設定を行うためには、root権限が必要になりますから、“su -”でrootにスイッチします。

Linuxを含むUNIX系OSでは、設定ファイルは殆どがテキスト形式なっているので、そのファイルを編集することで設定を変更することが出来ます。
Debianアーカイブに関する設定は、/ect/apt/source.listsに書かれているので、まずはこのファイルの中身を参照してみましょう。

テキストファイルの中身を参照するためには、“more”というコマンドを使って、次のように実行します。

debian:~# more /etc/apt/sources.list
# deb http://ftp.jp.debian.org/debian/ etch main
deb http://ftp.jp.debian.org/debian/ etch main
deb-src http://ftp.jp.debian.org/debian/ etch main
deb http://security.debian.org/ etch/updates main
deb-src http://security.debian.org/ etch/updates main

1行目は先頭に“#”が入っているので、コメントとして扱われます。3行目と4行目はインストールの時点で指定したミラーサイト、5行目と6行目はセキュリティアップデートが行われたパッケージをダウンロードしてくる為のサイトが指定されています。
ここでは、3行目と4行目の先頭に“#”を追加してコメントに変え、7行目以降に別のミラーサイトを指定しましょう。


viなどのテキストエディタを利用して、次のように変更します。

debian:~# more /etc/apt/sources.list
# deb http://ftp.jp.debian.org/debian/ etch main
#deb http://ftp.jp.debian.org/debian/ etch main
#deb-src http://ftp.jp.debian.org/debian/ etch main
deb http://security.debian.org/ etch/updates main
deb-src http://security.debian.org/ etch/updates main
# add CDN
deb http://cdn.debian.or.jp/debian etch main contrib non-free
deb-src http://cdn.debian.or.jp/debian etch main contrib non-free

変更が終わったら、パッケージデータベースのアップデートを行っておきます。

debian:~# aptitude update
Get:1 http://cdn.debian.or.jp etch Release.gpg [378B]
Get:2 http://cdn.debian.or.jp etch Release [58.2kB]
Get:3 http://cdn.debian.or.jp etch/main Packages [5638kB]
Get:4 http://cdn.debian.or.jp etch/contrib Packages [72.6kB]
Get:5 http://cdn.debian.or.jp etch/non-free Packages [102kB]
Get:6 http://cdn.debian.or.jp etch/main Sources [1653kB]
Get:7 http://cdn.debian.or.jp etch/contrib Sources [21.1kB]
Get:8 http://cdn.debian.or.jp etch/non-free Sources [33.2kB]
Get:9 http://security.debian.org etch/updates Release.gpg [189B]
Get:10 http://security.debian.org etch/updates Release [22.5kB]
Ign http://security.debian.org etch/updates/main Packages/DiffIndex
Ign http://security.debian.org etch/updates/main Sources/DiffIndex
Get:11 http://security.debian.org etch/updates/main Packages [93.4kB]
Get:12 http://security.debian.org etch/updates/main Sources [11.4kB]
Fetched 7705kB in 1m16s (101kB/s)
Reading package lists... Done

htop:プロセスの状態を見る

htopは、システムの稼働状況や、個々のプロセスがその程度リソースを消費しているのかなどの情報を表示してくれるコマンドです。
最小システムの状態でも、topというコマンドがあるので、そちらでもいいのですが、htopのほうがカラフルで見やすいこともあって、よく利用しています。

lsof:使用されているファイルを調べる

lsofは、プログラムがどのファイルを利用しているのかを調べるためのコマンドです。
僕は、どのプロセスがどのポートを使っているのか、といったことを調べるときに使うことが多いですね。

htopとlsofをインストール

インストールは簡単。“aptitude install htop lsof”と入力してリターンでおしまい。
細かい設定をする必要もないので、インストール直後から使えるようになります。

debian:~# aptitude install htop lsof
Reading package lists... Done
Building dependency tree... Done
Reading extended state information
Initializing package states... Done
Writing extended state information... Done
Reading task descriptions... Done
Building tag database... Done
The following packages have been kept back:
  linux-image-2.6.18-4-686
The following NEW packages will be installed:
  htop lsof
0 packages upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 251kB of archives. After unpacking 541kB will be used.
Writing extended state information... Done
Get:1 http://cdn.debian.or.jp etch/main lsof 4.77.dfsg.1-3 [205kB]
Get:2 http://cdn.debian.or.jp etch/main htop 0.6.3-1 [45.3kB]
Fetched 251kB in 0s (640kB/s)
Selecting previously deselected package lsof.
(Reading database ... 16825 files and directories currently installed.)
Unpacking lsof (from .../lsof_4.77.dfsg.1-3_i386.deb) ...
Selecting previously deselected package htop.
Unpacking htop (from .../archives/htop_0.6.3-1_i386.deb) ...
Setting up lsof (4.77.dfsg.1-3) ...
Setting up htop (0.6.3-1) ...

他にも、色々あるのだけど、必要になった時々で紹介していくので、今のところはこの二つだけ、ということで。

ん?“linux-image-2.6.18-4-686”ってなに?

さて、気が付いた人はいるだろうか?htopとlsofをインストールしたときに表示されたメッセージの中に、“linux-image-2.6.18-4-686”という文字列。
これは、インストールCD用のイメージファイルが作られた以降に、セキュリティ・アップデートという形で準備されたLinuxカーネルのパッケージが存在するということなのだけど、コレもインストールしておこう。セキュリティアップデートが行われたパッケージがあれば、同じように表示されるようになっています。
勿論、アップデートされたパッケージをインストールするかしないかは、各自の自由とも言えるんだけど、ほったらかしにしておくことで、他のインターネット上のサーバやユーザに迷惑をかけてしまったり、自分自身がトラブルに巻き込まれたりすることもあり得るので、こまめにアップデートしておきたい。

パッケージのアップデートも、aptitudeで行えるので、下の斜体のように入力してリターンキーで実行しよう。
途中、インストールを続けるか聞いてくるところがあるので、そこはリターンで進めてください。

debian:~# aptitude upgrade
Reading package lists... Done
Building dependency tree... Done
Reading extended state information
Initializing package states... Done
Reading task descriptions... Done
Building tag database... Done
The following packages will be upgraded:
  linux-image-2.6.18-4-686
1 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 16.3MB of archives. After unpacking 1815kB will be freed.
Do you want to continue? [Y/n/?]
Get:1 http://security.debian.org etch/updates/main linux-image-2.6.18-4-686 2.6.18.dfsg.1-12etch2 [16.3MB]
Fetched 14.6MB in 42m55s (5658B/s)
Preconfiguring packages ...
(Reading database ... 16861 files and directories currently installed.)
Preparing to replace linux-image-2.6.18-4-686 2.6.18.dfsg.1-12 (using .../linux-image-2.6.18-4-686_2.6.18.dfsg.1-12etch2_i386.deb) ...
The directory /lib/modules/2.6.18-4-686 still exists. Continuing as directed.
Done.
Unpacking replacement linux-image-2.6.18-4-686 ...
Running postrm hook script /sbin/update-grub.
You shouldn't call /sbin/update-grub. Please call /usr/sbin/update-grub instead!
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /boot/vmlinuz-2.6.18-4-686
Updating /boot/grub/menu.lst ... done
Setting up linux-image-2.6.18-4-686 (2.6.18.dfsg.1-12etch2) ...
 Hmm. The package shipped with a symbolic link /lib/modules/2.6.18-4-686/source
 However, I can not read the target: No such file or directory
 Therefore, I am deleting /lib/modules/2.6.18-4-686/source
Running depmod.
Finding valid ramdisk creators.
Using mkinitramfs-kpkg to build the ramdisk.
Not updating initrd symbolic links since we are being updated/reinstalled
(2.6.18.dfsg.1-12 was configured last, according to dpkg)
Not updating image symbolic links since we are being updated/reinstalled
(2.6.18.dfsg.1-12 was configured last, according to dpkg)
Running postinst hook script /sbin/update-grub.
You shouldn't call /sbin/update-grub. Please call /usr/sbin/update-grub instead!
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /boot/vmlinuz-2.6.18-4-686
Updating /boot/grub/menu.lst ... done

Linuxカーネルは、サーバを再起動しないと反映されないので、タイミングを見て“shutdown -r now”を実行して再起動しておくこと。
まぁ、自分ひとりで使う分には再起動のタイミングは気にする必要はないかも知れないけど、家族にも使わせるといった場合には、注意する必要があるかも知れません。

トラックバック(0)

コメントする