- Etcd 클러스터모드에 대한 설치방법입니다.
- 버전
- Etcd : 2.2.1 (2015.10.26기준 latest) https://github.com/coreos/etcd/releases
- OS : Ubuntu 14.04 trusty x86_64 on VirtualBox * 3 nodes
- sunny13~15 (192.168.56.203~204)
- 제약
- 각 노드들은 시간동기화가 되어있어야 함 (e.g., ntpd)
#----------------------------------------------------------
# Etcd 다운로드
#----------------------------------------------------------
sunny@sunny13:~$ mkdir -p /tmp/download/etcd
sunny@sunny13:~$ cd /tmp/download/etcd
sunny@sunny13:~$ wget https://github.com/coreos/etcd/releases/download/v2.2.1/etcd-v2.2.1-linux-amd64.tar.gz
sunny@sunny13:~$ tar xvfz etcd-v2.2.1-linux-amd64.tar.gz
#----------------------------------------------------------
# 바이너리이동 /opt/bin
#----------------------------------------------------------
sunny@sunny13:~$ sudo mkdir /opt/bin # Optional
sunny@sunny13:~$ sudo cp etcd-v2.2.1-linux-amd64/etcd* /opt/bin/
#----------------------------------------------------------
# Etcd 데이터파일 경로 생성 /data/etcd
#----------------------------------------------------------
sunny@sunny13:~$ sudo mkdir /data/etcd
#----------------------------------------------------------
# /etc/init/etcd.conf 생성
#----------------------------------------------------------
sunny@sunny13:~$ sudo vi /etc/init/etcd.conf
description "Etcd service"
start on (net-device-up
and local-filesystems
and runlevel [2345])
respawn
pre-start script
ETCD=/opt/bin/$UPSTART_JOB
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi
if [ -f $ETCD ]; then
exit 0
fi
echo "$ETCD binary not found, exiting"
exit 22
end script
script
# modify these in /etc/default/$UPSTART_JOB (/etc/default/docker)
ETCD=/opt/bin/$UPSTART_JOB
ETCD_OPTS=""
if [ -f /etc/default/$UPSTART_JOB ]; then
./etc/default/$UPSTART_JOB
fi
exec "$ETCD" $ETCD_OPTS
end script
#----------------------------------------------------------
# /etc/init.d/etcd 생성
#----------------------------------------------------------
sunny@sunny13:~$ sudo vi /etc/init.d/etcd
#!/bin/sh
set -e
### BEGIN INIT INFO
# Provides: etcd
# Required-Start: $docker
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: Start distrubted key/value pair service
# Description:
### END INIT INFO
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/opt/bin:
BASE=$(basename $0)
# modify these in /etc/default/$BASE (/etc/default/etcd)
ETCD=/opt/bin/$BASE
# This is the pid file managed by etcd itself
ETCD_PIDFILE=/var/run/$BASE.pid
ETCD_LOGFILE=/var/log/$BASE.log
ETCD_OPTS=""
ETCD_DESC="Etcd"
# Get lsb functions
. /lib/lsb/init-functions
if [ -f /etc/default/$BASE ]; then
. /etc/default/$BASE
fi
# see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it)
if false && [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; then
log_failure_msg "$ETCD_DESC is managed via upstart, try using service $BASE $1"
exit 1
fi
# Check etcd is present
if [ ! -x $ETCD ]; then
log_failure_msg "$ETCD not present or not executable"
exit 1
fi
fail_unless_root() {
if [ "$(id -u)" != '0' ]; then
log_failure_msg "$ETCD_DESC must be run as root"
exit 1
fi
}
ETCD_START="start-stop-daemon \
--start \
--background \
--quiet \
--exec $ETCD \
--make-pidfile \
--pidfile $ETCD_PIDFILE \
-- $ETCD_OPTS \
>> $ETCD_LOGFILE 2>&1"
ETCD_STOP="start-stop-daemon \
--stop \
--pidfile $ETCD_PIDFILE"
case "$1" in
start)
fail_unless_root
log_begin_msg "Starting $ETCD_DESC: $BASE"
$ETCD_START
log_end_msg $?
;;
stop)
fail_unless_root
log_begin_msg "Stopping $ETCD_DESC: $BASE"
$ETCD_STOP
log_end_msg $?
;;
restart | force-reload)
fail_unless_root
log_begin_msg "Restarting $ETCD_DESC: $BASE"
$ETCD_STOP
$ETCD_START
log_end_msg $?
;;
status)
status_of_proc -p "$ETCD_PIDFILE" "$ETCD" "$ETCD_DESC"
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
sunny@sunny13:~$ sudo chmod +x /etc/init.d/etcd
#----------------------------------------------------------
# /etc/default/etcd 생성 (etcd 데몬이 실행될때 읽어들이는 옵션)
# single 과 cluster 둘중 하나를 선택
#----------------------------------------------------------
sunny@sunny13:~$ sudo vi /etc/default/etcd
# single
ETCD_OPTS="-name etcd-cluster-0
-listen-client-urls http://0.0.0.0:4001
-advertise-client-urls http://127.0.0.1:4001
-data-dir /data/etcd"
# cluster
ETCD_OPTS="-name cluster-0
-data-dir /data/etcd
-listen-peer-urls http://0.0.0.0:2380
-initial-advertise-peer-urls http://$(ip a s | grep 'eth1' | grep 'inet' | cut -d '/' -f 1 | awk '{ print $2 }'):2380
-listen-client-urls http://0.0.0.0:4001
-advertise-client-urls http://0.0.0.0:4001
-initial-cluster
cluster-0=http://192.168.56.203:2380,cluster-1=http://192.168.56.204:2380,cluster-2=http://192.168.56.205:2380
-initial-cluster-state new
-initial-cluster-token etcd-cluster"
#----------------------------------------------------------
# 나머지 두 노드에 배포
#----------------------------------------------------------
# sunny14
sunny@sunny13:~$ scp /opt/bin/etcd sunny14:/tmp/etcd
sunny@sunny13:~$ scp /opt/bin/etcdctl sunny14:/tmp/etcdctl
sunny@sunny13:~$ scp /etc/default/etcd sunny14:/tmp/etcd_default
sunny@sunny13:~$ scp /etc/init/etcd.conf sunny14:/tmp/etcd.conf
sunny@sunny13:~$ scp /etc/init.d/etcd sunny14:/tmp/etc_init
sunny@sunny13:~$ ssh sunny14 'sudo mkdir /opt/bin; sudo mkdir /data/etcd'
sunny@sunny13:~$ ssh sunny14 'sudo mv /tmp/etcd /opt/bin/etcd'
sunny@sunny13:~$ ssh sunny14 'sudo mv /tmp/etcdctl /opt/bin/etcdctl'
sunny@sunny13:~$ ssh sunny14 'sudo mv /tmp/etcd_default /etc/default/etcd'
sunny@sunny13:~$ ssh sunny14 'sudo mv /tmp/etcd.conf /etc/init/etcd.conf'
sunny@sunny13:~$ ssh sunny14 'sudo mv /tmp/etc_init /etc/init.d/etcd'
sunny@sunny13:~$ ssh sunny14 "sudo sed -i 's/-name cluster-0/-name cluster-1/g' /etc/default/etcd"
# sunny15
sunny@sunny13:~$ scp /opt/bin/etcd sunny15:/tmp/etcd
sunny@sunny13:~$ scp /opt/bin/etcdctl sunny15:/tmp/etcdctl
sunny@sunny13:~$ scp /etc/default/etcd sunny15:/tmp/etcd_default
sunny@sunny13:~$ scp /etc/init/etcd.conf sunny15:/tmp/etcd.conf
sunny@sunny13:~$ scp /etc/init.d/etcd sunny15:/tmp/etc_init
sunny@sunny13:~$ ssh sunny15 'sudo mkdir /opt/bin; sudo mkdir /data/etcd'
sunny@sunny13:~$ ssh sunny15 'sudo mv /tmp/etcd /opt/bin/etcd'
sunny@sunny13:~$ ssh sunny15 'sudo mv /tmp/etcdctl /opt/bin/etcdctl'
sunny@sunny13:~$ ssh sunny15 'sudo mv /tmp/etcd_default /etc/default/etcd'
sunny@sunny13:~$ ssh sunny15 'sudo mv /tmp/etcd.conf /etc/init/etcd.conf'
sunny@sunny13:~$ ssh sunny15 'sudo mv /tmp/etc_init /etc/init.d/etcd'
sunny@sunny13:~$ ssh sunny15 "sudo sed -i 's/-name cluster-0/-name cluster-2/g' /etc/default/etcd"
#----------------------------------------------------------
# Etcd Cluster 시작
#----------------------------------------------------------
sunny@sunny13:~$ sudo service etcd start
sunny@sunny13:~$ ssh sunny14 'sudo service etcd start'
sunny@sunny13:~$ ssh sunny15 'sudo service etcd start'
#----------------------------------------------------------
# Cli 쉽게 사용하기 위해 PATH 추가
#----------------------------------------------------------
sunny@sunny13:~$ sudo /etc/profile
export PATH=$PATH:/opt/bin
sunny@sunny13:~$ source /etc/profile
#----------------------------------------------------------
# 상태 확인
#----------------------------------------------------------
sunny@sunny13:~$ etcdctl cluster-health
member 1bf71b8455ab493f is healthy: got healthy result from http://0.0.0.0:4001
member 1d326fcb4619fa15 is healthy: got healthy result from http://0.0.0.0:4001
member 8525390e06435a2f is healthy: got healthy result from http://0.0.0.0:4001
cluster is healthy
# 외부 접속시 주소를 함께 적어서 사용 가능
sunny@sunny10~$ etcdctl -C http://192.168.56.203:4001,http://192.168.56.204:4001,http://192.168.56.205:4001 ls /
/registry
/coreos.com
#----------------------------------------------------------
# 작업파일 삭제
#----------------------------------------------------------
sunny@sunny13:~$ rm -rf /tmp/download/etcd # Optional
#----------------------------------------------------------
# kubernetes 설치와 관련해서 아래 key/value가 들어 있어야 함.
# 참고 - /kubernetes/cluster/ubuntu/reconfDocker.sh
#----------------------------------------------------------
sunny@sunny13:~$ export FLANNEL_NET=172.16.0.0/16
sunny@sunny13:~$ etcdctl mk /coreos.com/network/config "{\"Network\":\"${FLANNEL_NET}\"}"
sunny@sunny13:~$ etcdctl get /coreos.com/network/config
설치경로
- 바이너리 : /opt/bin/etcd
- 설정파일 : /etc/default/etcd
- 데몬로그 : /var/log/upstart/etcd.log
- 시작종료 : sudo service etcd start|stop|status|restart
- 시작파일 : /etc/init/etcd.conf /etc/init.d/etcd
'IT > Kubernetes' 카테고리의 다른 글
3-1. Kubernetes 설치 (0) | 2019.01.23 |
---|---|
1. Kubernetes/Container 개요 (0) | 2018.08.05 |
댓글