etcd 集群部署
阿新 • • 發佈:2017-05-23
rect selinux $2 span amp amd -m ntpd working
關於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 集群部署