달력

4

« 2024/4 »

  • 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
2019. 5. 16. 17:27

mysql 컬럼만 select show 용-ILE/DB-mysql / oracle2019. 5. 16. 17:27


SELECT GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_name='table'

:
Posted by mastar

http://suite.tistory.com  2018.01  fs


* 시간 등록일 표시를 줄여서 표시

ex) 1년전 , 3개월전 1주전 , 2일전, 5분전 , 1분전, 1초전 

 

joda 라이브러리 이용  import org.joda.time.Interval;import org.joda.time.Period;


public String getSummaryPeriod(Date date) {
String resultPeriod = "";
Interval interval = new Interval(date.getTime(), new Date().getTime());
Period period = interval.toPeriod();
if (period.getYears() > 0) {
resultPeriod = period.getYears() + "년 전";
} else if (period.getMonths() > 0) {
resultPeriod = period.getMonths() + "개월 전";
} else if (period.getWeeks() > 0) {
resultPeriod = period.getWeeks() + "주 전";
} else if (period.getHours() > 0) {
resultPeriod = period.getDays() + "일 전";
} else if (period.getWeeks() > 0) {;
resultPeriod = period.getHours() + "시간 전";
} else if (period.getMinutes() > 0) {
resultPeriod = period.getMinutes() + "분 전";
} else if (period.getSeconds() > 0) {
resultPeriod = period.getSeconds() + "초 전";
}

return resultPeriod;
}



* 읽은 수 카운트 줄여서  표시

 ex) 1천 , 1.2만 , 1.5억  대략적인 수치로 줄임

참고소스 https://stackoverflow.com/questions/4753251/how-to-go-about-formatting-1200-to-1-2k-in-java

public String getSummaryCount(int count) throws IOException {
if (count < 1000) {
return "" + count;
}
int div = 4;
if (count < 10000) {
div = 3;
}
double value = count;
String suffix = "천만억";
String formattedNumber = "";
NumberFormat formatter = new DecimalFormat("#,###.#");
int power = (int) StrictMath.log10(value);
value = value / (Math.pow(10, (power / div) * div));
formattedNumber = formatter.format(value);
formattedNumber = formattedNumber + suffix.charAt(power / 4);
return formattedNumber;
}



:
Posted by mastar

2015.07 http://suite.tistory.com/


package 화된 jar 파일내 파일 읽기 함수 샘플


1. 파일 존재 확인 


if( this.getClass().getResource( "/file name") == null ) 이면 없는 거임

  * 절대 경로로 / 부터 찾기   , jar fxv pack.jar 풀어서 경로를 미리 보고 입력해도 됨 


2. stream -> BufferedReader -> readLine 


BufferedReader in=new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream( "/file name"), "UTF-8"));

String strLine = "";

while ((strLine = in.readLine()) != null) {

System.out.println("readLine"  + strLine);

}


:
Posted by mastar
2015. 4. 29. 11:37

[beginning] Linux & vi editor 용-ILE/SH/BASH/CSH2015. 4. 29. 11:37

http://suite.tistory.com 2015.05 fs

2010년에 작성했던 세미나용 문서 다시 보기



012345678910111213141516171819202122








linux_vi_201011.ppt


:
Posted by mastar

 


http://suite.tistory.com 2013.07 fs

 

패딩이 필요 없는 CTR 모드를

openssl(http://www.openssl.org/) 라이브러리 함수 이용하여

aes ctr 함수 [ AES_ctr128_encrypt() ] 샘플 작성해봄

 

참고 소스 링크


http://stackoverflow.com/questions/3141860/aes-ctr-256-encryption-mode-of-operation-on-openssl

참조 링크에서 다른점은  구현시 1024bytes 단위로 적용

 

openssl 라이브러리참조 빌드는 링크 참조 :

 http://suite.tistory.com/entry/AES-암호화-crypto-cbc-모드-샘플-by-openssl

 

샘플 코드

 

/** [AES KEY_SIZEbit - CTR MODE] implemented block 1024 bytes Reference source : http://stackoverflow.com/questions/3141860/aes-ctr-256-encryption-mode-of-operation-on-openssl Reference lib : openssl - libcrypto.a @copyleft http://suite.tistory.com fs 2013.07 **/ #include <openssl/aes.h> #include <stdio.h> #include <string.h> #include <stdlib.h>
#define BYTES_SIZE 1024
#define KEY_SIZE 128
unsigned char iv[8]={0x66,0x61,0x63,0x65,0x73,0x65,0x61,0x00};
struct ctr_state {
    unsigned char ivec[AES_BLOCK_SIZE];
    unsigned int num;
    unsigned char ecount[AES_BLOCK_SIZE];
};
unsigned char ckey[] =  "slrkrkfkgkdhkdld"; // It is 128bits though..

AES_KEY key;

int init_ctr(struct ctr_state *state, const unsigned char iv[8]){
    state->num = 0;
    memset(state->ecount, 0, AES_BLOCK_SIZE);
    memset(state->ivec+8 , 0, 8);
    memcpy(state->ivec, iv, 8);
}
// encrypt twice  == decrypt

void encrypt(unsigned char *indata,unsigned char *outdata ,int bytes_read){

    int i=0;
    int mod_len=0;

    AES_set_encrypt_key(ckey, KEY_SIZE, &key);

    if( bytes_read < BYTES_SIZE){
        struct ctr_state state;
        init_ctr(&state, iv);
        AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);
        return;
    }
    // loop block size  = [ BYTES_SIZE ]
    for(i=BYTES_SIZE; i <= bytes_read ;i+=BYTES_SIZE){
        struct ctr_state state;
        init_ctr(&state, iv);
        AES_ctr128_encrypt(indata, outdata, BYTES_SIZE, &key, state.ivec, state.ecount, &state.num);
        indata+=BYTES_SIZE;
        outdata+=BYTES_SIZE;
    }

    mod_len = bytes_read % BYTES_SIZE;
    if( mod_len != 0 ){
        struct ctr_state state;
        init_ctr(&state, iv);
        AES_ctr128_encrypt(indata, outdata, mod_len, &key, state.ivec, state.ecount, &state.num);
    }

}


int main(int argc, char *argv[]){
    int i=0;
    unsigned char fs[]={"abcdefgh"};
  
    printf("plain :[%s]\ne",fs);

    encrypt(fs ,fs ,8);
    printf("encode:[%s]\n",fs);

    encrypt(fs ,fs ,8);
    printf("decode:[%s]\n",fs);
    return 0;
}

 

 

 

 

 

:
Posted by mastar

http://suite.tistory.com 2013.06 fs

 

openssl 라이브러리 함수 이용하여 aes cbc 함수 샘플 작성해봄

 

1. openssl 최신버전 2013.06 기준 다운로드

$>wget http://www.openssl.org/source/openssl-1.0.1e.tar.gz

 

2. 압축 풀기

$>tar fxz openssl-1.0.1e.tar.gz

 

3. libcrypto.a 생성 


$>cd openssl-1.0.1e;make
-> $> ls 해서 libcrypto.a 파일 확인

 

4. openssl-1.0.1e/apps/speed.c 참고해서

 

build :  $>gcc fs_aes_cbc.c libcrypto.a

 

 

 

