hive, hadoop, hbase, sqoop 등을 사용하는 경우 

CDH-5.1.2 --> CDH-5.5.1 로의 업그레이드를 할 때, 사용할 수 있는 팁

hadoop-2.6.0+cdh5.5.1+924-1.cdh5.5.1.p0.15.el6.x86_64

hive-1.1.0+cdh5.5.1+327-1.cdh5.5.1.p0.15.el6.noarch



1. 단순 패치 (CDH-5.5.1 설치)

yum 으로 설치한 CDH-5.1.2 위에 단순히 CDH-5.5.1 설치를 진행했다. hadoop, hive 에러 발생했다.



2. yum 기존 패키지 (CDH-5.1.2) 삭제후 CDH-5.5.1 설치

hadoop, hive는 잘 되는데, sqoop 실행시 에러 발생


확인해보니 CDH5-1.2의 하위 avro lib (serialization lib이다.)때문에 dependency lib가 꼬인 문제였다.



3. yum 기존 패키지,CDH-5.5.1 설치 삭제, avro 관련 jar 관련 모든 파일을 삭제하고, 신규 CDH-5.5.1 재설치 


어떤 lib인지 몰라도. hbase도 설치해야 hive/hadoop/sqoop이 잘 동작했다.

sqoop은 mysql DB 연결하려면, mysql jdbc driver(mysql-connector-java-5.1.38.jar)를 다운받아 /usr/lib/sqoop/lib에 복사한다.


connection time out 나고 그러면 network acl 에 문제있는지 확인한다. hive 를 실행하는 서버가 아닌 data node쪽에서 telnet으로 db를 붙는지 확인한다.


그러나 과거에 잘 동작하던 hive에서 java.lang.OutOfMemoryError: Java heap space 가 발생했다.


(소스를 분석하면서 진행하는 것이 좋음)

/usr/lib/hive/conf/hive-env.sh 에서 메모리를 수정한다. (hive-env.sh.template를 참조한다.)


<원본>

# if [ "$SERVICE" = "cli" ]; then

#   if [ -z "$DEBUG" ]; then

#     export HADOOP_OPTS="$HADOOP_OPTS -XX:NewRatio=12 -Xmx1g -Xms1g -XX:MaxHeapFreeRatio=40 -XX:MinHeapFreeRatio=15 -XX:+UseParNewGC -XX:-UseGCOverheadLimit"

#   else

#     export HADOOP_OPTS="$HADOOP_OPTS -XX:NewRatio=12 -Xms10m -XX:MaxHeapFreeRatio=40 -XX:MinHeapFreeRatio=15 -XX:-UseGCOverheadLimit"

#   fi

# fi


# The heap size of the jvm stared by hive shell script can be controlled via:

#

# export HADOOP_HEAPSIZE=1024

 

 

<수정>

# if [ "$SERVICE" = "cli" ]; then

#   if [ -z "$DEBUG" ]; then

     export HADOOP_OPTS="$HADOOP_OPTS -XX:NewRatio=12 -Xmx1g -Xms1g -XX:MaxHeapFreeRatio=40 -XX:MinHeapFreeRatio=15 -XX:+UseParNewGC -XX:-UseGCOverheadLimit"

#   else

#     export HADOOP_OPTS="$HADOOP_OPTS -XX:NewRatio=12 -Xms10m -XX:MaxHeapFreeRatio=40 -XX:MinHeapFreeRatio=15 -XX:-UseGCOverheadLimit"

#   fi

# fi


# The heap size of the jvm stared by hive shell script can be controlled via:

#

 export HADOOP_HEAPSIZE=1024

 


참고로, CDH5 lib를 yum으로 설치하면, 디렉토리는 다음과 같다.


/usr/lib/hive/

/usr/lib/hadoop

/usr/lib/hbase/

/usr/lib/avro/

/usr/bin/sqoop/
/usr/lib/hadoop-mapreduce/




4. hadoop streaming


hadoop streaming을 쓰려면, 아래 lib을 참조한다.

/usr/lib/hadoop-mapreduce/hadoop-streaming-2.6.0-cdh5.5.1.jar


$ hadoop jar /usr/lib/hadoop-mapreduce/hadoop-streaming-2.6.0-cdh5.5.1.jar -D mapred.job.priority=LOW -D mapred.job.name="test" -D mapred.output.compress=false  -output=하둡디렉토리위치 -mapper=map.py -file=map.py -numReduceTasks 0

Posted by '김용환'
,


centos 6.5에서 popt 모듈의 기본 설치가 빠져서 logroate 바이너리를 만들지 못했다. 

