Javaな日々

NO JAVA, NO LIFE.

さくら VPS (CentOS 6.3) に LAMP を構築する - Apache インストール

  1. Apache のインストール
    今回は Web サーバーとして一般的な Apache をインストールする.アカウントを root に切り替えて yum から Apache のパッケージをインストール,起動の確認,スタートアップの設定をする.

    [admin@www****** ~]$ su -
    [root@www****** ~]# yum -y install httpd
    [root@www****** ~]# /etc/rc.d/init.d/httpd start
    [root@www****** ~]# chkconfig httpd on
    Starting httpd:                                            [  OK  ]
    [root@www****** ~]# chkconfig --list httpd
    httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off

  2. Apache の設定
    オリジナルの設定ファイルをバックアップしてからエディタで以下の項目を編集する.

    [root@ ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.org
    [root@ ~]# vi /etc/httpd/conf/httpd.conf

    • レスポンスヘッダの OS のバージョンを非表示

      ServerTokens OS
      ↓
      ServerTokens Prod

    • クライアントとの接続を保持

      KeepAlive Off
      ↓
      KeepAlive On

    • サーバー管理者を (自分のメールアドレスに) 変更

      ServerAdmin root@localhost
      ↓
      ServerAdmin admin@example.com

    • サーバー名を (自分のドメインに) 変更

      #ServerName www.example.com:80
      ↓
      ServerName www.example.com:80

    • ドキュメントルートを確認 (ここにおいたコンテンツが Web に公開される)

      DocumentRoot "/var/www/html" ←ドキュメントルートを確認

    • 以下の部分を探し,各所書き換える.

      <Directory "/var/www/html">
      
      #
      # Possible values for the Options directive are "None", "All",
      # or any combination of:
      #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
      #
      # Note that "MultiViews" must be named *explicitly* --- "Options All"
      # doesn't give it to you.
      #
      # The Options directive is both complicated and important.  Please see
      # http://httpd.apache.org/docs/2.2/mod/core.html#options
      # for more information.
      #
          # Options Indexes FollowSymLinks
          Options -Indexes ExecCGI FollowSymLinks # 変更: CGI許可,ファイル一覧表示禁止
      
      #
      # AllowOverride controls what directives may be placed in .htaccess files.
      # It can be "All", "None", or any combination of the keywords:
      #   Options FileInfo AuthConfig Limit
      #
          # AllowOverride None
          AllowOverride All # 変更: .htaccessを許可
      
      #
      # Controls who can get stuff from this server.
      #
          Order allow,deny
          Allow from all
      
      </Directory>

    • ユーザーディレクティブを有効にしたい場合は次のように書き換える
      (ユーザーディレクティブを利用する場合は /home/user_name のディレクトリを chmod でパーミッションを 755 などにしないといけない.また,ユーザーのホームディレクトリには public_html というディレクトリが必要でこれがドキュメントルートになる.)

      <IfModule mod_userdir.c>
          #
          # UserDir is disabled by default since it can confirm the presence
          # of a username on the system (depending on home directory
          # permissions).
          #
          #UserDir disabled # コメントアウトして有効化
      
          #
          # To enable requests to /~user/ to serve the user's public_html
          # directory, remove the "UserDir disabled" line above, and uncomment
          # the following line instead:
          # 
          UserDir public_html # コメントアウトを解除して設定を有効化
      
      </IfModule>
      #<Directory /home/*/public_html>
      #    AllowOverride FileInfo AuthConfig Limit
      #    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
      #    <Limit GET POST OPTIONS>
      #        Order allow,deny
      #        Allow from all
      #    </Limit>
      #    <LimitExcept GET POST OPTIONS>
      #        Order deny,allow
      #        Deny from all
      #    </LimitExcept>
      #</Directory>
      
      ↓
      
      <Directory /home/*/public_html>
          AllowOverride All # .htacess許可
          Options -Indexes ExecCGI FollowSymLinks # CGI許可,ファイル一覧表示禁止
          <Limit GET POST OPTIONS>
              Order allow,deny
              Allow from all
          </Limit>
          <LimitExcept GET POST OPTIONS>
              Order deny,allow
              Deny from all
          </LimitExcept>
      </Directory>

    • index の設定 (CGI を許可する)

      DirectoryIndex index.html index.html.var
      ↓
      DirectoryIndex index.html index.cgi index.html.var

    • ログの設定 (414 ERROR は記録しない)

      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
      ↓
      LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

    • カスタムログの設定 (worm と画像のアクセスをログに記録しない)

      CustomLog logs/access_log combined
      ↓
      SetEnvIf Request_URI "cmd\.exe" nolog
      SetEnvIf Request_URI "root\.exe" nolog
      SetEnvIf Request_URI "Admin\.dll" nolog
      SetEnvIf Request_URI "NULL\.IDA" nolog
      SetEnvIf Request_URI "^/_mem_bin/" nolog
      SetEnvIf Request_URI "^/_vti_bin/" nolog
      SetEnvIf Request_URI "^/c/" nolog
      SetEnvIf Request_URI "^/d/" nolog
      SetEnvIf Request_URI "^/msadc/" nolog
      SetEnvIf Request_URI "^/MSADC/" nolog
      SetEnvIf Request_URI "^/scripts/" nolog
      SetEnvIf Request_URI "^/default.ida" nolog
      SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(ico)|(css)$" nolog
      SetEnvIf Remote_Addr 192.168. no_log
      CustomLog logs/access_log combined env=!no_log

    • エラー画面でApacheのバージョン非表示

      ServerSignature On
      ↓
      ServerSignature Off

    • Indexes が OFF なのでファイル一覧表示のアイコンの設定はすべてコメントアウト

      Alias /icons/ "/var/www/icons/"
      <Directory "/var/www/icons">
          Options Indexes MultiViews
          AllowOverride None
          Order allow,deny
          Allow from all
      </Directory>
      ↓
      #Alias /icons/ "/var/www/icons/"
      #<Directory "/var/www/icons">
      #    Options Indexes MultiViews FollowSymLinks
      #    AllowOverride None
      #    Order allow,deny
      #    Allow from all
      #</Directory>

    • ScriptAlias は使わないためすべてコメントアウト

      ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
      <Directory "/var/www/cgi-bin">
           AllowOverride None
           Options None
           Order allow,deny
           Allow from all
      </Directory>
      ↓
      #ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
      #<Directory "/var/www/cgi-bin">
      #     AllowOverride None
      #     Options None
      #     Order allow,deny
      #     Allow from all
      #</Directory>

    • autoindexに関係する設定をすべてコメントアウト

      #
      # IndexOptions: Controls the appearance of server-generated directory
      # listings.
      #
      #IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8
      
      #
      # AddIcon* directives tell the server which icon to show for different
      # files or filename extensions.  These are only displayed for
      # FancyIndexed directories.
      #
      #AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
      
      #AddIconByType (TXT,/icons/text.gif) text/*
      #AddIconByType (IMG,/icons/image2.gif) image/*
      #AddIconByType (SND,/icons/sound2.gif) audio/*
      #AddIconByType (VID,/icons/movie.gif) video/*
      
      #AddIcon /icons/binary.gif .bin .exe
      #AddIcon /icons/binhex.gif .hqx
      #AddIcon /icons/tar.gif .tar
      #AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
      #AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
      #AddIcon /icons/a.gif .ps .ai .eps
      #AddIcon /icons/layout.gif .html .shtml .htm .pdf
      #AddIcon /icons/text.gif .txt
      #AddIcon /icons/c.gif .c
      #AddIcon /icons/p.gif .pl .py
      #AddIcon /icons/f.gif .for
      #AddIcon /icons/dvi.gif .dvi
      #AddIcon /icons/uuencoded.gif .uu
      #AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
      #AddIcon /icons/tex.gif .tex
      #AddIcon /icons/bomb.gif core
      
      #AddIcon /icons/back.gif ..
      #AddIcon /icons/hand.right.gif README
      #AddIcon /icons/folder.gif ^^DIRECTORY^^
      #AddIcon /icons/blank.gif ^^BLANKICON^^
      
      #
      # DefaultIcon is which icon to show for files which do not have an icon
      # explicitly set.
      #
      #DefaultIcon /icons/unknown.gif
      
      #
      # AddDescription allows you to place a short description after a file in
      # server-generated indexes.  These are only displayed for FancyIndexed
      # directories.
      # Format: AddDescription "description" filename
      #
      #AddDescription "GZIP compressed document" .gz
      #AddDescription "tar archive" .tar
      #AddDescription "GZIP compressed tar archive" .tgz
      
      #
      # ReadmeName is the name of the README file the server will look for by
      # default, and append to directory listings.
      #
      # HeaderName is the name of a file which should be prepended to
      # directory indexes.
      #ReadmeName README.html
      #HeaderName HEADER.html
      
      #
      # IndexIgnore is a set of filenames which directory indexing should ignore
      # and not include in the listing.  Shell-style wildcarding is permitted.
      #
      #IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t

    • AddLanguage ja .ja の行を最上位に移動して日本語を優先

      AddLanguage ja .ja
      AddLanguage ca .ca
      AddLanguage cs .cz .cs
      AddLanguage da .dk
      AddLanguage de .de
      AddLanguage el .el
      AddLanguage en .en
      AddLanguage eo .eo
      AddLanguage es .es
      AddLanguage et .et
      AddLanguage fr .fr
      AddLanguage he .he
      AddLanguage hr .hr
      AddLanguage it .it
      AddLanguage ko .ko
      AddLanguage ltz .ltz
      AddLanguage nl .nl
      AddLanguage nn .nn
      AddLanguage no .no
      AddLanguage pl .po
      AddLanguage pt .pt
      AddLanguage pt-BR .pt-br
      AddLanguage ru .ru
      AddLanguage sv .sv
      AddLanguage zh-CN .zh-cn
      AddLanguage zh-TW .zh-tw

    • MIME 言語タイプの適用優先順位で日本語を優先

      LanguagePriority ja en ca cs da de el eo es et fr he hr it ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW

    • CGI を許可

      # AddHandler cgi-script .cgi
      ↓
      AddHandler cgi-script .cgi .pl

    ここまで終わったら保存して終了.
    設定ファイルの文法チェックを行い,正常であれば Apache を再起動して設定を適用させる.

    [root@www****** ~]# apachectl configtest
    Syntax OK
    [root@www****** ~]# /etc/rc.d/init.d/httpd restart
    Stopping httpd:                                            [  OK  ]
    Starting httpd:                                            [  OK  ]

  3. HTTP 接続用のポートを開放.

    [admin@www****** ~]$ sudo vi /etc/sysconfig/iptables

    以下を追記します.

    -A FIREWALL -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

  4. 以下のコマンドでドキュメントルートにテスト用の簡易 HTML を配置,ブラウザで XXX.XXX.XXX.XXX を開いて確認してみる.

    [root@www****** ~]# echo '<!DOCTYPE html><html><head><title>Hello</title></head><body>Hello</body></html>' > /var/www/html/index.html

    一旦ここまででサーバーを再起動しておく.

    [root@www****** ~]# reboot

さくら VPS (CentOS 6.3) に LAMP を構築する - セキュリティ設定

  1. sudo の設定
    管理者権限を使う方法として,ユーザー切り替えの su コマンドで root ユーザーになる方法があるが,

    • 権限の範囲が指定できない
    • 管理者権限を使用したユーザーがわからない

    などのセキュリティ上の問題があるため,sudo コマンドを使う事が推奨されている.

    デフォルトでは sudo は root ユーザーのみが利用できる設定になっているため,先程設定した管理者グループ (wheel) で sudo が使えるように設定する.

    [root@www****** ~]# visudo

    visudo コマンドで開いた vi エディタで以下の行を探し,コメントアウトを解除する.

    # %wheel ALL=(ALL) ALL
    ↓
    %wheel ALL=(ALL) ALL

  2. su の設定
    su コマンドも wheel のユーザーのみが使用できるように設定を変更しておく.

    [root@www****** ~]# vi /etc/login.defs

    /etc/login.defs の最後の行に以下を追記.
    (2013/06/06 追記: 投稿時は SU_WHEEL_ONLY yes としていましたが,現在はこの記述で OK.)

    SU_WHEEL_ONLY

  3. ssh のポート番号変更 (任意)
    ssh のポート番号をデフォルト (22) のままにしておくと攻撃を受けることがあるため,ポート番号を変更しておく.

    [admin@www****** ~]$ sudo vi /etc/ssh/sshd_config

    /etc/ssh/sshd_config を以下のように書き換える.(xxxxx は一般的に他のアプリケーションと重複しない 10000 ~ 65535 の任意のポート番号を設定)

    #Port 22
    ↓
    Port xxxxx

    ssh を再起動してログインを確認する.

    [admin@www****** ~]$ sudo /etc/init.d/sshd restart
    sshd を停止中:                                             [  OK  ]
    sshd を起動中:                                             [  OK  ]
    [admin@www****** ~]$ exit
    logout
    Connection to XXX.XXX.XXX.XXX closed.

    サーバーとの接続を閉じ,変更したポートからログイン.

    $ ssh admin@XXX.XXX.XXX.XXX -p xxxxx (上で設定したポート番号)

  4. 公開鍵ログインの設定 (任意)
    個人の重要なデータを保存するサーバーの場合,パスワードによる ssh ログインを有効にしておくとセキュリティ上に問題があるとされるため,公開鍵暗号方式に切り替える.

    一旦サーバーとの接続を切る.

    [admin@www****** ~]# exit
    logout
    Connection to XXX.XXX.XXX.XXX closed.

    ローカル側で秘密鍵と公開鍵を作成.

    $ ssh-keygen -t rsa
    
    Enter file in which to save the key (/Users/name/.ssh/id_rsa): Enter
    Enter passphrase (empty for no passphrase): 任意のパスフレーズを設定
    Enter same passphrase again: もう一回入力
    Your identification has been saved in /Users/user/.ssh/id_rsa.
    Your public key has been saved in /Users/user/.ssh/id_rsa.pub.
    The key fingerprint is:
    xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx user@PC-Name.local
    The key's randomart image is:
    +--[ RSA 2048]----+
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    +-----------------+
    $ cat ~/.ssh/id_rsa.pub
    ssh-rsa xxxxxxxx...xxxx user@PC-Name.local

    ~/.ssh/id_rsa.pub が作成されていることを確認.

    次にサーバー側の設定.
    先ほど作成した作業用のアカウントで ssh ログインし,公開鍵登録用の .ssh というディレクトリをホームディレクトリに作成,パーミッションを 700 に設定.

    $ ssh admin@XXX.XXX.XXX.XXX -p xxxxx 
    [admin@www****** ~]$ cd ~
    [admin@www****** ~]$ mkdir .ssh
    [admin@www****** ~]$ chmod 700 .ssh/
    [admin@www****** ~]$ exit
    logout
    Connection to XXX.XXX.XXX.XXX closed.

    一旦接続を閉じてローカルの公開鍵を scp コマンドを用いて公開鍵をサーバーにアップロード.

    $ scp ~/.ssh/id_rsa.pub admin@XXX.XXX.XXX.XXX:~/.ssh/authorized_keys
    id_rsa.pub                100%  408     0.4KB/s   00:00

    作業用ユーザーでサーバーにログインし,登録した鍵のファイルのパーミッションを 600 に設定.

    $ ssh admin@XXX.XXX.XXX.XXX -p xxxxx
    [admin@www****** ~]$ chmod 600 .ssh/authorized_keys

    ssh の設定を公開鍵認証方式に切り替える.

    [admin@www****** ~]$ sudo vi /etc/ssh/sshd_config
    
    We trust you have received the usual lecture from the local System
    Administrator. It usually boils down to these three things:
    
        #1) Respect the privacy of others.
        #2) Think before you type.
        #3) With great power comes great responsibility.
    
    [sudo] password for admin: 

    vi エディタで /etc/ssh/sshd_config を開き,以下のように書き換える.

    #PermitRootLogin yes
    ↓
    PermitRootLogin no # rootでのログインを禁止
    #PasswordAuthentication yes
    ↓
    PasswordAuthentication no # パスワード認証を禁止
    #PermitEmptyPasswords no
    ↓
    PermitEmptyPasswords no # 空のパスワードを禁止
    UsePAM yes
    ↓
    UsePAM no # PAMのパスワード認証を禁止

    ssh を再起動させて設定を適用.

    [admin@www****** ~]$ sudo /etc/init.d/sshd restart
    [sudo] password for admin: 
    sshd を停止中:                                             [  OK  ]
    sshd を起動中:                                             [  OK  ]

    これでリモートコンソールからと秘密鍵を持った PC から作業用ユーザーでログインすることしかできなくなる.手順にミスがあると ssh でのログインが出来なくなるため注意.
    念のためログインできることを確認.

    [admin@www****** ~]$ exit
    logout
    Connection to XXX.XXX.XXX.XXX closed.

    一旦サーバーとの接続を閉じ,ローカルから再度 ssh

    $ ssh admin@XXX.XXX.XXX.XXX -p xxxxx 

    ※ ここでログイン出来ない場合はさくら VPS の管理メニューのリモートコンソールからローカルの公開鍵 (~/.ssh/id_rsa.pub) とアップロードした公開鍵 (/home/admin/.ssh/authorized_keys) を比較して同じことを確認する.違っていればコピペするなり編集.


  5. iptables によるパケットフィルタ設定
    パケットフィルタリングは,IPアドレスやポート番号等の情報を元に通信データにフィルターをかけて,通過・遮断・転送・記録する機能.これを設定することによって無駄なトラフィックを減らしたり,セキュリティを向上させることができる.

    [admin@www****** ~]$ sudo vi /etc/sysconfig/iptables

    /etc/sysconfig/ に iptables というファイルを作成し,以下の内容を書き込む.
    (今回は SSH の使用を許可する場合の設定を記述した.実際は各自の用途に合わせて設定.)

    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    :FIREWALL - [0:0]
    -A INPUT -j FIREWALL
    -A FORWARD -j FIREWALL
    -A FIREWALL -i lo -j ACCEPT
    -A FIREWALL -p icmp --icmp-type any -j ACCEPT
    -A FIREWALL -p 50 -j ACCEPT
    -A FIREWALL -p 51 -j ACCEPT
    -A FIREWALL -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
    -A FIREWALL -p udp -m udp --dport 631 -j ACCEPT
    -A FIREWALL -p tcp -m tcp --dport 631 -j ACCEPT
    -A FIREWALL -m state --state ESTABLISHED,RELATED -j ACCEPT
    # SSH (xxxxx は自分で指定したポート番号)
    -A FIREWALL -m state --state NEW -m tcp -p tcp --dport xxxxx -j ACCEPT
    
    -A FIREWALL -j REJECT --reject-with icmp-host-prohibited
    COMMIT

    設定した iptables を適用させ,フィルタリングの設定を確認する.

    [admin@www****** ~]$ sudo /etc/rc.d/init.d/iptables restart
    iptables: ファイアウォールルールを適用中:                  [  OK  ]
    [admin@www****** ~]$ sudo iptables -L
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         
    FIREWALL   all  --  anywhere             anywhere            
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         
    FIREWALL   all  --  anywhere             anywhere            
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination         
    
    Chain FIREWALL (2 references)
    target     prot opt source               destination         
    ACCEPT     all  --  anywhere             anywhere            
    ACCEPT     icmp --  anywhere             anywhere            icmp any 
    ACCEPT     esp  --  anywhere             anywhere            
    ACCEPT     ah   --  anywhere             anywhere            
    ACCEPT     udp  --  anywhere             224.0.0.251         udp dpt:mdns 
    ACCEPT     udp  --  anywhere             anywhere            udp dpt:ipp 
    ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ipp 
    ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 
    ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:10022
    REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 

さくら VPS (CentOS 6.3) に LAMP を構築する - 初期設定

  1. CentOS インストール
    公式マニュアル を参考に CentOS6 x86_64 をインストール.(ここで Keyboard Type はクライアントマシンが US キーボードの場合でも Java がプログラム内部で変換してくれる?らしいので jp106 を選択)
    OS インストール後,VPS の起動を確認してから Mac OS X 標準のターミナルを起動して root で ssh ログイン.

    $ ssh root@XXX.XXX.XXX.XXX

    ※ 以前 ssh で VPS にログインしていたりするとエラーが出てログイン出来ない場合がある (~/.ssh/known_hosts に証明書が残っているため).その場合は以下のコマンドを入力.

    $ ssh-keygen -R XXX.XXX.XXX.XXX

  2. yum 設定
    yum のアップデート可能なすべてのパケージをアップデート.
    yum-cron をインストールしてパッケージを毎日自動更新するように設定.(yum-cron のランレベルは 3, 4, 5 で on になっていることを確認)

    [root@www****** ~]# yum -y update
    [root@www****** ~]# yum -y install yum-cron
    [root@www****** ~]# /etc/rc.d/init.d/yum-cron start
    Enabling nightly yum update:                               [  OK  ]
    [root@www****** ~]# chkconfig yum-cron on
    [root@www****** ~]# chkconfig --list yum-cron
    yum-cron       	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    # ランレベルの一覧
    0: シャットダウンに向かう状態
    1: シングルユーザモード
    2: 使用されない
    3: 標準的な状態
    4: 使用されない
    5: GUIでログインする状態
    6: 再起動に向かう状態

  3. 作業用のユーザーを追加
    ここでは admin というユーザーを作成して wheel という管理者グループに追加して作業を進める.今後管理者権限を使えるユーザーを追加したい時はこの wheel グループに該当ユーザーを追加していけばいい.

    [root@www****** ~]# useradd admin
    [root@www****** ~]# passwd admin
    ユーザー admin のパスワードを変更。
    新しいパスワード: 任意のパスワードを入力
    新しいパスワードを再入力してください: 確認の為再入力
    passwd: 全ての認証トークンが正しく更新できました。
    [root@www****** ~]# usermod -G wheel admin

    ここからは作業用のユーザー admin に切り替えて作業します.

    [root@www****** ~]# su - admin

  4. bash の設定
    admin でログインした状態で bash (シェル) からシステム系コマンドを叩きやすくするためにパスを通しておく.

    [admin@www****** ~]$ vi ~/.bash_profile

    ~/.bash_profile を以下のように書き換える.

    # .bash_profile
    
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    	. ~/.bashrc
    fi
    
    # User specific environment and startup programs
    
    PATH=$PATH:$HOME/bin
    PATH=$PATH:/sbin           # 追記
    PATH=$PATH:/usr/sbin       # 追記
    PATH=$PATH:/usr/local/sbin # 追記
    
    export PATH

    書き換えた .bash_profile を適用する.

    [admin@www****** ~]$ source ./.bash_profile

CentOS に Play Framework をインストールする

環境

手順

  1. Play Framework 公式サイト から本体をダウンロード,解凍して配置,インストール.

    [admin ~]$ wget http://download.playframework.org/releases/play-2.0.4.zip
    --2013-01-06 12:52:34--  http://download.playframework.org/releases/play-2.0.4.zip
    download.playframework.org をDNSに問いあわせています... 88.190.20.213
    download.playframework.org|88.190.20.213|:80 に接続しています... 接続しました。
    HTTP による接続要求を送信しました、応答を待っています... 200 OK
    長さ: 101288372 (97M) [application/zip]
    `play-2.0.4.zip' に保存中
    
    100%[================>] 101,288,372 5.33M/s 時間 21s     
    
    2013-01-06 12:52:57 (4.51 MB/s) - `play-2.0.4.zip' へ保存完了 [101288372/101288372]
    
    [admin ~]$ unzip play-2.0.4.zip 
    [admin ~]$ sudo mv play-2.0.4/ /usr/local
    [admin ~]$ cd /usr/bin
    [admin bin]$ sudo ln -s /usr/local/play-2.0.4/play play
    [admin ~]$ cd ~
    [admin ~]$ play
    Getting net.java.dev.jna jna 3.2.3 ...
    :: retrieving :: org.scala-sbt#boot-app
    	confs: [default]
    	1 artifacts copied, 0 already retrieved (838kB/24ms)
    Getting Scala 2.9.1 (for console)...
    :: retrieving :: org.scala-sbt#boot-scala
    	confs: [default]
    	4 artifacts copied, 0 already retrieved (19939kB/72ms)
    Getting play console_2.9.1 2.0.4 ...
    :: retrieving :: org.scala-sbt#boot-app
    	confs: [default]
    	5 artifacts copied, 0 already retrieved (3667kB/28ms)
           _            _ 
     _ __ | | __ _ _  _| |
    | '_ \| |/ _' | || |_|
    |  __/|_|\____|\__ (_)
    |_|            |__/ 
                 
    play! 2.0.4, http://www.playframework.org
    
    This is not a play application!
    
    Use `play new` to create a new Play application in the current directory, 
    or go to an existing application and launch the development console using `play`.
    
    You can also browse the complete documentation at http://www.playframework.org.

  2. Play 用のポート 9000 番を開放.

    [admin ~]$ sudo vi /etc/sysconfig/iptables

    各自自分の環境に合わせて iptables を書き換える.

    -A INPUT -p tcp --dport 9000 -j ACCEPT

    設定を適用.

    [admin ~]$ sudo /etc/rc.d/init.d/iptables restart

CentOS に GlassFish をインストールする

環境

手順

  1. JDK をインストール.

    [admin ~]$ wget http://download.oracle.com/otn-pub/java/jdk/7u10-b18/jdk-7u10-linux-x64.rpm?AuthParam=1357419969_757bfc23a48c53055c2b34a0b9691ef7
    --2013-01-06 06:04:32--  http://download.oracle.com/otn-pub/java/jdk/7u10-b18/jdk-7u10-linux-x64.rpm?AuthParam=1357419969_757bfc23a48c53055c2b34a0b9691ef7
    download.oracle.com をDNSに問いあわせています... 210.149.135.46, 210.149.135.31
    download.oracle.com|210.149.135.46|:80 に接続しています... 接続しました。
    HTTP による接続要求を送信しました、応答を待っています... 200 OK
    長さ: 109839764 (105M) [application/x-redhat-package-manager]
    `jdk-7u10-linux-x64.rpm?AuthParam=1357419969_757bfc23a48c53055c2b34a0b9691ef7' に保存中
    
    100%[================>] 109,839,764 17.4M/s 時間 6.1s    
    
    2013-01-06 06:04:38 (17.3 MB/s) - `jdk-7u10-linux-x64.rpm?AuthParam=1357419969_757bfc23a48c53055c2b34a0b9691ef7' へ保存完了 [109839764/109839764]
    
    [admin ~]$ mv jdk-7u10-linux-x64.rpm\?AuthParam\=1357419969_757bfc23a48c53055c2b34a0b9691ef7 jdk-7u10-linux-x64.rpm

  2. rpm コマンドでインストール.

    [admin@www3204ui ~]$ sudo rpm -ivh jdk-7u10-linux-x64.rpm 
    [sudo] password for admin: 
    準備中...                ########################################### [100%]
       1:jdk                    ########################################### [100%]
    Unpacking JAR files...
    	rt.jar...
    Error: Could not open input file: /usr/java/jdk1.7.0_10/jre/lib/rt.pack
    	jsse.jar...
    Error: Could not open input file: /usr/java/jdk1.7.0_10/jre/lib/jsse.pack
    	charsets.jar...
    Error: Could not open input file: /usr/java/jdk1.7.0_10/jre/lib/charsets.pack
    	tools.jar...
    Error: Could not open input file: /usr/java/jdk1.7.0_10/lib/tools.pack
    	localedata.jar...
    Error: Could not open input file: /usr/java/jdk1.7.0_10/jre/lib/ext/localedata.pack

  3. GlassFish 本体 (glassfish-3.1.2.2-ml.zip) を ここ からダウンロード.

    [admin@www3204ui ~]$ wget http://dlc.sun.com.edgesuite.net/glassfish/3.1.2.2/release/glassfish-3.1.2.2-ml.zip
    --2013-01-06 08:18:48--  http://dlc.sun.com.edgesuite.net/glassfish/3.1.2.2/release/glassfish-3.1.2.2-ml.zip
    dlc.sun.com.edgesuite.net をDNSに問いあわせています... 210.149.135.13, 210.149.135.29
    dlc.sun.com.edgesuite.net|210.149.135.13|:80 に接続しています... 接続しました。
    HTTP による接続要求を送信しました、応答を待っています... 200 OK
    長さ: 103538855 (99M) [application/zip]
    `glassfish-3.1.2.2-ml.zip' に保存中
    
    100%[================>] 103,538,855 15.4M/s 時間 8.9s    
    
    2013-01-06 08:18:57 (11.1 MB/s) - `glassfish-3.1.2.2-ml.zip' へ保存完了 [103538855/103538855]
    </li>
    
    <li>[admin ~]$ sudo vi /etc/sysconfig/iptables

    iptable でポートを GlassFish 用に開けておく.以下は例.各自の環境に合わせて編集.

    -A INPUT -p tcp --dport 4848 -j ACCEPT
    -A INPUT -p tcp --dport 8080 -j ACCEPT
    -A INPUT -p tcp --dport 8181 -j ACCEPT
    -A INPUT -p tcp --dport 3820 -j ACCEPT
    -A INPUT -p tcp --dport 3920 -j ACCEPT
    -A INPUT -p tcp --dport 3700 -j ACCEPT
    [admin ~]$ sudo /etc/rc.d/init.d/iptables restart
    iptables: ファイアウォールルールを消去中:                  [  OK  ]
    iptables: チェインをポリシー ACCEPT へ設定中filter         [  OK  ]
    iptables: モジュールを取り外し中:                          [  OK  ]
    iptables: ファイアウォールルールを適用中:                  [  OK  ]

  4. インストール.

    [admin ~]$ unzip glassfish-3.1.2.2-ml.zip
    [admin ~]$ sudo mv glassfish3/ /usr/local/

  5. GlassFish を起動.

    [admin ~]$ cd /usr/local/glassfishv3/glassfish/bin
    [admin bin]$ sudo ./asadmin start-domain domain1
    domain1の起動を待機しています ........
    domain が正常に起動されました: domain1
    domain 場所: /usr/local/glassfishv3/glassfish/domains/domain1
    ログ・ファイル: /usr/local/glassfishv3/glassfish/domains/domain1/logs/server.log
    管理ポート: 4848
    コマンドstart-domainは正常に実行されました。

  6. admin ユーザーの設定

    [admin ~]$ /usr/local/glassfish3/bin/asadmin --host localhost --port 4848
    asadmin> change-admin-password
    管理ユーザー名を入力してください[デフォルト: admin]> admin
    管理パスワードを入力してください> 空Enter
    新しい管理パスワードを入力してください> 任意のパスワード
    新しい管理パスワードをもう一度入力してください> 再入力
    コマンドchange-admin-passwordは正常に実行されました。
    asadmin> enable-secure-admin
    管理ユーザー名を入力してください>  admin
    ユーザー"admin"の管理パスワードを入力してください> 
    セキュリティ保護された管理に対する変更を有効にするには、稼働中のすべてのサーバーを再起動する必要があります。
    コマンドenable-secure-adminは正常に実行されました。
    asadmin> stop-domain
    ドメインの停止を待機しています .....
    コマンドstop-domainは正常に実行されました。
    asadmin> start-domain
    domain1の起動を待機しています .......
    domain が正常に起動されました: domain1
    domain 場所: /usr/local/glassfish3/glassfish/domains/domain1
    ログ・ファイル: /usr/local/glassfish3/glassfish/domains/domain1/logs/server.log
    管理ポート: 4848
    コマンドstart-domainは正常に実行されました。

    ブラウザから XXX.XXX.XXX.XXX:4848 にアクセスして管理画面が開くことを確認.

さくら VPS (CentOS 6.3) に LAMP を構築する

(この記事は現在執筆中です)

目的

さくら VPS 上の CentOSApache, MySQL, PHP が動く一般的な Web サーバーを構築する.

環境

FreeBSDにJavaをインストール

環境

手順

# vi /etc/rc.conf

以下を追記してリブート.

linux_enable=”YES”

# cd /usr/ports/java/linux-sun-jdk17
# make clean install

このコマンドを実行してみると,/usr/ports/distfiles に自分でファイル落としてこいと言われるので必要なファイルを確認した後,ggってJDKのダウンロードリンクをゲット,ダウンロードしてくる (ライセンスの関係上こういうややこしいことになっているらしい).

# cd /usr/ports/distfiles
# wget "http://download.oracle.com/otn-pub/java/jdk/7u9-b05/jdk-7u9-linux-i586.tar.gz?AuthParam=1356070403_6c078dda9169b56bf68fcd423ea91938"
# mv jdk-7u9-linux-i586.tar.gz?AuthParam=1356070403_6c078dda9169b56bf68fcd423ea91938 jdk-7u9-linux-i586.tar.gz

改めてインストール.

# cd /usr/ports/java/linux-sun-jdk17
# make clean install

これで java コマンドを動かそうとしてみると,libjli.so not found とか言われる.
探してみたらインストールした Java ファイル郡の中 (/usr/local/linux-sun-jdk1.7.0/jre/lib/i386/jli/libjli.so) に普通に見つかったのでシンボリックリンクを作成して読み込めるようにする.

# ln -s /usr/local/linux-sun-jdk1.7.0/jre/lib/i386/jli/libjli.so /usr/local/lib/