How does Virtualbox help me in hacking with Netbeans, Glassfish and PostgreSQL ? (2)

Did you read yet Part 1 ? If not, I recommend to run through it here.

We started from the scratch with VirtualBox and created a new virtual machine running Ubuntu Server 9.10. The last step was to shutdown the virtual machine. Now it is time to clean up, update our server, finetune the configuration and install JDK and Glassfish.

  • Remove the CD (ISO image)
    To avoid the virtual machine booting from the install CD again, you need to remove the link to the virtual CD under Settings | Storage, changer to Empty.

    Installer CD (ISO)

  • Setup the network (Settings|Network)
    By default there is only 1 adapter enabled, type NAT. Without being expert in networking, this usually helps your GUEST OS to tap on the online connection of your HOST. That will not satisfy our need very long.

    Default Network Adapter

    Our requirements:

    1. We need the virtual server to visible in the network, aka get a IP address from the DHCP server top allow the other team-members to connect to the server (if you want that)
    2. We want to a network link between HOST and GUEST, even we are completely offline (running a mini virtual network)

    We enable 2 adapters. Change the first one to Bridged Adapter (that will get our virtual machine an own visible IP address)

    Adapter 1 (Bridged)

    Remarks: The bridged adapter settings depends a bit of your network configuration. If your network does not support self service IP addresses with DHCP, it wont work, but working in standard router environments, even at home with your DSL modem/router it will work fine.

    Adapter 2 we enable and set to Host-only adapter (will create mini network between HOST and GUEST OS)

    Adapter 2 (Host-only)

    To make the second adapter working you need to verify the settings of VirtualBox itself (not your virtuacl machine). Go to menu|File|Preferences|Network.

    VirtualBox Network Settings

    Select the default adapter vboxnet0 and click the screwdriver. You will see these values by default and they are good enough to get started. The IP address you see (192.168.56.1) is the address of your HOST (the machine running VirtualBox).

    Adapter

    Now enable your internal DHCP server. With the default settings the first virtual machine booting will get the IP address 192.168.56.101

    DHCP Server

    We need to do some changes “inside” our virtual server as well (see the following steps)

  • Boot the virtual machine and Login with your user account and change to root user
    sudo -i (plus user account password)

  • Open the network configuration
    vi /etc/network/interfaces

    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet dhcp
    
    

    We enabled 2 adapters for our virtual machine earlier, so we need to add a second adapter.

    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # The primary network interface
    auto eth1
    iface eth1 inet dhcp
    
    auto eth0
    iface eth0 inet dhcp
    
    # auto eth2
    # iface eth2 inet static
    # address 192.168.1.100
    # gateway 192.168.56.255
    # netmask 255.255.255.0
    

    Please note the eth2 entry for your reference, in case you need to have a static IP address.
    Save the changes and restart your network
    /etc/init.d/networking restart

    You should see something like this (values and names depend on your host and your network)

    root@vcb3:~# /etc/init.d/networking restart
     * Reconfiguring network interfaces...                                                There is already a pid file /var/run/dhclient.eth1.pid with pid 717
    killed old client process, removed PID file
    Internet Systems Consortium DHCP Client V3.1.2
    Copyright 2004-2008 Internet Systems Consortium.
    All rights reserved.
    For info, please visit http://www.isc.org/sw/dhcp/
    
    Listening on LPF/eth1/08:00:27:b8:d2:7b
    Sending on   LPF/eth1/08:00:27:b8:d2:7b
    Sending on   Socket/fallback
    DHCPRELEASE on eth1 to 192.168.56.100 port 67
    There is already a pid file /var/run/dhclient.eth0.pid with pid 804
    killed old client process, removed PID file
    Internet Systems Consortium DHCP Client V3.1.2
    Copyright 2004-2008 Internet Systems Consortium.
    All rights reserved.
    For info, please visit http://www.isc.org/sw/dhcp/
    
    Listening on LPF/eth0/08:00:27:0a:59:28
    Sending on   LPF/eth0/08:00:27:0a:59:28
    Sending on   Socket/fallback
    DHCPRELEASE on eth0 to 192.168.1.1 port 67
    Internet Systems Consortium DHCP Client V3.1.2
    Copyright 2004-2008 Internet Systems Consortium.
    All rights reserved.
    For info, please visit http://www.isc.org/sw/dhcp/
    
    Listening on LPF/eth1/08:00:27:b8:d2:7b
    Sending on   LPF/eth1/08:00:27:b8:d2:7b
    Sending on   Socket/fallback
    DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 4
    DHCPOFFER of 192.168.56.101 from 192.168.56.100
    DHCPREQUEST of 192.168.56.101 on eth1 to 255.255.255.255 port 67
    DHCPACK of 192.168.56.101 from 192.168.56.100
    bound to 192.168.56.101 -- renewal in 1543 seconds.
    Internet Systems Consortium DHCP Client V3.1.2
    Copyright 2004-2008 Internet Systems Consortium.
    All rights reserved.
    For info, please visit http://www.isc.org/sw/dhcp/
    
    Listening on LPF/eth0/08:00:27:0a:59:28
    Sending on   LPF/eth0/08:00:27:0a:59:28
    Sending on   Socket/fallback
    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3
    DHCPOFFER of 192.168.1.3 from 192.168.1.1
    DHCPREQUEST of 192.168.1.3 on eth0 to 255.255.255.255 port 67
    DHCPACK of 192.168.1.3 from 192.168.1.1
    bound to 192.168.1.3 -- renewal in 1443 seconds.
    
    

    Now we have 2 addresses, 1 from your external DHCP server and 1 from your HOST internal DHCP server.
    Test by opening a Shell on your HOST (or CMD in windows) and ping your server ping 192.168.56.101.

    I recommend to your virtual server address to your HOST hosts file. Later we can use the hostname when connecting from Netbeans instead of the IP.

    vi /etc/hosts

    127.0.0.1    localhost
    
    # Virtualbox Server
    192.168.56.101    vcb3
    
    # The following lines are desirable for IPv6 capable hosts
    ::1     ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    ff02::3 ip6-allhosts
    
    

    (vcb3 is only a sample, it is the name I choose to use)

  • Get the latest OS updates
    apt-get update

    root@vcb3:~# apt-get update
    Hit http://sg.archive.ubuntu.com karmic Release.gpg
    Ign http://sg.archive.ubuntu.com karmic/main Translation-en_US
    Ign http://sg.archive.ubuntu.com karmic/restricted Translation-en_US
    Ign http://sg.archive.ubuntu.com karmic/universe Translation-en_US
    [..]
    

    (The content depends on your location and your entries in /etc/apt/sources.list. By default you don’t need to touch it)
    apt-get upgrade
    Depending when you install the server a certain number of updates will appear and you will be asked if you want to install. Since we run manual updates, you need to run this once in a while (maybe once a week)

  • Install extra server tools
    (Also depending on your favorite tools or requirements, I only need a telnet/SSH and a ftp access)

    1. Regular Telnet Server: apt-get install telnetd
    2. or Secure Shell Server: apt-get install openssh-server
    3. FTP Server: apt-get vsftpd
      Update the config file: vi /etc/vsftpd.conf and change these settings to below values (my recommendation)

      [..]
      # Uncomment this to allow local users to log in.
      local_enable=YES
      [..]
      # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
      anonymous_enable=NO
      [..]
      # Uncomment this to enable any form of FTP write command.
      write_enable=YES
      [..]
      
    4. Unzip: apt-get install unzip (need that later for our downloaded GF)

    I recommend to restart the server proper startup of these services. There you would also be able to spot any problems.
    Try to open a telnet session to the server from your HOST.

  • Install the JDK
    still as root user:  apt-get install sun-java6-jdk
    (You need to confirm the license dialogs)
  • Install Glassfish
    Depending on your personal taste or requirements you can install Glassfish as root (maybe in /opt) or under your user account. I decide to install it as user.

    Go back to your user account
    exit

    root@vcb3:/home/user# exit
    logout
    user@vcb3:~$ cd ~
    user@vcb3:~$ pwd
    /home/user
    user@vcb3:~$
    

    Download the Glassfish ZIP file. At the time of writing it was @ https://glassfish.dev.java.net/downloads/v3-final.html . Just get the download link (like http://download.java.net/glassfish/v3/release/glassfish-v3.zip).
    (Download directly from your virtual server)
    wget http://download.java.net/glassfish/v3/release/glassfish-v3.zip

    user@vcb3:~$ wget http://download.java.net/glassfish/v3/release/glassfish-v3.zip
    --2010-02-09 13:26:06--  http://download.java.net/glassfish/v3/release/glassfish-v3.zip
    Resolving download.java.net... 72.5.124.114
    Connecting to download.java.net|72.5.124.114|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 77265571 (74M) [application/zip]
    Saving to: `glassfish-v3.zip'
    
     1% [                                                ] 1,287,288    285K/s  eta 5m 43s
    

    With Glassfish V3 we really enjoy the painless installation. Only unzip the file and there we go, no more installation procedures.

    unzip glassfish-v3.zip

    You should have now this path /home/{username}/glassfishv3

  • Get the latest Glassfish updates (without having a GUI)
    Go to the /home/{username}/glassfishv3/bin and type ./pkg image-update (the first time it will download some stuff to run updates)
  • Start Glassfish V3
    Go to  and type ./asadmin start-domain domain1
    This will start the default domain1. The rest (stop,restart,configuring) is regular Glassfish administration work and not part of this tutorial.

    user@vcb3:/home/user/glassfishv3rel/bin# ./asadmin start-domain domain1
    Waiting for DAS to start ......
    Started domain: domain1
    Domain location: /home/user/glassfishv3/glassfish/domains/domain1
    Log file: /home/user/glassfishv3/glassfish/domains/domain1/logs/server.log
    Admin port for the domain: 4848
    Command start-domain executed successfully.
    

    You can observe the logfile with  tail -f /home/user/glassfishv3/glassfish/domains/domain1/logs/server.log

    Jan 10, 2010 9:29:46 PM com.sun.enterprise.admin.launcher.GFLauncherLogger info
    INFO: JVM invocation command line:
    /usr/lib/jvm/java-6-sun-1.6.0.15/bin/java
    -cp
    /home/user/glassfishv3rel/glassfish/modules/glassfish.jar
    -XX:+UnlockDiagnosticVMOptions
    -XX:MaxPermSize=192m
    -XX:NewRatio=2
    -XX:+LogVMOutput
    -XX:LogFile=/home/user/glassfishv3rel/glassfish/domains/cb3domain/logs/jvm.log
    -Xmx512m
    -javaagent:/home/user/glassfishv3rel/glassfish/lib/monitor/btrace-agent.jar=unsafe=true,noServer=true
    -client
    -Dosgi.shell.telnet.maxconn=1
    -Djdbc.drivers=org.apache.derby.jdbc.ClientDriver
    -Dfelix.fileinstall.dir=/home/user/glassfishv3rel/glassfish/modules/autostart/
    -Djavax.net.ssl.keyStore=/home/user/glassfishv3rel/glassfish/domains/cb3domain/config/keystore.jks
    -Dosgi.shell.telnet.port=6666
    -Djava.security.policy=/home/user/glassfishv3rel/glassfish/domains/cb3domain/config/server.policy
    -Dfelix.fileinstall.poll=5000
    -Dcom.sun.aas.instanceRoot=/home/user/glassfishv3rel/glassfish/domains/cb3domain
    -Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory
    -Dosgi.shell.telnet.ip=127.0.0.1
    -Djava.endorsed.dirs=/home/user/glassfishv3rel/glassfish/modules/endorsed:/home/user/glassfishv3rel/glassfish/lib/endorsed
    -Dcom.sun.aas.installRoot=/home/user/glassfishv3rel/glassfish
    -Djava.ext.dirs=/usr/lib/jvm/java-6-sun-1.6.0.15/lib/ext:/usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/ext:/home/user/glassfishv3rel/glassfish/domains/cb3domain/lib/ext
    -Dfelix.fileinstall.bundles.new.start=true
    -Djavax.net.ssl.trustStore=/home/user/glassfishv3rel/glassfish/domains/cb3domain/config/cacerts.jks
    -Dcom.sun.enterprise.security.httpsOutboundKeyAlias=s1as
    -Djava.security.auth.login.config=/home/user/glassfishv3rel/glassfish/domains/cb3domain/config/login.conf
    [..]
    
  • Open the GF Index page and the admin page
    (From your HOST)

    GF V3 Index Page

    GF V3 Admin Page

    Please note there is no default password for GF V3, you need to set one.

  • Connect from Netbeans 6.8
    Go to the services folder and right-click Servers | Add Server..

    Add Server

    Add Server

    Add Server

    Connected to GF on virtual server

In Part 3 of this tutorial I will discuss PostgreSQL settings, remote debugging with Glassfish and create a Hello_World application using this setup.

Advertisements

2 thoughts on “How does Virtualbox help me in hacking with Netbeans, Glassfish and PostgreSQL ? (2)

  1. This has been a very enlightening post. I’m setting up an environment much as you described, and it’s working well so far. Thank you for documenting your setup process!

    I’d like to encourage you to post part 3. 🙂

    Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s