#####FUNCTION 생성

 

DROP FUNCTION IF EXISTS GETMASTER_SYMB;

DELIMITER $$
CREATE FUNCTION GETMASTER_SYMB(intput1 TEXT, intput2 TEXT) RETURNS TEXT
BEGIN

    DECLARE p_result    TEXT;
    DECLARE p_input1    TEXT;
    DECLARE p_input2    TEXT;

 

    SET p_input1 = intput1;
    SET p_input2 = intput2;

 

    SET p_result = (SELECT  SYMB FROM fssmaster WHERE ( COD2 = p_input1 OR COD1 = p_input2 ))
    ;

    RETURN p_result;
END $$
DELIMITER ;

 

 

#####FUNCTION 활용

C:\Users\kiwoom\Downloads>
C:\Users\kiwoom\Downloads>mysql -u root -p
Enter password: ***********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.1.35-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use fss;
Database changed
mysql> SELECT fss.GETMASTER_SYMB('4262', '4263');
+------------------------------------+
| fss.GETMASTER_SYMB('4262', '4263') |
+------------------------------------+
| AAV                                |
+------------------------------------+
1 row in set (0.02 sec)

mysql>
mysql>
mysql>

 

/*

 * gcc -c sample.c

 * gcc -o sample sample.o libmysql.lib

 */

 

#include "C:\Program Files\MySQL\MySQL Connector C 6.1\include\mysql.h"
#include <string.h>
#include <stdio.h>

#define DB_HOST "127.0.0.1"
#define DB_USER "root"
#define DB_PASS "eogksalsrnr"
#define DB_NAME "fss"
    
int main(void)
{
    MYSQL *connection=NULL, conn;
    MYSQL_RES *sql_result;
    MYSQL_ROW sql_row;
    int query_stat; 
    
    mysql_init(&conn);

    connection = mysql_real_connect(&conn, DB_HOST, DB_USER, DB_PASS, DB_NAME, 3306, (char *)NULL, 0);

    if (connection == NULL)
    {
        fprintf(stderr, "Mysql connection error : %s", mysql_error(&conn));
        return 1;
    }

    query_stat = mysql_query(connection, "SELECT fss.GETMASTER_SYMB('4262', '4263')");
    if (query_stat != 0)
    {
        fprintf(stderr, "Mysql query error : %s", mysql_error(&conn));
        return 1;
    }
    
    sql_result = mysql_store_result(connection);
    
    while ( (sql_row = mysql_fetch_row(sql_result)) != NULL )
    {
        printf(">>>>>>%s\n", sql_row[0]);
    }

    mysql_free_result(sql_result);

    mysql_close(connection);

    return 0;​
}
 

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

 

#define LEAP(y) ((y % 4 == 0 && y % 100 != 0 || y % 400 == 0) ? 1 : 0)

 

static void ha_ltona0(int idx, int length, char *answer);

static int ha_antol(char *request, int length);

static void cb1_compute_date (char *odate, char *idate, int addval);

static int getRemainDay(char *odate, char *idate);

 

int main(int argc, char *argv[])

{

    int rc,mm,dd;    char begin_date[10] = "20190101";

   char end_date [10];

   for(mm=1; mm<=12; mm++)

   {

      for(dd=1; dd<=31; dd++)

      {

         memset(end_date,0x00,sizeof(end_date));

         sprintf(end_date, "2019%.2d%.2d", mm, dd);

         rc = getRemainDay(end_date,begin_date);

         if(rc<0) printf("(%s)(%s):(%s)\n", begin_date, end_date, " is not valid day!! error");

         else printf("(%s)(%s):(%d)\n", begin_date, end_date, getRemainDay(end_date,begin_date));

      }

   }

for(mm=1; mm<=12; mm++) { for(dd=1; dd<=31; dd++)

{

memset(end_date,0x00,sizeof(end_date));

sprintf(end_date, "2019%.2d%.2d", mm, dd);

rc = getRemainDay(end_date,begin_date);

if(rc<0) printf("(%s)(%s):(%s)\n", begin_date, end_date, " is not valid day!! error");

}

}

   return 0;

}

 

