Installing and configuring etcd
Installation
Debian/Ubuntu packages
To install etcd from the official Debian/Ubuntu apt repositories:
sudo apt-get -y install etcd
You can check the version installed and the latest available version. If the version installed is out of date and you want to install the latest one, use the prebuilt binaries method.
RedHat-compatible packages
The PGDG yum extras repositories contains etcd packages.
To set up and use yum.postgresql.org on your systems, see the PostgreSQL Linux downloads website.
Depending on your system, enable the following repositories:
- RHEL 9: pgdg-rhel9-extras
- RHEL 8: pgdg-rhel8-extras
- RHEL 7: pgdg-rhel7-extras
For example, this command installs etcd on RHEL 8:
sudo dnf --enablerepo=pgdg-rhel8-extras install -y etcd
You can check the version installed and the latest available version. If the version installed is out of date and you want to install the latest one, use the prebuilt binaries method.
Prebuilt binaries
These commands output the version of the installed etcd binary and get the latest version from the etcd-io website:
etcd --version |head -1
etcd Version: 3.5.7
ETCD_RELEASE=$(curl -s https://api.github.com/repos/etcd-io/etcd/releases/latest|grep tag_name | cut -d '"' -f 4) echo
Latest etcd version released: v3.5.7
The easiest way to install the etcd latest release is from prebuilt binaries.
On amd64
hosts, use the following commands:
ETCD_RELEASE=$(curl -s https://api.github.com/repos/etcd-io/etcd/releases/latest|grep tag_name | cut -d '"' -f 4) curl -sL https://github.com/etcd-io/etcd/releases/download/${ETCD_RELEASE}/etcd-${ETCD_RELEASE}-linux-amd64.tar.gz \ | sudo tar xz -C /usr/bin --strip=1 --wildcards --no-anchored etcdctl etcd etcd --version |head -1
etcd Version: 3.5.7
Then, create the data directory and system user:
sudo mkdir -p /var/lib/etcd/ sudo mkdir /etc/etcd sudo groupadd --system etcd sudo useradd -s /sbin/nologin --system -g etcd etcd sudo chown -R etcd:etcd /var/lib/etcd/ sudo chmod -R a+rw /var/lib/etcd
Configure the systemd unit file:
cat <<EOF | sudo tee /etc/systemd/system/etcd.service [Unit] Description=etcd key-value store Documentation=https://github.com/etcd-io/etcd After=network-online.target local-fs.target remote-fs.target time-sync.target Wants=network-online.target local-fs.target remote-fs.target time-sync.target [Service] User=etcd Type=notify Environment=ETCD_DATA_DIR=/var/lib/etcd Environment=ETCD_NAME=%H EnvironmentFile=-/etc/etcd/etcd.conf ExecStart=/usr/bin/etcd Restart=always RestartSec=10s LimitNOFILE=40000 [Install] WantedBy=multi-user.target EOF sudo systemctl daemon-reload
Configuration
Configure the firewall if needed:
sudo firewall-cmd --quiet --zone=public --add-port=2379/tcp --permanent sudo firewall-cmd --quiet --zone=public --add-port=2380/tcp --permanent sudo firewall-cmd --quiet --reload
To configure and create a new etcd cluster, you need to define the initial cluster configuration by setting the ETCD_INITIAL_CLUSTER
variable. That list must contain all the etcd hosts and their IP addresses.
This example shows three etcd hosts: