Etcd集群的安装配置

第一章:环境

服务器相关信息:
Etcd集群的安装配置_第1张图片

第二章:安装配置etcd

一、docker环境
这里我们直接使用centos7.2中的yum命令安装
命令:yum -y install docker

二、etcd集群
Etcd是Kubernetes集群中的一个十分重要的组件,用于保存集群所有的网络配置和对象的状态信息。在后面具体的安装环境中,我们安装的etcd的版本是v3.2.22,整个kubernetes系统中一共有两个服务需要用到etcd用来协同和存储配置,分别是:
网络插件flannel、对于其它网络插件也需要用到etcd存储网络的配置信息
kubernetes本身,包括各种对象的状态和元信息配置
注意:flannel操作etcd使用的是v2的API,而kubernetes操作etcd使用的v3的API,所以在下面我们执行etcdctl的时候需要设置ETCDCTL_API环境变量,该变量默认值为2。

1.关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
getenforce

2.Master节点和Node节点的配置脚本

配置etcd(master)的脚本。
注意:脚本中的文件路径以及IP地址需要根据自己的实际情况进行更改。
并且一定记住等所有的etcd集群配置完成后,一起启动etcd服务。

#!/bin/bash

#判断docker和etcd是否安装,并且把防火墙和selinux进行关闭操作
dockerFile=`rpm -qa docker`
etcdFile=`rpm -qa etcd`

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
getenforce

if [ "${dockerFile}" != "" ];then
    echo "Programe is exist"
else
    yum -y install docker
fi

if [ "${etcdFile}" != ""  ];then
    echo "Program is exist"
else
    yum -y install etcd
fi

#etcd集群的配置文件内容
#Master节点

echo '''ETCD_NAME="master"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://172.16.1.200:2380,http://127.0.0.1:2380"
ETCD_LISTEN_CLIENT_URLS="http://172.16.1.200:2379,http://127.0.0.1:2379"

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://172.16.1.200:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://172.16.1.200:2379"
ETCD_INITIAL_CLUSTER="master=http://172.16.1.200:2380,node1=http://172.16.1.201:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"
''' > /etc/etcd/etcd.conf

echo '''[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
User=etcd
ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd \
--name=\"${ETCD_NAME}\" \
--data-dir=\"${ETCD_DATA_DIR}\" \
--listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\" \
--listen-peer-urls=\"${ETCD_LISTEN_PEER_URLS}\" \
--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=\"${ETCD_INITIAL_CLUSTER_STATE}\""
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
''' > /usr/lib/systemd/system/etcd.service

systemctl daemon-reload
systemctl restart docker 
systemctl enable docker
systemctl enable etcd

配置etcd(node)的脚本。

#!/bin/bash
#判断docker和etcd是否安装,并且把防火墙和selinux进行关闭操作
dockerFile=`rpm -qa docker`
etcdFile=`rpm -qa etcd`

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
getenforce

if [ "${dockerFile}" != "" ];then
    echo "Programe is exist"
else
    yum -y install docker
fi

if [ "${etcdFile}" != ""  ];then
    echo "Program is exist"
else
    yum -y install etcd
fi

echo '''
ETCD_NAME="node1"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://172.16.1.201:2380"
ETCD_LISTEN_CLIENT_URLS="http://172.16.1.201:2379,http://127.0.0.1:2379"

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://172.16.1.201:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://172.16.1.201:2379"
ETCD_INITIAL_CLUSTER="master=http://172.16.1.200:2380,node1=http://172.16.1.201:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"
''' > /etc/etcd/etcd.conf

echo '''
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
User=etcd
ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd \
--name=\"${ETCD_NAME}\" \
--data-dir=\"${ETCD_DATA_DIR}\" \
--listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\" \
--listen-peer-urls=\"${ETCD_LISTEN_PEER_URLS}\" \
--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=\"${ETCD_INITIAL_CLUSTER_STATE}\""
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
''' > /usr/lib/systemd/system/etcd.service

systemctl daemon-reload
systemctl restart docker
systemctl enable docker
systemctl enable etcd 

你可能感兴趣的:(kubernetes相关)