如何在Ubuntu 18.04/Ubuntu 16.04上安装etcd
时间:2020-02-23 14:32:09 来源:igfitidea点击:
Etcd是用Go编写的简单,可靠,快速和安全的开源键值存储。它使用Raft共识算法来管理高可用性的复制日志。在本教程中,我们将在Ubuntu 18.04/Ubuntu 16.04上安装单个节点(一个成员)etcd。
在Ubuntu 18.04/Ubuntu 16.04上安装etcd
尽管我们可以从源代码构建Etcd,但它作为二进制包分发。在本教程中,将下载预构建的二进制程序包。
在继续获取最新的发行标签之前,请检查预构建的发行二进制文件。
在Ubuntu 18.04/Ubuntu 16.04上下载最新版本的etcd:
sudo apt -y install wget export RELEASE="3.3.13" wget https://github.com/etcd-io/etcd/releases/download/v${RELEASE}/etcd-v${RELEASE}-linux-amd64.tar.gz
解压缩下载的存档文件。
tar xvf etcd-v${RELEASE}-linux-amd64.tar.gz
切换到新文件目录
cd etcd-v${RELEASE}-linux-amd64
将etcd
和etcdctl
二进制文件移至/usr/local/bin
目录。
sudo mv etcd etcdctl /usr/local/bin
确认版本。
$etcd --version etcd Version: 3.3.13 Git SHA: 98d3084 Go Version: go1.10.8 Go OS/Arch: linux/amd64
创建Etcd配置文件和数据目录。
sudo mkdir -p /var/lib/etcd/ sudo mkdir /etc/etcd
创建etcd系统用户
sudo groupadd --system etcd sudo useradd -s /sbin/nologin --system -g etcd etcd
将/var/lib/etcd /
目录所有权设置为etcd
用户。
sudo chown -R etcd:etcd /var/lib/etcd/
配置Systemd并启动etcd服务
为etcd创建一个新的systemd服务文件。
sudo vim /etc/systemd/system/etcd.service
将以下数据粘贴到文件中。
[Unit] Description=etcd key-value store Documentation=https://github.com/etcd-io/etcd After=network.target [Service] User=etcd Type=notify Environment=ETCD_DATA_DIR=/var/lib/etcd Environment=ETCD_NAME=%m ExecStart=/usr/local/bin/etcd Restart=always RestartSec=10s LimitNOFILE=40000 [Install] WantedBy=multi-user.target
在Ubuntu 18,04/Ubuntu 16,04上重新加载systemd服务并启动etcd
sudo systemctl daemon-reload sudo systemctl start etcd.service
检查服务状态:
$sudo systemctl status etcd.service ● etcd.service - etcd key-value store Loaded: loaded (/etc/systemd/system/etcd.service; disabled; vendor preset: enabled) Active: active (running) since Sat 2019-01-05 00:54:20 EAT; 23s ago Docs: https://github.com/etcd-io/etcd Main PID: 8792 (etcd) Tasks: 13 (limit: 4915) CGroup: /system.slice/etcd.service └─8792 /usr/local/bin/etcd Ama 05 00:54:20 mynix etcd[8792]: 8e9e05c52164694d received MsgVoteResp from 8e9e05c52164694d at term 2 Ama 05 00:54:20 mynix etcd[8792]: 8e9e05c52164694d became leader at term 2 Ama 05 00:54:20 mynix etcd[8792]: raft.node: 8e9e05c52164694d elected leader 8e9e05c52164694d at term 2 Ama 05 00:54:20 mynix etcd[8792]: setting up the initial cluster version to 3.3 Ama 05 00:54:20 mynix etcd[8792]: set the initial cluster version to 3.3 Ama 05 00:54:20 mynix etcd[8792]: enabled capabilities for version 3.3 Ama 05 00:54:20 mynix etcd[8792]: ready to serve client requests Ama 05 00:54:20 mynix etcd[8792]: published {Name:5fbf3d068d6c491eb687a7a427fc2263 ClientURLs:[http://localhost:2379]} to cluster cdf818194e3a8c32 Ama 05 00:54:20 mynix systemd[1]: Started etcd key-value store. Ama 05 00:54:20 mynix etcd[8792]: serving insecure client requests on 127.0.0.1:2379, this is strongly discouraged!
该服务将在本地主机地址端口" 2379"上启动
$ss -tunelp | grep 2379 tcp LISTEN 0 128 127.0.0.1:2379 0.0.0.0:* uid:998 ino:72981 sk:45c <-> $etcdctl member list 8e9e05c52164694d: name=5fbf3d068d6c491eb687a7a427fc2263 peerURLs=http://localhost:2380 clientURLs=http://localhost:2379 isLeader=true