/*- ------------------------------------------------ -*

 *- ha_ltona0

 *- ------------------------------------------------ -*/

void ha_ltona0(int idx, int length, char *answer)

{

    if(length==1)

    {

        sprintf(answer,"%.1d",idx);

    }

    else if(length==2)

    {

        sprintf(answer,"%.2d",idx);

    }

    else if(length==3)

    {

        sprintf(answer,"%.3d",idx);

    }

    else if(length==4)

    {

        sprintf(answer,"%.4d",idx);

    }

}

 

/*- ------------------------------------------------ -*

 *- ha_antol

 *- ------------------------------------------------ -*/

int ha_antol(char *request, int length)

{

char answer[100];

 

memset(answer,0x00,sizeof(answer));

 

memcpy(answer,request,length);

 

return(atoi(answer));

}

 

/*- ------------------------------------------------ -*

 *- cb1_compute_date

 *- ------------------------------------------------ -*/

void cb1_compute_date (odate, idate, addval)

char *odate;

char *idate;

int addval;

{

int yy;

int mm;

int dd;

int leap;

static int mmt[2] [13] =

{ {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},

   {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} };

 

yy = ha_antol(idate, 4);

mm = ha_antol(idate+4, 2);

dd = ha_antol(idate+6, 2) + addval;

leap = LEAP(yy);

if (addval == 0) {

sprintf(odate, "%.8s", idate);

return;

    }

else

if (addval > 0) {

     for ( ; dd > mmt[leap][mm]; mm++)

     {

     dd -= mmt[leap] [mm];

     if (mm >= 12)

     {

         mm = 0;

         yy++;

         leap = LEAP(yy);

     }

     }

}

else {

     mm--;

     if (mm == 0)

     {

     mm = 12;

     yy--;

     leap = LEAP(yy);

     }

 

     for ( ; dd < 1; mm--)

     {

     dd += mmt [leap] [mm];

     if (mm <= 1)

     {

         mm = 13;

         yy--;

         leap = LEAP(yy);

     }

     }

     mm++;

     if (mm > 12)

     {

     mm = 1;

     yy++;

     }

}

 

ha_ltona0(yy, 4, odate);

ha_ltona0(mm, 2, odate+4);

ha_ltona0(dd, 2, odate+6);

}

 

/*- ------------------------------------------------ -*

 *- getRemainDay

 *- ------------------------------------------------ -*/

int getRemainDay(char *odate, char *idate)

{

int k;

char begin_date[10];

 

if(strcmp(odate,idate)<0) return(-1);

 

if(memcmp(odate,idate,strlen("YYYYMMDD"))==0) return 1;

 

    for(k=1; k<9999; k++)

{

     memset(begin_date,0x00,sizeof(begin_date));

     cb1_compute_date(begin_date,idate,k);

 

if(memcmp(begin_date,odate,strlen("YYYYMMDD"))==0) break;

}

 

if(k==9999) return(-1);

return k+1;

}

 