/* ================================================================================ OpenSSL 1.0.1e 11 Feb 2013 Copyright (c) 1998-2011 The OpenSSL Project Copyright (c) 1995-1998 Eric A. Young, Tim J. Hudson All rights reserved. DESCRIPTION ----------- The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, fully featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a full-strength general purpose cryptography library. The project is managed by a worldwide community of volunteers that use the Internet to communicate, plan, and develop the OpenSSL toolkit and its related documentation. OpenSSL is based on the excellent SSLeay library developed from Eric A. Young and Tim J. Hudson. The OpenSSL toolkit is licensed under a dual-license (the OpenSSL license plus the SSLeay license) situation, which basically means that you are free to get and use it for commercial and non-commercial purposes as long as you fulfill the conditions of both licenses. ================================================================================ * aes_cbc() mode sample by openssl * openssl : wget http://www.openssl.org/source/openssl-1.0.1e.tar.gz * reference source : openssl-1.0.1e/apps/speed.c * build : $>gcc test_fs_aes_cbc.c libcrypto.a * copyleft @http://suite.tistory.com fs */ #include <stdio.h> #include <string.h> #include <openssl/aes.h>
  
 static const unsigned char key32[32]=
{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
#define BLOCK_SIZE 16
#define FREAD_COUNT 4096
#define KEY_BIT 256
#define IV_SIZE 16
#define RW_SIZE 1
#define SUCC 0
#define FAIL -1

AES_KEY aes_ks3;
unsigned char iv[IV_SIZE];

int fs_encrypt_aes(char *in_file,char *out_file)
{
    int i=0;
    int len=0;
    int padding_len=0;
    char buf[FREAD_COUNT+BLOCK_SIZE];

    FILE *fp=fopen(in_file,"rb");
    if( fp == NULL ){
        fprintf(stderr,"[ERROR] %d can not fopen('%s')\n",__LINE__,in_file);
        return FAIL;
    }

    FILE *wfp=fopen(out_file,"wb");
    if( wfp == NULL ){
        fprintf(stderr,"[ERROR] %d can not fopen('%s')\n",__LINE__,out_file);
        return FAIL;
    }

    memset(iv,0,sizeof(iv)); // init iv
    AES_set_encrypt_key(key32 ,KEY_BIT ,&aes_ks3);
    while( len = fread( buf ,RW_SIZE ,FREAD_COUNT, fp) ){
        if( FREAD_COUNT != len ){
            break;
        }

        AES_cbc_encrypt(buf ,buf ,len ,&aes_ks3 ,iv ,AES_ENCRYPT);
        fwrite(buf ,RW_SIZE ,len ,wfp);
    }


    // padding  : pkcs5? pkcs7?? http://wiki.dgoon.net/doku.php?id=ssl:pkcs_5
    padding_len=BLOCK_SIZE - len % BLOCK_SIZE;
    printf("enc padding len:%d\n",padding_len);
    memset(buf+len, padding_len, padding_len);
/**
    for(i=len; i < len+padding_len ;i++){
        buf[i]=padding_len;
    }
**/
    AES_cbc_encrypt(buf ,buf ,len+padding_len ,&aes_ks3, iv,AES_ENCRYPT);
    fwrite(buf ,RW_SIZE ,len+padding_len ,wfp);

    fclose(wfp);
    fclose(fp);

    return SUCC;
}

int fs_decrypt_aes(char *in_file,char *out_file)
{
    char buf[FREAD_COUNT+BLOCK_SIZE];
    int len=0;
    int total_size=0;
    int save_len=0;
    int w_len=0;

    FILE *fp=fopen(in_file,"rb");
    if( fp == NULL ){
        fprintf(stderr,"[ERROR] %d can not fopen('%s')\n",__LINE__,in_file);
        return FAIL;
    }

    FILE *wfp=fopen(out_file,"wb");
    if( wfp == NULL ){
        fprintf(stderr,"[ERROR] %d can not fopen('%s')\n",__LINE__,out_file);
        return FAIL;
    }

    memset(iv,0,sizeof(iv)); // the same iv
    AES_set_decrypt_key(key32 ,KEY_BIT ,&aes_ks3);

    fseek(fp ,0 ,SEEK_END);
    total_size=ftell(fp);
    fseek(fp ,0 ,SEEK_SET);
    printf("total_size %d\n",total_size);

    while( len = fread( buf ,RW_SIZE ,FREAD_COUNT ,fp) ){
        if( FREAD_COUNT == 0 ){
            break;
        }
        save_len+=len;
        w_len=len;

        AES_cbc_encrypt(buf ,buf ,len ,&aes_ks3 ,iv ,AES_DECRYPT);
        if( save_len == total_size ){ // check last block
            w_len=len - buf[len-1];
            printf("dec padding size %d\n" ,buf[len-1]);
        }

        fwrite(buf ,RW_SIZE ,w_len ,wfp);
    }

    fclose(wfp);
    fclose(fp);

    return SUCC;
}
//copyleft @http://suite.tistory.com fs
int main(int argc, char *args[])
{
    if( argc != 2 ){
        printf("[Usage] %s fs_src_file\n",args[0]);
        return FAIL;
    }


    if( fs_encrypt_aes(args[1],"fs_in.file") == SUCC){
        fs_decrypt_aes("fs_in.file","fs_out.file");
        printf("result:[fs_out.file]\n");
    }

    return 0;
}

 

* 실행 결과

  
$ vi fs_aes_cbc.c
$ make
gcc fs_aes_cbc.c libcrypto.a
$ ./a.out fs_aes_cbc.c
result:[out.file]
$ ls -ltr
합계 11512
-rw-rw-r--. 1 ir ir 3914268 2013-05-31 17:03 libcrypto.a
-rw-rw-r--. 1 ir ir      36 2013-06-04 15:10 Makefile
-rw-rw-r--. 1 i ir   2979 2013-06-04 15:10 fs_aes_cbc.c
-rwxrwxr-x. 1 ir i   23698 2013-06-04 16:21 a.out
-rw-rw-r--. 1 i ir    2992 2013-06-04 16:21 fs_in.file
-rw-rw-r--. 1 irtu irt   2979 2013-06-04 16:21 fs_out.file

실제 업무에서는 C++ 기반이면 class화 사용이 BEST!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* 참고 링크 :  http://misc-file.googlecode.com/svn/vm/aes_cbc_encrypt.cpp

 

* EVP? : openssl 암호화 관련 검색을 계속 해보면  EVP 관련 함수로 암호화 함수가 있다.

EVP 무슨약자인지는 찾지 못했고  "하이레벨 함수들" :  http://www.openssl.org/docs/crypto/evp.html

fs/openssl-1.0.1e/test/evp*.c 보면

EVP_CIPHER_CTX_init() , EVP_EncryptUpdate() , EVP_EncryptFinal()  이용해서 암호화 알고리즘을 적용 하는 예제가 있음 

 

 

 

 

 

 

:
Posted by mastar

http://suite.tistory.com 2013.06 fs

 

그동안 인코딩 관련해서 base64, urlencode, md5 나 경험하다가 

 

암호화 Algorithm (알고리즘? 알고리듬?) 개발은 아니고 

openssl 라이브러리를 사용해보기 위해  학습해 보았다.

구글링을 문서가 참 많은데 쭉~해오던게 아니니 생소한 용어를 많이 봄.

 그냥 개인적으로 양파 까듯이 개념 정리해봄(블로그/구글링 웹문서 참고)

 

1.  대칭형 암복호화 (AES,DES,SEED... 방식)

     암호화/복호화시 key가 동일한 형태  


 

2. 비대칭형 암복호화 (RSA...방식)

    암호화/복호화시 서로 다른 key를 사용한 형태

 

3. RSA (Ron Rivest, Adi Shamir,Leonard Adleman ) 1977년 만든 3사람 이름 약자

     소수를 이용하여 만든 Algorithm 공개되어 있지만  취약성이 아주 많이 없어 아주 많이 사용됨

      설명은 아래 링크 참고 :

http://kin.naver.com/qna/detail.nhn?d1id=11&dirId=11080102&docId=49010517&qb=cnNhIOqzteqwnCDtgqQg7JWU7Zi4IOuwqeyLnQ==&enc=utf8&section=kin&rank=2&search_sort=0&spq=0

 

4. DES(Data Encryption Standard)

    미국에서 예전에 표준으로 쓰던 암호화로 현재는 AES로 대체되어 사용 안한다고 함

 

5. AES (Advanced Encryption Standard)    1997년 9월 공모 2001년12월부터 AES 표준화 완료

   미국에서 DES 대체 방식으로 공모함 

   그중에 벨기에 수학자(Daemen과 Rijndael)이 만든  Rijndael 이 채택되어 구현됨

   * Rijndael 정확한 발음 모르겠음 (레인달, 라인댈,라인달...)

 

   KEY는 128bit, 192bit, 256bit 사용 가능하고 이론적으로는 key 길이는 무제한 이라고함

    KEY크기가 128bit(16byte) 면 Algorithm에 따라 라운드?를 9회 , 192bit(24byte) 11회 , 256bit(32byte) 13회 한다고하니

    키가 길면 좀더 암호화가 되고 시간?도 좀더 걸리는것 으로 예상됨    

 

6. SEED , ARIA

    한국에서 만든 암호화 암고리듬 , ARIA경우 우리나라 공공기관 및 산하기관 거의 표준으로 들어가야 하는데

   최소 한 1년정도 검증기간이 소요예상(카더라통신) ,  프로젝트 상황에 따라 국내 상용제품을 구매가 나을 듯

 

7. 블럭암호화

    AES 알아 보다 보면 블럭암호화가 나오고 ECB , CBC... 모드가 나온다.

    블럭암호화: 임의의 평문을 암호화하기 위해서 일정한 길이로 나눠서 하는거 

    ex)  기본 데이터 블럭은 16byte

 

   ECB (Electric CodeBook mode)  : 모든 글들이 비추천 사용하지 말라는 모드임 

   16byte 블럭단위가 동일키로 암호화 하는구조

    -> 평문이 같다면 암호화 블럭도 일정해진다.

    * 스트림 암호화 방식도 있다 1byte씩

 

 

    CBC(Cipher Block Chaining mode)  : 모든 글들이 권장모드 , 적극 사용 하라는 모드임

    ECB와 달리 IV를 활용하여 처음블럭이 다음 암호화 블럭에 영향을준다.
   -> 평문이 같아도 암호화 블럭이 달라진다.

   ECB vs CBC 비교 좋은 링크 : http://blog.naver.com/PostView.nhn?blogId=taketime62&logNo=90043063571 

   이외 좀 더 있다 (CFB,OFB,CTR)

 

