部署单节点etcd

发布时间 2023-11-16 17:10:41作者: NAVYSUMMER

1.下载并安装etcd

ETCD_VERSION='3.4.13'
wget https://github.com/etcd-io/etcd/releases/download/v${ETCD_VERSION}/etcd-v${ETCD_VERSION}-linux-amd64.tar.gz
tar -xvf etcd-v${ETCD_VERSION}-linux-amd64.tar.gz 
mv etcd-v${ETCD_VERSION}-linux-amd64 /opt/etcd
cp -a /opt/etcd/etcd /opt/etcd/etcdctl /usr/bin/

2.创建需要用到的目录

mkdir -p /opt/etcd/data          
mkdir -p /var/lib/etcd/
mkdir -p /etc/etcd/config/

3.编写配置文件

cat  > /etc/etcd/config/etcd.conf <<EOF
name: etcd
data-dir: /opt/etcd/data
listen-peer-urls: http://127.0.0.1:6677
listen-client-urls: http://0.0.0.0:7777
advertise-client-urls: http://127.0.0.1:7777
initial-advertise-peer-urls: http://10.1.1.7:2380
initial-cluster: etcd-1=http://127.0.0.1:2380
initial-cluster-token: etcd-cluster
initial-cluster-state: new
enable-grpc-gateway: true
EOF

4.编写服务文件

cat  > /etc/systemd/system/etcd.service <<EOF
[Unit]
Description=Etcd Server
Documentation=https://github.com/coreos/etcd
After=network.target

[Service]
User=root
Type=notify
ExecStart=/opt/etcd/etcd  --config-file  /etc/etcd/config/etcd.conf 
Restart=on-failure
RestartSec=10s
LimitNOFILE=40000

[Install]
WantedBy=multi-user.target
EOF

5.配置开机自启并启动

systemctl daemon-reload
systemctl enable etcd
systemctl restart etcd