이에 대한 해결책을 작성했다.


$ wget https://fedorahosted.org/releases/l/o/logrotate/logrotate-3.8.7.tar.gz 

$ tar zxvf logrotate-3.8.7.tar.gz

$ cd logrotate-3.8.7.tar.gz

$ make

cc -E -Wall -D_GNU_SOURCE -DLinux -DVERSION=\"3.8.7\"   -g    -M logrotate.c log.c config.c basenames.c  > .depend

logrotate.c:11:18: error: popt.h: 그런 파일이나 디렉터리가 없습니다

config.c:13:18: error: popt.h: 그런 파일이나 디렉터리가 없습니다



popt 모듈은 설치되어 있다.

$ rpm -ql popt

/etc/popt.d

/lib64/libpopt.so.0

/lib64/libpopt.so.0.0.0


하지만, popt.h 파일이 존재하지 않는다.

$ ls -al /usr/include/popt.h

ls: cannot access /usr/include/popt.h: 그런 파일이나 디렉터리가 없습니다


이 문제를 해결 하기 위해 popt-devel 모듈을 설치한다.

$ sudo yum install -y popt-devel


popt.h 파일을 포함해서 popt 연동 모듈을 추가되었다.

$ ls -al /usr/include/popt.h

-rw-r--r--. 1 root root 16566 2010-08-21 14:30 /usr/include/popt.h



다음 작업을 진행하면, 컴파일 및 설치가 성공된다.


$ make 

$ make install



Posted by '김용환'
,


curl을 이용한 time elapsed 확인할 수 있는 두가지 예제이다. 

구글 static map 호출시 얼마나 걸리는 지 코딩 전에 미리 테스트할 수 있었다.



1.  curl 의 -w 옵션에 다양한 매개변수를 주어 걸린 시간을 측정할 수 있다.

 $ curl -s -w "%{time_namelookup} %{time_connect} %{time_appconnect} %{time_pretransfer} %{time_redirect} %{time_starttransfer} %{time_total}\n" -o /dev/null 'https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=15&size=300x200&maptype=roadmap


0.001 0.217 1.078 1.078 0.000 1.349 1.790



한 번이 아닌 여러 번 실행하여 적당히 실행할 수 있다.


$ for i in {1..3}; do curl -s -w "%{time_namelookup} %{time_connect} %{time_appconnect} %{time_pretransfer} %{time_redirect} %{time_starttransfer} %{time_total}\n" -o /dev/null 'https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=15&size=300x200&maptype=roadmap'; done



0.001 0.217 1.078 1.078 0.000 1.349 1.790

0.001 0.171 0.781 0.781 0.000 1.090 1.263

0.001 0.181 0.784 0.784 0.000 1.101 1.281




2. curl 옵션 아닌 time 을 이용한다. 


time curl -I 'https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=15&size=300x200&maptype=roadmap' 



여러 번 호출해서 통계를 내볼 수 있다.


$ for i in {1..3}; do time curl -I 'https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=15&size=300x200&maptype=roadmap' ; done





HTTP/1.1 200 OK

Content-Type: image/png

Date: Sat, 22 Aug 2015 16:14:39 GMT

Expires: Sun, 23 Aug 2015 16:14:39 GMT

Cache-Control: public, max-age=86400

Vary: Accept-Language

Access-Control-Allow-Origin: *

Server: staticmap

Content-Length: 23448

X-XSS-Protection: 1; mode=block

X-Frame-Options: SAMEORIGIN

Alternate-Protocol: 443:quic,p=1

Alt-Svc: quic=":443"; p="1"; ma=604800



real 0m1.024s

user 0m0.037s

sys 0m0.010s

HTTP/1.1 200 OK

Content-Type: image/png

Date: Sat, 22 Aug 2015 16:14:40 GMT

Expires: Sun, 23 Aug 2015 16:14:40 GMT

Cache-Control: public, max-age=86400

Vary: Accept-Language

Access-Control-Allow-Origin: *

Server: staticmap

Content-Length: 23448

X-XSS-Protection: 1; mode=block

X-Frame-Options: SAMEORIGIN

Alternate-Protocol: 443:quic,p=1

Alt-Svc: quic=":443"; p="1"; ma=604800



real 0m1.533s

user 0m0.029s

sys 0m0.008s

HTTP/1.1 200 OK

Content-Type: image/png

Date: Sat, 22 Aug 2015 16:14:42 GMT

Expires: Sun, 23 Aug 2015 16:14:42 GMT

Cache-Control: public, max-age=86400

Vary: Accept-Language

Access-Control-Allow-Origin: *

Server: staticmap

Content-Length: 23448

