ETCD的安装

0,操作用户与环境

# whoami
root
# uname -a
Linux VM_0_2_centos 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

1,添加etcd用户及用户组

groupadd etcd && useradd -c "Etcd user" -g etcd -s /sbin/nologin -r etcd

etcd用户

tail /etc/passwd
etcd:x:995:1001:Etcd user:/home/etcd:/sbin/nologin

2,下载二进制文件

DOWNLOAD_URL=https://storage.googleapis.com/etcd  #etcd存储地址
ETCD_VER=v3.1.5  #设置etcd版本号
wget ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz
tar xvf etcd-${ETCD_VER}-linux-amd64.tar.gz

3,部署文件

将如下内容写入文件 /etc/etcd/etcd.conf 中:

# [member]
ETCD_NAME=default
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
# ETCD_WAL_DIR=""
# ETCD_SNAPSHOT_COUNT="10000"
# ETCD_HEARTBEAT_INTERVAL="100"
# ETCD_ELECTION_TIMEOUT="1000"
# ETCD_LISTEN_PEER_URLS="http://localhost:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
# ETCD_MAX_SNAPSHOTS="5"
# ETCD_MAX_WALS="5"
# ETCD_CORS=""
#
# [cluster]
# ETCD_INITIAL_ADVERTISE_PEER_URLS="http://localhost:2380"
# if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."
# ETCD_INITIAL_CLUSTER="default=http://localhost:2380"
# ETCD_INITIAL_CLUSTER_STATE="new"
# ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"
# ETCD_DISCOVERY=""
# ETCD_DISCOVERY_SRV=""
# ETCD_DISCOVERY_FALLBACK="proxy"
# ETCD_DISCOVERY_PROXY=""
#
# [proxy]
# ETCD_PROXY="off"
# ETCD_PROXY_FAILURE_WAIT="5000"
# ETCD_PROXY_REFRESH_INTERVAL="30000"
# ETCD_PROXY_DIAL_TIMEOUT="1000"
# ETCD_PROXY_WRITE_TIMEOUT="5000"
# ETCD_PROXY_READ_TIMEOUT="0"
#
# [security]
# ETCD_CERT_FILE=""
# ETCD_KEY_FILE=""
# ETCD_CLIENT_CERT_AUTH="false"
# ETCD_TRUSTED_CA_FILE=""
# ETCD_PEER_CERT_FILE=""
# ETCD_PEER_KEY_FILE=""
# ETCD_PEER_CLIENT_CERT_AUTH="false"
# ETCD_PEER_TRUSTED_CA_FILE=""
# [logging]
# ETCD_DEBUG="false"
# examples for -log-package-levels etcdserver=WARNING,security=DEBUG
# ETCD_LOG_PACKAGE_LEVELS=""

记得创建 目录

#mkdir -p /var/lib/etcd/default.etcd 

并修改权限

#chown -R etcd:etcd /var/lib/etcd/

4,将 etcd, etcdctl放入 /usr/bin/下,并将如下内容写进/usr/lib/systemd/system/etcd.service文

#cd etcd-${ETCD_VER}-linux-amd64
#cp etcd /usr/bin/
#cp etcdctl /usr/bin/

[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
User=etcd
# set GOMAXPROCS to number of processors
ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name=\"${ETCD_NAME}\" --data-dir=\"${ETCD_DATA_DIR}\" --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\""
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

5,运行

#systemctl start etcd.service && systemctl enable etcd
#systemctl status etcd
● etcd.service - Etcd Server
   Loaded: loaded (/usr/lib/systemd/system/etcd.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2018-06-22 14:04:50 CST; 13min ago
 Main PID: 4818 (etcd)
   CGroup: /system.slice/etcd.service
           └─4818 /usr/bin/etcd --name=default --data-dir=/var/lib/etcd/default.etcd --listen-client-urls=http://0.0.0.0:2379

Jun 22 14:04:50 VM_0_2_centos etcd[4818]: 8e9e05c52164694d received MsgVoteResp from 8e9e05c52164694d at term 2
Jun 22 14:04:50 VM_0_2_centos etcd[4818]: 8e9e05c52164694d became leader at term 2
Jun 22 14:04:50 VM_0_2_centos etcd[4818]: raft.node: 8e9e05c52164694d elected leader 8e9e05c52164694d at term 2
Jun 22 14:04:50 VM_0_2_centos etcd[4818]: setting up the initial cluster version to 3.1
Jun 22 14:04:50 VM_0_2_centos etcd[4818]: published {Name:default ClientURLs:[http://0.0.0.0:2379]} to cluster cdf818194e3a8c32
Jun 22 14:04:50 VM_0_2_centos etcd[4818]: ready to serve client requests
Jun 22 14:04:50 VM_0_2_centos etcd[4818]: serving insecure client requests on [::]:2379, this is strongly discouraged!
Jun 22 14:04:50 VM_0_2_centos systemd[1]: Started Etcd Server.
Jun 22 14:04:50 VM_0_2_centos etcd[4818]: set the initial cluster version to 3.1
Jun 22 14:04:50 VM_0_2_centos etcd[4818]: enabled capabilities for version 3.1
#netstat -anp|grep 2379
tcp6       0      0 :::2379                 :::*                    LISTEN      4818/etcd

资料来源:

1,在CentOS上安装kubernetes详细指 (笔者注: 缺少etcd用户以及文件夹的权限,故在本文章里填一下坑)

没有更多推荐了,返回首页