2014年4月16日水曜日

Vagrant & PostgreSQL9.3で構築1

Vagrant使って、実験環境構築やってみる。

ubuntu.comにクラウド用のファイルが準備されている。


https://cloud-images.ubuntu.com/vagrant/precise/20140407/ のなかにある
precise-server-cloudimg-amd64-vagrant-disk1.box を指定。

boxファイルをリストに加える。
新しく仮想マシン設定して、立ち上げる。


$ mkdir precise64

$ cd precise64/

$ vagrant box add u12s-amd64  https://cloud-images.ubuntu.com/vagrant/precise/20140407/precise-server-cloudimg-amd64-vagrant-disk1.box

$ vagrant init u12s-amd64

A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on

`vagrantup.com` for more information on using Vagrant.

$ vagrant up

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'precise-server-amd64'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: precise64_default_1397574231693_73861
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2202.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2202 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2202
    default: SSH username: vagrant
    default: SSH auth method: private key

    default: Warning: Connection timeout. Retrying...
...

ログインして構築開始。
passなしで入れるのはなんか拍子抜けだけど楽。

$ vagrant ssh

Welcome to Ubuntu 12.04.4 LTS (GNU/Linux 3.2.0-60-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Tue Apr 15 11:47:34 UTC 2014

  System load:  0.0               Processes:           72
  Usage of /:   4.0% of 39.37GB   Users logged in:     0
  Memory usage: 15%               IP address for eth0: 10.0.2.15
  Swap usage:   0%

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud


PostgreSQL 9.3インストール



$ sudo vi /etc/apt/sources.list.d/pgdg.list


ファイルの1行目に以下を書く。

deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main



wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

$ sudo apt-get update

sudo apt-get install -y postgresql-9.3

$ sudo adduser dolphin -disabled-password

$ sudo -u postgres createuser -P --interactive --replication dolphin

$ sudo -u dolphin createdb -lC -Ttemplate0 -EUTF-8 dolphin

確認してみる

$ sudo -u dolphin psql dolphin

dolphin=# \du

dolphin=# \q

OpenJDKインストール


$ sudo apt-get -y install openjdk-7-jdk

Wildfly展開


作成メモ2と同様に作成。もしくは展開

$ tar zxvf jboss-as-7.2.0-hibernate-4.2.11-resteasy-3.0.7.tgz 

$ sudo mv jboss /usr/local/

$ sudo useradd jboss

$ sudo chown -R jboss.jboss /usr/local/jboss


hibernate 4.2.11とresteasy 3.0.7に上がってました。

管理ユーザー登録を作成メモ1同様にする。



$ sudo -i
# /usr/local/jboss/bin/add-user.sh

一度ログオフ。
# exit
$ exit

ホストからアクセスできるようにVagrantfile を編集


$ vi Vagrantfile
...
#config.vm.network "private_network", ip: "192.168.33.10"
...

コメント外して、「”」外して「:」に書き換え
config.vm.network :private_network, ip: "192.168.33.10"

$ vagrant reload

==> default: Attempting graceful shutdown of VM...
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2201.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2201 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2201
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 4.1.12
    default: VirtualBox Version: 4.3
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/dolphin/OD-ORCA

==> default: VM already provisioned. Run `vagrant provision` or use `--provision` to force it

$ vagrant ssh

Welcome to Ubuntu 12.04.4 LTS (GNU/Linux 3.2.0-60-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Tue Apr 15 12:40:14 UTC 2014

  System load:  0.0               Processes:           77
  Usage of /:   4.7% of 39.37GB   Users logged in:     0
  Memory usage: 12%               IP address for eth0: 10.0.2.15
  Swap usage:   0%                IP address for eth1: 192.168.33.10

ホスト側から192.168.33.10でアクセスできる。

$ sudo /usr/local/jboss/bin/standalone.sh -b=192.168.33.10 -bmanagement=192.168.33.10

ホストからブラウザで入ってみる。

http://192.168.33.10:8080

0 件のコメント:

コメントを投稿