/*RESULT

Microsoft Windows [Version 6.1.7601]

Copyright (c) 2009 Microsoft Corporation. All rights reserved.

 

C:\Users\Downloads>10

,,

,,

,,

,,

(20190101)(20190818):(230)

(20190101)(20190819):(231)

(20190101)(20190820):(232)

(20190101)(20190821):(233)

(20190101)(20190822):(234)

(20190101)(20190823):(235)

(20190101)(20190824):(236)

(20190101)(20190825):(237)

(20190101)(20190826):(238)

(20190101)(20190827):(239)

(20190101)(20190828):(240)

(20190101)(20190829):(241)

(20190101)(20190830):(242)

(20190101)(20190831):(243)

(20190101)(20190901):(244)

(20190101)(20190902):(245)

(20190101)(20190903):(246)

(20190101)(20190904):(247)

(20190101)(20190905):(248)

(20190101)(20190906):(249)

(20190101)(20190907):(250)

(20190101)(20190908):(251)

(20190101)(20190909):(252)

(20190101)(20190910):(253)

(20190101)(20190911):(254)

(20190101)(20190912):(255)

(20190101)(20190913):(256)

(20190101)(20190914):(257)

(20190101)(20190915):(258)

(20190101)(20190916):(259)

(20190101)(20190917):(260)

(20190101)(20190918):(261)

(20190101)(20190919):(262)

(20190101)(20190920):(263)

(20190101)(20190921):(264)

(20190101)(20190922):(265)

(20190101)(20190923):(266)

(20190101)(20190924):(267)

(20190101)(20190925):(268)

(20190101)(20190926):(269)

(20190101)(20190927):(270)

(20190101)(20190928):(271)

(20190101)(20190929):(272)

(20190101)(20190930):(273)

(20190101)(20190931):( is not valid day!! error)

(20190101)(20191001):(274)

(20190101)(20191002):(275)

(20190101)(20191003):(276)

(20190101)(20191004):(277)

(20190101)(20191005):(278)

(20190101)(20191006):(279)

(20190101)(20191007):(280)

(20190101)(20191008):(281)

(20190101)(20191009):(282)

(20190101)(20191010):(283)

(20190101)(20191011):(284)

(20190101)(20191012):(285)

(20190101)(20191013):(286)

(20190101)(20191014):(287)

(20190101)(20191015):(288)

(20190101)(20191016):(289)

(20190101)(20191017):(290)

(20190101)(20191018):(291)

(20190101)(20191019):(292)

(20190101)(20191020):(293)

(20190101)(20191021):(294)

(20190101)(20191022):(295)

(20190101)(20191023):(296)

(20190101)(20191024):(297)

(20190101)(20191025):(298)

(20190101)(20191026):(299)

(20190101)(20191027):(300)

(20190101)(20191028):(301)

(20190101)(20191029):(302)

(20190101)(20191030):(303)

(20190101)(20191031):(304)

(20190101)(20191101):(305)

(20190101)(20191102):(306)

(20190101)(20191103):(307)

(20190101)(20191104):(308)

(20190101)(20191105):(309)

(20190101)(20191106):(310)

(20190101)(20191107):(311)

(20190101)(20191108):(312)

(20190101)(20191109):(313)

(20190101)(20191110):(314)

(20190101)(20191111):(315)

(20190101)(20191112):(316)

(20190101)(20191113):(317)

(20190101)(20191114):(318)

(20190101)(20191115):(319)

(20190101)(20191116):(320)

(20190101)(20191117):(321)

(20190101)(20191118):(322)

(20190101)(20191119):(323)

(20190101)(20191120):(324)

(20190101)(20191121):(325)

(20190101)(20191122):(326)

(20190101)(20191123):(327)

(20190101)(20191124):(328)

(20190101)(20191125):(329)

(20190101)(20191126):(330)

(20190101)(20191127):(331)

(20190101)(20191128):(332)

(20190101)(20191129):(333)

(20190101)(20191130):(334)

(20190101)(20191131):( is not valid day!! error)

(20190101)(20191201):(335)

(20190101)(20191202):(336)

(20190101)(20191203):(337)

(20190101)(20191204):(338)

(20190101)(20191205):(339)

(20190101)(20191206):(340)

(20190101)(20191207):(341)

(20190101)(20191208):(342)

(20190101)(20191209):(343)

(20190101)(20191210):(344)

(20190101)(20191211):(345)

(20190101)(20191212):(346)

(20190101)(20191213):(347)

(20190101)(20191214):(348)

(20190101)(20191215):(349)

(20190101)(20191216):(350)

(20190101)(20191217):(351)

(20190101)(20191218):(352)

(20190101)(20191219):(353)

(20190101)(20191220):(354)

(20190101)(20191221):(355)

(20190101)(20191222):(356)

(20190101)(20191223):(357)

(20190101)(20191224):(358)

(20190101)(20191225):(359)

(20190101)(20191226):(360)

(20190101)(20191227):(361)

(20190101)(20191228):(362)

(20190101)(20191229):(363)

(20190101)(20191230):(364)

(20190101)(20191231):(365)

(20190101)(20190229):( is not valid day!! error)

(20190101)(20190230):( is not valid day!! error)

(20190101)(20190231):( is not valid day!! error)

(20190101)(20190431):( is not valid day!! error)

(20190101)(20190631):( is not valid day!! error)

(20190101)(20190931):( is not valid day!! error)

(20190101)(20191131):( is not valid day!! error)

*/

 

