How to install CentOS5

友人のためにCentOS5のインストール入門を書いてみる。

  • インストールメディアを準備

http://www.centos.org/ からisoイメージをダウンロードして焼いておく。
32ビット版と64ビット版があるのでマシンに合わせて選ぶ。

  • インストール

一番面倒くさいのがパーティションの切り方。(本当はLVMを使ったほうが良いけど入門なので)

/boot --- 100MB --- ext3
swap  --- 2GB   --- swap
/     --- 10GB --- ext3
/tmp  --- 1GB --- ext3
/var  --- 残り全部 --- ext3

日本語は入れないこと。

キーボードのタイプは間違えないこと。

タイムゾーンはAsia/Tokyo

インストールタイプは、「Server」を選択。X-Windowは入れたら駄目。

インストール時のネットワークはDHCPでOK。

ファイアウォール(iptables)と SE Linux は無効化。

# system-config-securitylevel
Security Level: ( ) Enabled (*) Disabled  

SELinux: Enforcing
         Permissive
        *Disabled
  • ネットワークの設定

以下のコマンドで楽々設定

# system-config-network

こんな感じで、自宅の環境に合わせて。(Default gateway IPは、ブロードバンドルータIPアドレス

│ Name               eth0________________ │
│ Device             eth0________________ │
│ Use DHCP           [ ]                  │
│ Static IP          192.168.0.100_______ │
│ Netmask            255.255.255.0_______ │
│ Default gateway IP 192.168.0.1_________ │

設定を反映させるためにネットワークをリスタート

# service network restart

DNSを設定しましょう。

# vi /etc/resolv.conf

以下のような感じで。

nameserver 192.168.0.1   <-たいていはブロードバンドルータがDNSになってくれる。
nameserver 12.34.56.78   <-YahooBBなどの自分のプロバイダが提供しているDNSでももちろんOK。
  • RPMパッケージのインストール

よく使うソフトをインストールする。

yum コマンドおさらい

検索

# yum search <ソフトウェア名>
例
# yum search httpd

# yum provides <パッケージに含まれるファイル名>
例
# yum provides php.ini

インストール (-y を付けると勝手にインストールします。)

# yum install パッケージ名
例
# yum install httpd

# yum groupinstall パッケージグループ名
例
# yum groupinstall "Development Tools"


というわけでLAMP環境なら以下でOK。

# yum -y groupinstall "Development Tools"
# yum -y groupinstall "Web Server"
# yum -y groupinstall "MySQL Database"
# yum -y install php php-devel php-pear php-mysql php-gd php-mbstring subversion

あと、以下は良く使うので入れておく。

# yum install sysstat postfix ntp wget curl
  • 時間の設定

以下の設定をしておくとサーバーの時間がずれない。(毎日 4:56 に時刻が修正される)

# vi /etc/cron.d/ntpdate
56 4 * * * root /usr/sbin/ntpdate -s jp.pool.ntp.org
57 4 * * * root /sbin/hwclock --set --date=' `date`'
  • メールサーバーの設定

デフォルトでSendmail になっているので、Postfixに変更する。

# alternatives --config mta
There are 2 programs which provide 'mta'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/sbin/sendmail.sendmail
   2           /usr/sbin/sendmail.postfix

Enter to keep the current selection[+], or type selection number: 2

Postfixの設定ファイルを書き換える

# vi /etc/postfix/main.cf

relayhost を書き換える。

...
relayhost = [プロバイダから指定されたSMTPサーバーのIPアドレス]
...

これでこのLinuxサーバーからのメールはプロバイダがちゃんと管理しているメールサーバー経由で外に出て行く。

  • 各種デーモン(サービス)の設定

サービスの一覧

# chkconfig --list

サービスの削除

# chkconfig --del サービス名

サービスの追加
(/etc/init.d/ の下を見ると名前を確認できる)

# chkconfig --add サービス名

サービスのOn/Off

# chkconfig サービス名 on
# chkconfig サービス名 off

LAMP環境なら以下でとりあえずOK。「chkconfig --del サービス名」 を使って不要なデーモンをひたすら削除する。ランレベルは「3」のところだけ気にすればOK。

# chkconfig --list
httpd          	0:off	1:off	2:off	3:on	4:on	5:on	6:off
postfix        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
crond          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
sshd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
syslog         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
mysqld         	0:off	1:off	2:off	3:on	4:on	5:on	6:off


サービスの起動、停止、再起動

# service サービス名 start
# service サービス名 stop
# service サービス名 restart
  • manコマンド

わからないことが出てきたら以下のおまじないを唱える

# man わからない言葉
例
# man man
# man chkconfig
# man yum
  • Windowsから簡単にアクセスしたい時

samba を入れて、エクスプローラーから、

\\LINUXのIPアドレス\

でアクセスできる。

sambaインストール

# yum install samba

設定ファイル

# vi /etc/samba/smb.conf
[root]
    path = /
    writable = yes
    valid users = root

sambaにユーザ追加

# smbpasswd -a root

sambaリスタート

# service smb restart