Tuesday 31 May 2016

[Xen] Export snapshot to file shell script

1. Check Snapshot name




2. Run shell script







exportSnapshot.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
#########################################################
#
# Export Xen Snapshot to File
#
#########################################################
# Created by  : dorbae
# Created Date : 2016-05-31
# Last Update   : 2016-05-31
# Version : 1.0.0
#########################################################
#
# * History
#
# 1.0.0  Initialize
#
#########################################################

if [ "$#" -ne 1 ]; then
 echo "Usage: $0 [SNAPSHOT_NAME]"
 exit 1
fi

SNAPNAME=$1
DATE=`date +%Y%m%d`
TIMESTAMP=`date +%Y-%m-%d' '%T`
mkdir -p ~/xenBackup
LOGFILE=~/xenBackup/log/${SNAPNAME}.log
PIDFILE=~/xenBackup/${SNAPNAME}.pid
BACKUPDIR=/bak

echo $$ > $PIDFILE
echo "[INFO ] `date +%Y-%m-%d' '%T`: Export Snapshot Start...[PID=$$]" >> $LOGFILE

SNAPUUID=`xe snapshot-list | grep -B 1 ${SNAPNAME} | grep uuid | cut -d":" -f2 | sed 's/^ *//g'`
echo "[INFO ] `date +%Y-%m-%d' '%T`: SNAPUUID=$SNAPUUID" >> $LOGFILE

echo "[INFO ] `date +%Y-%m-%d' '%T`: Exporting $SNAPNAME Start..." >> $LOGFILE
BAKFILE=$BACKUPDIR/${SNAPNAME}.xva
echo "[INFO ] `date +%Y-%m-%d' '%T`: BAKFILE=$BAKFILE" >> $LOGFILE
xe vm-export vm=$SNAPUUID filename="$BAKFILE"

echo "[INFO ] `date +%Y-%m-%d' '%T`: Exporting $SNAPNAME End..." >> $LOGFILE

echo "[INFO ] `date +%Y-%m-%d' '%T`: Export End..." >> $LOGFILE

exit 0

[Shell] How to check for the correct number of arguments


1
2
3
4
if [ "$#" -ne 2 ]; then
     echo "Usage: $0 [IMAGE_NAME] [SNAP_UUID]"
     exit 1
fi

[Maria/MySQL] How to install TokuDB storage engine and set it enabled.(TokuDB 스토리지 엔진 설치 및 사용방법)

TokuDB is available on the following distributions:
DistributionIntroduced
CentOS 6 64-bit and newerMariaDB 5.5.36 and MariaDB 10.0.9
Debian 7 "wheezy"64-bit and newerMariaDB 5.5.33 and MariaDB 10.0.5
Fedora 19 64-bit and newerMariaDB 5.5.33 and MariaDB 10.0.5
openSUSE 13.1 64-bit and newerMariaDB 5.5.41 and MariaDB 10.0.15
Red Hat 6 64-bit and newerMariaDB 5.5.36 and MariaDB 10.0.9
Ubuntu 12.10 "quantal" 64-bit and newerMariaDB 5.5.33 and MariaDB 10.0.5

1. Installing TokuDB
TokuDB has been included with MariaDB since MariaDB 5.5.34 and MariaDB 10.0.6 and does not require separate installation.

1.1. Installing TokuDB on Fedora, RedHat, & CentOS

# yum install MariaDB-tokudb-engine

1.2. Installing TokuDB on Ubuntu & Debian

# apt-get install mariadb-tokudb-engine-5.5

I have 10.1.12 MariaDB. So don't not need to install tokudb engine package.

2. Enabling TokuDB

2.1. Enabling TokuDB in configuration file

It is applied after starting or restarting.

# vi /etc/my.cnf.d/tokudb.cnf
[mariadb]
# See https://mariadb.com/kb/en/how-to-enable-tokudb-in-mariadb/
# for instructions how to enable TokuDB
#
# See https://mariadb.com/kb/en/tokudb-differences/ for differences
# between TokuDB in MariaDB and TokuDB from http://www.tokutek.com/

plugin-load-add=ha_tokudb.so


2.2. Enabling TokuDB when MariaDB is running

# mysqld --plugin-load=ha_tokudb --plugin-dir=<MariaDB Library Directory>/plugin



2.3. Enabling TokuDB manually from the mysql command line

# mysql -uroot -p


INSTALL SONAME 'ha_tokudb';



3. Create TokuDB Engine Table