X-XSS-Protection: 1; mode=block

X-Frame-Options: SAMEORIGIN

Alternate-Protocol: 443:quic,p=1

Alt-Svc: quic=":443"; p="1"; ma=604800



real 0m1.622s

user 0m0.030s

sys 0m0.008s





Posted by '김용환'
,


rsync시 디렉토리 생성이 가능하다. 


예를 들어 로컬 장비의 특정 디렉토리를 host 장비로 rsync로 복사하려고 할때,

host 장비의  /home/www 디렉토리가 존재하고, backup_11 디렉토리가 존재하지 않을 때,

아래와 같은 명령어로 디렉토리를 복사할 수 있다.



rsync -rvv /home/www/backup_11/ www@host:/home/www/backup_11/


Posted by '김용환'
,


jenkins 서비스는 jenkins라는 계정으로 daemonize 하고 있다. 

따라서 jenkins 계정이 아닌 원래 사용 중인 계정을 써야 git 사용으로부터 자유로울 수 있다. (.ssh/known_hosts)


아래와 같은 에러가 나오면, 블로그 저자와 같은 방식으로 사용하는 것이 좋다.

Caused by: hudson.plugins.git.GitException: Command "git clone --progress -o origin git@github.com:adulion/.git /var/lib/jenkins/workspace/build social" returned status code 128:




1.jenkins rpm 설치 

(레드햇 계열) yum 설치 (가끔씩 yum 미러링 싸이트가 연결안될 때가 많다..)

https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Red+Hat+distributions

또는 rpm 다운로드 설치

http://pkg.jenkins-ci.org/redhat/

  (rpm -iVh jenkins.rpm)



2. jenkins 설치 스크립트를 수정한다.

$ sudo vi /etc/init.d/jenkins



start/stop 전 혹은 그 위에 매개변수 처리 전 코드에 아래를 추가한다.

JENKINS_USER=www




3. 권한을 추가한다.
(아래 디렉토리에 권한이 없으면 jenkins 데몬 죽어요.)

sudo chown -R www /var/log/jenkins

sudo chown -R www /var/lib/jenkins

sudo chown -R www /var/cache/jenkins




4. 데몬 설정 및 재시작


sudo chkconfig jenkins on

sudo service jenkins restart




5. git 연결

만약 git을 처음 사용한다면, linux 커맨드라인에서 연결하여 정상적으로 실행하도록 한다. (이미 git 실행한 적이 있다면 안해도 된다.)


$ git ls-remote -h git@github.com:profile/spec.git HEAD

(yes)



$ ssh git@github.com

PTY allocation request failed on channel 0

Hi html5/space! You've successfully authenticated, but GitHub does not provide shell access.

                                                                                            Connection to github.com closed.










Posted by '김용환'
,



awk에서 index() 함수를 이용해서 substring이 포함되었지를 확인할 수 있다.


$ cat > test.file

c1 place_1234 5


$ awk 'index($1, "place") == 0 {print}' test.file

c1 place_1234 5



$ awk 'index($1, "place") == 1 {print}' test.file

// 결과 없음


Posted by '김용환'
,


awk의 -v 옵션은 변수를 지정하는 것이다. 


아래 예제에서 ' (single quote)를 quote라는 변수로 지정했고, print 문에서 %s에서 single quotation 으로 활용되었다.




$ cat > test.file

c1 place_123 5



$ cat test.file | awk -v quote="'" '{ printf("insert into suggest_place (name, %s) values (%s,%s);\n", $1, quote $2 quote, $3 ); }'


// 결과
insert into suggest_place (name, c1) values ('place_123',5);



Posted by '김용환'
,


Redis가 OS의 swap 메모리를 쓰기 시작하면, 속도는 느려지는 것 뿐 아니라, 


커넥션에도 영향을 미친다. (일명 출렁이는 현상이 발생한다.)


이를 해결하기 위해서는 swap파일을 생성해서 빨리 데이터의 분산 (또는 fragement로 인한 재시작)을 진해해야 한다.


swap 파일을 만들 때 해당 서버(A 서버)에 들어가 명령을 내릴 수 있는데..



dd if=/dev/zero of=/home/samuel/swapfile bs=1M count=1024


부하를 많이 받게 하는 dd 명령어로 인해서 서버가 문제가 될 수 있다.


따라서, 다른 서버에서 swap 파일을 복사한 후 복사하게 한다.


1. B서버에서 file swap 파일을 생성한다.


dd if=/dev/zero of=/home/samuel/swapfile bs=1M count=1024


2. scp가 아닌 rsync로 복사한다.


