温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

配置Etcd集群和TLS认证

发布时间:2020-07-30 11:15:11 来源:网络 阅读:965 作者:jxzhfei 栏目:云计算

一、安装前准备

etcd软件版本:etcd-v3.3.10-linux-amd64.tar.gz

系统:centos7.3

防火墙关闭

systemctl stop firewalld

systemctl disable firewalld

 

selinux关闭

 

 

配置/etc/hosts(三台操作)

192.168.159.121 k8s-master-01

192.168.159.122 k8s-node01

192.168.159.123  k8s-node02

配置时间同步

yum -y install ntpdate

crontab e

#时间同步

*/5 * * * *  /usr/sbin/ntpdate 0.asia.pool.ntp.org

二、配置免密钥登录(三台操作)

三台先操作

ssh-keygen

三台操作

ssh-copy-id -i /root/.ssh/id_rsa.pub  root@k8s-node01

ssh-copy-id -i /root/.ssh/id_rsa.pub  root@k8s-node02

ssh-copy-id -i /root/.ssh/id_rsa.pub  root@k8s-master-01

 

三、安装etcd软件

三台创建目录

mkdir  -p  /app/etcd/{bin,cfg,ssl}

解压文件

tar zxvf etcd-v3.3.10-linux-amd64.tar.gz

cp etcd-v3.3.10-linux-amd64/{etcd,etcdctl} /app/etcd/bin/

