etcd使用教程.md

下載

service

直接下載二進制文件,解壓執行
https://github.com/etcd-io/etcd/releases/download/v3.3.13/etcd-v3.3.13-linux-amd64.tar.gz

客戶端

客戶端工具列表
https://coreos.com/etcd/docs/latest/integrations.html

python

測試

  • A機器 (192.168.31.247)
./etcd  --name infra0 --initial-advertise-peer-urls http://192.168.31.247:2380 \
  --listen-peer-urls http://192.168.31.247:2380 \
  --listen-client-urls http://192.168.31.247:2379,http://127.0.0.1:2379 \
  --advertise-client-urls http://192.168.31.247:2379 \
  --initial-cluster-token etcd-cluster-1 \
  --initial-cluster infra0=http://192.168.31.247:2380,infra1=http://192.168.31.150:2380 \
  --initial-cluster-state new

  • B機器(192.168.31.150)
/home/kgbot/kgbot_st/etcd/etcd  --name infra1 --initial-advertise-peer-urls http://192.168.31.150:2380 \
  --listen-peer-urls http://192.168.31.150:2380 \
  --listen-client-urls http://192.168.31.150:2379,http://127.0.0.1:2379 \
  --advertise-client-urls http://192.168.31.150:2379 \
  --initial-cluster-token etcd-cluster-1 \
  --initial-cluster infra0=http://192.168.31.247:2380,infra1=http://192.168.31.150:2380 \
  --initial-cluster-state new
  • 檢測
./etcdctl member list
./etcdctl cluster-health

Python腳本測試(使用api v2版本)

  • 在A機器上
import etcd

client = etcd.Client(port=2379)
client.write('/a/b', '12|1|1.6')
  • 在B機器上
import etcd

client = etcd.Client(port=2379)
result = client.read('/a/b')
print(result.value)

配置

在ubuntu16.04下配置

創建配置文件/usr/lib/systemd/system/etcd.service,內容如下

[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
WorkingDirectory=/home/kg/kg_db/etcd
#EnvironmentFile=-/home/kg/kg_st/etcd/etcd.conf
User=kg
# set GOMAXPROCS to number of processors
ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /home/kg/kg_st/etcd/etcd --config-file=/home/kg/kg_st/etcd/etcd.conf"
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target

其中/home/kg/kg_st/etcd/etcd.conf參考https://github.com/etcd-io/etcd/blob/master/etcd.conf.yml.sample, 主要修改如下參數

name: 'kg150'
listen-peer-urls: http://192.168.31.150:2380,http://127.0.0.1:2380
listen-client-urls: http://192.168.31.150:2379,http://127.0.0.1:2379
initial-advertise-peer-urls: http://192.168.31.150:2380
advertise-client-urls: http://192.168.31.150:2379
initial-cluster: kg247=http://192.168.31.247:2380,kg150=http://192.168.31.150:2380
initial-cluster-token: 'etcd-cluster'
initial-cluster-state: 'new'

啓動方式

/home/kg/kg_st/etcd/etcd --config-file=/home/kg/kg_st/etcd/etcd.conf

sudo systemctl daemon-reload
sudo systemctl start etcd
sudo systemctl stop etcd
sudo systemctl enable etcd
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章