이전 메이븐과 그래들로 도커 빌드/데몬 생성이 가능해졌다.


https://github.com/GoogleContainerTools/jib



mvn compile com.google.cloud.tools:jib-maven-plugin:0.9.10:build -Dimage=<MY IMAGE>



gradle jib --image=<MY IMAGE>



문서는 다음을 참조한다.


https://cloudplatform.googleblog.com/2018/07/introducing-jib-build-java-docker-images-better.html




Posted by '김용환'
,



etcd 2.2.5 클러스터링 구성하기



바이너리를 설치 static으로 구성한다. 


172.26.100.161 (로컬 호스트)에서 2380, 2480, 2580 포트의 etcd 데몬으로 클러스터링을 구성하고.


2680 포트의 새로운 etcd 데몬을 추가하는 예시이다.




1번째


 ./etcd --name etcd1  \

 --initial-advertise-peer-urls http://172.26.100.161:2380 \

 --listen-peer-urls http://172.26.100.161:2380 \

 --listen-client-urls http://172.26.100.161:2379,http://127.0.0.1:2379 \

 --advertise-client-urls http://172.26.100.161:2379 \

 --initial-cluster-token "etcd-cluster" \

 --initial-cluster etcd1=http://172.26.100.161:2380,etcd2=http://172.26.100.161:2480,etcd3=http://172.26.100.161:2580 \

 --initial-cluster-state new



2번째


./etcd --name etcd2 \

--initial-advertise-peer-urls http://172.26.100.161:2480 \

--listen-peer-urls http://172.26.100.161:2480 \

--listen-client-urls http://172.26.100.161:2479,http://127.0.0.1:2479 \

--advertise-client-urls http://172.26.100.161:2479 \

--initial-cluster-token "etcd-cluster" \

--initial-cluster etcd1=http://172.26.100.161:2380,etcd2=http://172.26.100.161:2480,etcd3=http://172.26.100.161:2580 \

--initial-cluster-state new




3번째


./etcd --name etcd3 \

--initial-advertise-peer-urls http://172.26.100.161:2580 \

--listen-peer-urls http://172.26.100.161:2580 \

--listen-client-urls http://172.26.100.161:2579,http://127.0.0.1:2579 \

--advertise-client-urls http://172.26.100.161:2579 \

--initial-cluster-token "etcd-cluster" \

--initial-cluster etcd1=http://172.26.100.161:2380,etcd2=http://172.26.100.161:2480,etcd3=http://172.26.100.161:2580 \

--initial-cluster-state new



다 클러스터링이 동기되면. 로그에 다음과 같은 로그가 찍힌다. 정상적이다. 


2018-09-05 06:33:42.154287 N | etcdserver: updated the cluster version from 2.1 to 2.2





버전을 확인하면 제대로 설치됨을 알 수 있다. 


$curl -L http://127.0.0.1:2379/version

{"etcdserver":"2.2.5","etcdcluster":"2.2.0"}




여기에 새로운 etcd 노드를 추가하려고 한다.


./etcd --name etcd4 \

--initial-advertise-peer-urls http://172.26.100.161:2680 \

--listen-peer-urls http://172.26.100.161:2680 \

--listen-client-urls http://172.26.100.161:2679,http://127.0.0.1:2679 \

--advertise-client-urls http://172.26.100.161:2679 \

--initial-cluster-token "etcd-cluster" \

--initial-cluster etcd1=http://172.26.100.161:2380,etcd2=http://172.26.100.161:2480,etcd3=http://172.26.100.161:2580,etcd4=http://172.26.100.161:2680 \

--initial-cluster-state new

(사실 initial-cluster-state을 new라 하면 안된다)


기존의 클러스터링에 추가되지 못해 나오는 에러가 나오고..


기존 로그에 추가할 수 없다고 나온다. 


2018-09-05 06:41:58.886604 C | etcdmain: couldn't find local name "etcd4" in the initial cluster configuration




이제 클러스터링을 확인한다. 


$  ./etcdctl member list

6564723d6ed1fc93: name=etcd2 peerURLs=http://172.26.100.161:2480 clientURLs=http://172.26.100.161:2479

edbc16344886488f: name=etcd3 peerURLs=http://172.26.100.161:2580 clientURLs=http://172.26.100.161:2579

fc0c8fe65a431b34: name=etcd1 peerURLs=http://172.26.100.161:2380 clientURLs=http://172.26.100.161:2379




추가할 멤버를 추가한다. 

$ ./etcdctl member add etcd4 http://172.26.100.161:2680

Added member named etcd4 with ID 60859f242d8b1d4a to cluster