8. IV (initialization vector) : 초기화백터?

   CBC 모드 알아 보다 보면 16byte 크기가 IV가 있다

   KEY와는 다르고 CBC 모드에서 체인형식으로 앞블럭 뒤에 블럭 영향을 주도록 하는것 같다.

   IV값은 처음 시작할때 값과 암호화후 값을 보면 달라진다.

 

  주의할점은 IV 값을 복호화시에 반드시 최초값과 동일하게 해야함

   ex) IV 값을 0으로 암호화 시작했다면 , 복호화시에 IV 값을 0으로 해야한다.

  -> 어떻게 보면 기본 key 값에 또 하나의 2중 key 값이라고도 할수 있다고 개인적으로 생각

 

9. 패딩 (padding)

   블럭단위로 암호화시 분명 소스 데이타가 블럭길이가 딱 맞지 않을 수 있다.

   그걸경우 마지막 블럭도 단위에 맞게 패딩(추가Byte)을 해서 블럭을 맞게 해준다.

   openssl - AES_cbc_encrypt() 에서 패딩도 해주면 좋았을텐데 안해줘서

   구글링해서 좋은 글을 찾았다.

   http://wiki.dgoon.net/doku.php?id=ssl:pkcs_5

   패딩글을 보다보면 PKCS5 PKCS7 나온다.  

 

