https://etcd.io/docs/v3.6/install/
Install pre-built binaries
- Download the compressed archive file for your platform from Releases
ETCD_VER=v3.6.6
# choose either URL
GOOGLE_URL=https://storage.googleapis.com/etcd
GITHUB_URL=https://github.com/etcd-io/etcd/releases/download
DOWNLOAD_URL=${GOOGLE_URL}
curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
- Unpack the archive file. This results in a directory containing the binaries.
tar xvf etcd-${ETCD_VER}-linux-amd64.tar.gz
- Add the executable binaries to your path. For example, rename and/or move the binaries to a directory in your path (like
/usr/local/bin), or add the directory created by the previous step to your path.
cd etcd-${ETCD_VER}-linux-amd64
sudo mv etcd etcdctl etcdutl /usr/local/bin/
- From a shell, test that
etcdis in your path:
$ etcd --version
etcd Version: 3.6.6
...
Add etcd to systemd
- Start by creating a configuration and data directory for the etcd service.
$ sudo mkdir -p /var/lib/etcd/default
$ sudo mkdir /etc/etcd/
- Change the ownership of the
/var/lib/etcddirectory to your target user.
$ sudo useradd etcd -r -s /sbin/nologin
$ sudo chown -R etcd:etcd /var/lib/etcd
- Create
/etc/systemd/system/etcd.serviceand add the following content to it.
[Unit]
Description=etcd - highly-available key value store
Documentation=https://etcd.io/docs
After=network.target
Wants=network-online.target
[Service]
# Using non-login system users.
User=etcd
Group=etcd
# Load environment variables from an optional configuration file
# For example: /etc/default/etcd
EnvironmentFile=-/etc/default/%p
# Set the working directory of the process
WorkingDirectory=/var/lib/etcd/default
Type=notify
# The main command to start etcd
# $DAEMON_ARGS will be replaced by the value in the EnvironmentFile or the Environment directive.
ExecStart=/usr/local/bin/etcd $DAEMON_ARGS
Restart=on-abnormal
RestartSec=10s
# Set a high file descriptor limit for etcd
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
- Configuration file
/etc/default/etcd
A single-node etcd instance (used for development or simple applications).
DAEMON_ARGS="\
--name etcd-node1 \
--data-dir /var/lib/etcd/default \
--listen-client-urls http://172.20.42.221:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://172.20.42.221:2379 \
"
- Run the etcd
sudo systemctl daemon-reload
sudo systemctl start etcd
%p is a specifier provided by systemd, and can be considered a dynamic variable.
-
Meaning: It represents the “prefix name” or “primary name” of the unit. Specifically, it’s the part of the unit filename without the type suffix (
.service,.target, etc.). -
In your example:
-
Your service filename is
etcd.service. -
When
systemdparses this file, it automatically replaces%pwithetcd. -
Therefore, the line
EnvironmentFile=-/etc/default/%pis ultimately interpreted asEnvironmentFile=-/etc/default/etcd.
-
EnvironmentFile=:Load environment variable file
This command tells systemd to read environment variables from a specified file before starting the service.
-
Function:
i.
systemdwill open this file.ii. It will read the file content line by line, looking for lines in the format
KEY=VALUE.iii. For each valid key-value pair,
systemdwill set an environment variable with the same name for the service process that is about to start. -
File Format: This file is a simple list of key-value pairs, and comments can begin with
#. For example, the content of the/etc/default/etcdfile could be:# /etc/default/etcd # # Etcd daemon arguments DAEMON_ARGS="--name my-etcd-1 --initial-cluster-token etcd-cluster-1 --listen-client-urls http://0.0.0.0:2379" # Other environment variables ETCD_HEARTBEAT_INTERVAL=100 ETCD_ELECTION_TIMEOUT=1000When the service starts,
$DAEMON_ARGSin the commandExecStart=/usr/local/bin/etcd $DAEMON_ARGSwill be replaced with the long string defined above.
Comments