추가된 멤버는 unstarted로 나온다. 


[~/dev/etcd/4] ./etcdctl member  list

60859f242d8b1d4a[unstarted]: peerURLs=http://172.26.100.161:2680

6564723d6ed1fc93: name=etcd2 peerURLs=http://172.26.100.161:2480 clientURLs=http://172.26.100.161:2479

edbc16344886488f: name=etcd3 peerURLs=http://172.26.100.161:2580 clientURLs=http://172.26.100.161:2579

fc0c8fe65a431b34: name=etcd1 peerURLs=http://172.26.100.161:2380 clientURLs=http://172.26.100.161:2379




이제 4번째 장비에서 다음을 입력한다. 


오랜 시간이 흘러, 이제 새로운 클러스터를 추가한다. 


이 때 initial cluster state 옵션의 값을 new 대신 existing으로 하다.


$ ./etcd 

--initial-advertise-peer-urls http://172.26.100.161:2680 \

--listen-peer-urls http://172.26.100.161:2680 \

--listen-client-urls http://172.26.100.161:2679,http://127.0.0.1:2679 \

--advertise-client-urls http://172.26.100.161:2679 \

--initial-cluster-token "etcd-cluster" \

 --initial-cluster etcd1=http://172.26.100.161:2380,etcd2=http://172.26.100.161:2480,etcd3=http://172.26.100.161:2580,etcd4=http://172.26.100.161:2680 \

--initial-cluster-state existing

  




* 참고

클러스터링 구축하다가 문제가 발생하면..

추가할 etcd 디렉토리에서 데이터 디렉토리를 다 지워야 한다. 디폴트는 {이름}.etcd로 되어 있다. 







$ ./etcdctl member  list

60859f242d8b1d4a: name=etcd4 peerURLs=http://172.26.100.161:2680 clientURLs=http://172.26.100.161:2679

6564723d6ed1fc93: name=etcd2 peerURLs=http://172.26.100.161:2480 clientURLs=http://172.26.100.161:2479

edbc16344886488f: name=etcd3 peerURLs=http://172.26.100.161:2580 clientURLs=http://172.26.100.161:2579

fc0c8fe65a431b34: name=etcd1 peerURLs=http://172.26.100.161:2380 clientURLs=http://172.26.100.161:2379





클러스티링 추가가 완료되었다.


Posted by '김용환'
,





etcd는 3가지 방식으로 클러스터를 구성할 수 있다.


https://coreos.com/etcd/docs/latest/v2/clustering.html


- Static : 클러스터 주소와 크기를 안 상태에서 설정하는 것을 말한다. --initial-cluster를 사용한다. 일반적으로 사용하는 방식이다.

- etcd Discovery : 클러스터 환경에서 DHCP를 사용하는 환경에서 사용된다. 정적 설정이 아닌 동적 설정(discovery) 환경에서 적합. etcd노드를 추가할때 주로 사용하며 --discovery를 사용한다.

- DNS Discovery : 클러스터 환경에서 DHCP를 사용하는 환경에서 사용된다. 정적 설정이 아닌 동적 설정(discovery) 환경에서 적합. DNS의 SRV 레코드를 사용해 etcd 노드를 추가한다. --discovery-srv를 사용한다.




가장 쉬운 방식인 static으로 구성한다. 


https://github.com/etcd-io/etcd/releases에서 etcd 3.2.9 바이너리를 다운받는다. (현재 기준)

$ wget etcd.zip


zip 파일을 풀어 1, 2, 3 디렉토리로 binary를 복사한다.


$ ls -al 하면 다음 디렉토리와 같다.

drwxr-xr-x   8 samuel.kim  staff       272  7 25 02:13 1

drwxr-xr-x   8 samuel.kim  staff       272  7 25 02:13 2

drwxr-xr-x   8 samuel.kim  staff       272  7 25 02:13 3


 

1번 디렉토리로 이동

./etcd --name etcd1 \

--initial-advertise-peer-urls http://172.26.100.161:2380 \

--listen-peer-urls http://172.26.100.161:2380 \

--listen-client-urls http://172.26.100.161:2379,http://127.0.0.1:2379 \

--advertise-client-urls http://172.26.100.161:2379 \

--initial-cluster-token "etcd-cluster" \

--initial-cluster etcd1=http://172.26.100.161:2380,etcd2=http://172.26.100.161:2480,etcd3=http://172.26.100.161:2580 \

--initial-cluster-state new



다른 터미널을 열어, 2번 디렉토리로 이동

./etcd --name etcd2 \

