配置Etcd集群和TLS认证-创新互联
一、安装前准备
创新互联专注于勐腊网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供勐腊营销型网站建设,勐腊网站制作、勐腊网页设计、勐腊网站官网定制、小程序制作服务,打造勐腊网络公司原创品牌,更为您提供勐腊网站排名全网营销落地服务。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-yinstall 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 < { "signing": { "default": { "expiry": "87600h" }, "profiles": { "www": { "expiry": "87600h", "usages": [ "signing", "key encipherment", "server auth", "client auth" ] } } } } EOF cat > ca-csr.json < { "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 < { "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 把生成证书到三台/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加证书 1、k8s-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 另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站栏目:配置Etcd集群和TLS认证-创新互联
文章出自:http://pwwzsj.com/article/dchpdp.html