Hi! This is my first post of this blog and I would like start with my last cookbook “wildfly-clu”.   We will create a simple Wildlfy cluster(domain mode) composed by 3 servers. For this test I will use CentOS release 6.3 (Final).

Final result:

  • Reach HelloWorld application to http://myserver1/helloworld  ( passing through reverse proxy)

You can reach the app directly from the nodes:
http://myserver1:8080/helloworld/
http://myserver2:8080/helloworld/
http://myserver3:8080/helloworld/

  • http://myserver1:9990/console  (user: admin,  password: admin)

WILDLFYCONS

  • http://myserver1:22002/ HAPROXY admin console.

haproxy

 

Quick HowTo:
check if the vagrant-berkshelf plugin is installed. If not, launch ” vagrant plugin install vagrant-berkshelf”
git clone https://github.com/EugenioMarzo/cookbook-wildfly-clu
cd wildfly-clu
vagrant up

Detailed Description:

Node1 (myserver1) => Domain controller –  Application Server – Reverse proxy

Node2 (myserver2) => Slave – Application Server

Node3 (myserver3) => Slave – Application Server

Prerequisites:  Virtualbox 4.3.10 ,Vagrant 1.4.3 , Ruby 1.9.3,Git

Let’s start..

1. Configure your /etc/hosts in order to resolve locally the name of all VMs
33.33.33.11 myserver1
33.33.33.13 myserver3
33.33.33.12 myserver2

2.  Clone the cookbook
`git clone https://github.com/EugenioMarzo/cookbook-wildfly-clu`

3. Quick overview of Vagrantfile
Vagrant can configure multiple virtual-machines. An example of ./mycookbook/Vagrantfile:
#This will be the configuration for myserver1. Being a cluster you will have the same configuration for myserver2 and myserver3

config.vm.define "myserver1" do |myserver1|

myserver1.vm.hostname = “myserver1”
myserver1.vm.network :private_network, ip: “33.33.33.11”
myserver1.vm.network :public_network
myserver1.vm.provision :chef_solo do |chef|
chef.json = {
:java => {:jdk_version => “7”}

}

chef.run_list = [
“recipe[java]”,  #to install java
“recipe[wildfly-clu::default]”,  #install wildfly
“recipe[wildfly-clu::logs]”, #log rotation
“recipe[wildfly-clu::domain]” # when is in run_list configure the domain mode

]
end
end

3. show the VMs configured in Vagrantfile

check if the vagrant-berkshelf plugin is installed. If not, launch ” vagrant plugin install vagrant-berkshelf”
root@myclient1:~/vagrantlab/wildfly-clu# vagrant status
Current machine states:

myserver1 not created (virtualbox)
myserver2 not created (virtualbox)
myserver3 not created (virtualbox)

 

4. a quick overview of the most important attributes of the cookbook

Version and URL of Wildfly8
default['wildfly-clu']['wildfly']['version'] = "8.0.0"
default['wildfly-clu']['wildfly']['url']="http://download.jboss.org/wildfly/8.0.0.Final/wildfly-8.0.0.Final.tar.gz"

#######################################################################
## Set the following variable to true if you want use the domain mode.
default[‘wildfly-clu’][‘mode’][‘domain’] = true
##
#######################################################################

#if you create this file the recipe will not change domain.xml,host.xml and mgmt-******.properties after the first installation
default[‘wildfly-clu’][‘wildfly’][‘lock’] = “/usr/local/#{node[‘wildfly-clu’][‘name’]}/conf.lock”

The cluster schema

default[‘wildfly-clu’][‘cluster_schema’] = {
“myserver1” => { :role => “domain-controller” ,
:ip => “33.33.33.11”,
:port_offset => “0” },
“myserver2” => { :role => “slave” ,
:ip => “33.33.33.12” ,
:master => “myserver1” ,
:port_offset => “0”},
“myserver3” => { :role => “slave” ,
:ip => “33.33.33.13” ,
:master => “myserver1” ,
:port_offset => “0” }

}

#set this to true in order to deploy an helloworld application
default[‘wildfly-clu’][‘wildfly’][‘deploy_hello_world’] = true

#set this to true in order to configure an haproxy with the slaves declared in the cluster_schema
default[‘wildfly-clu’][‘wildfly’][‘haproxy’] = true

#DEFAULT java options to use in all slaves and the master for run the application.
default[‘wildfly-clu’][‘java_opts’] = {
“heap-size” => “64m”,
“max-heap-size” => “64m”,
“permgen-size” => “64m”,
“max-permgen-size” => “64m” }

5. Setting up the test environment with Vagrant

root@myclient1:~/vagrantlab/wildfly-clu# vagrant up

