Chef: chef-solo provision для Vagrant — установка IBM WebSphere Application Server

Автор: | 12/15/2015
 

pic-chef-logoЗадача: установить IBM WebSphere Application Server на Vagrant box с помощью chef-colo.

Операционная система — Ubutnu.

Подготовка

 

Создаем саму машину:

$ mkdir ~/websphere_dev
$ cd ~/websphere_dev/
$ vagrant init ubuntu/trusty64

Редактируем Vagrantfile:

Vagrant.configure(2) do |config|

  # vagrant box image to run
  config.vm.box = "ubuntu/trusty64"
  # set hostname
  config.vm.hostname = "webpsoheredev"
  # WebSphere will work on 9080 by default
  config.vm.network "forwarded_port", guest: 9080, host: 9080
  # DHCP setting for hosts bridge interface
  config.vm.network "public_network"

  # add mmemory
  config.vm.provider "virtualbox" do |vb|
     vb.memory = "2048"
  end

  # exacly provisionining here
  # will use chef-solo here
  config.vm.provision "chef_solo" do |chef|

    # run this receipe for that box
    # during provisioning
    chef.add_recipe "wlp"

    # set attributes for that recipe on that box
    # we need accept WebSphere licence, as it is "false" by default
    chef.json = {
        "wlp" => {
           "archive" => {
               "accept_license" => "true"
           }
        }
    }
  end

end

Тут же создаем Berksfile:

$ vim Berksfile

В котором перечисляем наши рецепты:

$ cat Berksfile
source 'https://supermarket.chef.io'

cookbook "apt"
cookbook "java"
cookbook "wlp", git: "https://github.com/WASdev/ci.chef.wlp"
  • apt — для управления пакетами — обновить списки, установить необходимое и т.д.;
  • java — установим Java из рецепта в supermarket.chef.io;
  • wlp — рецепт самого IBM WebSphere Application Server.

Так как это первый запуск, то можно выполнить просто vagrant up — без явного указания provision:

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
    default: The Berkshelf shelf is at "/Users/username/.berkshelf/vagrant-berkshelf/shelves/berkshelf20151214-8866-1l4mix5-default"
==> default: Sharing cookbooks with VM
...
==> default: Updating Vagrant's Berkshelf...
==> default: Resolving cookbook dependencies...
==> default: Using apt (2.9.2)
==> default: Using wlp (0.3.1) from https://github.com/WASdev/ci.chef.wlp (at master)
==> default: Using java (1.36.0)
==> default: Vendoring apt (2.9.2) to /Users/username/.berkshelf/vagrant-berkshelf/shelves/berkshelf20151214-8866-1l4mix5-default/apt
==> default: Vendoring java (1.36.0) to /Users/username/.berkshelf/vagrant-berkshelf/shelves/berkshelf20151214-8866-1l4mix5-default/java
==> default: Vendoring wlp (0.3.1) to /Users/username/.berkshelf/vagrant-berkshelf/shelves/berkshelf20151214-8866-1l4mix5-default/wlp
...
==> default: Running provisioner: chef_solo...
    default: Installing Chef (latest)...
...
==> default: * execute[apt-get update] action run
==> default: [2015-12-14T08:55:16+00:00] INFO: execute[apt-get update] ran successfully
...
==> default:   * apt_package[openjdk-6-jdk] action install
==> default: [2015-12-14T08:58:16+00:00] INFO: apt_package[openjdk-6-jdk] installed openjdk-6-jdk at 6b37-1.13.9-1ubuntu0.14.04.1
==> default:
==> default: - install version 6b37-1.13.9-1ubuntu0.14.04.1 of package openjdk-6-jdk
...
==> default: * remote_file[/var/chef/cache/wlp-extended-8.5.5.8.jar] action create
==> default: [2015-12-14T08:59:44+00:00] INFO: remote_file[/var/chef/cache/wlp-extended-8.5.5.8.jar] created file /var/chef/cache/wlp-extended-8.5.5.8.jar
==> default:
==> default: - create new file /var/chef/cache/wlp-extended-8.5.5.8.jar
==> default: [2015-12-14T08:59:44+00:00] INFO: remote_file[/var/chef/cache/wlp-extended-8.5.5.8.jar] updated file contents /var/chef/cache/wlp-extended-8.5.5.8.jar
...
==> default:     - execute java -jar /var/chef/cache/wlp-extended-8.5.5.8.jar --acceptLicense /opt/was/liberty
==> default: [2015-12-14T08:59:47+00:00] INFO: Chef Run complete in 284.570550854 seconds
...
==> default: Chef Client finished, 21/35 resources updated in 04 minutes 48 seconds

Подключаемся:

$ vagrant ssh
$ sudo -s

Создаем defaultServer:

# sudo -u wlp /opt/was/liberty/wlp/bin/server create

Запускаем, и проверяем:

# sudo -u wlp /opt/was/liberty/wlp/bin/server start
Starting server defaultServer.
Server defaultServer started with process ID 11261.
# netstat -anp | grep 9080
tcp6       0      0 127.0.0.1:9080          :::*                    LISTEN      11261/java
# curl localhost:9080
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>WebSphere Application Server V8.5.5.8</title>
<style type="text/css">
...

По умолчанию WebSphere запускается на localhost.

Обновляем конфиг в /opt/was/liberty/wlp/usr/servers/defaultServer/server.xml, и указываем:

...
    <httpEndpoint id="defaultHttpEndpoint"
                  host="webspheredev"
                  httpPort="9080"
                  httpsPort="9443" />
...

Где строка host="webspheredev" указывает на запуск WebSphere на IP заданного тут имени хоста.

Добавляем запись в hosts:

# echo "10.11.100.46 webspheredev" >> /etc/hosts

Перезапускаем WepShere:

# sudo -u wlp /opt/was/liberty/wlp/bin/server stop
Stopping server defaultServer.
# sudo -u wlp /opt/was/liberty/wlp/bin/server start
Starting server defaultServer.
Server defaultServer started with process ID 2167.

Проверяем:

# netstat -anp | grep java
tcp6       0      0 10.11.100.46:9080       :::*                    LISTEN      2378/java
tcp6       0      0 127.0.0.1:59748         :::*                    LISTEN      2378/java
unix  2      [ ]         STREAM     CONNECTED     13830    2378/java

Проверяем порт на хост-машине:

$ lsof -n -i4TCP:9080 | grep LISTEN
VBoxHeadl 9450 username   18u  IPv4 0x696fb3615e7c3dab      0t0  TCP *:glrpc (LISTEN)

Открываем в браузере:

Screen Shot 2015-12-14 at 11.49.38