Akio's Log

ソフトウェア開発、プロジェクトマネジメント、プログラミング、ランニングなどなど

自分サーバの構築その8:初期設定の続き

昨日の初期設定の続き。

パッケージ管理システム設定(yum)

yumでパッケージインストールする際に最適なミラーサイトを自動選択する「fastestmirror」プラグインをインストールする。

[root@xxxxxx ~]# yum -y install yum-fastestmirror
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for yum-fastestmirror to pack into transaction set.
yum-fastestmirror-1.0.4-2 100% |=========================| 5.0 kB    00:00
---> Package yum-fastestmirror.noarch 0:1.0.4-2.el5.centos set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 yum-fastestmirror       noarch     1.0.4-2.el5.centos  extras             11 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 11 k
Downloading Packages:
(1/1): yum-fastestmirror- 100% |=========================|  11 kB    00:01
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897
Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) <centos-5-key@centos.org>" from http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: yum-fastestmirror            ######################### [1/1]

Installed: yum-fastestmirror.noarch 0:1.0.4-2.el5.centos
Complete!
[root@xxxxxx ~]#

あっという間に終わった。

次に、インストール済みパッケージを一括でアップデートする。

[root@xxxxxx ~]# yum update
Loading "installonlyn" plugin
Loading "fastestmirror" plugin
Setting up Update Process
Setting up repositories
Determining fastest mirrors
Reading repository metadata in from local files
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Package vim-minimal.i386 2:7.0.109-3.el5.3 set to be updated
---> Package vixie-cron.i386 4:4.1-70.el5 set to be updated
---> Package Deployment_Guide-ja-JP.noarch 0:5.0.0-21.el5.centos set to be updated
---> Package bind-utils.i386 30:9.3.3-8.el5 set to be updated
---> Package libgcc.i386 0:4.1.1-52.el5.2 set to be updated
(以下、略)

インストール済みのパッケージを自動更新するために、yum-cronをインストール

[root@xxxxxx ~]# yum -y install yum-cron
Loading "installonlyn" plugin
Loading "fastestmirror" plugin
Setting up Install Process
Setting up repositories
Loading mirror speeds from cached hostfile
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for yum-cron to pack into transaction set.
yum-cron-0.1-1.el5.centos 100% |=========================| 3.4 kB    00:00
---> Package yum-cron.noarch 0:0.1-1.el5.centos set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 yum-cron                noarch     0.1-1.el5.centos  base               12 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 12 k
Downloading Packages:
(1/1): yum-cron-0.1-1.el5 100% |=========================|  12 kB    00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: yum-cron                     ######################### [1/1]

Installed: yum-cron.noarch 0:0.1-1.el5.centos
Complete!
[root@xxxxxx ~]#

yumのアップデート通知デーモンを停止する。

[root@xxxxxx ~]# /etc/rc.d/init.d/yum-updatesd stop
yum-updates を停止中: [ OK ]
[root@xxxxxx ~]#

アップデート通知デーモンの自動起動設定を、chkconfigコマンドを使ってoffにする

[root@xxxxxx ~]# chkconfig yum-updatesd off
[root@xxxxxx ~]# chkconfig --list
(略)
yum-updatesd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

停止された。

root宛メールを転送する

システムからroot宛に重要なメールが送られてくるので、root宛メールを普段使用しているメールアドレス宛に転送するようにする。

再度、このサイト
「CentOS5初期設定 - CentOS自宅サーバー構築」
http://centossrv.com/centos5-init.shtml
を参考にしているが、

[root@centos ~]# sed -i '/^root:/d' /etc/aliases ← 旧root宛メール転送設定削除
[root@centos ~]# echo "root: hoge@nifty.com" >> /etc/aliases
 ← root宛メールを普段使用しているメールアドレス(例:hoge@nifty.com)宛に転送する
[root@centos ~]# newaliases ← 転送設定反映
[root@centos ~]# echo test|mail root ← テストメールをroot宛に送信する
テストメールが転送先メールアドレス宛に届いていることを確認する

このsedコマンドの「-i」オプションの意味がわからなかった。
「Manpage of SED
http://www.linux.or.jp/JM/html/GNU_sed/man1/sed.1.html
で調べてみるも、「-i」オプションの記述はなし。

ぐぐってみると、このページに解説が載っていた。
sed, a stream editor: 2. 呼び出し」
http://www.fan.gr.jp/~ring/doc/sed/sed-ja_2.html

-i[SUFFIX]

    • in-place[=SUFFIX]

このオプションは,その場でファイルを編集することを指定します. GNU sedは一時的なファイルを作成し,標準出力の代わりにこのファイルに出力を送ります(1).

このオプションは`-s'を暗黙に指定します.

ファイルの終りに到達したとき,一時ファイルの名前を出力ファイルの元の名前に変更します.拡張子が与えられている場合,一時ファイル(それによってバックアップのコピー(2)が作成されます)の名前を変える前に古いファイルの名前を編集するために,以下の規則を使用します.

拡張子が*を含まない場合,それはファイル名の接尾子として現在のファイル名の終りに後置されます.拡張子が一つ以上の*文字を含む場合, それぞれのアスタリスクは現在のファイル名で置換されます.これで,バックアップファイルに接尾子の代わりに(または接尾子に追加で)接頭辞を追加することや,オリジナルのファイルのバックアップのコピーを(既存のディレクトリを提供することで)他のディレクトリに配置することさえ可能になります.

拡張子が与えられていない場合,本埜ファイルはバックアップを使用せず上書きされます.

sedコマンドを実行した結果を、標準出力に出力するのではなく、その指定ファイルに上書きしてしまう、というオプションらしい。


ちなみに、/etc/aliasesファイルの意味はこちらに書いてあった。
ITmedia エンタープライズ : Linux Tips「システム設定ファイルを知ろう〓/etc/aliases〓」」
http://www.itmedia.co.jp/help/tips/linux/l0349.html

/etc/aliasesファイルは,Sendmail用のエイリアス(別名)を行う設定ファイル。ほかにもSendmail互換のPostfixで設定ファイル(main.cf)に定義すれば,/etc/aliasesファイルを利用することも可能だ。qmailなどのMTAを利用している場合には無効となる。

だそうだ。

先ほどsedコマンドでroot宛のメール転送設定を削除したが、そもそも既存のaliasesファイルには、

(略)
# Person who should get root's mail
#root: marc

root宛てのメール転送設定はコメントアウトされていた。

なので、普通にviでこの下の行にメール転送設定を追加。

[root@xxxxxx ~]# vi /etc/aliases
(略)
root: hanzawa_akio@xxxxxx.co.jp ---> この行を追加
:
[root@xxxxxx ~]# newaliases ---> 転送設定を反映させる
/etc/aliases: 77 aliases, longest 30 bytes, 799 bytes total
[root@xxxxxx ~]# echo test | mail root --->root宛てにテストメール送信

テストメールを送ってみる。






あれ?届かない?
なぜ?

調べてみたら、sendmailが起動していなかった。そりゃそうだ。初回起動時のSetupAgentウィザードの「System Services」で「sendmail」のチェックをOFFにしてしまっているのだから。アホだ。

気を取り直して、sendmailを起動

[root@xxxxxx ~]# service sendmail start
sendmail を起動中: [ OK ]
sm-client を起動中: [ OK ]
[root@xxxxxx ~]# chkconfig sendmail on --->自動起動設定ON
[root@xxxxxx ~]# echo test | mail root

これで再度テストメールを送信したところ、無事受信できた。めでたしめでたし