我是靠谱客的博主 正直薯片,最近开发中收集的这篇文章主要介绍Ubuntu 16.04安装配置etcd转载自http://www.cnblogs.com/sammyliu/p/8182078.html安装etcd配置etcd集群备注:,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

转载自http://www.cnblogs.com/sammyliu/p/8182078.html

安装etcd

$ ETCD_VER=v3.3.1

$ GITHUB_URL=https://github.com/coreos/etcd/releases/download

$ rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz

$ rm -rf /tmp/etcd-download-test && mkdir -p /tmp/etcd-download-test

$ curl -L ${GITHUB_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-{ETCD_VER}-linux-amd64.tar.gz

$ tar -xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /opt/bin --strip-components=1

$ rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz

$ /opt/bin /etcd –version (或者是/opt/bin /etcd-${ETCD_VER}-linux-amd64/etcd –version)

<<输出结果

etcd Version: 3.3.1

Git SHA: 28f3f26c0

Go Version: go1.9.4

Go OS/Arch: linux/amd64

输出结果>>

$ ETCDCTL_API=3 /opt/bin/etcd-${ETCD_VER}-linux-amd64/etcd–version version

<<输出结果

etcdctl version: 3.3.1

API version: 3.3

输出结果>>


配置etcd集群

以3台机器为例:

Name             IP                     Master/slave

Node0      172.23.100.4             Master

Node1      172.23.100.5             Node

Node2      172.23.100.6             Node

1 在三个节点分别执行:

$ sudo mkdir -p /var/lib/etcd/

$ sudo mkdir -p /opt/config/

2 在每个节点分别创建/opt/config/etcd.conf 文件(不同节点不同),注意修改ip地址为本机地址以及ETCD_NAME:

node0

ETCD_DATA_DIR=/var/lib/etcd

ETCD_NAME="kub-node-0"

ETCD_INITIAL_CLUSTER="kub-node-0=http://172.23.100.4:2380,kub-node-1=http://172.23.100.5:2380,kub-node-2=http://172.23.100.6:2380"

ETCD_INITIAL_CLUSTER_STATE=new

ETCD_LISTEN_PEER_URLS=http://172.23.100.4:2380

ETCD_INITIAL_ADVERTISE_PEER_URLS=http://172.23.100.4:2380

ETCD_ADVERTISE_CLIENT_URLS=http://172.23.100.4:2379

ETCD_LISTEN_CLIENT_URLS=http://172.23.100.4:2379,http://127.0.0.1:2379

而在node1

ETCD_DATA_DIR=/var/lib/etcd

ETCD_NAME="kub-node-1"

ETCD_INITIAL_CLUSTER="kub-node-0=http://172.23.100.4:2380,kub-node-1=http://172.23.100.5:2380,kub-node-2=http://172.23.100.6:2380"

ETCD_INITIAL_CLUSTER_STATE=new

ETCD_LISTEN_PEER_URLS=http://172.23.100.5:2380

ETCD_INITIAL_ADVERTISE_PEER_URLS=http://172.23.100.5:2380

ETCD_ADVERTISE_CLIENT_URLS=http://172.23.100.5:2379

ETCD_LISTEN_CLIENT_URLS=http://172.23.100.5:2379,http://127.0.0.1:2379

3 创建/lib/systemd/system/etcd.service文件(不同节点相同配置):

[Unit]

Description=Etcd Server

Documentation=https://github.com/coreos/etcd

After=network.target

[Service]

User=root

Type=simple

EnvironmentFile=-/opt/config/etcd.conf

ExecStart=/opt/bin/etcd-${ETCD_VER}-linux-amd64/etcd

Restart=on-failure

RestartSec=10s

LimitNOFILE=40000

[Install]

WantedBy=multi-user.target

4 分别在三个节点上启动服务:

$ sudo systemctl daemon-reload

$ sudo systemctl enable etcd

$ sudo systemctl start etcd

5 查看etcd是否正常启动:

$ sudo systemctl status etcd

如果显示Active: active (running),则启动成功,否则可以尝试再次执行步骤4;

6 查看端口是否正常开放:

$ sudo netstat -apn | grep 2379

7 查看集群状态:

$ /opt/bin/etcd-v3.3.1-linux-amd64/etcdctl cluster-health

输出结果:

member 664b85ff39242fbc is healthy: gothealthy result from http://172.23.100.6:2379

member 9dd263662a4b6f73 is healthy: gothealthy result from http://172.23.100.4:2379

member b17535572fd6a37b is healthy: gothealthy result from http://172.23.100.5:2379

cluster is healthy

8 查看 etcd 集群成员:

$ /opt/bin/etcd-v3.3.1-linux-amd64/etcdctl member list

输出结果:

9dd263662a4b6f73:name=kub-node-0 peerURLs=http://172.23.100.4:2380clientURLs=http://172.23.100.4:2379 isLeader=true

b17535572fd6a37b:name=kub-node-1 peerURLs=http://172.23.100.5:2380clientURLs=http://172.23.100.5:2379 isLeader=false

e6db3cac1db23670:name=kub-node-2 peerURLs=http://172.23.100.6:2380clientURLs=http://172.23.100.6:2379 isLeader=false

备注:

1 集群ip地址变化后,除了修改/opt/config/etcd.conf 文件并重新启用服务外,还需要删除/var/lib/etcd目录下保存的数据;

2 .conf文件中不支持环境变量;


最后

以上就是正直薯片为你收集整理的Ubuntu 16.04安装配置etcd转载自http://www.cnblogs.com/sammyliu/p/8182078.html安装etcd配置etcd集群备注:的全部内容,希望文章能够帮你解决Ubuntu 16.04安装配置etcd转载自http://www.cnblogs.com/sammyliu/p/8182078.html安装etcd配置etcd集群备注:所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部