Thursday, February 13, 2014

Ubuntu 12.04 - swappiness configuration

- cat /proc/sys/vm/swappiness
- sudo sysctl vm.swappiness=10
- sudo vi /etc/sysctl.conf
- add 'vm.swappiness = 10'

Wednesday, February 12, 2014

Cloudera Manager 4.8.1 - Cluster Setup

Note: repeat step 1, 2, 3, 4 at all cluster nodes

1. Ubuntu

- install Ubuntu Server 12.04 64-bit
- Note: cloudera manager will use a lot of space of /var by default

2. Network interface

- sudo vi /etc/network/interfaces
- add network interface information
- example

auto eth0
iface eth0 inet static
gateway 10.10.10.1
address 10.10.10.10
netmask 255.255.255.0
dns-nameservers 168.126.63.1

3. User

- sudo vi /etc/sudoers
- change '%sudo   ALL=(ALL:ALL) ALL' to '%sudo   ALL=(ALL:ALL) NOPASSWD:ALL'

4. Hosts

- sudo vi /ets/hosts
- leave '127.0.0.1 localhost' and delete other information
- add cluster information
- example

10.10.10.10 hostname1
10.10.10.11 hostname2
10.10.10.12 hostname3

5. SSH

- cd
- ssh-keygen -t rsa
- cp .ssh/id_rsa.pub .ssh/authorized_keys
- scp .ssh/id_rsa.pub username@hostnameN:
- ssh hostnameN
- mkdir .ssh
- mv id_rsa.pub .ssh/authorized_keys

6. Cloudera Manager

- http://www.cloudera.com
- download cloudera-manager-installer.bin
- chmod u+x cloudera-manager-installer.bin
- sudo ./cloudera-manager-installer.bin
- http://hostname1:7180
- admin / admin
- add IP addresses of the cluster
- example

10.10.10.[10-12]

- choose 'Another User'

Monday, February 10, 2014

Java - close (try-with-resources)

// Note: try-with-resources is available from JDK 7

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class Test {

public static void main(String[] args) throws IOException {
final String fileName = "d:\\Test.java";

System.out.println(readFile01(fileName));
System.out.println(readFile02(fileName));
System.out.println(readFile03(fileName));
}

public static String readFile01(String fileName) throws IOException {
FileReader fileReader = new FileReader(new File(fileName));
BufferedReader bufferedReader = new BufferedReader(fileReader);
String data = null;

try {
data = bufferedReader.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
}

return data;
}

public static String readFile02(String fileName) throws IOException {
FileReader fileReader = new FileReader(new File(fileName));
String data = null;

try (BufferedReader bufferedReader = new BufferedReader(fileReader)) {
data = bufferedReader.readLine();
}

return data;
}

public static String readFile03(String fileName) throws IOException {
FileReader fileReader01 = new FileReader(new File(fileName));
FileReader fileReader02 = new FileReader(new File(fileName));
String data = null;

try (BufferedReader bufferedReader01 = new BufferedReader(fileReader01);
BufferedReader bufferedReader02 = new BufferedReader(
fileReader02)) {
data = new StringBuilder(bufferedReader01.readLine()).append(
bufferedReader02.readLine()).toString();
}

return data;
}
}