2013年9月22日日曜日

さくらのVPSでPlay Frameworkを動かす:Playのインストール

ようやくPlayのインストールになります。

Play2.1.5のインストール


今開発中のアプリケーションはPlay2.1.x系で作っているので、Play 2.1.5をVPSにインストールしたいと思います。

ちなみにPlayの場合は2.1.x系と2.2.x系だと全く別物になっている可能性があるので、注意が必要です。

cd /usr/local/src/
wget http://downloads.typesafe.com/play/2.1.5/play-2.1.5.zip
unzip play-2.1.5.zip
mv play-2.1.5 /var/lib/
don’t install to /opt, /usr/local
http://www.playframework.com/documentation/2.1.3/Installing
とのことで、インストール先には/usr/localは避けたほうがいいようです。

バージョンアップの際にさくっと切り替えられるようにしたいのでシンボリックリンクを貼っておきます。

cd /usr/local/
ln -s /var/lib/play-2.1.5 play
ls -lat
Jenkinsからplayインストールフォルダを操作できるようにパーミッションの変更をします。

Play! 2.0 / 2.1 ぐらいで play コマンドを実行したときに Permission denied な例外が発生する問題への対処

chmod -R go+wx /var/lib/play-2.1.5 play/framework/sbt/boot
chmod -R go+wx /var/lib/play-2.1.5 play/repository

Playにパスを通す


どこからでもplayコマンドが実行できるようにするため、パスを通します。

export PATH=$PATH:/usr/local/play

パスが通っているか確認をします。

cd /root/
play help

ヘルプが表示されればOKです。


さくらのVPSでPlay Frameworkを動かす:JDKのインストール

今作っているPlay Frameworkのアプリケーションは2.1.x系で作っています。

2.1.x系のバージョンのJavaは

http://www.playframework-ja.org/documentation/2.1.3/Installingによると

Play framework の実行には、JDK 6以降 が必要です。

とあるので、JDK7系で行ってみようかと思います。

JDKインストール


さくらのVPSは64ビットなので
から

 jdk-7u40-linux-x64.rpm

をダウンロードして、VPS上に転送をします。

サーバー上のターミナルからJDKのインストールを行います。

rpm -ivh jdk-7u40-linux-x64.rpm 
インストールが上手く行ったかバージョン確認コマンドを実行してみます。

java -version
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
javac -version
javac 1.7.0_40

不要になった jdk-7u40-linux-x64.rpm は削除しておきました。

/etc/profileの編集


/etc/profileを編集しておきます。

vim /etc/profile
export JAVA_HOME=/usr/java/default
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

編集した内容を反映させます。

source /etc/profile


2013年9月21日土曜日

さくらのVPSでPlay Frameworkを動かす:MySQLの設定をする

Apacheに比べて設定する箇所の多いMySQL。
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-character-set = utf8
skip-character-set-client-handshake
innodb_file_per_table
query-cache-size=16M
#Change Buffer Pool Size
innodb_buffer_pool_size = 512M
innodb_log_file_size = 128M
tmp_table_size = 64M
table_cache = 256
key_buffer = 128M
default-storage-engine=INNODB
# Slow Query
log-slow-queries = /var/log/mysql-slow.log
long_query_time=1
log-queries-not-using-indexes
[mysql]
default-character-set = utf8
[client]
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid 

こんなかんじに設定をしました。さくらのVPS 1Gプランなので、半分ほどMySQLにメモリを割り当ててみました。

service mysqld start
MySQLを起動したら初期設定を行います。

mysql_secure_installation
パスワード等のもろもろの設定を行います。

ログローテーションの設定をします。

vim /etc/logrotate.d/mysql-log-rotate
/var/log/mysql/error.log {
        # create 600 mysql mysql
        notifempty
    daily
        rotate 3
        missingok
        compress
    postrotate
    # just if mysqld is really running
    if test -x /usr/bin/mysqladmin && \
       /usr/bin/mysqladmin ping &>/dev/null
    then
       /usr/bin/mysqladmin flush-logs
    fi
    endscript
}

/var/log/mysql/query.log {
        # create 600 mysql mysql
        notifempty
    daily
        rotate 3
        missingok
        compress
    postrotate
    # just if mysqld is really running
    if test -x /usr/bin/mysqladmin && \
       /usr/bin/mysqladmin ping &>/dev/null
    then
       /usr/bin/mysqladmin flush-logs
    fi
    endscript
}

/var/log/mysql-slow.log {
        # create 600 mysql mysql
        notifempty
    daily
        rotate 3
        missingok
        compress
    postrotate
    # just if mysqld is really running
    if test -x /usr/bin/mysqladmin && \
       /usr/bin/mysqladmin ping &>/dev/null
    then
       /usr/bin/mysqladmin flush-logs
    fi
    endscript
}
ログローテーションに伴う設定を追加します。

vim /etc/my.cnf
[mysqladmin]
password = "パスワード"
user = root

再起動します。

service mysqld restart





さくらのVPSでPlay Frameworkを動かす:Apacheの設定をする

Apacheの設定を行います。

vim /etc/httpd/conf/httpd.conf

phpもindexに設定しておきます。

DirectoryIndex index.html index.html.var index.php

セキュリティ対策として以下を設定しておきます。

ServerTokens Prod
ServerSignature Off

Apacheを再起動します。

service httpd restart



さくらのVPSでPlay Frameworkを動かす:Apache,MySQL,PHPのインストール

以下の設定をします。

文字コードの設定

vim/etc/sysconfig/i18n
#LANG="C"
LANG="ja_JP.UTF-8"
SYSFONT="latarcyrheb-sun16"

http://support.sakura.ad.jp/manual/vps/ossetup.html

yum パッケージの更新

yum update

chkrootkit インストール

yum install chkrootkit

Apache,MySQL,PHPのインストール

yum install httpd httpd-devel mod_ssl mysql mysql-server mysql-devel php php-pdo php-mysql php-mbstring php-mcrypt php-xml gd php-gd php-devel php-pear php-openssl
自動起動の設定をしておく

chkconfig mysqld on
chkconfig httpd on