2012年7月15日日曜日

nginx 1.2 のインストール

ユーザの追加


# useradd -s /sbin/nologin nginx

インストール


# ./configure \
--user=nginx \
--group=nginx \
--prefix=/opt/nginx-1.2.2 \
--with-pcre \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module
# make
# make install

起動スクリプトの準備


# vi /etc/init.d/nginx

=== ここから
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

#nginx="/usr/sbin/nginx"
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

#NGINX_CONF_FILE="/etc/nginx/nginx.conf"
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

make_dirs() {
   # make required directories
   user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
   for opt in $options; do
       if [ `echo $opt | grep '.*-temp-path'` ]; then
           value=`echo $opt | cut -d "=" -f 2`
           if [ ! -d "$value" ]; then
               # echo "creating" $value
               mkdir -p $value && chown -R $user $value
           fi
       fi
   done
}

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    sleep 1
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac
=== ここまで

nginx の起動


# /etc/init.d/nginx start

2012年7月7日土曜日

MySQL 5.5.24 をインストールする。

mysql ユーザの作成

$ groupadd mysql
$ useradd -g mysql -d /home/mysql mysql

すでに mysql ユーザが存在している場合は,useradd の代わりに usermod を使用する。
これは,自分の環境が /home 配下へのディスク割り当てが多かったため。

$ usermod -g mysql -d /home/mysql -m mysql

-m オプションは,既存のユーザディレクトリを -d で指定した場所へ変更する。

cmake のインストール

$ yum install cmake

mysql のインストール

5.5 からは,configure ではなく,cmake にてビルドする方法になったようなので,以下のようにオプションを指定して実行する。

$ cmake . -DCMAKE_INSTALL_PREFIX=/home/mysql/5.5.24/master \ 
-DMYSQL_DATADIR=/home/mysql/5.5.24/master/data \
-DDEFAULT_CHARSET=utf8 \ 
-DDEFAULT_COLLATION=utf8_general_ci \ 
-DENABLED_LOCAL_INFILE=true \ 
-DWITH_EXTRA_CHARSETS=all \ 
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ 
-DWITH_READLINE=ON \ 
-DSYSCONFDIR=/home/mysql/5.5.24/master

あとは,いつもの通り。

$ make
# make install

インストールが済んだら,データベースの初期化を行う。

/home/mysql/scripts/mysql_install_db \
  --user=mysql \
  --basedir=/home/mysql \
  --datadir=/home/mysql/data


参考:
UbuntuでMySQL5.5を再インストールする方法と複数起動させる方法 http://namakesugi.blog42.fc2.com/blog-entry-120.html

[DB] CentOS に MySQL をソースコードからインストール
http://codenote.net/db/mysql/229.html