Etcd集群环境搭建
程序员文章站
2022-07-13 22:19:28
...
参考自
https://github.com/etcd-io/etcd/releases/
https://etcd.io/docs/v3.3.12/op-guide/clustering/
https://www.cnblogs.com/li-peng/p/9259793.html
单个Etcd
- 版本:v3.3.15
1、部署安装
ETCD_VER=v3.3.15
# 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
# copy execute file to /usr/local/bin
cd /tmp/etcd-download-test
sudo cp etcd* /usr/local/bin/
2、启动检查
# version check
etcd --version
ETCDCTL_API=3 etcdctl version
# start a local etcd server
etcd
# write,read to etcd
ETCDCTL_API=3 etcdctl --endpoints=localhost:2379 put foo bar
ETCDCTL_API=3 etcdctl --endpoints=localhost:2379 get foo
Etcd集群搭建
- 三个Etcd实例组成的集群,每个实例部署在一台机器上
- name选择每台机器的hostname值
1、创建etcd数据存储目录
mkdir -p /home/admin/etcd
2、10.0.0.1上创建/etc/systemd/system/etcd0.service
[Unit]
Description=etcd
Documentation=https://github.com/coreos/etcd
Conflicts=etcd.service
Conflicts=etcd2.service
[Service]
Type=notify
Restart=always
RestartSec=5s
LimitNOFILE=40000
TimeoutStartSec=0
ExecStart=/usr/local/bin/etcd --name hostname1
--data-dir /home/admin/etcd
--initial-advertise-peer-urls http://10.0.0.1:2380
--listen-peer-urls http://10.0.0.1:2380
--listen-client-urls http://10.0.0.1:2379,http://127.0.0.1:2379
--advertise-client-urls http://10.0.0.1:2379
--initial-cluster-token etcd-cluster-1
--initial-cluster hostname1=http://10.0.0.1:2380,hostname2=http://10.0.0.2:2380,hostname3=http://10.0.0.3:2380
--initial-cluster-state new
[Install]
WantedBy=multi-user.target
3、10.0.0.2上创建/etc/systemd/system/etcd1.service
[Unit]
Description=etcd
Documentation=https://github.com/coreos/etcd
Conflicts=etcd.service
Conflicts=etcd2.service
[Service]
Type=notify
Restart=always
RestartSec=5s
LimitNOFILE=40000
TimeoutStartSec=0
ExecStart=/usr/local/bin/etcd --name hostname2
--data-dir /home/admin/etcd
--initial-advertise-peer-urls http://10.0.0.2:2380
--listen-peer-urls http://10.0.0.2:2380
--listen-client-urls http://10.0.0.2:2379,http://127.0.0.1:2379
--advertise-client-urls http://10.0.0.2:2379
--initial-cluster-token etcd-cluster-1
--initial-cluster hostname1=http://10.0.0.1:2380,hostname2=http://10.0.0.2:2380,hostname3=http://10.0.0.3:2380
--initial-cluster-state new
[Install]
WantedBy=multi-user.target
4、10.0.0.3上创建/etc/systemd/system/etcd2.service
[Unit]
Description=etcd
Documentation=https://github.com/coreos/etcd
Conflicts=etcd.service
[Service]
Type=notify
Restart=always
RestartSec=5s
LimitNOFILE=40000
TimeoutStartSec=0
ExecStart=/usr/local/bin/etcd --name hostname3
--data-dir /home/admin/etcd
--initial-advertise-peer-urls http://10.0.0.3:2380
--listen-peer-urls http://10.0.0.3:2380
--listen-client-urls http://10.0.0.3:2379,http://127.0.0.1:2379
--advertise-client-urls http://10.0.0.3:2379
--initial-cluster-token etcd-cluster-1
--initial-cluster hostname1=http://10.0.0.1:2380,hostname2=http://10.0.0.2:2380,hostname3=http://10.0.0.3:2380
--initial-cluster-state new
[Install]
WantedBy=multi-user.target
5、启动服务
sudo systemctl daemon-reload
sudo systemctl enable etcd0.service
sudo systemctl start etcd0.service
sudo systemctl daemon-reload
sudo systemctl enable etcd1.service
sudo systemctl start etcd1.service
sudo systemctl daemon-reload
sudo systemctl enable etcd2.service
sudo systemctl start etcd2.service
6、集群测试
# check status
ETCDCTL_API=3 etcdctl --endpoints 10.0.0.1:2379,10.0.0.2:2379,10.0.0.3:2379 endpoint status --write-out="table"
# write on one machine
ETCDCTL_API=3 etcdctl put foo1 bar1
#read on another machine
ETCDCTL_API=3 etcdctl get foo1
推荐阅读
-
PHP+Oracle本地开发环境搭建方法详解
-
VS2015 搭建Asp.net core开发环境的方法
-
.net core i上 K8S(一)集群搭建
-
一张图讲解最少机器搭建FastDFS高可用分布式集群安装说明
-
2021年 Win10 20H2 安装JDK 环境搭建
-
ubuntu下搭建php开发环境(nginx+(cgi)php5fpm+memcached+xdebug)
-
如何搭建PhpStorm 10.0.2开发环境?PhpStorm 10.0.2环境搭建安装图文教程
-
Android SDK + Appium 环境搭建
-
CentOS7 LNMP+phpmyadmin环境搭建 第三篇phpmyadmin安装
-
CentOS7 LNMP+phpmyadmin环境搭建 第一篇虚拟机及centos7安装