CREATE TABLE TB_IOT_DHT_DATA
(
 MCU_NO int NOT NULL COMMENT 'MCU번호',
 SENSOR_NO int NOT NULL COMMENT '센서번호',
 SENSOR_DT datetime NOT NULL COMMENT '센서일시',
 SERVER_DT datetime COMMENT '서버일시',
 HUMI double COMMENT '습도',
 TEMP_C double COMMENT '섭씨온도',
 TEMP_F double COMMENT '화씨온도',
 LOC_LAT double COMMENT '위도',
 LOC_LON double COMMENT '경도',
 VOLTAGE int COMMENT '전압',
 PRIMARY KEY (MCU_NO, SENSOR_NO, SENSOR_DT)
) COMMENT = '온습도수집데이터', ENGINE = 'TokuDB';

Wednesday 11 May 2016

[Java] How to dump and analyze jvm heap memory using jmap, jhat (jmap, jhat을 이용한 JVM 힙메모리 덤프 및 분석)

JDK(Java Development Kit) has various java tools like javac, jps, jmap, jhat.

Sometimes, you want to analyze heap memory of running java process. For example, in case such as OutOfMemoryError.

If want to do that, you can use jmap and jhat java tools.

1. jmap

jmap prints shared object memory maps or heap memory details of a given process or core file or a remote debug server. If the given process is running on a 64-bit VM, you may need to specify the -J-d64 option.

Usage:
    jmap [option] <pid>
        (to connect to running process)
    jmap [option] <executable <core>
        (to connect to a core file)
    jmap [option] [server_id@]<remote server IP or hostname>
        (to connect to remote debug server)

where <option> is one of:
    <none>               to print same info as Solaris pmap
    -heap                to print java heap summary
    -histo[:live]        to print histogram of java object heap; if the "live"
                         suboption is specified, only count live objects
    -permstat            to print permanent generation statistics
    -finalizerinfo       to print information on objects awaiting finalization
    -dump:<dump-options> to dump java heap in hprof binary format
                         dump-options:
                           live         dump only live objects; if not specified,
                                        all objects in the heap are dumped.
                           format=b     binary format
                           file=<file>  dump heap to <file>
                         Example: jmap -dump:live,format=b,file=heap.bin <pid>
    -F                   force. Use with -dump:<dump-options> <pid> or -histo
                         to force a heap dump or histogram when <pid> does not
                         respond. The "live" suboption is not supported
                         in this mode.
    -h | -help           to print this help message
    -J<flag>             to pass <flag> directly to the runtime system


2. jhat

The jhat command parses a java heap dump file and launches a web server. jhat enables you to browse heap dumps using your favorite web browser. jhat supports pre-designed queries (such as 'show all instances of a known class "Foo"') as well as OQL (Object Query Language) - a SQL-like query language to query heap dumps.


C:\Users\Administrator>jhat
ERROR: No arguments supplied
Usage:  jhat [-stack <bool>] [-refs <bool>] [-port <port>] [-baseline <file>] [-debug <int>] [-version] [-h|-help] <file>

        -J<flag>          Pass <flag> directly to the runtime system. For
                          example, -J-mx512m to use a maximum heap size of 512MB
        -stack false:     Turn off tracking object allocation call stack.
        -refs false:      Turn off tracking of references to objects
        -port <port>:     Set the port for the HTTP server.  Defaults to 7000
        -exclude <file>:  Specify a file that lists data members that should
                          be excluded from the reachableFrom query.
        -baseline <file>: Specify a baseline object dump.  Objects in
                          both heap dumps with the same ID and same class will
                          be marked as not being "new".
        -debug <int>:     Set debug level.
                            0:  No debug output
                            1:  Debug hprof file parsing
                            2:  Debug hprof file parsing, no server
        -version          Report version number
        -h|-help          Print this help and exit
        <file>            The file to read

For a dump file that contains multiple heap dumps,
you may specify which dump in the file
by appending "#<number>" to the file name, i.e. "foo.hprof#3".

All boolean options default to "true"

3. Example

3.1. Check PID

C:\Users\Administrator>jps -ml
22160 sun.tools.jps.Jps -ml
26688
18736 BTCBrokerBridge.jar
40704
30532
6408 org/netbeans/Main --branding visualvm --cachedir C:\Users\Administrator\AppData\Local\VisualVM\Cache/7u14 --openid 5804750059758362
4204 com.sun.jme.toolkit.bootstrap.Container
19508
27316
35124 D:\activemq\apache-activemq-5.11.4\bin\../bin/activemq.jar start
40400

3.2. Dump Heap memory map