Bringing machine ‘myserver1’ up with ‘virtualbox’ provider…
Bringing machine ‘myserver2’ up with ‘virtualbox’ provider…
Bringing machine ‘myserver3’ up with ‘virtualbox’ provider…

#downloading the virtualbox machine used as template
[myserver1] Importing base box ‘Berkshelf-CentOS-6.3-x86_64-minimal’…
Progress: 90%

[myserver1] Available bridged network interfaces:
1) eth0
2) virbr0
3) lxcbr0
4) virbr1
#Choose 1 if you want bridge the network cards of the VM to eth0

[myserver1] Booting VM…
[myserver1] Waiting for machine to boot. This may take a few minutes…
[myserver1] Machine booted and ready!
[myserver1] Configuring and enabling network interfaces.

Through Chef-Solo will be configured the VMs just created. Below the most important steps
Running chef-solo…
[2014-04-03T13:25:55+00:00] INFO: *** Chef 10.14.2 ***
[2014-04-03T13:26:01+00:00] INFO: Run List is [recipe[java], recipe[wildfly-clu::default], recipe[wildfly-clu::logs], recipe[wildfly-clu::domain]]
[2014-04-03T13:26:08+00:00] INFO: package[java-1.7.0-openjdk] installing java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5 from upda
[2014-04-03T13:26:35+00:00] INFO: package[java-1.7.0-openjdk-devel] installing java-1.7.0-openjdk-devel-1.7.0.51-2.4.4.1.el6_5 from updates repository

#Downloading Wildfly..
[2014-04-03T13:26:46+00:00] INFO: user[wildfly] created
[2014-04-03T13:27:00+00:00] INFO: remote_file[wildfly] updated
[2014-04-03T13:27:00+00:00] INFO: remote_file[wildfly] owner changed to 502
[2014-04-03T13:27:00+00:00] INFO: remote_file[wildfly] group changed to 503
[2014-04-03T13:27:00+00:00] INFO: remote_file[wildfly] mode changed to 775
[2014-04-03T13:27:00+00:00] INFO: remote_file[wildfly] sending run action to bash[wildfly_extract] (immediate)
[2014-04-03T13:27:01+00:00] INFO: bash[wildfly_extract] ran successfully
[2014-04-03T13:27:01+00:00] INFO: bash[wildfly_extract] sending create action to link[/usr/local/wildfly] (immediate)
[2014-04-03T13:27:01+00:00] INFO: link[/usr/local/wildfly] created
[2014-04-03T13:27:01+00:00] INFO: link[/usr/local/wildfly] sending create action to template[/etc/default/wildfly.conf] (immediate)

# Copy configuration read by init script
[2014-04-03T13:27:01+00:00] INFO: template[/etc/default/wildfly.conf] updated content

#Copy configuration for domain mode
[2014-04-03T13:27:06+00:00] INFO: template[/usr/local/wildfly/domain/configuration/domain.xml] mode changed to 775

#installing Haproxy
[2014-04-03T13:27:06+00:00] INFO: package[haproxy] installing haproxy-1.4.24-2.el6 from base repository

#deploy Hello world!
[2014-04-03T13:27:15+00:00] INFO: cookbook_file[helloworld.war] sending run action to bash[deploy_helloworld] (delayed)
[2014-04-03T13:27:19+00:00] INFO: bash[deploy_helloworld] ran successfully
[2014-04-03T13:27:19+00:00] INFO: Chef Run complete in 77.838215277 seconds

The same operation will be for each virtual machines described in Vagrantfile.

 

6. a quick overview inside the virtual machines:

#use it to connect via SSH
root@myclient1:~/vagrantlab/wildfly-clu# vagrant ssh myserver1

[vagrant@myserver1 ~]$ sudo su
[root@myserver1 vagrant]# cat /etc/redhat-release
CentOS release 6.3 (Final)

[root@myserver1 vagrant]# /etc/init.d/wildfly status
wildfly is running (pid 5032)

#cron job for rotate logs
[root@myserver1 vagrant]# cat /var/spool/cron/root
# Chef Name: Wildfly log rotation 0
0 0 * * * find /usr/local/wildfly/domain/log -name ‘*’ -a ! -name ‘*.gz’ -mtime +1 -a ! -name ‘console.log’ -a ! -name ‘boot.log’ -exec gzip ‘{}’ ;
# Chef Name: Wildfly log rotation 1
0 0 * * * find /usr/local/wildfly/domain/log -name ‘*.txt.gz’ -mtime +30 -exec rm -f ‘{}’ ;

[root@myserver1 vagrant]# cat /etc/default/wildfly.conf
export JBOSS_USER=wildfly
export JBOSS_HOME=/usr/local/wildfly
export JBOSS_CONSOLE_LOG=/usr/local/wildfly/domain/log/console.log
export JBOSS_MODE=”domain”

Posted 3th April by Eugenio Marzo