Difference between pages "OpenVZ on Funtoo Linux" and "Installing Java"

From Funtoo
(Difference between pages)
Jump to: navigation, search
(Network - After)
 
 
Line 1: Line 1:
== Introduction ==
+
== What is Java? What purpose does it serve? ==
 +
==== Definition ====
 +
"Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!" ([http://www.java.com/en/download/faq/whatis_java.xml Oracle page on Java])
  
OpenVZ (see [http://wiki.openvz.org wiki.openvz.org]) is an OS-level server virtualization solution,
+
==== JRE vs. JDK ====
built on Linux. OpenVZ allows the creation of isolated, secure virtual Linux containers (called "VE"s) on a single physical server. Each container has its own local uptime, power state, network interfaces, resource limits and isolated portion of the host's filesystem. OpenVZ is often described as "chroot on steroids."
+
JRE: Just the Java Virtual Machine.
 
+
JDK: The Java Software Development Kit - this includes command line tools for launching .jar files, the JRE, compilers, and tools for creating Java-based programs.
Funtoo supports OpenVZ in the following ways:
+
== Installing java ==
 
+
==== Options ====
* Building of OpenVZ templates using [[Metro]], our distribution build tool.
+
On Funtoo, there are several different java packages that you can emerge:
* Improvement of <tt>vzctl</tt>, by developing an improved/patched version hosted on [http://www.github.com/funtoo/vzctl GitHub].
+
* '''virtual/jre''' - When you emerge this, it pulls in the java runtime environment for your current profile.
* Integration of [[Funtoo Linux Networking]] support into vzctl (these patches have been accepted upstream by the OpenVZ project.)
+
* '''virtual/jdk''' - When you emerge this, it pulls in the java development kit for your current profile.
* Improvement of vzctl startup scripts to do things like properly initialize veth and vzeventd.
+
* '''dev-java/icedtea''' - A Gentoo-made binary of the IcedTea JDK, this is the JDK pulled in when you emerge '''virtual/jdk''' on the desktop profile.  
* Integrating additional patches into openvz-rhel6-stable and openvz-rhel5-stable ebuilds in order to ensure production-quality OpenVZ functionality.
+
* '''dev-java/oracle-jdk-bin''' - Oracle's version of the Java Development Kit. This package and dev-java/oracle-jre-bin both require you to manually download the file and place it in /usr/portage/distfiles due to the fact that Oracle wants you to accept a license before downloading the package.
* Maintaining compatibility with production RHEL5-based OpenVZ kernels, as well as instructions on how to get Funtoo Linux set up for these kernels in our [[RHEL5 Kernel HOWTO]]. (Note: openvz-rhel6-kernel RHEL6-based kernel is now the recommended kernel for deploying OpenVZ.)
+
* '''dev-java/oracle-jre-bin''' - Similar to the above, this only includes the Java Runtime Environment.  
 
+
In addition, Daniel is currently employed at [http://www.zenoss.com Zenoss] and is the author and maintainer of the [http://community.zenoss.org/blogs/zenossblog/2012/01/24/openvz-and-zenoss Zenoss OpenVZ ZenPack] ([https://github.com/zenoss/ZenPacks.zenoss.OpenVZ GitHub link])
+
 
+
== Recommended Versions ==
+
 
+
For setting up OpenVZ on Funtoo Linux so that you can create Linux-based containers, an <tt>x86-64bit</tt> version of Funtoo Linux is strongly recommended. The <tt>openvz-rhel6-stable</tt> ebuild is the recommended kernel to use. If you emerge this kernel with the <tt>binary</tt> USE flag enabled, it will build a binary kernel and initrd using the default Red Hat configuration which should boot on nearly all hardware. After emerging, you will need to edit <tt>/etc/boot.conf</tt>, run [[boot-update]], and reboot into the new OpenVZ kernel.
+
 
+
Alternatively, you could emerge <tt>openvz-rhel5-stable</tt> with the <tt>binary</tt> USE flag enabled to use the older RHEL5-based OpenVZ kernel. This requires additional steps which are covered in the [[RHEL5 Kernel HOWTO]].
+
 
+
You will also need to emerge <tt>vzctl</tt>, which are the OpenVZ userspace tools.
+
 
+
== Configuration ==
+
 
+
After booting into an OpenVZ-enabled kernel, OpenVZ can be enabled as follows:
+
  
 +
==== Emerging java ====
 +
To install java, run the following command:
 
<console>
 
<console>
# ##i##emerge vzctl
+
##r## # ##b##emerge -av virtual/jdk
# ##i##rc-update add vz default
+
# ##i##rc
+
</console>
+
  
== Funtoo Linux OpenVZ Templates ==
+
##g##These are the packages that would be merged, in order:
  
The Funtoo Linux stage directory also contains Funtoo Linux OpenVZ templates in the openvz/ directory. These can be used as follows:
+
Calculating dependencies... done!
 
+
[ebuild  N    ] dev-java/java-config-wrapper-0.16  8 kB
<console>
+
[ebuild  N    ] sys-apps/baselayout-java-0.1.0  71 kB
# ##i##cd /vz/template/cache
+
[ebuild  N    ] dev-java/java-config-2.2.0-r1000:2  PYTHON_ABIS="2.7 3.3 -2.6 -3.1 -3.2 (-3.4)" 51 kB
# ##i##wget http://ftp.osuosl.org/pub/funtoo/funtoo-current/openvz/x86-64bit/funtoo-openvz-core2_64-funtoo-current-2011-12-31.tar.xz
+
[ebuild  N    ] app-admin/eselect-java-0.1.0  71 kB
# ##i##vzctl create 100 --ostemplate funtoo-openvz-core2_64-funtoo-current-2011-12-31
+
[ebuild  N    ] dev-java/icedtea-bin-7.2.3.9:7  USE="X alsa cups -cjk -doc -examples -nsplugin -source" 47,781 kB
Creating container private area (funto-openvz-core2-2010.11.06)
+
[ebuild  N    ] virtual/jdk-1.7.0:1.7  0 kB
Performing postcreate actions
+
[ebuild  N    ] virtual/jre-1.7.0:1.7  0 kB
Container private area was created
+
Would you like to merge these packages? [Yes/No] ##b##yes
 
</console>
 
</console>
  
If you are not using Funtoo Linux, you may need to convert the .xz template to a .gz template for this to work.
+
== Testing to see if it emerged ==
 
+
To check that java installed on your system, run the following command:
== Resource Limits ==
+
 
+
If you do not need to have any resource limits in place for the VE, then on a Funtoo Linux host, they can be enabled as follows:
+
 
+
 
<console>
 
<console>
ninja1 ~ # ##i##vzctl set 100 --applyconfig unlimited --save
+
##b##java -version
 
</console>
 
</console>
 
+
If you get something like this, you are ready to use java!:
== Starting the Container ==
+
 
+
Here's how to start the container:
+
 
+
 
<console>
 
<console>
ninja1 ~ # ##i##vzctl start 100
+
java version "1.7.0_21"OpenJDK Runtime Environment (IcedTea 2.3.9) (Gentoo build 1.7.0_21-b02)OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
Starting container ...
+
Container is mounted
+
Setting CPU units: 1000
+
Container start in progress...
+
ninja1 ~ #
+
 
</console>
 
</console>
 +
== Using the java command ==
 +
==== Overview of the command ====
 +
The java command can be run like so:
 +
* '''java [options] class [argument ...]'''
 +
* '''java [options] -jar file.jar [argument ...]'''
  
== Networking ==
+
==== Example command usage ====
 
+
Compiling code:
=== veth networking ===
+
 
+
OpenVZ has two types of networking. The first is called "veth", which provides the VE with a virtual ethernet interface. This allows the VE to do things like broadcasting and multicasting, which means that DHCP can be used. The best way to set up veth networking is to use a bridge on the physical host machine. For the purposes of this example, we'll assume your server has a wired eth0 interface that provides Internet connectivity - it does not need to have an IP address. To configure a bridge, we will create a network interface called "br0", a bridge device, and assign your static ip to br0 rather than eth0. Then, we will configure eth0 to come up, but without an IP, and add it as a "slave" of bridge br0. Once br0 is configured, we can add other network interfaces (each configured to use a unique static IP address) as slaves of bridge br0, and these devices will be able to communicate out over your Ethernet link.
+
 
+
Let's see how this works.
+
 
+
==== Network - Before ====
+
 
+
Before the bridge is configured, we probably have an <tt>/etc/conf.d/netif.eth0</tt> that looks like this:
+
 
+
{{File
+
|/etc/conf.d/netif.eth0|<pre>
+
template="interface"
+
ipaddr="10.0.1.200/24"
+
gateway="10.0.1.1"
+
nameservers="10.0.1.1"
+
domain="funtoo.org"
+
</pre>}}
+
 
+
==== Network - After ====
+
 
+
To get the bridge-based network configured, first connect to a physical terminal or management console, as eth0 will be going down
+
for a bit as we make these changes.
+
 
+
We are now going to set up a bridge with eth0's IP address, and add eth0 to the bridge with no IP. Then we can throw container interfaces into the bridge and then can all communicate out using eth0.
+
 
+
We will <tt>mv netif.eth0 netif.br0</tt>, and then edit the file so it looks like this (first line modified, new line added at end):
+
 
+
{{File
+
|/etc/conf.d/netif.br0|<pre>
+
template="bridge"
+
ipaddr="10.0.1.200/24"
+
gateway="10.0.1.1"
+
nameservers="10.0.1.1"
+
domain="funtoo.org"
+
slaves="netif.eth0"
+
</pre>}}
+
 
+
If you want to bridge the wlan0 device, you'll need the additional wpa_supplicant flag '''''-b br0''.'''
+
In most cases for wlan0 it is much better to use a route:
+
<console>
+
# ##i##iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o wlan0 -j SNAT your_host_ip_address
+
</console>
+
 
+
Now, time to create a new /etc/conf.d/netif.eth0, but this time we won't associate an IP address with it. Config file looks like this, a single line:
+
 
+
<pre>
+
template="interface-noip"
+
</pre>
+
 
+
Now, we need to create a necessary symlink in /etc/init.d and get our bridge added to the default runlevel:
+
 
+
 
<console>
 
<console>
# ##i##cd /etc/init.d
+
##bl##$ ##b##javac -d bin -sourcepath src -cp lib/lib1.jar;lib/lib2.jar src/com/example/Application.java
# ##i##ln -s netif.tmpl netif.br0
+
# ##i##rc-update add netif.br0 default
+
 
</console>
 
</console>
  
Now, let's enable our new network interfaces:
+
Running code:  
 
+
 
<console>
 
<console>
# ##i##/etc/init.d/netif.eth0 stop
+
##bl##$ ##b##java -cp bin;lib/lib1.jar;lib/lib2.jar com.example.Application
# ##i##rc
+
 
</console>
 
</console>
  
The result of these changes is that you now have initscripts to create a "br0" interface (with static IP), with "eth0" as its slave (with no IP). Networking should still work as before, but now you are ready to provide bridged connectivity to your virtual containers since you can add their "veth" interfaces to "br0" and they will be bridged to your existing network.
+
Running a jarfile:
 
+
==== Using The Bridge ====
+
 
+
To add a veth "eth0" interface to your VE, type the following:
+
 
+
 
<console>
 
<console>
# ##i##vzctl stop 100
+
##bl##$ ##b##java -jar Application.jar
# ##i##vzctl set 100 --netif_add eth0,,,,br0 --save
+
# ##i##vzctl start 100
+
 
</console>
 
</console>
  
Once the VE is started, the network interface inside the VE will be called "eth0", and the network interface on the host system will be named "veth100.0". Because we specified "br0" after the 4 commas, vzctl will automatically add our new "veth100.0" interface to bridge br0 for us. We can see this by typing "brctl show" after we have started the VE by typing "vzctl start 100".
+
== More Information ==
 
+
* [http://docs.oracle.com/javase/ Java SE at Oracle.com]
<console>
+
* [http://en.wikipedia.org/wiki/Java_(programming_language) Wikipedia article]
# ##i##brctl show
+
* [http://docs.oracle.com/javase/tutorial/ Very informative tutorials]
bridge name    bridge id              STP enabled    interfaces
+
br0            8000.0026b92c72f5      no              eth0
+
                                                        veth100.0
+
</console>
+
 
+
==== VE Configuration ====
+
 
+
You will also need to manually configure the VE to acquire/use a valid IP address - DHCP or static assignment will both work; typically, this is done by starting the VE with "vzctl start 100" and then typing "vzctl enter 100", which will give you a root shell inside the VE. Then, once you have configured the network, you can ensure that the VE is accessible remotely via SSH. Note that once inside the VE (with "vzctl enter 100"), you configure the VE's network interface as you would on a regular Linux distribution - the VE will be bridged into your LAN, so it can talk to your DHCP server, and can use an IP address that it acquires via DHCP or it can use a static address.
+
 
+
=== venet networking ===
+
 
+
"venet" is OpenVZ's other form of host networking. It can be easier to configure than veth, but does not allow the use of broadcast or multicast, so DHCP is not possible on the VE side. For this reason, an IP address must be statically assigned to the VE, as follows:
+
 
+
<console>
+
# ##i##vzctl set 100 --ipadd 10.0.1.201 --save
+
# ##i##vzctl set 100 --nameserver 8.8.4.4 --save #google public DNS server
+
# ##i##vzctl set 100 --hostname foobar --save
+
</console>
+
 
+
With venet configuration, some additional steps are required in case of PPPoE Internet connection. We will use iptables to get network working in all VE's.
+
 
+
<console># ##i##echo 1 > /proc/sys/net/ipv4/ip_forward</console>
+
 
+
or, alternatively set it in /etc/sysctl.conf to have ip forward at boot
+
 
+
<console># ##i##echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
+
# ##i##sysctl -p</console>
+
 
+
Add an iptables rule, save and start the firewall:
+
<console># ##i##iptables -t nat -A POSTROUTING -o ppp0 (or your desired interface) -j MASQUERADE
+
# ##i##/etc/init.d/iptables save
+
# ##i##rc-update add iptables default
+
# ##i##rc</console>
+
All VE's now have a network connection from HN.
+
 
+
When using venet, OpenVZ will handle the process of ensuring the VE has its network properly configured at boot. As of vzctl-3.0.24.2-r4 in Funtoo Linux, Funtoo Linux VEs should be properly auto-configured when using venet.
+
  
With venet, there is no need to add any interfaces to a bridge - OpenVZ treats venet interfaces as virtual point-to-point interfaces so that traffic is automatically routed properly from the VE to the host system, out the default route of the host system if necessary.
+
== Sources ==
 +
([http://www.sergiy.ca/how-to-compile-and-launch-java-code-from-command-line/ Information provided for example command usage])
  
[[Category:Virtualization]]
+
[[Category:System]]

Revision as of 19:44, 28 October 2013

What is Java? What purpose does it serve?

Definition

"Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!" (Oracle page on Java)

JRE vs. JDK

JRE: Just the Java Virtual Machine. JDK: The Java Software Development Kit - this includes command line tools for launching .jar files, the JRE, compilers, and tools for creating Java-based programs.

Installing java

Options

On Funtoo, there are several different java packages that you can emerge:

  • virtual/jre - When you emerge this, it pulls in the java runtime environment for your current profile.
  • virtual/jdk - When you emerge this, it pulls in the java development kit for your current profile.
  • dev-java/icedtea - A Gentoo-made binary of the IcedTea JDK, this is the JDK pulled in when you emerge virtual/jdk on the desktop profile.
  • dev-java/oracle-jdk-bin - Oracle's version of the Java Development Kit. This package and dev-java/oracle-jre-bin both require you to manually download the file and place it in /usr/portage/distfiles due to the fact that Oracle wants you to accept a license before downloading the package.
  • dev-java/oracle-jre-bin - Similar to the above, this only includes the Java Runtime Environment.

Emerging java

To install java, run the following command:

 # emerge -av virtual/jdk

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] dev-java/java-config-wrapper-0.16  8 kB
[ebuild  N     ] sys-apps/baselayout-java-0.1.0  71 kB
[ebuild  N     ] dev-java/java-config-2.2.0-r1000:2  PYTHON_ABIS="2.7 3.3 -2.6 -3.1 -3.2 (-3.4)" 51 kB
[ebuild  N     ] app-admin/eselect-java-0.1.0  71 kB
[ebuild  N     ] dev-java/icedtea-bin-7.2.3.9:7  USE="X alsa cups -cjk -doc -examples -nsplugin -source" 47,781 kB
[ebuild  N     ] virtual/jdk-1.7.0:1.7  0 kB
[ebuild  N     ] virtual/jre-1.7.0:1.7  0 kB
Would you like to merge these packages? [Yes/No] yes

Testing to see if it emerged

To check that java installed on your system, run the following command:

java -version

If you get something like this, you are ready to use java!:

java version "1.7.0_21"OpenJDK Runtime Environment (IcedTea 2.3.9) (Gentoo build 1.7.0_21-b02)OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

Using the java command

Overview of the command

The java command can be run like so:

  • java [options] class [argument ...]
  • java [options] -jar file.jar [argument ...]

Example command usage

Compiling code:

$ javac -d bin -sourcepath src -cp lib/lib1.jar;lib/lib2.jar src/com/example/Application.java

Running code:

$ java -cp bin;lib/lib1.jar;lib/lib2.jar com.example.Application

Running a jarfile:

$ java -jar Application.jar

More Information

Sources

(Information provided for example command usage)