scp /app/etcd/bin/* root@k8s-node01:/app/etcd/bin/

scp /app/etcd/bin/* root@k8s-node02:/appt/etcd/bin/

 

 

四、配置etcd tls

1、下载cfssl(三台操作)

curl -L https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 -o /usr/local/bin/cfssl

curl -L https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 -o /usr/local/bin/cfssljson

curl -L https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64 -o /usr/local/bin/cfssl-certinfo

chmod +x /usr/local/bin/cfssl /usr/local/bin/cfssljson /usr/local/bin/cfssl-certinfo

 

2、生成证书

mkdir etcd-cert

cd  etcd-cert

 

vi  etcd-cert.sh

 

cat > ca-config.json <<EOF

{

  "signing": {

    "default": {

      "expiry": "87600h"

    },

    "profiles": {

      "www": {

         "expiry": "87600h",

         "usages": [

            "signing",

            "key encipherment",

            "server auth",

            "client auth"

        ]

      }

    }

  }

}

EOF

 

cat > ca-csr.json <<EOF

{

    "CN": "etcd CA",

    "key": {

        "algo": "rsa",

        "size": 2048

    },

    "names": [

        {

            "C": "CN",

            "L": "zhejiang",

            "ST": "hangzhou"

        }

    ]

}

EOF

 

cfssl gencert -initca ca-csr.json | cfssljson -bare ca -

 

#-----------------------

 

cat > server-csr.json <<EOF

{

    "CN": "etcd",

    "hosts": [

    "192.168.159.121",

    "192.168.159.122",

    "192.168.159.123"

    ],

    "key": {

        "algo": "rsa",

        "size": 2048

    },

    "names": [

        {

            "C": "CN",

            "L": "zhejiang",

            "ST": "hangzhou"

        }

    ]

}

EOF

 

cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=www server-csr.json | cfssljson -bare server

 

 

执行脚本生成证书

sh  etcd-cert.sh

配置Etcd集群和TLS认证配置Etcd集群和TLS认证 

把生成证书到三台/app/etcd/ssl/

cp  ca.pem server-key.pem server.pem /app/etcd/ssl/

scp  /app/etcd/ssl/*  k8s-node01:/app/etcd/ssl/

scp  /app/etcd/ssl/*  k8s-node02:/app/etcd/ssl/

 

五、配置etcd加证书

1k8s-master-01主机配置

配置

vi  /app/etcd/cfg/etcd

 

#[Member]

ETCD_NAME="etcd01"

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"

ETCD_LISTEN_PEER_URLS="https://192.168.159.121:2380"

ETCD_LISTEN_CLIENT_URLS="https://192.168.159.121:2379"

 

#[Clustering]

ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.159.121:2380"

ETCD_ADVERTISE_CLIENT_URLS="https://192.168.159.121:2379"

ETCD_INITIAL_CLUSTER="etcd01=https://192.168.159.121:2380,etcd02=https://192.168.159.122:2380,etcd03=https://192.168.159.123:2380"

ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"

ETCD_INITIAL_CLUSTER_STATE="new"

 

配置etcd自动启动脚本

vi  /usr/lib/systemd/system/etcd.service

 

[Unit]

Description=Etcd Server

After=network.target

After=network-online.target

Wants=network-online.target

 

[Service]

Type=notify

EnvironmentFile=/app/etcd/cfg/etcd

ExecStart=/app/etcd/bin/etcd --name=${ETCD_NAME} --data-dir=${ETCD_DATA_DIR} --listen-peer-urls=${ETCD_LISTEN_PEER_URLS} --listen-client-urls=${ETCD_LISTEN_CLIENT_URLS},http://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=/app/etcd/ssl/server.pem --key-file=/app/etcd/ssl/server-key.pem --peer-cert-file=/app/etcd/ssl/server.pem --peer-key-file=/app/etcd/ssl/server-key.pem --trusted-ca-file=/app/etcd/ssl/ca.pem --peer-trusted-ca-file=/app/etcd/ssl/ca.pem

Restart=on-failure

LimitNOFILE=65536

 

[Install]

WantedBy=multi-user.target

 

2配置k8s-node01主机配置

配置

vi  /app/etcd/cfg/etcd

 

#[Member]

ETCD_NAME="etcd02"

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"

ETCD_LISTEN_PEER_URLS="https://192.168.159.122:2380"

ETCD_LISTEN_CLIENT_URLS="https://192.168.159.122:2379"

 

#[Clustering]

ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.159.122:2380"

ETCD_ADVERTISE_CLIENT_URLS="https://192.168.159.122:2379"

ETCD_INITIAL_CLUSTER="etcd01=https://192.168.159.121:2380,etcd02=https://192.168.159.122:2380,etcd03=https://192.168.159.123:2380"

ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"

ETCD_INITIAL_CLUSTER_STATE="new"

 

配置etcd自动启动脚本

vi  /usr/lib/systemd/system/etcd.service

 

[Unit]

Description=Etcd Server

After=network.target

After=network-online.target

Wants=network-online.target

 

[Service]

Type=notify

EnvironmentFile=/app/etcd/cfg/etcd

ExecStart=/app/etcd/bin/etcd --name=${ETCD_NAME} --data-dir=${ETCD_DATA_DIR} --listen-peer-urls=${ETCD_LISTEN_PEER_URLS} --listen-client-urls=${ETCD_LISTEN_CLIENT_URLS},http://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=/app/etcd/ssl/server.pem --key-file=/app/etcd/ssl/server-key.pem --peer-cert-file=/app/etcd/ssl/server.pem --peer-key-file=/app/etcd/ssl/server-key.pem --trusted-ca-file=/app/etcd/ssl/ca.pem --peer-trusted-ca-file=/app/etcd/ssl/ca.pem

Restart=on-failure

LimitNOFILE=65536

 

[Install]

WantedBy=multi-user.target

 

3配置k8s-node02主机配置

配置

vi  /app/etcd/cfg/etcd

 

#[Member]

ETCD_NAME="etcd03"

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"

ETCD_LISTEN_PEER_URLS="https://192.168.159.123:2380"

ETCD_LISTEN_CLIENT_URLS="https://192.168.159.123:2379"

 

#[Clustering]

ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.159.123:2380"

ETCD_ADVERTISE_CLIENT_URLS="https://192.168.159.123:2379"

ETCD_INITIAL_CLUSTER="etcd01=https://192.168.159.121:2380,etcd02=https://192.168.159.122:2380,etcd03=https://192.168.159.123:2380"

ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"

ETCD_INITIAL_CLUSTER_STATE="new"

 

配置etcd自动启动脚本

vi  /usr/lib/systemd/system/etcd.service

 

[Unit]

Description=Etcd Server

After=network.target

After=network-online.target

Wants=network-online.target

 

[Service]

Type=notify

EnvironmentFile=/app/etcd/cfg/etcd

ExecStart=/app/etcd/bin/etcd --name=${ETCD_NAME} --data-dir=${ETCD_DATA_DIR} --listen-peer-urls=${ETCD_LISTEN_PEER_URLS} --listen-client-urls=${ETCD_LISTEN_CLIENT_URLS},http://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=/app/etcd/ssl/server.pem --key-file=/app/etcd/ssl/server-key.pem --peer-cert-file=/app/etcd/ssl/server.pem --peer-key-file=/app/etcd/ssl/server-key.pem --trusted-ca-file=/app/etcd/ssl/ca.pem --peer-trusted-ca-file=/app/etcd/ssl/ca.pem

Restart=on-failure

LimitNOFILE=65536

 

[Install]

WantedBy=multi-user.target

 

 

 

启动etcd

systemctl daemon-reload

systemctl  restart etcd

systemctl  status etcd

systemctl enable etcd

 


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI