k8s记录-etcd集群部署(三)

https://blog.csdn.net/fy_long/article/details/86542872

1)程序准备
tar xvf etcd-v3.3.11-linux-amd64.tar.gz
mkdir -p etcd/{bin,cfg,ssl}
mv etcd-v3.3.11-linux-amd64/{etcd,etcdctl} etcd/bin
2)拷贝CA证书
cp ca*pem server*pem etcd/ssl
scp ca*pem server*pem app@192.168.0.2:etcd/ssl
scp ca*pem server*pem app@192.168.0.3:etcd/ssl
以下步骤每一台机器部署注意名称、IP、路径等修改(脚本文件、配置文件)
3)修改配置
etcd

#!/bin/bash
ETCD_HOME=etcd
ETCD01_IP=192.168.0.1
ETCD02_IP=192.168.0.2
ETCD03_IP=192.168.0.3
#[Member]
ETCD_NAME="etcd01"
ETCD_DATA_DIR= $ETCD_HOME/data
ETCD_LISTEN_PEER_URLS=https://$ETCD01_IP:2380
ETCD_LISTEN_CLIENT_URLS=https://ETCD01:2379
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS=https://$ETCD01_IP:2380
ETCD_ADVERTISE_CLIENT_URLS=https://$ETCD01_IP:2379
ETCD_INITIAL_CLUSTER=etcd01=https:// $ETCD01_IP:2380,etcd02=https:// $ETCD02_IP:2380,etcd03=https:// $ETCD03_IP:2380
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

4)开启与停止服务
a.开启服务

#!/bin/bash
ETCD_HOME=etcd

source $ETCD_HOME/cfg/etcd
nohup $ETCD_HOME/bin/etcd \
--name=${ETCD_NAME} \
--data-dir=${ETCD_DATA_DIR} \
--listen-peer-urls=${ETCD_LISTEN_PEER_URLS} \
--listen-client-urls=${ETCD_LISTEN_CLIENT_URLS},https://127.0.0.1:2379 \
--advertise-client-urls=${ETCD_ADVERTISE_CLIENT_URLS} \
--initial-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS} \
--initial-cluster=${ETCD_INITIAL_CLUSTER} \
--initial-cluster-token=${ETCD_INITIAL_CLUSTER_TOKEN} \
--initial-cluster-state=new \
--cert-file=$ETCD_HOME/ssl/server.pem \
--key-file=$ETCD_HOME/ssl/server-key.pem \
--peer-cert-file=$ETCD_HOME/ssl/server.pem \
--peer-key-file=$ETCD_HOME/ssl/server-key.pem \
--trusted-ca-file=$ETCD_HOME/ssl/ca.pem \
--peer-trusted-ca-file=$ETCD_HOME/ssl/ca.pem &

b.停止服务

#!/bin/bash
kill -9 `ps -ef | grep name=etcd | grep -v grep | awk '{print $2}'`

5)查看ETCD集群状态
Master节点操作

#!/bin/bash
ETCD_HOME=etcd
ETCD01_IP=192.166.0.1
ETCD02_IP=192.168.0.2
ETCD03_IP=192.168.0.3

$ETCD_HOME/bin/etcdctl \
--ca-file=$ETCD_HOME/ssl/ca.pem \
--cert-file=$ETCD_HOME/ssl/server.pem \
--key-file=$ETCD_HOME/ssl/server-key.pem \
--endpoints=https://$ETCD01_IP:2379, https://$ETCD02_IP:2379,https://$ETCD03_IP:2379  cluster-health

6)ETCD写入网络信息
Master节点操作

#!/bin/bash
ETCD_HOME=etcd
ETCD01_IP=192.168.0.1
ETCD02_IP=192.168.0.2
ETCD03_IP=192.168.0.3

$ETCD_HOME/bin/etcdctl \
--ca-file=$ETCD_HOME/ssl/ca.pem \
--cert-file=$ETCD_HOME/ssl/server.pem \
--key-file=$ETCD_HOME/ssl/server-key.pem \
--endpoints="https://$ETCD01_IP:2379,\
https://$ETCD02_IP:2379,https://$ETCD03_IP:2379" \
set /coreos.com/network/config  '{ "Network": "10.1.0.0/16", "Backend": {"Type": "vxlan"}}'

注意IP地址、Network(集群网络可自行设置)地址修改

posted @ 2019-09-29 16:59  信方  阅读(288)  评论(0编辑  收藏  举报