1. 程式人生 > >etcd單節點安裝

etcd單節點安裝

證書 移動 bar 環境 chm online etc sts accept

本篇安裝單個etcd,然後進行擴容etcd節點至2個、3個

二進制安裝k8s 1.11.0 實驗架構 master: 192.168.0.91 etcd node2: 192.168.0.92 node3: 192.168.0.93 1、環境配置 如下操作在所有節點操作 配置hosts解析 [root@host-10-1-1-8 k8s]# hostnamectl set-hostname master [root@host-10-1-1-68 ~]# hostnamectl set-hostname node2 [root@host-10-1-1-111 ~]# hostnamectl set-hostname
node3 cat >>/etc/hosts<<EOF 192.168.0.91 master 192.168.0.92 node2 192.168.0.93 node3 EOF 禁用selinux sed -i s/SELINUX=permissive/SELINUX=disabled/ /etc/sysconfig/selinux 關閉swap 註釋/etc/fstab文件裏swap相關的行 所有節點都重啟 開啟forward iptables -P FORWARD ACCEPT 配置轉發相關參數 cat >> /etc/sysctl.d/k8s.conf <<EOF net.bridge.bridge
-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 vm.swappiness=0 EOF sysctl --system 加載ipvs相關內核模塊 如果重新開機,需要重新加載 modprobe ip_vs modprobe ip_vs_rr modprobe ip_vs_wrr modprobe ip_vs_sh modprobe nf_conntrack_ipv4 lsmod | grep ip_vs 2、安裝docker 如下操作在所有節點操作 v1.11.0版本推薦使用docker v17.03, v1.11
,v1.12,v1.13, 也可以使用,再高版本的docker可能無法正常使用。 測試發現17.09無法正常使用,不能使用資源限制(內存CPU) 卸載自帶docker yum remove -y docker-ce docker-ce-selinux container-selinux 配置Docker倉庫鏡像 wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm 安裝 Docker 和依賴包 yum install -y docker-ce-*.rpm 開機啟動 systemctl enable docker 啟動 docker 服務 systemctl start docker 3、安裝CFSSL證書生成工具 只在master節點操作 mkdir -pv /server/software/k8s cd /server/software/k8s wget下載cfssl工具 wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 wget https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64 安裝cfssl工具 只要把安裝包改下名字,移動到usr/local/bin/下,加上授權即可 mv cfssl-certinfo_linux-amd64 /usr/local/bin/cfssl-certinfo mv cfssl_linux-amd64 /usr/local/bin/cfssl mv cfssljson_linux-amd64 /usr/local/bin/cfssljson chmod +x /usr/local/bin/cfssl* 4、創建CA配置文件:生成其他組件ca證書時需要用到(除了根證書) 只在master節點操作 mkdir -p $HOME/ssl && cd $HOME/ssl cat >ca-config.json<<EOF { "signing": { "default": { "expiry": "87600h" }, "profiles": { "kubernetes": { "usages": [ "signing", "key encipherment", "server auth", "client auth" ], "expiry": "87600h" } } } } EOF 5、生成 ca 根證書和私鑰: 生成其他組件ca證書時需要用到 只在master節點操作 cd $HOME/ssl cat >ca-csr.json<<EOF { "CN": "kubernetes", "key": { "algo": "rsa", "size": 2048 }, "names": [ { "C": "CN", "ST": "BeiJing", "L": "BeiJing", "O": "k8s", "OU": "System" } ], "ca": { "expiry": "87600h" } } EOF cfssl gencert -initca ca-csr.json | cfssljson -bare ca 查看生成的證書和私鑰 ca-key.pem ca.pem 把根證書和私鑰復制到一個目錄裏面 mkdir -p /etc/kubernetes/cert/ cp ca*.pem /etc/kubernetes/cert/ 6、安裝、配置、啟動etcd 只在master節點上操作 6.1、生成etcd的ca證書和私鑰 cd $HOME/ssl cat >etcd-csr.json<<EOF { "CN": "etcd", "hosts": [ "127.0.0.1", "192.168.0.91", "192.168.0.92", "192.168.0.93" ], "key": { "algo": "rsa", "size": 2048 }, "names": [ { "C": "CN", "ST": "BeiJing", "L": "BeiJing", "O": "etcd", "OU": "Etcd Security" } ] } EOF cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes etcd-csr.json | cfssljson -bare etcd 查看生成的證書和私鑰 etcd-key.pem etcd.pem 把etcd證書復制到一個目錄裏面 mkdir -p /etc/etcd/cert/ cp etcd*.pem /etc/etcd/cert/ 6.2、安裝etcd mkdir -p /server/software/k8s mkdir -p /opt/k8s/bin cd /server/software/k8s wget https://github.com/coreos/etcd/releases/download/v3.2.18/etcd-v3.2.18-linux-amd64.tar.gz tar -xf etcd-v3.2.18-linux-amd64.tar.gz mv etcd-v3.2.18-linux-amd64/etcd* /opt/k8s/bin chmod +x /opt/k8s/bin/* ln -s /opt/k8s/bin/etcd /usr/bin/etcd etcd --version 6.3 配置etcd啟動腳本 cat >> /etc/profile << EOF export ETCD_NAME=$(hostname) export INTERNAL_IP=$(hostname -i | awk ‘{print $NF}‘) export ECTD_CLUSTER=‘master=https://192.168.0.91:2380‘ EOF source /etc/profile mkdir -p /data/etcd cat > /etc/systemd/system/etcd.service <<EOF [Unit] Description=Etcd Server After=network.target After=network-online.target Wants=network-online.target Documentation=https://github.com/coreos [Service] Type=notify WorkingDirectory=/data/etcd EnvironmentFile=-/etc/etcd/etcd.conf ExecStart=/opt/k8s/bin/etcd \ --name $ETCD_NAME \ --cert-file=/etc/etcd/cert/etcd.pem \ --key-file=/etc/etcd/cert/etcd-key.pem \ --peer-cert-file=/etc/etcd/cert/etcd.pem \ --peer-key-file=/etc/etcd/cert/etcd-key.pem \ --trusted-ca-file=/etc/kubernetes/cert/ca.pem \ --peer-trusted-ca-file=/etc/kubernetes/cert/ca.pem \ --initial-advertise-peer-urls https://${INTERNAL_IP}:2380 \ --listen-peer-urls https://${INTERNAL_IP}:2380 \ --listen-client-urls https://${INTERNAL_IP}:2379,http://127.0.0.1:2379 \ --advertise-client-urls https://${INTERNAL_IP}:2379 \ --initial-cluster-token my-etcd-token \ --initial-cluster $ECTD_CLUSTER \ --initial-cluster-state new \ --data-dir=/data/etcd Restart=on-failure RestartSec=5 LimitNOFILE=65536 [Install] WantedBy=multi-user.target EOF 6.4、啟動etctd、設置開機啟動 systemctl daemon-reload #一定要執行,否則報錯 systemctl start etcd systemctl status etcd systemctl enable etcd systemctl stop etcd 6.5、查看單個etcd集群狀態 [root@master ~]# etcdctl cluster-health member 42f7141ed6110de1 is healthy: got healthy result from https://192.168.0.91:2379 cluster is healthy

etcd單節點安裝