快速启动

Docker单机快速

新镜像:gcr.io/etcd-development/etcd

  1. #v2
  2. export NODE1=10.0.1.42
  3. docker run -d --name etcd \
  4. -p 2379:2379 \
  5. -p 2380:2380 \
  6. --volume=/Users/arvon/Documents/own-project/etcd-data:/etcd-data \
  7. quay.io/coreos/etcd:v3.3.10 \
  8. /usr/local/bin/etcd \
  9. --data-dir=/etcd-data \
  10. --name node1 \
  11. --initial-advertise-peer-urls http://${NODE1}:2380 \
  12. --listen-peer-urls http://0.0.0.0:2380 \
  13. --advertise-client-urls http://${NODE1}:2379 \
  14. --listen-client-urls http://0.0.0.0:2379 \
  15. --initial-cluster node1=http://${NODE1}:2380 \
  16. --force-new-cluster
  17. docker exec etcd etcdctl ls
  18. #v3
  19. docker cp snapshot.db etcd:/
  20. docker exec -e ETCDCTL_API=3 \
  21. etcd \
  22. etcdctl snapshot restore snapshot.db \
  23. --name node1 \
  24. --data-dir=/etcd-data/rs \
  25. --initial-advertise-peer-urls http://${NODE1}:2380 \
  26. --initial-cluster node1=http://${NODE1}:2380
  27. docker stop etcd
  28. docker run -d --rm --name etcd \
  29. -p 2379:2379 \
  30. -p 2380:2380 \
  31. --volume=/Users/arvon/Documents/own-project/etcd-data:/etcd-data/ \
  32. quay.io/coreos/etcd:v3.1.20 \
  33. /usr/local/bin/etcd \
  34. --data-dir=/etcd-data/rs \
  35. --name node1 \
  36. --initial-advertise-peer-urls http://${NODE1}:2380 \
  37. --listen-peer-urls http://0.0.0.0:2380 \
  38. --advertise-client-urls http://${NODE1}:2379 \
  39. --listen-client-urls http://0.0.0.0:2379 \
  40. --initial-cluster node1=http://${NODE1}:2380 \
  41. --initial-cluster-state=existing

docker版集群快速启动
  1. version: '2'
  2. services:
  3. etcd0:
  4. image: quay.io/coreos/etcd
  5. ports:
  6. - 2379
  7. volumes:
  8. - etcd0:/etcd_data
  9. command:
  10. - /usr/local/bin/etcd
  11. - -name
  12. - etcd0
  13. - --data-dir
  14. - /etcd_data
  15. - -advertise-client-urls
  16. - http://etcd0:2379
  17. - -listen-client-urls
  18. - http://0.0.0.0:2379
  19. - -initial-advertise-peer-urls
  20. - http://etcd0:2380
  21. - -listen-peer-urls
  22. - http://0.0.0.0:2380
  23. - -initial-cluster
  24. - etcd0=http://etcd0:2380,etcd1=http://etcd1:2380,etcd2=http://etcd2:2380
  25. etcd1:
  26. image: quay.io/coreos/etcd
  27. ports:
  28. - 2379
  29. volumes:
  30. - etcd1:/etcd_data
  31. command:
  32. - /usr/local/bin/etcd
  33. - -name
  34. - etcd1
  35. - --data-dir
  36. - /etcd_data
  37. - -advertise-client-urls
  38. - http://etcd1:2379
  39. - -listen-client-urls
  40. - http://0.0.0.0:2379
  41. - -initial-advertise-peer-urls
  42. - http://etcd1:2380
  43. - -listen-peer-urls
  44. - http://0.0.0.0:2380
  45. - -initial-cluster
  46. - etcd0=http://etcd0:2380,etcd1=http://etcd1:2380,etcd2=http://etcd2:2380
  47. etcd2:
  48. image: quay.io/coreos/etcd
  49. ports:
  50. - 2379
  51. volumes:
  52. - etcd2:/etcd_data
  53. command:
  54. - /usr/local/bin/etcd
  55. - -name
  56. - etcd2
  57. - --data-dir
  58. - /etcd_data
  59. - -advertise-client-urls
  60. - http://etcd2:2379
  61. - -listen-client-urls
  62. - http://0.0.0.0:2379
  63. - -initial-advertise-peer-urls
  64. - http://etcd2:2380
  65. - -listen-peer-urls
  66. - http://0.0.0.0:2380
  67. - -initial-cluster
  68. - etcd0=http://etcd0:2380,etcd1=http://etcd1:2380,etcd2=http://etcd2:2380
  69. etcd-browser:
  70. build: ./etcd-browser
  71. ports:
  72. - 8000
  73. environment:
  74. ETCD_HOST: etcd0
  75. ETCD_PORT: 2379
  76. depends_on:
  77. - etcd0
  78. volumes:
  79. etcd0:
  80. etcd1:
  81. etcd2:

etcd可视化工具
  1. docker run -d --name etcd-view -p 38080:8080 nikfoundas/etcd-viewer
  2. #printf "taiyouxi:$(openssl passwd -crypt ro3GwH6iTfYc8uFiW)\n" >/usr/local/nginx/taiyouxi_passwd.db

etcd集群还原

