Monday, November 28, 2016

How can I install Sun/Oracle's proprietary Java JDK 6/7/8 or JRE



http://askubuntu.com/questions/56104/how-can-i-install-sun-oracles-proprietary-java-jdk-6-7-8-or-jre


There is a similar answer on how to install JRE 7.

 

How can I install Sun/Oracle's proprietary Java JDK 6/7/8 or JRE

 

Install Java JDK

The manual way

  • Download the 32-bit or 64-bit Linux "compressed binary file" - it has a ".tar.gz" file extension.
  • Uncompress it
    tar -xvf jdk-8-linux-i586.tar.gz (32-bit)
    tar -xvf jdk-8-linux-x64.tar.gz (64-bit)
    The JDK 8 package is extracted into ./jdk1.8.0 directory. N.B.: Check carefully this folder name since Oracle seem to change this occasionally with each update.
  • Now move the JDK 8 directory to /usr/lib
    sudo mkdir -p /usr/lib/jvm
    sudo mv
        ./jdk1.8.0 /usr/lib/jvm/
  • Now run
    sudo update-alternatives --install
        "/usr/bin/java" "java"
        "/usr/lib/jvm/jdk1.8.0/bin/java" 1
    sudo update-alternatives --install
        "/usr/bin/javac" "javac"
        "/usr/lib/jvm/jdk1.8.0/bin/javac" 1
    sudo
        update-alternatives --install "/usr/bin/javaws"
        "javaws" "/usr/lib/jvm/jdk1.8.0/bin/javaws" 1
    This will assign Oracle JDK a priority of 1, which means that installing other JDKs will replace it as the default. Be sure to use a higher priority if you want Oracle JDK to remain the default.
  • Correct the file ownership and the permissions of the executables:
    sudo chmod a+x /usr/bin/java
    sudo chmod a+x /usr/bin/javac
    sudo chmod a+x /usr/bin/javaws
    sudo chown -R
        root:root /usr/lib/jvm/jdk1.8.0
    N.B.: Remember - Java JDK has many more executables that you can similarly install as above. java, javac, javaws are probably the most frequently required. This answer lists the other executables available.
  • Run
    sudo
        update-alternatives --config java
    You will see output similar to the one below - choose the number of jdk1.8.0 - for example 3 in this list (unless you have have never installed Java installed in your computer in which case a sentence saying "There is nothing to configure" will appear):
    $ sudo
        update-alternatives --config java
    There are 3 choices
        for the alternative java (providing /usr/bin/java).
      Selection
           Path                                            Priority  
        Status
    ------------------------------------------------------------
      0
                   /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071 
            auto mode
      1
                   /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071 
            manual mode
    * 2           
        /usr/lib/jvm/jdk1.7.0/bin/java                   1         manual
        mode
      3
                   /usr/lib/jvm/jdk1.8.0/bin/java                   1    
            manual mode
    Press enter to keep
        the current choice[*], or type selection number: 3
    update-alternatives:
        using /usr/lib/jvm/jdk1.8.0/bin/java to provide /usr/bin/java
        (java) in manual mode
    Repeat the above for:
    sudo
        update-alternatives --config javac
    sudo
        update-alternatives --config javaws
Note for NetBeans users!
You need to set the new JDK as default editing the configuration file.

If you want to enable the Mozilla Firefox plugin:
32 bit:
ln -s
   /usr/lib/jvm/jdk1.8.0/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/

   
64 bit:
ln
   -s /usr/lib/jvm/jdk1.8.0/jre/lib/amd64/libnpjp2.so
   ~/.mozilla/plugins/
N.B.: You can link the plugin (libnpjp2.so) to /usr/lib/firefox/plugins/ for a system-wide installation (/usr/lib/firefox-addons/plugins from 15.04 onwards). For Ubuntu 13.10, the path to the plugin directory is /usr/lib/firefox/browser/plugins/.
Depending on your configuration, you might need to update the apparmor profile for Firefox (or other browsers) in /etc/apparmor.d/abstractions/ubuntu-browsers.d/java:
# Replace the two
   lines:
# 
   /usr/lib/jvm/java-*-sun-1.*/jre/bin/java{,_vm} cx ->
   browser_java,
# 
   /usr/lib/jvm/java-*-sun-1.*/jre/lib/*/libnp*.so cx ->
   browser_java,
# with those (or adapt
   to your new jdk folder name)
/usr/lib/jvm/jdk*/jre/bin/java{,_vm}
   cx -> browser_java,