10. 메시지 다이제스트(Message Digest)

   원문에서 일정한 길이로 문자열을 변환해주는거(해쉬함수) 

   복호화는 없다고 봐야하는데~ MD5 경우 텍스트경우 좀 됨 (인터넷에 변환사이트 많음)

   보통 사용자 암호저장시 활용

   MD5 , SHA 요즘은 MD5 보완취약하다고 SHA-1 이상 방식 권장 한다고함  

 

11. KMS(Key Management Server)

   KMS 용어 참많다!  암호화에서는 full name 그대로 암호화 key를  관리하는 서버

 

12. openssl (http://www.openssl.org/)

   오픈소스로 여러가지 암호화(인코딩)/복호화(디코딩) Algorithm을 착한분들이  c 라이브로로 만들어줌

   다음 포스트에 openssl - libcrypto.a 활용한

   AES  256 CBC모드 함수 AES_cbc_encrypt()  샘플

-> http://suite.tistory.com/entry/AES-암호화-crypto-cbc-모드-샘플-by-openssl


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* 관련해서 많이본 포스팅  작성자분에게 감사합니다.  (펌글이라면 출처를 넣어주는 센스가...)

http://www.parkjonghyuk.net/lecture/modernCrypto/lecturenote/chap04.pdf 

http://blog.daum.net/thermidor/8933157

http://linuxforge.tistory.com/191

http://www.cyworld.com/duetys/14268419

https://www.google.co.kr/search?newwindow=1&noj=1&q=PKCS5Padding&spell=1&sa=X&ei=0EOrUervBYqXkQX87IHwBw&ved=0CCoQBSgA&biw=1440&bih=766

http://thenine.egloos.com/321704

http://www.di-mgt.com.au/cryptopad.html

http://blog.naver.com/PostView.nhn?blogId=hyoguri81&logNo=150098915801

http://blog.naver.com/PostView.nhn?blogId=taketime62&logNo=90043063571 

http://wiki.dgoon.net/doku.php?id=ssl:pkcs_5

http://www.eglobalsys.co.kr/sub2/06.php

http://blog.naver.com/imchan123?Redirect=Log&logNo=10168165622

http://kin.naver.com/qna/detail.nhn?d1id=11&dirId=11080102&docId=49010517&qb=cnNhIOqzteqwnCDtgqQg7JWU7Zi4IOuwqeyLnQ==&enc=utf8&section=kin&rank=2&search_sort=0&spq=0

http://blog.naver.com/typeofb?Redirect=Log&logNo=166253556

http://andstory.com/zb41/zboard.php?id=tip_board&page=18&sn1=&divpage=1&sn=off&ss=on&sc=on&select_arrange=headnum&desc=desc&no=490

 

 

 

:
Posted by mastar

http://suite.tistory.com 2012.12

 

1) 공인 IP eth 추가   (가상서버에서)

