首页 > 代码库 > etcd 集群部署
etcd 集群部署
关于etcd的介绍,我这里就不做介绍。百度一下即可,主要还是讲一下部署。
一、环境介绍
1.1 主机环境
IP地址 | 主机名 | 角色 | 备注 |
192.168.15.131 | k8s-master01 | k8s-master/etcd_cluster01 | |
192.168.15.132 | k8s-master02 | k8s-master/etcd_cluster01 | |
192.168.15.133 | k9s-master03 | k8s-master/etcd_cluster01 |
提示:这样命名主要是因为部署k8s集群,整个etcd也是给k8s提供使用;
1.2 系统环境
###更改主机名(略)
###更改hosts文件
127.0.0.1 k8s-master01
::1 k8s-master01
192.168.15.131 k8s-master01
192.168.15.132 k8s-master02
192.168.15.133 k8s-master03
###禁止selinux以及防火墙
setenfore 0
systemctl stop firewalld systemctl disable firewalld
###安装相关软件包
yum -y install ntppdate gcc git vim wget
###配置定时更新
*/5 * * * * /usr/sbin/ntpdate time.windows.com >/dev/null 2>&1
二、开始安装etcd集群
2.1 下载并解压相关软件包
wget https://github.com/coreos/etcd/releases/download/v3.1.6/etcd-v3.1.6-linux-amd64.tar.gz
tar -xvf etcd-v3.1.6-linux-amd64.tar.gz
cp mv etcd-v3.1.6-linux-amd64/etcd* /root/local/bin
2.2 编写相关脚本
#!/bin/bash
# Copyright 2014 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
## Create etcd.conf, etcd.service, and start etcd service.
ETCD_NAME=`hostname`
ETCD_DATA_DIR=/var/lib/etcd
ETCD_CONF_DIR=/etc/etcd
ETCD_CLUSTER=‘etcd1=http://192.168.15.131:2380,etcd2=http://192.168.15.132:2380,etcd3=http://192.168.15.133:2380‘
ETCD_LISTEN_IP=`ip addr show eno16777736 |grep -w ‘inet‘ |awk -F " " ‘{print $2}‘ |awk -F "/" ‘{print $1}‘`
mkdir -p $ETCD_DATA_DIR $ETCD_CONF_DIR
chown -R etcd.etcd $ETCD_DATA_DIR
cat <<EOF >/etc/etcd/etcd.conf
# [member]
ETCD_NAME="$ETCD_NAME"
ETCD_DATA_DIR="${ETCD_DATA_DIR}/default.etcd"
#ETCD_SNAPSHOT_COUNTER="10000"
#ETCD_HEARTBEAT_INTERVAL="100"
#ETCD_ELECTION_TIMEOUT="1000"
ETCD_LISTEN_PEER_URLS="http://$ETCD_LISTEN_IP:2380"
ETCD_LISTEN_CLIENT_URLS="http://$ETCD_LISTEN_IP:2379,http://127.0.0.1:2379"
#ETCD_MAX_SNAPSHOTS="5"
#ETCD_MAX_WALS="5"
#ETCD_CORS=""
#
#[cluster]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://$ETCD_LISTEN_IP:2380"
# if you use different ETCD_NAME (e.g. test),
# set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."
ETCD_INITIAL_CLUSTER="$ETCD_INITIAL_CLUSTER"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="k8s-etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://$ETCD_LISTEN_IP:2379"
#ETCD_DISCOVERY=""
#ETCD_DISCOVERY_SRV=""
#ETCD_DISCOVERY_FALLBACK="proxy"
#ETCD_DISCOVERY_PROXY=""
#
#[proxy]
#ETCD_PROXY="off"
#
#[security]
#ETCD_CA_FILE=""
#ETCD_CERT_FILE=""
#ETCD_KEY_FILE=""
#ETCD_PEER_CA_FILE=""
#ETCD_PEER_CERT_FILE=""
#ETCD_PEER_KEY_FILE=""
EOF
cat <<EOF >//usr/lib/systemd/system/etcd.service
[Unit]
Description=Etcd Server
After=network.target
[Service]
Type=simple
WorkingDirectory=${etcd_data_dir}
EnvironmentFile=-/etc/etcd/etcd.conf
User=etcd
# set GOMAXPROCS to number of processors
ExecStart=/usr/local/bin/etcd
Type=notify
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable etcd
systemctl restart etcd
2.3 相关集群检查
etcdctl cluster-health
提示:这里有点细节需要说明,etcd在3台集群的情况下,如果坏掉一台是能够提供读请求的,但是此时是不能写入数据的;
etcd 集群部署
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。