/usr/lib/jvm/jdk*/jre/lib/*/libnp*.so
   cx -> browser_java,
Then restart apparmor:
sudo
   /etc/init.d/apparmor restart

The easy way

The easiest way to install the JDK 7 is to do it with the Web Up8 Oracle Java OOS. However, it is believed that this PPA is sometimes out of date. Also note the dangers of using a PPA.
This installs JDK 7 (which includes Java JDK, JRE and the Java browser plugin):
sudo apt-get install
   python-software-properties
sudo add-apt-repository
   ppa:webupd8team/java
sudo apt-get update
sudo apt-get install
   oracle-java7-installer
# or if you want JDK 8:
# sudo apt-get install
   oracle-java8-installer
# these commands
   install Oracle JDK7/8 and set them as default VMs automatically:
# sudo apt-get install
   oracle-java7-set-default
#
   sudo apt-get install oracle-java8-set-default
N.B.: Before someone screams this is against the Oracle redistribution license - the PPA does not actually have Java in the personal repository. Instead, the PPA directly downloads from Oracle and installs it.

The Script way

If you're on a fresh installation of Ubuntu with no previous Java installations, this script automates the process outlined above if you don't want to type all that into a console. Remember, you still need to download Java from Oracle's website -- Oracle's links are not wget friendly.
Before using this make sure that this script is in the same directory as the .tar.gz file extension that you downloaded and there are no files that start with jdk-7 in the same folder. If there are, please move them out of the folder temporarily. Remember to make the script executable (chmod +x <script's file>).
#!/bin/sh

   
tar -xvf jdk-7*
sudo mkdir /usr/lib/jvm
sudo mv ./jdk1.7*
   /usr/lib/jvm/jdk1.7.0
sudo
   update-alternatives --install "/usr/bin/java" "java"
   "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo
   update-alternatives --install "/usr/bin/javac" "javac"
   "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo
   update-alternatives --install "/usr/bin/javaws" "javaws"
   "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
sudo chmod a+x
   /usr/bin/java
sudo chmod a+x
   /usr/bin/javac
sudo
   chmod a+x /usr/bin/javaws
If you want to install the plugin for Firefox then add this to the end of the script:
mkdir
   ~/.mozilla/plugins
ln -s
   /usr/lib/jvm/jdk1.7.0/jre/lib/amd64/libnpjp2.so
   ~/.mozilla/plugins/
sudo
   /etc/init.d/apparmor restart

Check if installation was successful

You can check if the installation succeeded with the following command:
java
   -version
You should see something like
java version "1.8.0"
Java(TM) SE Runtime
   Environment (build 1.8.0-b132)
Java
   HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
You can check if the JRE Mozilla plugin has been successful by using the official oracle website.





Monday, November 21, 2016

Restoring data from corrupted ext4 partition under LVM - fsck or repair bad blocks first?






Restoring data from corrupted ext4 partition under LVM - fsck or repair bad blocks first?



   dmesg | tail
   fsck.ext4 -vy /dev/sda1
   mkfs.ext4 -S /dev/sda1
   mount /dev/sda1 /test  
   mkfs.ext4 -S /dev/sda1 
    e2fsck -b 32768 /dev/sda1
    mount /dev/sda /test
    dmesg | tail
    smartctl -a /dev/sda | grep -i reallocated
     mount -t ext4 /dev/sda1 /mnt
 

     mount -o remount,rw /dev/sda1 /test

    
lvm vgscan
lvm vgchange -ay
lvm lvs
 

Tuesday, November 8, 2016

CentOS / Redhat: Install KVM Virtualization Software



CentOS / Redhat: Install KVM Virtualization Software

  1. kmod-kvm : kvm kernel module(s)
  2. kvm : Kernel-based Virtual Machine
  3. kvm-qemu-img : Qemu disk image utility
  4. kvm-tools : KVM debugging and diagnostics tools
  5. python-virtinst : Python modules and utilities for installing virtual machines
  6. virt-manager : Virtual Machine Manager (GUI app, to install and configure VMs)
  7. virt-viewer: Virtual Machine Viewer (another lightweight app to view VM console and/or install VMs)
  8. bridge-utils : Utilities for configuring the Linux Ethernet bridge (this is recommended for KVM networking)

KVM Package Group

RHEL comes with KVM software group which includes full virtualization support with KVM. You can list all packages in the group as follows:
# yum groupinfo KVM

A Note About libvirt

libvirt is an open source API and management tool for managing platform virtualization. It is used to manage Linux KVM and Xen virtual machines through graphical interfaces such as Virtual Machine Manager and higher level tools such as oVirt. See the official website for more information.

A Note About QEMU

QEMU is a processor emulator that relies on dynamic binary translation to achieve a reasonable speed while being easy to port on new host CPU architectures. When used as a virtualizer, QEMU achieves near native performances by executing the guest code directly on the host CPU. QEMU supports virtualization when executing under the Xen hypervisor or using the KVM kernel module in Linux. When using KVM, QEMU can virtualize x86, server and embedded PowerPC, and S390 guests. See the official website for more information.

A Note About Virtio Drivers

Virtio is paravirtualized drivers for kvm/Linux. With this you can can run multiple virtual machines running unmodified Linux or Windows VMs. Each virtual machine has private virtualized hardware a network card, disk, graphics adapter, etc. According to Redhat:
Para-virtualized drivers enhance the performance of fully virtualized guests. With the para-virtualized drivers guest I/O latency decreases and throughput increases to near bare-metal levels. It is recommended to use the para-virtualized drivers for fully virtualized guests running I/O heavy tasks and applications.

Host Operating System

Your main operating system such as CentOS or RHEL is known as host operating system. KVM is a Linux kernel module that enables a modified QEMU program to use hardware virtualization. You only need to install KVM under host operating systems.

KVM Domains

It is nothing but a guest operating system running under host operating system. Each kvm domain must have a unique name and ID (assigned by system).

Guest Operating Systems

KVM supports various guest operating systems such as
  1. MS-Windows 2008 / 2000 / 2003 Server
  2. MS-Windows 7 / Vista / XP
  3. FreeBSD
  4. OpenBSD
  5. Sun Solaris
  6. Various Linux distributions.
  7. NetBSD
  8. MINIX
  9. QNX
  10. MS DOS
  11. FreeDOS
  12. Haiku
  13. Amiga Research OS

Install KVM

Type the following command to install KVM under RHEL or CentOS:
# yum install kvm virt-viewer virt-manager libvirt libvirt-python python-virtinst
OR
# yum groupinstall KVM

Important Configuration And Log Files (Directories) Location

The following files are required to manage and debug KVM problems:
  1. /etc/libvirt/ – Main configuration directory.
  2. /etc/libvirt/qemu/ – Virtual machine configuration directory. All xml files regarding VMs are stored here. You can edit them manually or via virt-manager.
  3. /etc/libvirt/qemu/networks/ – Networking for your KVM including default NAT. NAT is only recommended for small setup or desktops. I strongly suggest you use bridged based networking for performance.
  4. /etc/libvirt/qemu/networks/default.xml – The default NAT configuration used by NAT device virbr0.
  5. /var/log/libvirt/ – The default log file directory. All VM specific logs files are stored here.
  6. /etc/libvirt/libvirtd.conf – Master libvirtd configuration file.
  7. /etc/libvirt/qemu.conf – Master configuration file for the QEMU driver.

TCP/UDP Ports

By default libvirt does not opens any TCP or UDP ports. However, you can configure the same by editing the /etc/libvirt/libvirtd.conf file. Also, VNC is configured to listen on 127.0.0.1 by default. To make it listen on all public interfaces, edit /etc/libvirt/qemu.conf file.

Virtual Machine Configuration

  • Bridged mode networking (eth0 == br0 and eth1 == br1) with full access to both LAN and Internet.
  • Accelerator virtio drivers used for networking (model=virtio)
  • Accelerator virtio drivers for disk (if=virtio) and disk will show up as /dev/vd[a-z][1-9] in VM.
  • Various virtual machines running different guest operating systems as per requirements.
LAN -->
Switch    -->  eth0 --> -+   10.10.21.70                       
     |
                                 | ---> br0
-+      +----------------+       +-------------> vm#3 (
10.10.21.73 / 123.1.2.6, OpenBSD 4.x Firewall )
                                 |           |
===> |   RHEL Server  |  -----+  
                                 |           |  
   |      KVM       |       +-------------> vm#4 ( 10.10.21.74 /
123.1.2.7, Solaris 10 Testing Server )
                                 | ---> br1
-+      +----------------+       |     
Wan --> ISP
Router --> eth1 --> -+   123.1.2.3           

Thursday, November 3, 2016

How to migrate all users to an new server



I found the way to migrate all unix accounts, samba accounts and configuration from the old samba file server to new one. It is simple, justcopy the following files from the old filer server, then replace at the new file server:
/etc/passwd (User name and account info)
/etc/shadow (Passwords)
/etc/group (Group names and membership)
/etc/gshadow - Contains group encrypted passwords.
/etc/samba/*
/var/lib/samba/*
After copying completion, restart the following services
service smbd restart
service nmbd restart
Then all users login to new file server and share the files