scp도 부하를 줄 수 있지만, rsync는 대역폭을 줄 수 있어서 A서버에 부하를 많이 줄일 수 있다.


초당 5M로 복사하는 경우라면 다음과 같이 비슷하게 B 서버에서 실행하면 될 것이다.


rsync --bwlimit=5120  -v  /home/samuel/swapfile  A.server::R`pwd`/swapfile 

Posted by '김용환'
,


linux에서는 swap을 사용할 수 있고, 설정에 따라서 linux oom killer가 프로세스를 종료시킬 수 있다. 


운영을 하면서 Nosql, Java, DB, Redis를 사용시 프로세스 종료가 일어나는 최악의 상황을 발생하기 위해서는 이 부분을 반드시 알아야 한다.  이런 oom killer의 설정은 vm.overcommit_memory 커널 설정에 의존을 가지고 있다.

디폴트 값은 0인 휴리스틱(메모리 요구시 kill)이다. (참고로 1은 overcommit 사용, 2는 overcommit 사용하지 않음- vm.overcommit_memory_ratio 적용 값)

메모리를 다 썼을 때, 프로세스를 종료되게 할 것인가, 안할 것인가에 대한 고민이 있다. 문제가 될 만한 상황이라도 종료보다는 차라리 잘 진행되기를 바라는 경우가 있다. (redis master의 데이터를 slave 로 보낼때, swap을 만들어도 메모리가 없는 상황에서..)


overcommit을 사용하려면, 다음과 같이 설정한다.


$ sysctl -a | grep overcommit

vm.overcommit_memory=2


$ sysctl vm.overcommit_memory=1

echo "vm.overcommit_memory=1" >> /etc/sysctl.conf






참조 자료


https://www.kernel.org/doc/Documentation/vm/overcommit-accounting

The Linux kernel supports the following overcommit handling modes

0	-	Heuristic overcommit handling. Obvious overcommits of
		address space are refused. Used for a typical system. It
		ensures a seriously wild allocation fails while allowing
		overcommit to reduce swap usage.  root is allowed to 
		allocate slightly more memory in this mode. This is the 
		default.

1	-	Always overcommit. Appropriate for some scientific
		applications. Classic example is code using sparse arrays
		and just relying on the virtual memory consisting almost
		entirely of zero pages.

2	-	Don't overcommit. The total address space commit
		for the system is not permitted to exceed swap + a
		configurable amount (default is 50%) of physical RAM.
		Depending on the amount you use, in most situations
		this means a process will not be killed while accessing
		pages but will receive errors on memory allocation as
		appropriate.

		Useful for applications that want to guarantee their
		memory allocations will be available in the future
		without having to initialize every page.
 

The overcommit policy is set via the sysctl `vm.overcommit_memory'.



http://knight76.tistory.com/entry/Swap-%EB%A9%94%EB%AA%A8%EB%A6%AC


http://blog.lastmind.net/archives/188


http://www.hanbit.co.kr/network/view.html?bi_id=1313


http://mimul.com/pebble/default/2013/05/10/1368171783727.html


http://www.oracle.com/technetwork/articles/servers-storage-dev/oom-killer-1911807.html


https://charsyam.wordpress.com/2013/01/24/%EC%9E%85-%EA%B0%9C%EB%B0%9C-redis-vm-overcommit_memory-%EC%9D%84-%EC%95%84%EC%8B%9C%EB%82%98%EC%9A%94/


Posted by '김용환'
,


mac os나 리눅스를 사용할 때, 기존의 실행했던 명령어나 파라미터를 수정하려 할때, 이동하려면 힘들다. 

보통 emacs 가 편집기로 되어 있다. 이를 vi 타입으로 실행할 수 있다.


우선 콘솔에 다음과 같이 실행한다.


$ set -o vi 



ps 앞에 오타를 입력한 상태이다. 


$ aps -ef | grep java  (커서 위치)



Esc (command 모드로 들어감) 를 입력하고 ^ (맨 앞으로 이동하는 vi 단축키)를 입력하면 맨 앞으로 이동한다. 


$ (커서 위치) aps -ef | grep java



오타를 수정하고 명령어를 내리면 된다. 이렇게 vi 단축키를 써서 터미널의 콘솔을 편하게 사용할 수 있다. 




$ set -o vi 


$ sdf afdadsfsadfsadf (커서 위치) 


여기서 Esc(command 모드)를 누르고 v 를 입력하면 vi 창이 실행된다. 

다음과 같이 vi 창에서 입력후 ':wq'를 입력하고 엔터를 치면 결과가 실행된다.


ps -ef | grep java 







Posted by '김용환'
,