--initial-advertise-peer-urls http://172.26.100.161:2480 \

--listen-peer-urls http://172.26.100.161:2480 \

--listen-client-urls http://172.26.100.161:2479,http://127.0.0.1:2479 \

--advertise-client-urls http://172.26.100.161:2479 \

--initial-cluster-token "etcd-cluster" \

--initial-cluster etcd1=http://172.26.100.161:2380,etcd2=http://172.26.100.161:2480,etcd3=http://172.26.100.161:2580 \

--initial-cluster-state new




다른 터미널을 열어, 3번 디렉토리로 이동

./etcd --name etcd3 \

--initial-advertise-peer-urls http://172.26.100.161:2580 \

--listen-peer-urls http://172.26.100.161:2580 \

--listen-client-urls http://172.26.100.161:2579,http://127.0.0.1:2579 \

--advertise-client-urls http://172.26.100.161:2579 \

--initial-cluster-token "etcd-cluster" \

--initial-cluster etcd1=http://172.26.100.161:2380,etcd2=http://172.26.100.161:2480,etcd3=http://172.26.100.161:2580 \

--initial-cluster-state new




3대를 모두 실행할 때까지 클러스터링이 안되서 warning이 발생할 수 있다. 



etcd 디렉토리에 디폴트로 etcd3.etcd 데이터 디렉토리가 생성된다.


사용자 지정을 하고 싶다면 --data-dir /opt/etcd/data 와 같이 진행한다.





다른 터미널을 열어, 4번 디렉토리로 이동

./etcd --name etcd4 \

--initial-advertise-peer-urls http://172.26.100.161:2680 \

--listen-peer-urls http://172.26.100.161:2680 \

--listen-client-urls http://172.26.100.161:2679,http://127.0.0.1:2679 \

--advertise-client-urls http://172.26.100.161:2679 \

--initial-cluster-token "etcd-cluster" \

--initial-cluster etcd1=http://172.26.100.161:2380,etcd2=http://172.26.100.161:2480,etcd3=http://172.26.100.161:2580,etcd4=http://172.26.100.161:2680 \

--initial-cluster-state new




* 주의 할 점.



etcd1,etcd2,etcd3에 없는 etcd4를 실행하면..

4번에서는 에러가 많이 발생한다. 

2018-09-05 02:13:01.674392 E | rafthttp: request sent was ignored (cluster ID mismatch: peer[6564723d6ed1fc93]=c00bfb0bce868ccb, local=fbee3df97f467d62)

2018-09-05 02:13:01.674400 E | rafthttp: request sent was ignored (cluster ID mismatch: peer[edbc16344886488f]=c00bfb0bce868ccb, local=fbee3df97f467d62)


1,2,3번 에서는 

2018-09-05 02:13:19.659255 E | rafthttp: request cluster ID mismatch (got fbee3df97f467d62 want c00bfb0bce868ccb)

2018-09-05 02:13:19.659316 E | rafthttp: request cluster ID mismatch (got fbee3df97f467d62 want c00bfb0bce868ccb)


따라서 1,2,3번에서 --initial-cluster에 etcd4를 추가하고 --initial-cluster-state new 대신 --initial-cluster-state existing를 실행하면 좋을 것 같지만.. 동작이 안된다. 


etcdctl member add etcd4 http://172.26.100.161:2680





* 클러스터링 멤버 구성



 ./etcdctl member list

6564723d6ed1fc93, started, etcd2, http://172.26.100.161:2480, http://172.26.100.161:2479

edbc16344886488f, started, etcd3, http://172.26.100.161:2580, http://172.26.100.161:2579

fc0c8fe65a431b34, started, etcd1, http://172.26.100.161:2380, http://172.26.100.161:2379



여기서 하나를 뺀다.

./etcdctl member remove 6564723d6ed1fc93

Member 6564723d6ed1fc93 removed from cluster c00bfb0bce868ccb


 ./etcdctl member list

edbc16344886488f, started, etcd3, http://172.26.100.161:2580, http://172.26.100.161:2579

fc0c8fe65a431b34, started, etcd1, http://172.26.100.161:2380, http://172.26.100.161:2379


이때 etcd2는 종료된다.

다시 etcd2를 실행하면, 마지막에 아래 로그가 나오고 종료된다.


2018-09-05 05:16:18.342165 I | rafthttp: stopped peer 2fa514e820fdcf1e



아래와 같이 등록해도.  한번 빠지면 끝이다..

./etcdctl member add etcd4  --peer-urls=http://172.26.100.161:2479





클러스터 멤버 추가는 2점대와 동일하다.


Posted by '김용환'
,