参考: https://www.jianshu.com/p/c60c08effaaa https://www.ityoudao.cn/posts/etcd-v2-disaster-recovery/ 简述:

  • 原启动方式不变,停止所有节点的etcd服务
  • 删除所有节点上etcd的数据目录,即member
  • 下载备份的数据并替换至其中一个节点,即下载数据替换存放于member目录
  • 使用命令行启动此节点
  • 修改更新此节点信息,update
  • 添加一个节点
  • 在添加的节点上执行命令启动
  • 以此类推其他节点
  1. /usr/local/bin/etcd \
  2. -name etcd1 \
  3. --data-dir /opt/etcd/etcd-data \
  4. -initial-advertise-peer-urls http://10.31.2.65:2380 \
  5. -listen-peer-urls http://10.31.2.65:2380 \
  6. -listen-client-urls http://10.31.2.65:2379,http://127.0.0.1:2379 \
  7. -advertise-client-urls http://10.31.2.65:2379 \
  8. -initial-cluster-token etcd-cluster-wpys \
  9. -initial-cluster-state new \
  10. --force-new-cluster &
  11. etcdctl member list
  12. etcdctl member update 706ad66c870001 http://10.31.2.65:2380
  13. etcdctl member list
  14. etcdctl member add etcd2 http://10.31.2.238:2380
  15. /usr/local/bin/etcd \
  16. -name etcd2 \
  17. --data-dir /opt/etcd/etcd-data \
  18. -initial-advertise-peer-urls http://10.31.2.238:2380 \
  19. -listen-peer-urls http://10.31.2.238:2380 \
  20. -listen-client-urls http://10.31.2.238:2379,http://127.0.0.1:2379 \
  21. -advertise-client-urls http://10.31.2.238:2379 \
  22. -initial-cluster-token etcd-cluster-wpys \
  23. -initial-cluster etcd1=http://10.31.2.65:2380,etcd2=http://10.31.2.238:2380 \
  24. -initial-cluster-state existing &
  25. etcdctl member list
  26. etcdctl member add etcd3 http://10.31.2.205:2380
  27. /usr/local/bin/etcd \
  28. -name etcd3 \
  29. --data-dir /opt/etcd/etcd-data \
  30. -initial-advertise-peer-urls http://10.31.2.205:2380 \
  31. -listen-peer-urls http://10.31.2.205:2380 \
  32. -listen-client-urls http://10.31.2.205:2379,http://127.0.0.1:2379 \
  33. -advertise-client-urls http://10.31.2.205:2379 \
  34. -initial-cluster-token etcd-cluster-wpys \
  35. -initial-cluster etcd1=http://10.31.2.65:2380,etcd2=http://10.31.2.238:2380,etcd3=http://10.31.2.205:2380 \
  36. -initial-cluster-state existing &
  37. ## Etcd还原
  38. Etcd地址:http://13.250.157.52:18000/etcd?9
  39. 账号密码:taiyouxi/ro3GwH6iTfYc8uFiW
  40. #https://www.jianshu.com/p/c60c08effaaa
  41. #https://www.ityoudao.cn/posts/etcd-v2-disaster-recovery/
  42. /usr/local/bin/etcd \
  43. -name etcd1 \
  44. --data-dir /opt/etcd/etcd-data \
  45. -initial-advertise-peer-urls http://10.31.2.65:2380 \
  46. -listen-peer-urls http://10.31.2.65:2380 \
  47. -listen-client-urls http://10.31.2.65:2379,http://127.0.0.1:2379 \
  48. -advertise-client-urls http://10.31.2.65:2379 \
  49. -initial-cluster-token etcd-cluster-wpys \
  50. -initial-cluster-state new \
  51. --force-new-cluster &
  52. etcdctl member list
  53. etcdctl member update 706ad66c870001 http://10.31.2.65:2380
  54. etcdctl member list
  55. etcdctl member add etcd2 http://10.31.2.238:2380
  56. /usr/local/bin/etcd \
  57. -name etcd2 \
  58. --data-dir /opt/etcd/etcd-data \
  59. -initial-advertise-peer-urls http://10.31.2.238:2380 \
  60. -listen-peer-urls http://10.31.2.238:2380 \
  61. -listen-client-urls http://10.31.2.238:2379,http://127.0.0.1:2379 \
  62. -advertise-client-urls http://10.31.2.238:2379 \
  63. -initial-cluster-token etcd-cluster-wpys \
  64. -initial-cluster etcd1=http://10.31.2.65:2380,etcd2=http://10.31.2.238:2380 \
  65. -initial-cluster-state existing &
  66. etcdctl member list
  67. etcdctl member add etcd3 http://10.31.2.205:2380
  68. /usr/local/bin/etcd \
  69. -name etcd3 \
  70. --data-dir /opt/etcd/etcd-data \
  71. -initial-advertise-peer-urls http://10.31.2.205:2380 \
  72. -listen-peer-urls http://10.31.2.205:2380 \
  73. -listen-client-urls http://10.31.2.205:2379,http://127.0.0.1:2379 \
  74. -advertise-client-urls http://10.31.2.205:2379 \
  75. -initial-cluster-token etcd-cluster-wpys \
  76. -initial-cluster etcd1=http://10.31.2.65:2380,etcd2=http://10.31.2.238:2380,etcd3=http://10.31.2.205:2380 \
  77. -initial-cluster-state existing &