zoukankan      html  css  js  c++  java
  • etcd数据单机部署

    单机下载

    版本信息请参考https://github.com/etcd-io/etcd/releases

    本次以最新版本3.4.1为例https://github.com/etcd-io/etcd/releases/download/v3.4.1/etcd-v3.4.1-linux-amd64.tar.gz

     主机名为sht-sgmhadoopnn-01,IP地址172.16.101.55

    # cd /usr/local/
    # wget https://github.com/etcd-io/etcd/releases/download/v3.4.1/etcd-v3.4.1-linux-amd64.tar.gz
    # tar -zxf etcd-v3.4.1-linux-amd64.tar.gz .
    # ln -s etcd-v3.4.1-linux-amd64 etcd
    # grep "PATH" ~/.bash_profile
    PATH=/usr/local/etcd:$PATH:$HOME/bin
    # ls -lh /usr/local/etcd/
    total 40M
    drwxr-xr-x 14 1922357897 wheel 4.0K Sep 28 16:24 Documentation
    -rwxr-xr-x  1 1922357897 wheel  23M Sep 18 05:02 etcd
    -rwxr-xr-x  1 1922357897 wheel  17M Sep 18 05:02 etcdctl
    -rw-r--r--  1 1922357897 wheel  43K Sep 18 05:02 README-etcdctl.md
    -rw-r--r--  1 1922357897 wheel 8.3K Sep 18 05:02 README.md
    -rw-r--r--  1 1922357897 wheel 7.7K Sep 18 05:02 READMEv2-etcdctl.md

     启动etcd,以命令行和参数启动

    etcd 
    --name 'sht-sgmhadoopnn-01' 
    --data-dir '/usr/local/etcd/data' 
    --listen-client-urls 'http://0.0.0.0:2379' 
    --advertise-client-urls 'http://0.0.0.0:2379',http://127.0.0.1:2379 
    --listen-peer-urls 'http://0.0.0.0:2380' 
    --initial-advertise-peer-urls 'http://0.0.0.0:2380,http://127.0.0.1:2380'
    --enable-v2=true"

    输出log

    # etcd --logger=zap --name 'sht-sgmhadoopnn-01' --data-dir '/usr/local/etcd/data' --listen-client-urls 'http://0.0.0.0:2379' --advertise-client-urls 'http://0.0.0.0:2379' --listen-peer-urls 'http://0.0.0.0:2380' --initial-advertise-peer-urls 'http://0.0.0.0:2380'
    {"level":"info","ts":"2019-09-28T16:38:59.917+0800","caller":"embed/etcd.go:117","msg":"configuring peer listeners","listen-peer-urls":["http://0.0.0.0:2380"]}
    {"level":"info","ts":"2019-09-28T16:38:59.918+0800","caller":"embed/etcd.go:127","msg":"configuring client listeners","listen-client-urls":["http://0.0.0.0:2379"]}
    {"level":"info","ts":"2019-09-28T16:38:59.918+0800","caller":"embed/etcd.go:299","msg":"starting an etcd server","etcd-version":"3.4.1","git-sha":"a14579fbf","go-version":"go1.12.9","go-os":"linux","go-arch":"amd64","max-cpu-set":2,"max-cpu-available":2,"member-initialized":false,"name":"sht-sgmhadoopnn-01","data-dir":"/usr/local/etcd/data","wal-dir":"","wal-dir-dedicated":"","member-dir":"/usr/local/etcd/data/member","force-new-cluster":false,"heartbeat-interval":"100ms","election-timeout":"1s","initial-election-tick-advance":true,"snapshot-count":100000,"snapshot-catchup-entries":5000,"initial-advertise-peer-urls":["http://0.0.0.0:2380"],"listen-peer-urls":["http://0.0.0.0:2380"],"advertise-client-urls":["http://0.0.0.0:2379"],"listen-client-urls":["http://0.0.0.0:2379"],"listen-metrics-urls":[],"cors":["*"],"host-whitelist":["*"],"initial-cluster":"sht-sgmhadoopnn-01=http://0.0.0.0:2380","initial-cluster-state":"new","initial-cluster-token":"etcd-cluster","quota-size-bytes":2147483648,"pre-vote":false,"initial-corrupt-check":false,"corrupt-check-time-interval":"0s","auto-compaction-mode":"periodic","auto-compaction-retention":"0s","auto-compaction-interval":"0s","discovery-url":"","discovery-proxy":""}
    {"level":"info","ts":"2019-09-28T16:38:59.943+0800","caller":"etcdserver/backend.go:79","msg":"opened backend db","path":"/usr/local/etcd/data/member/snap/db","took":"24.695882ms"}
    {"level":"info","ts":"2019-09-28T16:38:59.963+0800","caller":"etcdserver/raft.go:456","msg":"starting local member","local-member-id":"1c70f9bbb41018f","cluster-id":"a0d2de0531db7884"}
    {"level":"info","ts":"2019-09-28T16:38:59.964+0800","caller":"raft/raft.go:1530","msg":"1c70f9bbb41018f switched to configuration voters=()"}
    {"level":"info","ts":"2019-09-28T16:38:59.964+0800","caller":"raft/raft.go:700","msg":"1c70f9bbb41018f became follower at term 0"}
    {"level":"info","ts":"2019-09-28T16:38:59.964+0800","caller":"raft/raft.go:383","msg":"newRaft 1c70f9bbb41018f [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]"}
    {"level":"info","ts":"2019-09-28T16:38:59.964+0800","caller":"raft/raft.go:700","msg":"1c70f9bbb41018f became follower at term 1"}
    {"level":"info","ts":"2019-09-28T16:38:59.964+0800","caller":"raft/raft.go:1530","msg":"1c70f9bbb41018f switched to configuration voters=(128088275939295631)"}
    {"level":"warn","ts":"2019-09-28T16:38:59.988+0800","caller":"auth/store.go:1317","msg":"simple token is not cryptographically signed"}
    {"level":"info","ts":"2019-09-28T16:38:59.998+0800","caller":"etcdserver/quota.go:98","msg":"enabled backend quota with default value","quota-name":"v3-applier","quota-size-bytes":2147483648,"quota-size":"2.1 GB"}
    {"level":"info","ts":"2019-09-28T16:39:00.006+0800","caller":"etcdserver/server.go:791","msg":"starting etcd server","local-member-id":"1c70f9bbb41018f","local-server-version":"3.4.1","cluster-version":"to_be_decided"}
    {"level":"info","ts":"2019-09-28T16:39:00.008+0800","caller":"etcdserver/server.go:657","msg":"started as single-node; fast-forwarding election ticks","local-member-id":"1c70f9bbb41018f","forward-ticks":9,"forward-duration":"900ms","election-ticks":10,"election-timeout":"1s"}
    {"level":"info","ts":"2019-09-28T16:39:00.009+0800","caller":"raft/raft.go:1530","msg":"1c70f9bbb41018f switched to configuration voters=(128088275939295631)"}
    {"level":"info","ts":"2019-09-28T16:39:00.009+0800","caller":"membership/cluster.go:392","msg":"added member","cluster-id":"a0d2de0531db7884","local-member-id":"1c70f9bbb41018f","added-peer-id":"1c70f9bbb41018f","added-peer-peer-urls":["http://0.0.0.0:2380"]}
    {"level":"info","ts":"2019-09-28T16:39:00.012+0800","caller":"embed/etcd.go:241","msg":"now serving peer/client/metrics","local-member-id":"1c70f9bbb41018f","initial-advertise-peer-urls":["http://0.0.0.0:2380"],"listen-peer-urls":["http://0.0.0.0:2380"],"advertise-client-urls":["http://0.0.0.0:2379"],"listen-client-urls":["http://0.0.0.0:2379"],"listen-metrics-urls":[]}
    {"level":"info","ts":"2019-09-28T16:39:00.013+0800","caller":"embed/etcd.go:576","msg":"serving peer traffic","address":"[::]:2380"}
    {"level":"info","ts":"2019-09-28T16:39:00.065+0800","caller":"raft/raft.go:923","msg":"1c70f9bbb41018f is starting a new election at term 1"}
    {"level":"info","ts":"2019-09-28T16:39:00.065+0800","caller":"raft/raft.go:713","msg":"1c70f9bbb41018f became candidate at term 2"}
    {"level":"info","ts":"2019-09-28T16:39:00.065+0800","caller":"raft/raft.go:824","msg":"1c70f9bbb41018f received MsgVoteResp from 1c70f9bbb41018f at term 2"}
    {"level":"info","ts":"2019-09-28T16:39:00.065+0800","caller":"raft/raft.go:765","msg":"1c70f9bbb41018f became leader at term 2"}
    {"level":"info","ts":"2019-09-28T16:39:00.065+0800","caller":"raft/node.go:325","msg":"raft.node: 1c70f9bbb41018f elected leader 1c70f9bbb41018f at term 2"}
    {"level":"info","ts":"2019-09-28T16:39:00.069+0800","caller":"etcdserver/server.go:2015","msg":"published local member to cluster through raft","local-member-id":"1c70f9bbb41018f","local-member-attributes":"{Name:sht-sgmhadoopnn-01 ClientURLs:[http://0.0.0.0:2379]}","request-path":"/0/members/1c70f9bbb41018f/attributes","cluster-id":"a0d2de0531db7884","publish-timeout":"7s"}
    {"level":"info","ts":"2019-09-28T16:39:00.070+0800","caller":"etcdserver/server.go:2500","msg":"setting up initial cluster version","cluster-version":"3.4"}
    {"level":"info","ts":"2019-09-28T16:39:00.071+0800","caller":"embed/serve.go:139","msg":"serving client traffic insecurely; this is strongly discouraged!","address":"[::]:2379"}
    {"level":"info","ts":"2019-09-28T16:39:00.076+0800","caller":"membership/cluster.go:558","msg":"set initial cluster version","cluster-id":"a0d2de0531db7884","local-member-id":"1c70f9bbb41018f","cluster-version":"3.4"}
    {"level":"info","ts":"2019-09-28T16:39:00.076+0800","caller":"api/capability.go:76","msg":"enabled capabilities for version","cluster-version":"3.4"}
    {"level":"info","ts":"2019-09-28T16:39:00.076+0800","caller":"etcdserver/server.go:2532","msg":"cluster version is updated","cluster-version":"3.4"}
    View Code

    查看节点状态

    # etcdctl endpoint status --write-out=table
    +----------------+-----------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
    |    ENDPOINT    |       ID        | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
    +----------------+-----------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
    | 127.0.0.1:2379 | 1c70f9bbb41018f |   3.4.1 |   20 kB |      true |      false |         2 |          5 |                  5 |        |
    +----------------+-----------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
    # etcdctl endpoint health --write-out=table
    +----------------+--------+------------+-------+
    |    ENDPOINT    | HEALTH |    TOOK    | ERROR |
    +----------------+--------+------------+-------+
    | 127.0.0.1:2379 |   true | 3.109338ms |       |
    +----------------+--------+------------+-------+
    # etcdctl member list --write-out=table
    +-----------------+---------+--------------------+---------------------+---------------------+------------+
    |       ID        | STATUS  |        NAME        |     PEER ADDRS      |    CLIENT ADDRS     | IS LEARNER |
    +-----------------+---------+--------------------+---------------------+---------------------+------------+
    | 1c70f9bbb41018f | started | sht-sgmhadoopnn-01 | http://0.0.0.0:2380 | http://0.0.0.0:2379 |      false |
    +-----------------+---------+--------------------+---------------------+---------------------+------------+

     以服务模式启动

    # cat /usr/lib/systemd/system/etcd.service 
    [Unit]
    Description=etcd service
    Documentation=https://github.com/etcd-io/etcd
    After=network.target
    After=network-online.target
    Wants=network-online.target
    
    [Service]
    User=tnuser
    Type=notify
    WorkingDirectory=/usr/local/etcd
    ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/local/etcd/etcd 
      --data-dir=/usr/local/etcd/data 
      --name sht-sgmhadoopnn-01 
      --listen-client-urls http://0.0.0.0:2379 
      --advertise-client-urls http://0.0.0.0:2379 
      --initial-advertise-peer-urls http://0.0.0.0:2380 
      --listen-peer-urls http://0.0.0.0:2380 
      --enable-v2=true"
    Restart=always
    RestartSec=10s
    LimitNOFILE=65536
    
    [Install]
    WantedBy=multi-user.target
    # systemctl daemon-reload
    # systemctl start etcd
    # systemctl status etcd
    ● etcd.service - etcd service
       Loaded: loaded (/usr/lib/systemd/system/etcd.service; disabled; vendor preset: disabled)
       Active: active (running) since Sat 2019-09-28 17:24:13 CST; 2min 51s ago
         Docs: https://github.com/etcd-io/etcd
     Main PID: 3181 (etcd)
        Tasks: 10
       Memory: 3.3M
       CGroup: /system.slice/etcd.service
               └─3181 /usr/local/etcd/etcd --data-dir=/usr/local/etcd/data --name sht-sgmhadoopnn-01 --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379 --initial-advertise-peer-urls http://0.0.0.0:2380 --listen-peer-urls...
    
    Sep 28 17:24:12 sht-sgmhadoopnn-01 etcd[3181]: listening for peers on [::]:2380
    Sep 28 17:24:13 sht-sgmhadoopnn-01 bash[3181]: raft2019/09/28 17:24:13 INFO: 1c70f9bbb41018f is starting a new election at term 2
    Sep 28 17:24:13 sht-sgmhadoopnn-01 bash[3181]: raft2019/09/28 17:24:13 INFO: 1c70f9bbb41018f became candidate at term 3
    Sep 28 17:24:13 sht-sgmhadoopnn-01 bash[3181]: raft2019/09/28 17:24:13 INFO: 1c70f9bbb41018f received MsgVoteResp from 1c70f9bbb41018f at term 3
    Sep 28 17:24:13 sht-sgmhadoopnn-01 bash[3181]: raft2019/09/28 17:24:13 INFO: 1c70f9bbb41018f became leader at term 3
    Sep 28 17:24:13 sht-sgmhadoopnn-01 bash[3181]: raft2019/09/28 17:24:13 INFO: raft.node: 1c70f9bbb41018f elected leader 1c70f9bbb41018f at term 3
    Sep 28 17:24:13 sht-sgmhadoopnn-01 etcd[3181]: published {Name:sht-sgmhadoopnn-01 ClientURLs:[http://0.0.0.0:2379]} to cluster a0d2de0531db7884
    Sep 28 17:24:13 sht-sgmhadoopnn-01 etcd[3181]: ready to serve client requests
    Sep 28 17:24:13 sht-sgmhadoopnn-01 etcd[3181]: serving insecure client requests on [::]:2379, this is strongly discouraged!
    Sep 28 17:24:13 sht-sgmhadoopnn-01 systemd[1]: Started etcd service.

     以服务模式启动

    # cat /usr/lib/systemd/system/etcd.service 
    [Unit]
    Description=etcd service
    Documentation=https://github.com/etcd-io/etcd
    After=network.target
    After=network-online.target
    Wants=network-online.target
    
    [Service]
    User=tnuser
    Type=notify
    EnvironmentFile=/usr/local/etcd/etcd.conf
    WorkingDirectory=/usr/local/etcd
    ExecStart=/usr/local/etcd/etcd
    Restart=always
    RestartSec=10s
    LimitNOFILE=65536
    
    [Install]
    WantedBy=multi-user.target
    # cat /usr/local/etcd/etcd.conf 
    ETCD_NAME="sht-sgmhadoopnn-01"
    ETCD_DATA_DIR="/usr/local/etcd/data"
    ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
    ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379,http://127.0.0.1:2379"
    ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
    ETCD_INITIAL_ADVERTISE_PEER_URLS="http://0.0.0.0:2380,http://127.0.0.1:2380"
    ETCD_ENABLE_V2="true"
  • 相关阅读:
    引自天天安全网 ——※ 中华民族传统文化精髓___二十四孝 ※
    Microsoft 技术与安全大会
    Linux的用户和用户组管理
    vsftpd设置与使用总结
    MySQL与NoSQL——SQL与NoSQL的融合
    linux下查看用户及用户组的方法
    软件系统开发中的数据交换协议
    Ubuntu实用简单的FTP架设
    淘宝网商品库优化实践访谈
    current attention url
  • 原文地址:https://www.cnblogs.com/ilifeilong/p/11603526.html
Copyright © 2011-2022 走看看