Etcd集群搭建

/ 随笔 / 0 条评论 / 3623浏览

安装

去https://github.com/coreos/etcd/releases/下载想要的版本

解压etcd包 解压后进入目录,增加x权限

chmod +x etcd
chmod +x etcdctl

并将etcd和etcdctl 复制到 /bin

配置启动

简单启动

./bin/etcd 这样就可以启动使用

集群配置

在两台机器上部署了简单的集群

172.16.5.106
172.16.5.107
172.16.5.21

启动集群

nohup etcd --name infra1 --initial-advertise-peer-urls http://172.16.5.106:2380 --listen-peer-urls http://172.16.5.106:2380 --listen-client-urls http://172.16.5.106:2379,http://127.0.0.1:2379 --advertise-client-urls http://172.16.5.106:2379 --initial-cluster-token etcd-cluster-1 --initial-cluster infra1=http://172.16.5.106:2380,infra2=http://172.16.5.107:2380,infra3=http://172.16.5.21:2380 --initial-cluster-state new > /home/logs/etcd.log 2>&1 &
nohup etcd --name infra2 --initial-advertise-peer-urls http://172.16.5.107:2380 --listen-peer-urls http://172.16.5.107:2380 --listen-client-urls http://172.16.5.107:2379,http://127.0.0.1:2379 --advertise-client-urls http://172.16.5.107:2379 --initial-cluster-token etcd-cluster-1 --initial-cluster infra1=http://172.16.5.106:2380,infra2=http://172.16.5.107:2380,infra3=http://172.16.5.21:2380 --initial-cluster-state new > /home/logs/etcd.log 2>&1 &
nohup etcd --name infra3 --initial-advertise-peer-urls http://172.16.5.21:2380 --listen-peer-urls http://172.16.5.21:2380 --listen-client-urls http://172.16.5.21:2379,http://127.0.0.1:2379 --advertise-client-urls http://172.16.5.21:2379 --initial-cluster-token etcd-cluster-1 --initial-cluster infra1=http://172.16.5.106:2380,infra2=http://172.16.5.107:2380,infra3=http://172.16.5.21:2380 --initial-cluster-state new > /home/logs/etcd.log 2>&1 &

查看日志

tail -f /home/logs/etcd.log

etcd命令

COMMANDS:
   backup        backup an etcd directory
   cluster-health    check the health of the etcd cluster
   mk            make a new key with a given value
   mkdir        make a new directory
   rm            remove a key or a directory
   rmdir        removes the key if it is an empty directory or a key-value pair
   get            retrieve the value of a key
   ls            retrieve a directory
   set            set the value of a key
   setdir        create a new or existing directory
   update        update an existing key with a given value
   updatedir        update an existing directory
   watch        watch a key for changes
   exec-watch        watch a key for changes and exec an executable
   member        member add, remove and list subcommands
   import        import a snapshot to a cluster
   user            user add, grant and revoke subcommands
   role            role add, grant and revoke subcommands
   auth            overall auth controls

   help, h        Shows a list of commands or help for one command

命令说明

nohup command 退出账号,进程不中断。 nohup详解

ps -ef | grep ${command} 查看进程是否启动,command为启动进程命令中的关键字

kill -9 ${pid} 杀死指定pid的进程