#include <stdio.h>

 

#if(1)

#pragma pack(1)

struct PacketHeader {

    char flags;    // 1 BYTE

    int seq;       // 4 BYTE

};

#pragma pack()

#endif

 

#if(0)

struct PacketHeader {

    char flags;    // 1 BYTE

    int seq;       // 4 BYTE

} __attribute__((aligned(1), packed));

#endif

 

#if(0)

struct PacketHeader {

    char flags;    // 1 BYTE

    int seq;       // 4 BYTE

};

#endif

 

int main()

{

    struct PacketHeader header;

 

    printf("%d\n", sizeof(header.flags));

    printf("%d\n", sizeof(header.seq));  

    printf("%d\n", sizeof(header));      

 

    return 0;

}

 

//정상적인 경우는 1+4=8바이트의 크기로 구조체크기가 결정되지만

//#pragma pack(1)를 사용함으로써 구조체 정렬 크기조정할수 있다.

 

 

#include <stdio.h>

 

int main(void)

{

    printf("%.2f\n\n", 0.25676);

    return 0;

}

 

/*

결과:0.26

*/

'c 언어 > 초급과정' 카테고리의 다른 글

중복되지않는 문자출력  (0) 2020.08.26
printf () 함수 활용  (0) 2019.10.31
[C언어] Header File 한번만 포함하기.  (0) 2019.10.31
WINDOWS, 키보드 주므르기(102)  (0) 2019.10.31
WINDOWS, 키보드 주므르기(101)  (0) 2019.10.31

C언어로 프로그래밍을 하다보면 하나의 헤더파일이 여러 곳에서 참조될 때가 있다.

컴파일 시 해당 헤더파일이 여러번 중복되서 참조되는 상황을 막기 위해

 

#ifndef 와 #define이 사용된다.

 

예를 들어 test.h라는 헤더파일이 있다고 하자.

 

헤더파일의 가장 위에

 

#ifndef __TEST_H__

#define __TEST_H__

 

// 내용 작성

#define MAX_LEVEL 999

 

#endif

 

위와 같이 작성하게 되면 __TEST_H__이 상수화 되어 헤더파일 참조 시 해당 파일 참조되었으므로 

한번만 참조하게 된다.

 

#변수가 아닌이상, 여러번 참조해도 괜찮지만, 코드의 가독성및 사이즈에 영향을 미치게 된다.

#변수가 아닌이상, 여러번 참조해도 괜찮지만, 코드의 가독성및 사이즈에 영향을 미치게 된다.

#변수가 아닌이상, 여러번 참조해도 괜찮지만, 코드의 가독성및 사이즈에 영향을 미치게 된다.

#변수가 아닌이상, 여러번 참조해도 괜찮지만, 코드의 가독성및 사이즈에 영향을 미치게 된다.

#변수가 아닌이상, 여러번 참조해도 괜찮지만, 코드의 가독성및 사이즈에 영향을 미치게 된다.

#변수가 아닌이상, 여러번 참조해도 괜찮지만, 코드의 가독성및 사이즈에 영향을 미치게 된다.

#변수가 아닌이상, 여러번 참조해도 괜찮지만, 코드의 가독성및 사이즈에 영향을 미치게 된다.

#변수가 아닌이상, 여러번 참조해도 괜찮지만, 코드의 가독성및 사이즈에 영향을 미치게 된다.

#변수가 아닌이상, 여러번 참조해도 괜찮지만, 코드의 가독성및 사이즈에 영향을 미치게 된다.

 

 

 

 

#APACHE KAFKA 데이타마이그래이션 작업

 

> cd /home1/irteamsu/kafka2/kafka_2.11-1.1.0/

 

> base

> bin/kafka-server-stop.sh

> bin/zookeeper-server-stop.sh

 

