Saturday, November 1, 2014

How to install JDK on Redhat/CentOS usng the alternatives command


http://www.if-not-true-then-false.com/2010/install-sun-oracle-java-jdk-jre-7-on-fedora-centos-red-hat-rhel/

Install Java JDK or JRE package

## JDK 32-bit ##
rpm -Uvh /path/to/binary/jdk-7u67-linux-i586.rpm
 
## JDK 64-bit ##
rpm -Uvh /path/to/binary/jdk-7u67-linux-x64.rpm
 
## JRE 32-bit ##
rpm -Uvh /path/to/binary/jre-7u67-linux-i586.rpm
 
## JRE 64-bit ##
rpm -Uvh /path/to/binary/jre-7u67-linux-x64.rpm
 
 

Install Sun/Oracle JDK java, javaws, libjavaplugin.so (for Firefox/Mozilla) and javac with alternatives –install command

## java ##
alternatives --install /usr/bin/java java /usr/java/latest/jre/bin/java 200000
## javaws ##
alternatives --install /usr/bin/javaws javaws /usr/java/latest/jre/bin/javaws 200000
 
## Java Browser (Mozilla) Plugin 32-bit ##
alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/latest/jre/lib/i386/libnpjp2.so 200000
 
## Java Browser (Mozilla) Plugin 64-bit ##
alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/latest/jre/lib/amd64/libnpjp2.so 200000
 
## Install javac only if you installed JDK (Java Development Kit) package ##
alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 200000
alternatives --install /usr/bin/jar jar /usr/java/latest/bin/jar 200000

Saturday, October 25, 2014

Unable to start historyserver service


If you see error as below in your log file while failed to start the history server, then you can use the command sudo su -l hdfs -c "hadoop dfs -chmod -R 755 /" to fix it and then restart the service with sudo service hadoop-mapreduce-historyserver restart 

Permission denied: user=robing, access=WRITE, inode="/":mapred:hadoop:rwxr-xr-x

Friday, August 29, 2014

ORACLE: How do I set up passwords to NEVER expire?


Run the below query to set up SYSTEM password never expire

SQL> select profile from dba_users where username = 'SYSTEM';
PROFILE
--------------------------
DEFAULT

SQL> alter profile DEFAULT limit password_life_time unlimited;

Profile altered.


After doing this...Reset the password of the user again.

SQL> alter user SYSTEM identified by new-password;

User altered.

By doing this,the password will never expire.

Saturday, August 2, 2014

Docker tricks and tips

https://gist.github.com/wsargent/7049221


http://stackoverflow.com/questions/17157721/getting-a-docker-containers-ip-address-from-the-host?rq=1

How to get the container's IP address ?


You can use docker inspect
Example:
> CID=$(docker run -d -p 4321 base nc -lk 4321); > docker inspect $CID -or-
> docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${CID}

How to get the full container ID ?


> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d8e703d7e303 solidleon/ssh:latest /usr/sbin/sshd -D cranky_pare
> docker inspect -f '{{.Id}}' cranky_pare
or
> docker inspect -f '{{.Id}}' d8e703d7e303
d8e703d7e3039a6df6d01bd7fb58d1882e592a85059eb16c4b83cf91847f88e5

Where is the full container ID stored ?
It is in the host file system under /var/lib/docker/aufs/mnt/


How to copy file from host to container ?
Get full container ID as mentioned above and then use the 'cp' command from the host
> sudo cp file.txt /var/lib/docker/aufs/mnt/d8e703d7e3039a6df6d01bd7fb58d1882e592a85059eb16c4b83cf91847f88e5/root/file.txt

How to coy file from container to host ?
>docker cp d8e703d7e303:/file/path/within/container /host/path/target


Friday, August 1, 2014

How to create Docker image with OpenSSH

http://flnkr.com/2013/12/creating-a-docker-ubuntu-13-10-image-with-openssh/

I’ve posted the stephens/sshd image to the docker site and  you can download it with the command: (The root password is password.)
> docker pull stephens/sshd

To run an instance of the image as a daemon, execute:
> docker run -d -p 22 stephens/sshd

To run the image in the foreground and enter the shell, execute:
> docker run -i -t -p 22 stephens/sshd /bin/bash

To connect to the image, first find the port that was assigned to the ssh port and then connect with the ssh client:
> docker ps
> ssh root@localhost -p 

Wednesday, July 30, 2014

How to upgrade Docker on Ubuntu 14.04 ?

http://askubuntu.com/questions/472412/how-do-i-upgrade-docker
http://xmodulo.com/2014/05/manage-linux-containers-docker-ubuntu.html
http://xmodulo.com/2014/05/docker-containers-centos-fedora.html
https://fredjean.net/running-docker-under-linux-mint-16/

