Kohei Nozaki's blog 

さくらVPSにJRE, WildFly, PostgreSQL, Apacheを入れる


Posted on Tuesday Jan 21, 2014 at 07:24AM in Technology


環境

  • さくらインターネット VPS 1G
  • CentOS 6.5
  • ここに書いた作業をした後

何をするの?

  1. JRE (jre-7u51-linux-x64.rpm) を入れる
  2. WildFly (wildfly-8.0.0.CR1.tar.gz) を入れる
  3. PostgreSQL 9.2.6を入れる
  4. Apacheを入れる

JREを入れる

いまのところこのへんにあります。私はjre-7u51-linux-x64.rpmを取ってきました。

<![CDATA[
sudo rpm -ivh jre-7u51-linux-x64.rpm
]]>

動作確認

$ java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
$ 

WildFlyを入れる

ユーザを作ります

sudo useradd wildfly

tarballを展開します

sudo tar zxvf wildfly-8.0.0.CR1.tar.gz -C /usr/local --no-same-owner
sudo chown -R wildfly:wildfly /usr/local/wildfly-8.0.0.CR1
sudo ln -s /usr/local/wildfly-8.0.0.CR1 /usr/local/wildfly

設定ファイルを作ります

sudo mkdir /etc/java
sudo sh -c 'cat > /etc/java/java.conf' <<EOF
export JAVA_HOME=/usr/java/default
EOF
sudo sh -c 'cat > /etc/default/wildfly.conf' <<EOF
export JBOSS_HOME=/usr/local/wildfly
export JBOSS_USER=wildfly
export LANG=ja_JP.UTF-8
EOF

ログとpid出力用のディレクトリを作ります

sudo mkdir /var/run/wildfly
sudo mkdir /var/log/wildfly

起動スクリプトを置きます

sudo cp /usr/local/wildfly-8.0.0.CR1/bin/init.d/wildfly-init-redhat.sh /etc/init.d/wildfly
sudo chkconfig --add wildfly
sudo chkconfig wildfly on

起動してみます

$ sudo service wildfly start
Starting wildfly:                                          [  OK  ]
$

ログとpidファイルを確認してみます

$ ls -l /var/log/wildfly
合計 8
-rw-r--r-- 1 root root 4670  1月 19 11:54 2014 console.log
$ ls -l /var/run/wildfly
合計 4
-rw-r--r-- 1 wildfly wildfly 6  1月 19 11:54 2014 wildfly.pid
$ 

ログを見てみます

=========================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: /usr/local/wildfly

  JAVA: /usr/java/default/bin/java

  JAVA_OPTS:  -server -XX:+UseCompressedOops -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true

=========================================================================