기존 사설ip용으로 설정한 /etc/sysconfig/network-scripts/ifcfg-eth0 을

/etc/sysconfig/network-scripts/ifcfg-eth0:1 로 복사 후

DEVICE=eth0:1 명
IPADDR=새로운ip
GATEWAY=새로운ip에 해당하는 게이트웨이

$> service network restart  후 /sbin/ifconfig -a

eth0 , eth0:1 두개 확인

 

2) virbr0 삭제 (kvm이 설치된 물리서버에서)

사설IP는 NAT 방식으로 해서 지정 했었음 $>virsh net-list 하면 default  or  /sbin/ifconfig -a 하면 virbr0 확인됨

virbr0 을 삭제해야  각 설치된 서버( guest os) 에서  공인 IP 지정 가능?

삭제는  http://blog.naver.com/orion_203?Redirect=Log&logNo=130116210048 참고

$> virsh net-destroy default
$> service libvirtd restart

 

3) br0 사용하도록 지정  (kvm이 설치된 물리서버에서)

원격지에서 xwindow 로 virtual machine manager (가상머신관리자) 를 사용 못해 가상서버의 쉘에서 virsh 를 이용하여 설정

virsh 을 이용하여 가상화 os를 shutdown 하고 start 할때 오류 발생

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

오류메시지 한글 :

