sh Etcd安装脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Etcd安装脚本相关的知识,希望对你有一定的参考价值。
# update host IPs before running this on all 3 nodes
host0=192.168.56.70
host1=192.168.56.71
host2=192.168.56.72
#run this on host0
echo ':: Installing Etcd k/v database ...'
curl -fsSL https://github.com/coreos/etcd/releases/download/v3.2.6/etcd-v3.2.6-linux-amd64.tar.gz | \
tar -xvz --strip=1 -f - -C /usr/local/bin etcd-v3.2.6-linux-amd64/etcdctl etcd-v3.2.6-linux-amd64/etcd
useradd -d /var/lib/etcd -s /bin/false -m etcd
cat > /lib/systemd/system/etcd.service << _eof
[Unit]
Description=etcd key-value store
After=network.target
[Service]
User=etcd
Type=notify
PermissionsStartOnly=true
Environment=ETCD_NAME=%H
EnvironmentFile=-/etc/default/%p
ExecStart=/usr/local/bin/etcd --name infra0 --initial-advertise-peer-urls http://$host0:2380 \
--listen-peer-urls http://$host0:2380 \
--listen-client-urls http://$host0:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://$host0:2379 --data-dir /var/lib/etcd/default \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster infra0=http://$host0:2380,infra1=http://$host1:2380,infra2=http://$host2:2380 \
--initial-cluster-state new
Restart=on-abnormal
RestartSec=10s
LimitNOFILE=40000
[Install]
WantedBy=multi-user.target
_eof
systemctl enable etcd
systemctl restart etcd
# run this on host1
echo ':: Installing Etcd k/v database ...'
curl -fsSL https://github.com/coreos/etcd/releases/download/v3.2.6/etcd-v3.2.6-linux-amd64.tar.gz | \
tar -xvz --strip=1 -f - -C /usr/local/bin etcd-v3.2.6-linux-amd64/etcdctl etcd-v3.2.6-linux-amd64/etcd
useradd -d /var/lib/etcd -s /bin/false -m etcd
cat > /lib/systemd/system/etcd.service << _eof
[Unit]
Description=etcd key-value store
After=network.target
[Service]
User=etcd
Type=notify
PermissionsStartOnly=true
Environment=ETCD_NAME=%H
EnvironmentFile=-/etc/default/%p
ExecStart=/usr/local/bin/etcd --name infra1 --initial-advertise-peer-urls http://$host1:2380 \
--listen-peer-urls http://$host1:2380 \
--listen-client-urls http://$host1:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://$host1:2379 --data-dir /var/lib/etcd/default \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster infra0=http://$host0:2380,infra1=http://$host1:2380,infra2=http://$host2:2380 \
--initial-cluster-state new
Restart=on-abnormal
RestartSec=10s
LimitNOFILE=40000
[Install]
WantedBy=multi-user.target
_eof
systemctl enable etcd
systemctl restart etcd
#run this on host2
echo ':: Installing Etcd k/v database ...'
curl -fsSL https://github.com/coreos/etcd/releases/download/v3.2.6/etcd-v3.2.6-linux-amd64.tar.gz | \
tar -xvz --strip=1 -f - -C /usr/local/bin etcd-v3.2.6-linux-amd64/etcdctl etcd-v3.2.6-linux-amd64/etcd
useradd -d /var/lib/etcd -s /bin/false -m etcd
cat > /lib/systemd/system/etcd.service << _eof
[Unit]
Description=etcd key-value store
After=network.target
[Service]
User=etcd
Type=notify
PermissionsStartOnly=true
Environment=ETCD_NAME=%H
EnvironmentFile=-/etc/default/%p
ExecStart=/usr/local/bin/etcd --name infra2 --initial-advertise-peer-urls http://$host2:2380 \
--listen-peer-urls http://$host2:2380 \
--listen-client-urls http://$host2:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://$host2:2379 --data-dir /var/lib/etcd/default \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster infra0=http://$host0:2380,infra1=http://$host1:2380,infra2=http://$host2:2380 \
--initial-cluster-state new
Restart=on-abnormal
RestartSec=10s
LimitNOFILE=40000
[Install]
WantedBy=multi-user.target
_eof
systemctl enable etcd
systemctl restart etcd
# once the cluster is up and running then edit the etcd.service files to remove the --initial-cluster args.
# then do this
systemctl daemon-reload
systemctl restart etcd.service
# verify that the cluster is running
# from one of the hosts verify that you can insert foo=bar
etcdctl set foo bar
# from another host verify that you can retrieve foo and get bar
etcdctl get foo
以上是关于sh Etcd安装脚本的主要内容,如果未能解决你的问题,请参考以下文章
K8S------Kubernetes二进制搭建中的脚本文件集合
K8S------Kubernetes二进制搭建中的脚本文件集合
Kubernetes 集群 之 二进制安装部署(单Master节点)