Suppose it is Ubuntu Trusty (14.04) release, which has 0.9.1 officially
Update to 0.11.1 release
If you want to upgrade in this release, see new launchpad https://launchpad.net/~docker-maint/+archive/testing, better use ppa installation.
sudo add-apt-repository ppa:docker-maint/testing
sudo apt-get update
sudo apt-get install docker.io
Now I get the latest one
$ docker -v
Docker version 0.11.1, build fb99f99
Be aware, with the 1.0 GA release, this method may be changed
Update to latest release(now 1.1.1)
This is the way stated to install docker for 12.04 LTS in official document and noticed inubuntuupdates.org, which looks work for 14.04 as well.
Refer the command to Getting Docker Installed on Ubuntu 12.04 LTS as well
$ wget -qO- https://get.docker.io/gpg | sudo apt-key add -
$ sudo sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
$ sudo apt-get update
$ sudo apt-get install lxc-docker
Now I get
$ docker -v
Docker version 1.1.1, build bd609d2
lxc-docker will remove old docker package, therefore please backup the configuration in advance.

Monday, July 28, 2014

Java/Scala benchmark and tools

http://shipilev.net/blog/2014/java-scala-divided-we-fail/
http://openjdk.java.net/projects/code-tools/jmh/
http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/

As a good tradition, we will take some diversions into benchmarking methodology, so that even though the post itself is targeted to platform people, the non-platform people can still learn a few tricks. As usual, if you still haven’t learned about JMH and/or haven’t looked through the JMH samples, then I suggest you do that first before reading the rest of this post for the best experience.

Benchmark

The discussion in that particular StackOverflow thread dates back a few questions, so instead of digging there, we will just take the latest benchmark code, and wrap it up with JMH. JMH already has the bindings for Java and Scala, which somewhat alleviates the difference in testing methodology. You can find full benchmark code here (warning, it contains spoilers).

Wednesday, July 23, 2014

How to run R from Shell script ?

http://stackoverflow.com/questions/2151212/how-can-i-read-command-line-parameters-from-an-r-script
http://stackoverflow.com/questions/5391124/in-r-select-rows-of-a-matrix-that-meet-a-condition
http://stackoverflow.com/questions/7201341/how-can-2-strings-be-concatenated-in-r

I made two files: exmpl.bat and exmpl.r.
  • exmpl.bat:
    set R_Script="C:\Program Files\R-3.0.2\bin\RScript.exe"
    %R_Script% exmpl.R 2010-01-28 example 100 > exmpl.batch 2>&1
    Alternatively using Rterm.exe:
    set R_TERM="C:\Program Files\R-3.0.2\bin\i386\Rterm.exe"
    %R_TERM% --no-restore --no-save --args 2010-01-28 example 100 < exmpl.R > exmpl.batch 2>&1
  • exmpl.r:
    options(echo=TRUE) # if you want see commands in output file
    args <- span=""> commandArgs(trailingOnly = TRUE)
    print(args)
    # trailingOnly=TRUE means that only your arguments are returned, check:
    # print(commandsArgs(trailingOnly=FALSE))
    
    start_date <- span=""> as.Date(args[1])
    name <- span=""> args[2]
    n <- span=""> as.integer(args[3])
    rm(args)
    
    # Some computations:
    x <- span=""> rnorm(n)
    png(paste(name,".png",sep=""))
    plot(start_date+(1L:n), x)
    dev.off()
    
    summary(x)
Save both files in the same directory and start exmpl.bat. In result you got:
  • example.png with some plot
  • exmpl.batch with all what was done
Just to add - you could add environment variable %R_Script%:
"C:\Program Files\R-3.0.2\bin\RScript.exe"
and use it in your batch scripts as %R_Script% .......
Differences between RScript and Rterm:

======================================================================
> colnames <- c="" col1="" col3="" div="" nbsp="">
> data[ , colnames] 
  col1 col3
1    1    4
2    2    5
3    3    6
> data[ , colnames] 
  col1 col3
1    1    4
2    2    5
3    3    6
> r <- colnames="" data="" div="" nbsp="">
> r
  col1 col3
1    1    4
2    2    5
3    3    6
> r[r$col1 == 2,]
  col1 col3
2    2    5
> # this is a comment line
> r[r$col1 == 2 || r$col1==3,]
[1] col1 col3
<0 rows=""> (or 0-length row.names)
> r[r$col1 == 2,]
  col1 col3
2    2    5
> r[r$col1 == 2 | r$col1==3,]
  col1 col3
2    2    5
3    3    6