因爲最近在學習kubernetes,etcd做爲kubernetes集羣的主數據庫,必須先啓動。node
etcds實例名稱 | IP地址 | Hostname |
---|---|---|
etcd 1 | 192.168.142.161 | kubernetes-node1.example.com |
etcd 2 | 192.168.142.162 | kubernetes-node2.example.com |
etcd 3 | 192.168.142.163 | kubernetes-node3.example.com |
vim /usr/lib/systemd/system/etcd.service 內容以下: [Unit] Description=Etcd Server After=network.target [Service] Type=simple WorkingDirectory=/var/lib/etcd/ EnvironmentFile=-/etc/etcd/etcd.conf #配置文件路徑 ExecStart=/usr/bin/etcd Type=notify [Install] WantedBy=multi-user.target
vim /etc/etcd/etcd.conf # [member] ETCD_NAME=etcd1 #etcd實例名稱 ETCD_DATA_DIR="/var/lib/etcd" #etcd數據保存目錄 ETCD_LISTEN_CLIENT_URLS="http://192.168.142.161:2379,http://127.0.0.1:2379" #供外部客戶端使用的url ETCD_ADVERTISE_CLIENT_URLS="http://192.168.142.161:2379,http://127.0.0.1:2379" #廣播給外部客戶端使用的url #[cluster] ETCD_LISTEN_PEER_URLS="http://192.168.142.161:2380" #集羣內部通訊使用的URL ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.142.161:2380" #廣播給集羣內其餘成員訪問的URL ETCD_INITIAL_CLUSTER="etcd1=http://192.168.142.161:2380,etcd2=http://192.168.142.162:2380,etcd3=http://192.168.142.163:2380" #初始集羣成員列表 ETCD_INITIAL_CLUSTER_STATE="new" #初始集羣狀態,new爲新建集羣 ETCD_INITIAL_CLUSTER_TOKEN="k8s-etcd-cluster" #集羣的名稱
啓動etcd1服務器上的etcd服務。git
systemctl restart etcdetcd2和etcd3爲加入k8s-etcd-cluster集羣的實例,須要將其ETCD_INITIAL_CLUSTER_STATE設置爲"exist"。etcd2的完整配置以下:github
# [member] ETCD_NAME=etcd2 ETCD_DATA_DIR="/var/lib/etcd" ETCD_LISTEN_CLIENT_URLS="http://192.168.142.162:2379,http://127.0.0.1:2379" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.142.162:2379,http://127.0.0.1:2379" #[cluster] ETCD_LISTEN_PEER_URLS="http://192.168.142.162:2380" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.142.162:2380" ETCD_INITIAL_CLUSTER="etcd1=http://192.168.142.161:2380,etcd2=http://192.168.142.162:2380,etcd3=http://192.168.142.163:2380" ETCD_INITIAL_CLUSTER_STATE="exist" ETCD_INITIAL_CLUSTER_TOKEN="k8s-etcd-cluster"
啓動etcd2和etcd3服務器上的etcd服務。數據庫
systemctl restart etcdvim
啓動完成後,在任意節點執行etcdctl cluster-healthy命令來查看運行狀態。服務器
使用etcdctl member list 來查看集羣中的成員列表。學習
etcd集羣搭建 下載二進制軟件包 https://github.com/coreos/etcd/releases 解壓 將兩個執行文件複製到/usr/bin/ etcd和etcdctl文件複製到/usr/bin目錄 配置etcd-1 vi /etc/etcd/etcd.yml name: etcd-1 data-dir: /var/lib/etcd listen-client-urls: http://163.44.167.92:2379,http://127.0.0.1:2379 advertise-client-urls: http://163.44.167.92:2379,http://127.0.0.1:2379 listen-peer-urls: http://163.44.167.92:2380 initial-advertise-peer-urls: http://163.44.167.92:2380 initial-cluster: etcd-1=http://163.44.167.92:2380,etcd-2=http://150.95.148.52:2380,etcd-3=http://133.130.122.48:2380 initial-cluster-token: etcd-cluster-token initial-cluster-state: new 配置etcd-2 vi /etc/etcd/etcd.yml name: etcd-2 data-dir: /var/lib/etcd listen-client-urls: http://150.95.148.52:2379,http://127.0.0.1:2379 advertise-client-urls: http://150.95.148.52:2379,http://127.0.0.1:2379 listen-peer-urls: http://150.95.148.52:2380 initial-advertise-peer-urls: http://150.95.148.52:2380 initial-cluster: etcd-1=http://163.44.167.92:2380,etcd-2=http://150.95.148.52:2380,etcd-3=http://133.130.122.48:2380 initial-cluster-token: etcd-cluster-token initial-cluster-state: new 配置etcd-3 name: etcd-3 data-dir: /var/lib/etcd listen-client-urls: http://133.130.122.48:2379,http://127.0.0.1:2379 advertise-client-urls: http://133.130.122.48:2379,http://127.0.0.1:2379 listen-peer-urls: http://133.130.122.48:2380 initial-advertise-peer-urls: http://133.130.122.48:2380 initial-cluster: etcd-1=http://163.44.167.92:2380,etcd-2=http://150.95.148.52:2380,etcd-3=http://133.130.122.48:2380 initial-cluster-token: etcd-cluster-token initial-cluster-state: new 最後啓動 etcd --config-file=/etc/etcd/etcd.yml & 查當作員 etcdctl member list 每一個節點上執行查看健康狀態 etcdctl cluster-health