etcd安装及集群配置

来源:互联网 发布:数据分析 培训 上海 编辑:程序博客网 时间:2024/04/27 23:10
1、安装

解压安装包,拷贝etcd、etcdctl到/usr/bin下
#此时可以直接etcd启动,但是不建议这么做,因为没有利用配置文件制定参数,则default.etcd会出现在当前目录下,不好管理且不利于参数管理及集群管理。

#以下两个配置文件可以在别的虚拟机以yum install etcd安装之后在相同的位置得到。
将配置文件etcd.conf拷贝到/etc/etcd下
将配置文件etcd.service拷贝到/usr/lib/systemd/system下

启动:systemctl start etcd
状态:systemctl status etcd
停止:systemctl stop etcd

2、集群--这里只讨论static方式
static静态集群:在确切知道节点情况的时候可采取这种方式,又分为两种方式:
命令行方式,如下:
etcd --name infra0 --initial-advertise-peer-urls http://192.168.75.137:2380 \
  --listen-peer-urls http://192.168.75.137:2380 \
  --listen-client-urls http://192.168.75.137:2379,http://127.0.0.1:2379 \
  --advertise-client-urls http://192.168.75.137:2379 \
  --initial-cluster-token etcd-cluster-1 \
  --initial-cluster infra0=http://192.168.75.137:2380,infra1=http://192.168.75.138:2380,infra2=http://192.168.75.139:2380 \
  --initial-cluster-state new

================================

etcd --name infra1 --initial-advertise-peer-urls http://192.168.75.138:2380 \
  --listen-peer-urls http://192.168.75.138:2380 \
  --listen-client-urls http://192.168.75.138:2379,http://127.0.0.1:2379 \
  --advertise-client-urls http://192.168.75.138:2379 \
  --initial-cluster-token etcd-cluster-1 \
  --initial-cluster infra0=http://192.168.75.137:2380,infra1=http://192.168.75.138:2380,infra2=http://192.168.75.139:2380 \
  --initial-cluster-state new

================================

etcd --name infra2 --initial-advertise-peer-urls http://192.168.75.139:2380 \
  --listen-peer-urls http://192.168.75.139:2380 \
  --listen-client-urls http://192.168.75.139:2379,http://127.0.0.1:2379 \
  --advertise-client-urls http://192.168.75.139:2379 \
  --initial-cluster-token etcd-cluster-1 \
  --initial-cluster infra0=http://192.168.75.137:2380,infra1=http://192.168.75.138:2380,infra2=http://192.168.75.139:2380 \
  --initial-cluster-state new


配置文件方式,如下:
vim /opt/etcd/etcd-v3.1.6-linux-amd64/etcd.conf

ETCD_NAME=etcd00
ETCD_DATA_DIR="/opt/etcd/etcd-v3.1.6-linux-amd64/etcd00"
ETCD_LISTEN_PEER_URLS="http://192.168.75.137:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.75.137:2379,http://127.0.0.1:2379"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.75.137:2380"
ETCD_INITIAL_CLUSTER="etcd00=http://192.168.75.137:2380,etcd01=http://192.168.75.138:2380,etcd02=http://192.168.75.139:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-00"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.75.137:2379"

vim /usr/lib/systemd/system/etcd.service
[Unit]
Description=EtcdServer
After=network.target
After=network-online.target
Wants=network-online.target
 
[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
User=etcd
# setGOMAXPROCS to number of processors
ExecStart=/bin/bash-c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name=\"${ETCD_NAME}\"\
  --data-dir=\"${ETCD_DATA_DIR}\" \
  --initial-advertise-peer-urls=\"${ETCD_INITIAL_ADVERTISE_PEER_URLS}\" \
  --listen-peer-urls=\"${ETCD_LISTEN_PEER_URLS}\" \
  --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\"\
  --advertise-client-urls=\"${ETCD_ADVERTISE_CLIENT_URLS}\"\
  --initial-cluster-token=\"${ETCD_INITIAL_CLUSTER_TOKEN}\"\
  --initial-cluster=\"${ETCD_INITIAL_CLUSTER}\" \
  --initial-cluster-state=\"${ETCD_INITIAL_CLUSTER_STATE}\""

Restart=on-failure
LimitNOFILE=65536
 
[Install]
WantedBy=multi-user.target

================================================

ETCD_NAME=etcd01
ETCD_DATA_DIR="/var/lib/etcd/etcd00"
ETCD_LISTEN_PEER_URLS="http://192.168.75.138:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.75.138:2379,http://127.0.0.1:2379"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.75.138:2380"
ETCD_INITIAL_CLUSTER="etcd00=http://192.168.75.137:2380,etcd01=http://192.168.75.138:2380,etcd02=http://192.168.75.139:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-00"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.75.138:2379"

vim /usr/lib/systemd/system/etcd.service
[Unit]
Description=EtcdServer
After=network.target
After=network-online.target
Wants=network-online.target
 
[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
User=etcd
# setGOMAXPROCS to number of processors
ExecStart=/bin/bash-c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name=\"${ETCD_NAME}\"\
  --data-dir=\"${ETCD_DATA_DIR}\" \
  --initial-advertise-peer-urls=\"${ETCD_INITIAL_ADVERTISE_PEER_URLS}\" \
  --listen-peer-urls=\"${ETCD_LISTEN_PEER_URLS}\" \
  --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\"\
  --advertise-client-urls=\"${ETCD_ADVERTISE_CLIENT_URLS}\"\
  --initial-cluster-token=\"${ETCD_INITIAL_CLUSTER_TOKEN}\"\
  --initial-cluster=\"${ETCD_INITIAL_CLUSTER}\" \
  --initial-cluster-state=\"${ETCD_INITIAL_CLUSTER_STATE}\""
Restart=on-failure
LimitNOFILE=65536
 
[Install]
WantedBy=multi-user.target

============================================

ETCD_NAME=etcd02
ETCD_DATA_DIR="/var/lib/etcd/etcd00"
ETCD_LISTEN_PEER_URLS="http://192.168.75.139:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.75.139:2379,http://127.0.0.1:2379"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.75.139:2380"
ETCD_INITIAL_CLUSTER="etcd00=http://192.168.75.137:2380,etcd01=http://192.168.75.138:2380,etcd02=http://192.168.75.139:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-00"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.75.139:2379"

vim /usr/lib/systemd/system/etcd.service
[Unit]
Description=EtcdServer
After=network.target
After=network-online.target
Wants=network-online.target
 
[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
User=etcd
# setGOMAXPROCS to number of processors
ExecStart=/bin/bash-c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name=\"${ETCD_NAME}\"\
  --data-dir=\"${ETCD_DATA_DIR}\" \
  --initial-advertise-peer-urls=\"${ETCD_INITIAL_ADVERTISE_PEER_URLS}\" \
  --listen-peer-urls=\"${ETCD_LISTEN_PEER_URLS}\" \
  --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\"\
  --advertise-client-urls=\"${ETCD_ADVERTISE_CLIENT_URLS}\"\
  --initial-cluster-token=\"${ETCD_INITIAL_CLUSTER_TOKEN}\"\
  --initial-cluster=\"${ETCD_INITIAL_CLUSTER}\" \
  --initial-cluster-state=\"${ETCD_INITIAL_CLUSTER_STATE}\""
Restart=on-failure
LimitNOFILE=65536
 
[Install]
WantedBy=multi-user.target

以上是常规安装方式,我采取的是解压之后自己指定路径的方式,而并没有将etcd和etcdctl拷贝到bin目录下面,也没有采取默认的相关路径。这样有利于配置文件和数据文件的维护。



















0 0
原创粉丝点击