m_shige1979のときどきITブログ

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

Github(変なおっさんの顔でるので気をつけてね)

https://github.com/mshige1979

JavaEEのサンプルアプリをCentOSに入れてみる

公開前の予行演習

実際にどうするかはわからないけどNetBeansで作成だけというのも変なので
ちょっとwarファイルをあげてみる

環境

vagrantのCentOS6.7
Java8
glassfish4.1

Vagrantの設定ファイル

Vagrantfile
#-*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
 # Every Vagrant development environment requires a box. You can search for
 # boxes at https://atlas.hashicorp.com/search.
 config.vm.box = "centos67_01"

 # Create a private network, which allows host-only access to the machine
 # using a specific IP.
 config.vm.network "private_network", ip: "192.168.33.10"

 # Share an additional folder to the guest VM. The first argument is
 # the path on the host to the actual folder. The second argument is
 # the path on the guest to mount the folder. And the optional third
 # argument is a set of non-required options.
 config.vm.synced_folder "./", "/vagrant", \
       create: true, owner: 'vagrant', group: 'vagrant', \
       mount_options: ['dmode=777,fmode=777']

 # Provider-specific configuration so you can fine-tune various
 # backing providers for Vagrant. These expose provider-specific options.
 # Example for VirtualBox:
 #
 config.vm.provider "virtualbox" do |vb|
   # Customize the amount of memory on the VM:
   vb.memory = "1024"
 end

end

ツールインストール

Java8
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.rpm
sudo rpm -ivh jdk-8u91-linux-x64.rpm
Glassfish4.1
wget http://download.java.net/glassfish/4.1/release/glassfish-4.1.zip
unzip glassfish-4.1.zip
sudo mv glassfish4 /usr/local/.
apache
sudo yum install httpd httpd-devel -y
sudo service httpd start
sudo chkconfig httpd on

glassfish設定

glassfishlocalhost以外で使用する場合はちょっと制限がある

起動
sudo /usr/local/glassfish4/bin/asadmin start-domain
管理者パスワード変更
$ sudo /usr/local/glassfish4/bin/asadmin change-admin-password
Enter admin user name [default: admin]>
Enter the admin password>
Enter the new admin password>
Enter the new admin password again>
Command change-admin-password executed successfully.
$

※ユーザーは"admin"、パスワードは空文字になっているのでそれ以降のところにパスワードを設定する

ログインストアにパスワードを登録
$ sudo /usr/local/glassfish4/bin/asadmin login
Enter admin user name [Enter to accept default]> admin
Enter admin password>
Login information relevant to admin user name [admin] for host [localhost] and admin port [4848] stored at [/root/.gfclient/pass] successfully.
Make sure that this file remains protected. Information stored in this file will be used by administration commands to manage associated domain.
Command login executed successfully.
$

※管理者パスワードと同じものにする

SSLを有効化
$ sudo /usr/local/glassfish4/bin/asadmin enable-secure-admin
You must restart all running servers for the change in secure admin to take effect.
Command enable-secure-admin executed successfully.
$
glassfish再起動
$ sudo /usr/local/glassfish4/bin/asadmin stop-domain
Waiting for the domain to stop .
Command stop-domain executed successfully.
[vagrant@localhost ~]$ sudo /usr/local/glassfish4/bin/asadmin start-domain
Waiting for domain1 to start .....
Successfully started the domain : domain1
domain  Location: /usr/local/glassfish4/glassfish/domains/domain1
Log File: /usr/local/glassfish4/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.
$

JavaDB制御

/usr/java/jdk1.8.0_91/jre/lib/security/java.policy
grant {
        // 追加
        permission java.net.SocketPermission "localhost:1527", "listen,resolve";
};

※最後の方に追加する

JavaDB起動
sudo /usr/local/glassfish4/bin/asadmin start-database
データベース作成
$ /usr/local/glassfish4/javadb/bin/ij
ijバージョン10.10
ij> connect 'jdbc:derby://localhost/MemoDB;create=true';
ij> create table memo(
>   id int not null generated always as identity ( start with 1, increment by 1),
>   memo varchar(512),
>   constraint pk_memo primary key(id)
> );
0行が挿入/更新/削除されました
ij> select * from memo;
ID         |MEMO
--------------------------------------------------------------------------------------------------------------------------------------------

0行が選択されました
ij> exit;
$

デプロイ

アプリケーションを指定してデプロイする

f:id:m_shige1979:20160601210839p:plain

warをアップロード

f:id:m_shige1979:20160601211011p:plain

パラメータ設定

f:id:m_shige1979:20160601211226p:plain

プロキシ設定

/etc/httpd/conf/httpd.conf
<IfModule mod_proxy.c>
ProxyRequests Off
<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
ProxyPassReverseCookieDomain 127.0.0.1:8080 192.168.33.10
ProxyPassReverseCookiePath / /
</IfModule>

※末尾に追加

再起動
sudo service httpd restart

確認

f:id:m_shige1979:20160601211901p:plain

所感

とりあえずこんな感じで対応する。
http://ほげほげ/の場合の画面をどうするか考えないといけない
なかなか設定サンプルがないのでいろいろ探して考えてみる