C:\Users\Administrator>jmap -dump:format=b,file=D:/activemq.dump 35124
Dumping heap to D:\activemq.dump ...
Heap dump file created

3.3. Analyze Heap memory


C:\Users\Administrator>jhat D:/activemq.dump
Reading from D:/activemq.dump...
Dump file created Wed May 11 13:57:33 KST 2016
Snapshot read, resolving...
Resolving 251686 objects...
Chasing references, expect 50 dots..................................................
Eliminating duplicate references..................................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.




[Java] Make Java Doc in Eclipse (이클립스에서 자바독 생성)







Tuesday 10 May 2016

[Xen] How display snapshot information list using command.(스냅샷 정보 출력)


[root@testsvr bak]# xe snapshot-list | more
uuid ( RO)                : 01b7e3c2-6fd8-faec-f4ca-2196f6605ff1
          name-label ( RW): SNAPSHOT_BTC70_20160507
    name-description ( RW): AT/AT COMPATIBLE


uuid ( RO)                : 808c69e1-f7cb-75a0-6f5b-8d6a50d20aa4
          name-label ( RW): SNAPSHOT_BTC70_20151019
    name-description ( RW): AT/AT COMPATIBLE


uuid ( RO)                : 1ec647c0-edc4-8f78-2d90-52b9dec8f34f
          name-label ( RW): SNAPSHOT_BTC70_20151219
    name-description ( RW): AT/AT COMPATIBLE


uuid ( RO)                : db5590b3-0570-55b7-7905-dcca4b0cadc0
          name-label ( RW): SNAPSHOT_BTC70_20151024
    name-description ( RW): AT/AT COMPATIBLE


uuid ( RO)                : 33a515e3-be8c-3427-c225-4fa39545086b
          name-label ( RW): SNAPSHOT_BTC70_20151114
    name-description ( RW): AT/AT COMPATIBLE


uuid ( RO)                : a3e25464-dc9d-cbb0-ad11-77e76e0fcdde
          name-label ( RW): SNAPSHOT_BTC70_20151020
    name-description ( RW): AT/AT COMPATIBLE


uuid ( RO)                : cb1db0e5-fd24-02ac-18c3-5d0e8e0245b5
          name-label ( RW): SNAPSHOT_iSharkTestServer_CentOS6(64bit)_20160423
    name-description ( RW): Server for testing iShark


uuid ( RO)                : 1ce5f0a9-ce8e-4a09-60e0-c370aa8c67db
          name-label ( RW): SNAPSHOT_BTC70_20160102
    name-description ( RW): AT/AT COMPATIBLE


uuid ( RO)                : 54c757ea-7ead-3945-08f3-ebb70f793f4e
          name-label ( RW): SNAPSHOT_BTC70_20151121
    name-description ( RW): AT/AT COMPATIBLE

[Linux] How to connect SFTP server that port number is not default 22.(디폴트 22번 포트 아닌 SFTP 서버에 접속)


root@testsvr bak]# sftp -oport=222 bizteco@192.168.0.5:/home/dorbae/Images
Connecting to 192.168.0.5...
The authenticity of host '192.168.0.5 (192.168.0.5)' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.5' (RSA) to the list of known hosts.
bizteco@192.168.0.5's password:
Changing to: /home/dorbae/Images

[Java] How to create synchronized set.(동기화 Set 만드는 방법)

Java supports various synchronized collections in java.util.concurrent package.
ex) java.util.concurrent.BlockingQueue, java.util.concurrent.ConcurrentMap ...

But, the Set collection is not included in this package. You can create synchronized set like this.

1
public static final java.util.Set< String> INTERNAL_DEVICE_DEAD_SET = Collections.synchronizedSet( new HashSet< String>());

Monday 9 May 2016

[Eclipse] How to install VisualVM plug-in.(VisualVM 이클럽스 플러그인 추가)

VisualVM is very useful tool for monitoring java processes, calling MBean method and so on.

VisualVM is embedded in JDK 1.7+ named jvisualvm.exe.

I think VisaulVM is NetBean RCP Program. But it supports Eclipse plug-in.

But, I do not recommend this way. It is unnecessary. It is eqaul to run JVM and execute VisualVM.exe simultaneously.

1. Download Plug-in
http://visualvm.java.net/eclipse-launcher.html

















2. Unzip Plug-in
Unzip plug-in in eclipse plugins directory.















3. Install Plug-in
Help -> Install New Software...




















4. VisualVM Configuration
Windows -> Preferences
Set JDK Home and VisualVM exe file path.


5. Run Configuration
Run JVM and VisualVM.























6. Run