########################cp -R /tmp/kafka-logs/ /home1/irteamsu/kafkadata/

 

cp /tmp/kafka-logs/20180416-0/* /home1/irteamsu/kafkadata/kafka-logs/20180416-0/

cp /tmp/kafka-logs/recovery-point-offset-checkpoint /home1/irteamsu/kafkadata/kafka-logs/

cp /tmp/kafka-logs/log-start-offset-checkpoint /home1/irteamsu/kafkadata/kafka-logs/

cp /tmp/kafka-logs/replication-offset-checkpoint /home1/irteamsu/kafkadata/kafka-logs/

 

 

> /home1/irteamsu/kafka2/kafka_2.11-1.1.0/config/server.properties 변경

 

> bin/zookeeper-server-start.sh config/zookeeper.properties &

> bin/kafka-server-start.sh config/server.properties &

 

 

#APACHE KAFKA 데이타마이그래이션 작업 확인

 

> bin/kafka-topics.sh --list --zookeeper localhost:2181

 

[irteamsu@cdb021.imgr kafka_2.11-1.1.0]$ netstat -an | grep 2181

tcp        0      0 0.0.0.0:2181            0.0.0.0:*               LISTEN

tcp        0      0 127.0.0.1:49964         127.0.0.1:2181          TIME_WAIT

tcp        0      0 127.0.0.1:35802         127.0.0.1:2181          ESTABLISHED

tcp        0      0 127.0.0.1:2181          127.0.0.1:35802         ESTABLISHED

[irteamsu@cdb021.imgr kafka_2.11-1.1.0]$

[irteamsu@cdb021.imgr kafka_2.11-1.1.0]$

 

[irteamsu@cdb021.imgr kafka_2.11-1.1.0]$

[irteamsu@cdb021.imgr 20180509-0]$ netstat -an | grep 9092

tcp        0      0 0.0.0.0:9092            0.0.0.0:*               LISTEN

tcp        0     52 10.113.68.29:9092       10.113.68.28:59222      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59274      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59254      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59268      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59278      ESTABLISHED

tcp        0      0 127.0.0.1:9092          127.0.0.1:42516         ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59276      ESTABLISHED

tcp        0     44 10.113.68.29:9092       10.113.68.28:59246      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59272      ESTABLISHED

tcp        0     72 10.113.68.29:52474      10.113.68.29:9092       ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59234      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59270      ESTABLISHED

tcp        0     44 10.113.68.29:9092       10.113.68.28:59240      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59266      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59262      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59284      ESTABLISHED

tcp        0     52 10.113.68.29:9092       10.113.68.28:59227      ESTABLISHED

tcp        0     52 10.113.68.29:9092       10.113.68.28:59226      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.29:52474      ESTABLISHED

tcp        0     44 10.113.68.29:9092       10.113.68.28:59242      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59250      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59248      ESTABLISHED

tcp        0     52 10.113.68.29:9092       10.113.68.28:59252      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59446      ESTABLISHED

tcp        0     52 10.113.68.29:9092       10.113.68.28:59230      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59224      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59286      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59280      ESTABLISHED

tcp        1      0 10.113.68.29:52470      10.113.68.29:9092       CLOSE_WAIT

tcp        0      0 10.113.68.29:9092       10.113.68.28:59258      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59256      ESTABLISHED

tcp        0     44 10.113.68.29:9092       10.113.68.28:59244      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59232      ESTABLISHED

tcp        0     52 10.113.68.29:9092       10.113.68.28:59236      ESTABLISHED

tcp        0      0 127.0.0.1:42516         127.0.0.1:9092          ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59220      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59448      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59264      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:59238      ESTABLISHED

[irteamsu@cdb021.imgr 20180509-0]$

 

 

 

 

 

[irteamsu@cdb021.imgr kafka_2.11-1.1.0]$

[irteamsu@cdb021.imgr kafka_2.11-1.1.0]$ bin/kafka-topics.sh --list --zookeeper localhost:2181

[2018-04-16 18:14:17,021] INFO Accepted socket connection from /127.0.0.1:54720 (org.apache.zookeeper.server.NIOServerCnxnFactory)

[2018-04-16 18:14:17,024] INFO Client attempting to establish new session at /127.0.0.1:54720 (org.apache.zookeeper.server.ZooKeeperServer)

[2018-04-16 18:14:17,025] INFO Established session 0x162cdbb20e00001 with negotiated timeout 30000 for client /127.0.0.1:54720 (org.apache.zookeeper.server.ZooKeeperServer)

20180411

20180412

20180413

20180414

20180415

20180416

20180417

20180418

20180419

20180420

20180421

20180422

20180423

20180424

20180425

20180426

20180427

20180428

20180429

20180430

20180431

 

[2018-04-16 18:14:17,066] INFO Processed session termination for sessionid: 0x162cdbb20e00001 (org.apache.zookeeper.server.PrepRequestProcessor)

[2018-04-16 18:14:17,067] INFO Closed socket connection for client /127.0.0.1:54720 which had sessionid 0x162cdbb20e00001 (org.apache.zookeeper.server.NIOServerCnxn)

[irteamsu@cdb021.imgr kafka_2.11-1.1.0]$

[irteamsu@cdb021.imgr kafka_2.11-1.1.0]$ netstat -an | grep 2181

tcp        0      0 0.0.0.0:2181            0.0.0.0:*               LISTEN

tcp        0      0 127.0.0.1:54646         127.0.0.1:2181          ESTABLISHED

tcp        0      0 127.0.0.1:54720         127.0.0.1:2181          TIME_WAIT

tcp        0      0 127.0.0.1:2181          127.0.0.1:54646         ESTABLISHED

[irteamsu@cdb021.imgr kafka_2.11-1.1.0]$ netstat -an | grep 9092

tcp        0      0 0.0.0.0:9092            0.0.0.0:*               LISTEN

tcp        0      0 10.113.68.29:9092       10.113.68.28:45470      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45450      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45414      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45476      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45424      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45440      ESTABLISHED

tcp        0      0 127.0.0.1:9092          127.0.0.1:48314         ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45426      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45442      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.29:58272      ESTABLISHED

tcp        0      0 127.0.0.1:48314         127.0.0.1:9092          ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45462      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45436      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45432      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45458      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45474      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45446      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45434      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45472      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.29:58268      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45460      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45420      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45464      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45444      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45438      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45422      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45452      ESTABLISHED

tcp        0      0 10.113.68.29:58268      10.113.68.29:9092       ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45428      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45448      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45418      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45478      ESTABLISHED

tcp        0      0 10.113.68.29:58272      10.113.68.29:9092       ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45480      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45454      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45466      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45430      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.10:53490      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45456      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45468      ESTABLISHED

tcp        0      0 10.113.68.29:9092       10.113.68.28:45416      ESTABLISHED

[irteamsu@cdb021.imgr kafka_2.11-1.1.0]$

Linux - du (Disk Usage)

Syntax
du [OPTION]... [FILE]...
du [OPTION]... --files0-from=F

SAMPLE>>>>
[irteamsu@cdb021.imgr kafka-logs]$ du -sch 2018*
4.0K    20180411-0
4.0K    20180412-0
8.0K    20180413-0
4.0K    20180414-0
4.0K    20180415-0
4.0K    20180416-0
4.0K    20180417-0
838M    20180418-0
8.0K    20180419-0
6.7G    20180420-0
1.1M    20180421-0
1.2M    20180422-0
17G     20180423-0
18G     20180424-0
18G     20180425-0
18G     20180426-0
18G     20180427-0
1.2M    20180428-0
1.1M    20180429-0
17G     20180430-0
0       20180431-0
1.1M    20180501-0
18G     20180502-0
17G     20180503-0
13G     20180504-0


3.1 - Options
3.1.1 - Data Filtering
-a, –all: get info for all files, not just directories
--max-depth=N: print the total for a directory (or file, with --all) only if it is N or fewer levels below the command line argument; --max-depth=0 is the same as --summarize
-X FILE, --exclude-from=FILE: Exclude files that match any pattern in FILE.
--exclude=PATTERN Exclude files that match PATTERN.
3.1.2 - Summarize
-s, --summarize display only a total for each argument
-c, --total: produce a grand total
3.1.3 - Calculation
-S, --separate-dirs do not include size of subdirectories
--apparent-size: print apparent sizes, rather than disk usage; although the apparent size is usually smaller, it may be larger due to holes in (“sparse”) files, internal fragmentation, indirect blocks, and the like

3.1.4 - Symlink
-l, --count-links: show sizes many times if hard linked
-L, --dereference: dereference all symbolic links
-P, --no-dereference: don’t follow any symbolic links (this is the default)
3.1.5 - Formatting
3.1.5.1 - Time
--time show time of the last modification of any file in the directory, or any of its subdirectories
--time=WORD show time as WORD instead of modification time: atime, access, use, ctime or status
--time-style=STYLE show times using style STYLE:
full-iso,
long-iso,
iso,
+FORMAT FORMAT is interpreted like ‘date’
3.1.5.2 - Newline
-0, --null: end each output line with 0 byte rather than newline
3.1.5.3 - Size
-h, --human-readable: print sizes in human readable format (e.g., 1K 234M 2G)
--si like -h, but use powers of 1000 not 1024
--block-size=SIZE: display the size as a multiple of SIZE. Shortcut
-b: bit --block-size=SIZE
-k: --block-size=1k
-m: --block-size=1M

Apache Kafka ( 아파치 카프카 ) 2.11-0.9.0.0 소개 및 설치하기

Apache Kafka ( 아파치 카프카 ) 
2.11-0.9.0.0 소개 및 설치하기

아파치 카프카(Apache Kafka)는 아파치 소프트웨어 재단이 스칼라로 개발한 오픈 소스 메시지 브로커 프로젝트이다. 
이 프로젝트는 실시간 데이터 피드를 관리하기 위해 통일된, 높은 스루풋의 낮은 레티어신을 지닌 플랫폼을 제공하는 것이 목표이다. 
요컨대 분산 트랜잭션 로그로 구성된, 상당히 확장 가능한 pub/sub 메시지 큐로 정의할 수 있으며, 스트리밍 데이터를 처리하기 위한 기업 인프라를 위한 고부가 가치 기능이다.
디자인은 트랜잭션 로그에 많은 영향을 받았다
아파치 카프카는 원래 링크드인이 개발한 것으로, 2011년 초에 최종적으로 오픈 소스화되었다. 2012년 10월 23일에는 아파치 인큐베이터로부터 완전히 빠져나왔다. 
2014년 11월 링크드인에서 카프카를 만들던 일부 엔지니어들이 카프카에 집중하기 위해 Confluent라는 새로운 회사를 창립하였다

카프카 설치는 간단합니다.

아파치 카프카 다운로드 링크
https://kafka.apache.org/downloads


이후 설치할 공간에서 압출을 푼 뒤

$tar zvxf kafka_2.11-0.9.0.0.tgz
$cd kafka_2.11-0.9.0.0

환경 설정을 진행합니다.
환경설정 파일은 config 폴더에 위치해 있습니다.

vi config/server.properties

그 후 사용할 Datadir 폴더와 
DataLogdir 폴더를 사용할 위치에 만들어 줍니다.
데이터가 큰 경우에는 OS에 구성하면 안되고 Data 영역에 사용하여야 합니다.

log.dirs 설정
만들어 준 위치를 넣어줍니다.

broker.id 를 설정해 줍니다.
유니크한 숫자를 브로커 마다 각각 입력하시면 됩니다.
주키퍼를 설치한 서버정보를 입력합니다.


설치를 안했을 경우 주키퍼를 실행하기 위해서
vi config/zookeeper.properties
zookeeper.connect=localhost:2181 (주키퍼를 설치한 서버)

주키퍼 설정을 해줍시다.

bin/zookeeper-server-start.sh config/zookeeper.properties
(주키퍼 실행 미리 설치 안했을 경우)

bin/kafka-server-start.sh config/server.properties 
(카프카 실행)

+ Recent posts