いつものCentOS

適当なサーバを1台用意してそれまるまる使ってWEBサービスをまずは開始しようってときにする設定はそんなに凝らない場合がほとんどでほぼ同じ場合もよくあるからメモ。
構築するサービスに適したもの選んで設定してけばいい。

作業ディレクトリの作成

mkdir /root/src

yum の設定

cd /root/src
yum -y install yum-fastestmirror
wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm \
-O /root/src/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uhv /root/src/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
wget http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt -O /root/src/RPM-GPG-KEY.dag.txt
rpm --import /root/src/RPM-GPG-KEY.dag.txt

「/etc/yum.repos.d/rpmforge.repo」を編集。

[...]
enabled = 0
[...]

postfix のインストール

yum -y install postfix
service postfix start
chkconfig postfix on

詳細な設定に関しては今回は省略。

dnsmasq のインストール

yum -y install dnsmasq
service dnsmasq start
chkconfig dnsmasq on

ここで必要であれば「/etc/hosts」を編集。
編集したらネットワークを再起動。

service network restart

php のインストール

yum -y remove 'php*'
yum -y install httpd-devel pcre-devel libmcrypt-devel mysql-devel \
libjpeg-devel libpng-devel freetype-devel libtool-ltdl-devel
yum -y install gcc libxml2-devel libxml2 openssl-devel bzip2-devel \
libmcrypt gmp-devel libc-client libc-client-devel libungif-devel \
libungif libungif-devel autoconf automake imake curl curl-devel \
libidn libidn-devel net-snmp-devel
wget http://museum.php.net/php5/php-5.2.9.tar.bz2
tar -jxvf php-5.2.9.tar.bz2
cd php-5.2.9
./configure --build=i686-redhat-linux-gnu --host=i686-redhat-linux-gnu \
--target=i386-redhat-linux-gnu --program-prefix= --prefix=/usr \
--exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc \
--datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib \
--libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/usr/com \
--mandir=/usr/share/man --infodir=/usr/share/info --cache-file=../config.cache \
--with-libdir=lib --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d \
--disable-debug --with-exec-dir=/usr/bin --enable-shared --with-pic --disable-rpath \
--with-pear --with-bz2=shared --with-curl=shared --with-freetype-dir=/usr \
--with-png-dir=/usr --enable-gd-native-ttf --with-gettext=shared --with-gmp=shared \
--with-iconv=shared --with-jpeg-dir=/usr --with-openssl=shared --with-pcre-regex=/usr \
--with-zlib=shared --with-layout=GNU --enable-exif --enable-ftp --enable-sockets \
--enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-wddx --with-kerberos \
--enable-ucd-snmp-hack --with-unixODBC=shared,/usr --enable-shmop --enable-calendar \
--with-mime-magic=/usr/share/file/magic.mime --without-sqlite --without-pdo-sqlite \
--with-libxml-dir=/usr --with-apxs2=/usr/sbin/apxs --with-mysql=shared,/usr \
--with-mysqli=shared,/usr/bin/mysql_config --with-gd=shared --disable-dba \
--without-unixODBC --enable-mbstring --enable-mbregex --enable-bcmath \
--with-xmlrpc=shared -enable-dom=shared --with-snmp=shared,/usr --enable-soap=shared \
--with-xsl=shared,/usr --enable-xmlreader=shared --enable-xmlwriter=shared \
--enable-pdo=shared --with-pdo-mysql=shared,/usr --enable-gd-jis-conv \
--enable-zip=shared --enable-zend-multibyte --with-mcrypt --with-apxs2=/usr/sbin/apxs
make clean
make
make install

APC のインストール

pecl install APC

memcache のインストール

pecl install memcache

httpd.conf の設定

「/etc/httpd/conf/httpd.conf」以下の一行をコメントアウト

#LoadModule php5_module        /usr/lib/httpd/modules/libphp5.so

php.conf の作成

「/etc/httpd/conf.d/php.conf」を作成し、以下の通り記述。

LoadModule php5_module        /usr/lib/httpd/modules/libphp5.so
AddType application/x-httpd-php .php
DirectoryIndex index.php

php.ini の設定

cp /root/src/php-5.2.9/php.ini-recommended /etc/php.ini

「/etc/php.ini」を編集

[...]
upload_max_filesize = 10M

[...]
extension_dir = "/usr/lib/20060613/"

[...]
extension=apc.so
extension=bz2.so
extension=curl.so
extension=dom.so
extension=gd.so
extension=gettext.so
extension=gmp.so
extension=iconv.so
extension=memcache.so
extension=mysql.so
extension=mysqli.so
extension=openssl.so
extension=pdo.so
extension=pdo_mysql.so
extension=snmp.so
extension=soap.so
extension=xmlreader.so
extension=xmlrpc.so
extension=xmlwriter.so
extension=xsl.so
extension=zip.so
extension=zlib.so

[...]
sendmail_path = "/usr/sbin/sendmail.postfix -t -i"