11:48:59,714 INFO  [org.jboss.modules] (main) JBoss Modules version 1.3.0.Final
11:49:05,184 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.0.CR1
11:49:05,351 INFO  [org.jboss.as] (MSC service thread 1-2) JBAS015899: WildFly 8.0.0.CR1 "WildFly" starting
11:49:07,201 INFO  [org.xnio] (MSC service thread 1-1) XNIO version 3.2.0.Beta4
11:49:07,208 INFO  [org.jboss.as.server] (Controller Boot Thread) JBAS015888: Creating http management service using socket-binding (management-http)
11:49:07,216 INFO  [org.xnio.nio] (MSC service thread 1-1) XNIO NIO Implementation Version 3.2.0.Beta4
11:49:07,278 INFO  [org.jboss.remoting] (MSC service thread 1-1) JBoss Remoting version (unknown)
11:49:07,302 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 33) JBAS010280: Activating Infinispan subsystem.
11:49:07,314 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 41) JBAS011800: Activating Naming Subsystem
11:49:07,325 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 50) JBAS015537: Activating WebServices Extension
11:49:07,317 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 46) JBAS013171: Activating Security Subsystem
11:49:07,376 INFO  [org.jboss.as.security] (MSC service thread 1-2) JBAS013170: Current PicketBox version=4.0.20.Beta2
11:49:07,395 INFO  [org.jboss.as.jsf] (ServerService Thread Pool -- 39) JBAS012615: Activated the following JSF Implementations: [main]
11:49:07,616 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017502: Undertow 1.0.0.Beta30 starting
11:49:07,665 INFO  [org.jboss.as.naming] (MSC service thread 1-2) JBAS011802: Starting Naming Service
11:49:07,646 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-1) JBAS017502: Undertow 1.0.0.Beta30 starting
11:49:07,715 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-4) JBAS015400: Bound mail session [java:jboss/mail/Default]
11:49:07,716 INFO  [org.jboss.as.connector.logging] (MSC service thread 1-4) JBAS010408: Starting JCA Subsystem (IronJacamar 1.1.2.Final)
11:49:07,725 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
11:49:07,775 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) JBAS010417: Started Driver service with driver-name = h2
11:49:07,947 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017527: Creating file handler for path /usr/local/wildfly/welcome-content
11:49:07,978 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-3) JBAS017525: Started server default-server.
11:49:08,004 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-2) JBAS017531: Host default-host starting
11:49:08,497 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-4) JBAS017519: Undertow HTTP listener default listening on /127.0.0.1:8080
11:49:09,116 INFO  [org.jboss.as.remoting] (MSC service thread 1-2) JBAS017100: Listening on 127.0.0.1:9999
11:49:09,147 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-1) JBAS015012: Started FileSystemDeploymentService for directory /usr/local/wildfly/standalone/deployments
11:49:09,248 INFO  [org.jboss.ws.common.management] (MSC service thread 1-3) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.2.3.Final
11:49:09,310 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
11:49:09,474 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
11:49:09,475 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
11:49:09,475 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.0.0.CR1 "WildFly" started in 10253ms - Started 184 of 232 services (78 services are lazy, passive or on-demand)
ログはもう一カ所 /usr/local/wildfly/standalone/log にもあります。こっちがメインっぽいです。

listenしているポートを確認してみます

$ netstat -an | grep LISTEN | grep tcp
tcp        0      0 127.0.0.1:9999              0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:8080              0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:9990              0.0.0.0:*                   LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN      
$ 
localhostしかlistenしてないのでこのままでいいかな。

WildFlyの管理ユーザを作ります

別に今すぐは使いませんが一応。

sudo -u wildfly /usr/local/wildfly/bin/add-user.sh [USERNAME] [PASSWORD]

Webの管理コンソールから設定状況を見てみます

手元の端末でトンネルを作ります

ssh [IP ADDRESS] -L 10080:localhost:80 -L 19990:localhost:9990

ここにアクセスするとトンネル経由でWebの管理コンソールにアクセス出来ます。ユーザ名とパスワードは先ほど入力した物を使います。

止めてみます

$ sudo service wildfly stop
Stopping wildfly:                                          [  OK  ]
$ ps -Af | grep java
kyle     25222 24452  0 11:58 pts/0    00:00:00 grep java
$
問題なさげ。一応リブートしてシャットダウンスクリプトと起動スクリプトが走るか確認しておくとベターかも。

PostgreSQLを入れる

インストール

<![CDATA[
sudo yum install http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm
sudo yum install postgresql92-server postgresql92-contrib
sudo service postgresql-9.2 initdb
sudo chkconfig postgresql-9.2 on
]]>

WildFlyから接続できるように認証方式を変更する

sudo -u postgres cp /var/lib/pgsql/9.2/data/pg_hba.conf /var/lib/pgsql/9.2/data/pg_hba.conf.bak
sudo -u postgres sed -i -e "s/^host    all             all             127.0.0.1\/32            ident/host    all             all             127.0.0.1\/32            md5/" /var/lib/pgsql/9.2/data/pg_hba.conf

動かしてみる

$ sudo service postgresql-9.2 start
Starting postgresql-9.2 service:                           [  OK  ]
$

Apacheを入れる

インストール

sudo yum install httpd
sudo chkconfig httpd on

動かしてみる

$ sudo service httpd start
Starting httpd:                                            [  OK  ]
$

アクセスしてみる

普通に手元の端末のブラウザからアクセス可。

参考文献



No one has commented yet.

Leave a Comment

HTML Syntax: NOT allowed