오류:도메인 *** 시작하기 실패
오류:네트워크를 찾을 수 없음: 일치하는 'default'라는 이름의 네트워크 없음

오류메시지 영문 :

error: Failed to start domain ***
error: Network not found: no network with matching name ‘default’

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 /etc/libvirt/qemu/guestos.xml 열때 vi 열지말고 http://blog.boxcorea.com/wp/archives/tag/kvm 없는 내용으로

$>virsh edit /etc/libvirt/qemu/guestos.xml 해야 수정 사항이 반영됨 (xml 상단 주석에 설명 되어 있음)

<interface type='bridge'>
<mac address=’54:52:00:5e:53:d2′/>
<source bridge='br0'/>
</interface>

수정후 가상화 os start

$) virsh start guestos

centos 6.3에서...

:
Posted by mastar

http://suite.tistory.com 2012.12

/etc/sysconfig/vncservers 유저 추가시 숫자가 기본 포트 5900 플러스해서 LISTEN 포트 10901 + 2개 생성됨

예를 들어  VNCSERVERS="5001:root" 설정 후 재시작 : /etc/init.d/vncserver restart

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

$netstat -nap |grep Xvnc | grep LISTEN
tcp        0      0 0.0.0.0:10801               0.0.0.0:*                   LISTEN      13550/Xvnc
tcp        0      0 0.0.0.0:10901               0.0.0.0:*                   LISTEN      13550/Xvnc
tcp        0      0 0.0.0.0:11001               0.0.0.0:*                   LISTEN      13550/Xvnc
tcp        0      0 :::11001                    :::*                        LISTEN      13550/Xvnc
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

11001 한개만 했을때는 안되고  10801 , 10901 , 11001  3개 모두 외부에서 접속시 방화벽 열면 접속됨 (2개는 테스트 안해봄)

vnc client로 접속시 사용한 포트 10901로 했음

:
Posted by mastar

http://suite.tistory.com  fs 2012.10 

 

매번 검색해서 사용하던거 정리 

java.lang.OutOfMemoryError: Java heap space 에러나지 MAX_BUF_BYTE 단위로 loop !


※ Buffered*클래스 사용하면 큰파일에 유리하다고 구글링!~ 

 

1.  InputStream 으로 파일 쓰기

 		private final int MAX_BUF_BYTE = 1024000; 

		FileInputStream in = null;
		FileOutputStream fos = null;
		BufferedInputStream bis = null;
		BufferedOutputStream bos = null;

		try {

			
			byte[] buffer = new byte[MAX_BUF_BYTE];

			in = new FileInputStream(new File("file"));
			fos = new FileOutputStream(filename);
			bis = new BufferedInputStream(in);

			bos = new BufferedOutputStream(fos);
			int len = 0;
			while ((len = bis.read(buffer)) >= 0) {
				bos.write(buffer, 0, len);
			}

		} catch (Exception e) {
			LOG.info(e.toString());
		} finally {
			try {

				bos.close();
				bis.close();
				fos.close();
				in.close();
			} catch (Exception e) {
			}
		}


2.   stream을 byte 로 변환  

ByteArrayOutputStream 클래스 활용 


		InputStream in = null;
		BufferedInputStream bis = null;
		ByteArrayOutputStream arrayBuff = new ByteArrayOutputStream();
		try {

			byte[] buffer = new byte[MAX_BUF_BYTE];

			in=new FileInputStream(new File("readFile"));
			bis = new BufferedInputStream(in);
			int len = 0;
			while ((len = bis.read(buffer)) >= 0) {
				arrayBuff.write(buffer, 0, len);
			}

		} catch (Exception e) {
			LOG.info(e.toString());
		} finally {

			try {
		
				in.close();
				bis.close();

			} catch (Exception e) {
			}
		}
		return arrayBuff.toByteArray();


:
Posted by mastar