[...]
mbstring.language = Japanese

[...]
mbstring.internal_encoding = UTF-8

[...]
mbstring.http_input = pass

[...]
mbstring.http_output = pass

[...]
mbstring.encoding_translation = Off

[...]
mbstring.detect_order = UTF-8,SJIS,EUC-JP,JIS,ASCII

[...]
mbstring.substitute_character = none;

[...]
mbstring.func_overload = 0

[...]
[apc]
apc.enabled=1
apc.shm_segments=1
apc.shm_size=30
apc.optimization=0
apc.num_files_hint=1000
apc.ttl=0
apc.gc_ttl=3600
apc.cache_by_default=1
apc.filters=NULL
apc.mmap_file_mask=NULL
apc.slam_defense=0
apc.file_update_protection=2

ntp のインストール

yum -y install ntp

「/etc/cron.daily/hwclock」ファイルを作成。

#!/bin/sh
/sbin/hwclock --systohc

権限を変更。

chmod 755 /etc/cron.daily/hwclock

「/etc/ntp.conf」を編集。

[...]
#server 0.centos.pool.ntp.org
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org
server ntp1.jst.mfeed.ad.jp
server ntp2.jst.mfeed.ad.jp
server ntp3.jst.mfeed.ad.jp
service ntpd stop
ntpdate ntp1.jst.mfeed.ad.jp
hwclock --systohc
service ntpd start
chkconfig ntpd on

MySQL のインストール

yum -y install mysql
yum -y install mysql-server
service mysqld start
chkconfig mysqld on

詳細な設定に関しては今回は省略。

memcached のインストール

yum -y --enablerepo=rpmforge install memcached

「/etc/sysconfig/memcached」の編集。

USER="root"
MAXCONN="20480"
CACHESIZE="512"
PORT="11211"
OPTIONS="-P /var/run/memcached.pid -f 1.5"

httpdの起動

chkconfig httpd on
service httpd start

Courier-Authlib, Courier-IMAP のインストール

インストール用ユーザの作成

useradd -m -s /bin/bash compileuser
passwd compileuser

compileuserに権限の追加

visudo
[...]
root    ALL=(ALL)       ALL
compileuser   ALL=(ALL)       ALL
[...]

ユーザの切り替え

su compileuser

ビルド環境の作成

mkdir $HOME/rpm
mkdir $HOME/rpm/SOURCES
mkdir $HOME/rpm/SPECS
mkdir $HOME/rpm/BUILD
mkdir $HOME/rpm/SRPMS
mkdir $HOME/rpm/RPMS
mkdir $HOME/rpm/RPMS/i386
mkdir $HOME/rpm/RPMS/x86_64
echo "%_topdir $HOME/rpm" >> $HOME/.rpmmacros

作業用ディレクトリの作成

mkdir $HOME/src

ソースファイルのダウンロード

cd $HOME/src
wget http://sourceforge.net/projects/courier/files/authlib/0.63.0/courier-authlib-0.63.0.tar.bz2/download
wget http://sourceforge.net/projects/courier/files/imap-devel/20100320/courier-imap-4.7.0.20100320.tar.bz2/download

Courier-Authlibのビルド

cd $HOME/src
rpmbuild -ta courier-authlib-0.63.0.tar.bz2

依存関係でエラーになる場合は必要なパッケージをインストール(下記は一例)

yum -y install postgresql-devel expect

インストール

cd $HOME/rpm/RPMS/i386/
sudo rpm -ivh courier-authlib-*.rpm

Courier-IMAPのビルド

cd $HOME/src
rpmbuild -ta courier-imap-4.7.0.20100320.tar.bz2

fam.h関連のエラーになる場合は以下のパッケージをインストール

yum -y install gamin-devel

インストール

cd $HOME/rpm/RPMS/i386/
sudo rpm -ivh courier-imap-4.7.0.20100320-1.i386.rpm

ユーザの切り替え

exit

デフォルトではimap,imap-ssl,pop3,pop3-sslの全てが有効になっているので、不要なサービスは起動しないよう変更。
「/usr/lib/courier-imap/etc/imapd」「/usr/lib/courier-imap/etc/imapd-ssl」「/usr/lib/courier-imap/etc/pop3d」「/usr/lib/courier-imap/etc/pop3d-ssl」のウチ、不要なサービスのファイル中の「*****START=YES」を「*****START=NO」に変更する。

サービスの起動と自動起動の設定

service courier-authlib start
service courier-imap start
chkconfig courier-authlib on
chkconfig courier-imap on

メール受信ユーザの作成(ここでは例にsupportグループのsupportユーザを作成)

先にグループの作成

groupadd support

ユーザの作成

useradd -g support support

メール保存用ディレクトリの作成

su support
maildirmake $HOME/Maildir
exit

「/etc/aliases」にて、supportユーザのメールをpostmasterに転送する設定が記述してある場合は該当行をコメントアウト


以上!
かなり雑になった。。