CenOS 5.4の初期設定
CentOS 5.4のインストールの続き。OSのインストールが終わり、最初の再起動が終わってからの初期設定について。
- 更新(2009-12-15):不要なサービスの停止についての説明を追加。
- 更新(2009-12-15):IPv6を無効化する場合の手順を追加。
1. ログイン
再起動が終わると、こんな画面が表示される。
CentOS release 5.4 (Final) Kernel 2.6.18-164.6.1.el5 on an i686 localhost login: _
ここで「root」と入力し、Enterキーを押すとパスワードを聞かれるので、インストール時に設定したrootパスワードを入力する。
localhost login: root Password: (表示されない)
Enterキーを押し、ログイン。
2. ログインポリシーの変更
wheelグループに所属するユーザーのみがsuでrootになれるよう、設定を変更する。
[root@localhost ~]# vi /etc/pam.d/su
以下と同じ行を探し、コメントアウトを解除する。
#auth required pam_wheel.so use_uid
これでOK。
3. ユーザーの追加
その後、rootでしかログインできないのは不便なので管理用のユーザーを追加する。以下、「hoge」ユーザーを追加する場合。
[root@localhost ~]# useradd hoge [root@localhost ~]# passwd hoge Changing password for user hoge. New UNIX password: (hogeユーザーのパスワードを入力) Retype new UNIX password: (同じパスワードを再入力) passwd: all authentication tokens updated successfully.
先ほどの設定変更により、wheelグループに属していないとrootになれないため、hogeユーザーをwheelに参加させる。
[root@localhost ~]# usermod -G wheel hoge
一度ログアウトし、hogeユーザーでログインする。さらにsuでrootになれることを確認する。
4. yumの設定
標準の自動更新 yum-updatesd では色々と不都合があるため、yum-cron を導入し、yum-updatesd は完全に削除する。
[root@localhost ~]# service yum-updatesd stop [root@localhost ~]# yum -y remove yum-updatesd [root@localhost ~]# yum -y install yum-cron [root@localhost ~]# service yum-cron start [root@localhost ~]# chkconfig yum-cron on
ついでにインストール済みパッケージを一括アップデート。
[root@localhost ~]# yum -y update
5. SELinuxの無効化
SELinuxは色々と鬱陶しいのでOFFにする。
[root@localhost ~]# getenforce Enforcing [root@localhost ~]# setenforce 0 [root@localhost ~]# getenforce Permissive
設定ファイルを編集し、再起動後もSELinuxが有効にならないようにする。
[root@localhost ~]# vi /etc/sysconfig/selinux SELINUX=enforcing ↓ SELINUX=disabled
6. 不要なサービスの停止
手順通りインストール・初期設定を行った場合でも、意外に不要なサービスが起動していることがわかった。不要なサービスの停止については独立した記事としてまとめてあるので、そちらを参照して欲しい。
CentOS 5.4でNTPサーバーの構築
CentOS 5.4にntpdをインストールし、自動で時刻合わせが行われるようにすると共に、ローカルネットワーク用のNTPサーバーとしても使用できるようにする。
1. インストール
[root@localhost ~]# yum -y install ntp
2. 設定ファイルの編集
/etc/ntp.conf を以下のように編集する。編集のポイントは
- 東大およびmfeedのサーバーから同期するようにする(今回、ISPに標準のNTPサーバーがなかったため。ISPでNTPサーバーが用意されている場合はそちらを利用した方がよい)。
- ローカルネットワークによる問い合わせを許可する。
- その他のネットワークからの問い合わせを拒否する。
それ以外の設定はデフォルトのままのはず……。
[root@localhost ~]# vi /etc/ntp.conf # Ignore all access restrict default ignore # Permit all access over the loopback interface. This could # be tightened as well, but to do so would effect some of # the administrative functions. restrict 127.0.0.1 restrict -6 ::1 # Hosts on local network are less restricted. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap restrict 192.168.78.0 mask 255.255.255.0 nomodify notrap # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). server 130.69.251.23 # ntp.nc.u-tokyo.ac.jp server 210.173.160.27 # ntp1.jst.mfeed.ad.jp server 210.173.160.57 # ntp2.jst.mfeed.ad.jp server 210.173.160.87 # ntp3.jst.mfeed.ad.jp # Do not permit public servers to query or modify the service on this system restrict 130.69.251.23 noquery nomodify restrict 210.173.160.27 noquery nomodify restrict 210.173.160.57 noquery nomodify restrict 210.173.160.87 noquery nomodify # Drift file. Put this in a directory which the daemon can write to. # No symbolic links allowed, either, since the daemon updates the file # by creating a temporary in the same directory and then rename()'ing # it to the file. driftfile /var/lib/ntp/drift # Key file containing the keys and key identifiers used when operating # with symmetric key cryptography. keys /etc/ntp/keys
3. 時刻合わせ
時刻がずれているとNTPサーバーが起動できないため、手動で一度時刻合わせを行う。IPの部分は自分が利用するNTPサーバーを指定すること。
[root@localhost ~]# ntpdate 130.69.251.23
4. NTPサーバーの起動と確認
NTPサーバーを起動し、その状態を確認する。
[root@localhost ~]# service ntpd start ntpd を起動中: [ OK ] [root@localhost ~]# ntpq -p localhost remote refid st t when poll reach delay offset jitter ============================================================================== ntp.nc.u-tokyo. .GPS. 1 u 18 64 1 5.152 -3.412 0.001 ntp1.jst.mfeed. 210.173.160.56 2 u 17 64 1 3.885 -3.115 0.001 ntp2.jst.mfeed. 133.243.236.17 2 u 16 64 1 4.537 -2.902 0.001 ntp3.jst.mfeed. 133.243.236.19 2 u 15 64 1 4.691 -2.812 0.001
5. 自動実行の設定
次回からNTPサーバーが自動で起動するように設定する。
[root@localhost ~]# chkconfig ntpd on [root@localhost ~]# chkconfig --list ntpd ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
とりあえずここまで。