Etcd单机部署

A distributed, reliable key-value store for the most critical data of a distributed system

bash

ETCD_VER=v3.5.0

# choose either URL
GOOGLE_URL=https://storage.googleapis.com/etcd
GITHUB_URL=https://github.com/etcd-io/etcd/releases/download
DOWNLOAD_URL=${GOOGLE_URL}

rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
rm -rf /tmp/etcd-download-test && mkdir -p /tmp/etcd-download-test

curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/etcd-download-test --strip-components=1
rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz

/tmp/etcd-download-test/etcd --version
/tmp/etcd-download-test/etcdctl version
/tmp/etcd-download-test/etcdutl version

# Move them to the bin folder
mv /tmp/etcd-download-test/etcd /usr/local/bin
mv /tmp/etcd-download-test/etcdctl /usr/local/bin
mv /tmp/etcd-download-test/etcdutl /usr/local/bin

bash

etcd \
--name 'default' \
--data-dir '/data/etcd/' \
--listen-client-urls 'http://0.0.0.0:2379' \
--advertise-client-urls 'http://0.0.0.0:2379' \
--listen-peer-urls http://0.0.0.0:2380 \
--initial-advertise-peer-urls http://0.0.0.0:2380 \
--initial-cluster default=http://0.0.0.0:2380 \
--enable-v2=true

/etc/etcd目录中创建一个名为etcd.conf

bash

mkdir /etc/etcd
cat > /etc/etcd/etcd.conf <<EOF
# [Member Flags]
ETCD_NAME=default
ETCD_DATA_DIR=“/data/etcd/”
ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
#ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380
# [Cluster Flags]
ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379
#ETCD_INITIAL_ADVERTISE_PEER_URLS=http://0.0.0.0:2380
#ETCD_INITIAL_CLUSTER="default=http://0.0.0.0:2380"
ETCD_ENABLE_V2="true"
EOF

/lib/system/systemd处创建文件etcd.service,内容如下:

bash

cat > /lib/systemd/system/etcd.service <<EOF
[Unit]
Description=etcd key-value store
Documentation=https://github.com/etcd-io/etcd
After=network.target
 
[Service]
Type=notify
EnvironmentFile=/etc/etcd/etcd.conf
ExecStart=/usr/local/bin/etcd
Restart=always
RestartSec=10s
LimitNOFILE=40000
 
[Install]
WantedBy=multi-user.target
EOF

bash

systemctl enable etcd
systemctl start etcd

bash

docker run -d \
  -p 2379:2379 \
  -p 2380:2380 \
  -v /data/etcd:/etcd-data/member \
  --name etcd \
  quay.io/coreos/etcd:v3.5.0 \
  /usr/local/bin/etcd \
  --name default \
  --data-dir /etcd-data \
  --listen-client-urls http://0.0.0.0:2379 \
  --advertise-client-urls http://0.0.0.0:2379 \
  --listen-peer-urls http://0.0.0.0:2380 \
  --initial-advertise-peer-urls http://0.0.0.0:2380 \
  --initial-cluster default=http://0.0.0.0:2380 \
  --initial-cluster-token tkn \
  --initial-cluster-state new \
  --log-level info \
  --logger zap \
  --log-outputs stderr

相关内容