etcd数据库集群部署

1、下载安装
二进制下载:
https://github.com/coreos/etcd/releases/download/v3.3.13/etcd-v3.3.13-linux-amd64.tar.gz

 1 [root@k8s-master01 ~]# tar xf etcd-v3.3.13-linux-amd64.tar.gz 
 2 [root@k8s-master01 ~]# cd etcd-v3.3.13-linux-amd64
 3 [root@k8s-master01 etcd-v3.3.13-linux-amd64]# ll
 4 总用量 29776
 5 drwxr-xr-x 10 1000 1000 4096 5月 3 2019 Documentation
 6 -rwxr-xr-x 1 1000 1000 16927136 5月 3 2019 etcd
 7 -rwxr-xr-x 1 1000 1000 13498880 5月 3 2019 etcdctl
 8 -rw-r--r-- 1 1000 1000 38864 5月 3 2019 README-etcdctl.md
 9 -rw-r--r-- 1 1000 1000 7262 5月 3 2019 README.md
10 -rw-r--r-- 1 1000 1000 7855 5月 3 2019 READMEv2-etcdctl.md

只有etcd,etcdctl两个文件有用

 

2、安装etcd

 1 #创建etcd所需要的目录
 2 [root@k8s-master01 opt]# mkdir -p etcd/{bin,cfg,ssl}
 3 #拷贝下载下来的可执行命令
 4 [root@k8s-master01 ~]# cp etcd-v3.3.13-linux-amd64/{etcd,etcdctl} /opt/etcd/bin/
 5 #拷贝我们生成的自签证书
 6 [root@k8s-master01 ~]# cp k8s/tls/etcd/{server,server-key,ca}.pem /opt/etcd/ssl/
 7 [root@k8s-master01 ~]# tree /opt/etcd
 8 /opt/etcd
 9 ├── bin
10 │   ├── etcd
11 │   └── etcdctl
12 ├── cfg
13 └── ssl
14     ├── ca.pem
15     ├── server-key.pem
16     └── server.pem

3、生成启动和配置文件
#配置文件

 

 

 1 [root@k8s-master01 ~]# cat /opt/etcd/cfg/etcd.conf 
 2 
 3 #[Member]
 4 ETCD_NAME="etcd-1"
 5 ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
 6 ETCD_LISTEN_PEER_URLS="https://etcd01:2380"
 7 ETCD_LISTEN_CLIENT_URLS="https://etcd01:2379"
 8 
 9 #[Clustering]
10 ETCD_INITIAL_ADVERTISE_PEER_URLS="https://etcd01:2380"
11 ETCD_ADVERTISE_CLIENT_URLS="https://etcd01:2379"
12 ETCD_INITIAL_CLUSTER="etcd-1=https://etcd01:2380,etcd-2=https://etcd02:2380,etcd-3=https://etcd03:2380"
13 ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
14 ETCD_INITIAL_CLUSTER_STATE="new"

 

#启动文件

 

 

 1 [root@k8s-master01 etcd]# cat /opt/etcd/etcd.service 
 2 [Unit]
 3 Description=Etcd Server
 4 After=network.target
 5 After=network-online.target
 6 Wants=network-online.target
 7 
 8 [Service]
 9 Type=notify
10 EnvironmentFile=/opt/etcd/cfg/etcd.conf
11 ExecStart=/opt/etcd/bin/etcd \
12         --name=${ETCD_NAME} \
13         --data-dir=${ETCD_DATA_DIR} \
14         --listen-peer-urls=${ETCD_LISTEN_PEER_URLS} \
15         --listen-client-urls=${ETCD_LISTEN_CLIENT_URLS},http://127.0.0.1:2379 \
16         --advertise-client-urls=${ETCD_ADVERTISE_CLIENT_URLS} \
17         --initial-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS} \
18         --initial-cluster=${ETCD_INITIAL_CLUSTER} \
19         --initial-cluster-token=${ETCD_INITIAL_CLUSTER_TOKEN} \
20         --initial-cluster-state=new \
21         --cert-file=/opt/etcd/ssl/server.pem \
22         --key-file=/opt/etcd/ssl/server-key.pem \
23         --peer-cert-file=/opt/etcd/ssl/server.pem \
24         --peer-key-file=/opt/etcd/ssl/server-key.pem \
25         --trusted-ca-file=/opt/etcd/ssl/ca.pem \
26         --peer-trusted-ca-file=/opt/etcd/ssl/ca.pem
27 Restart=on-failure
28 LimitNOFILE=65536
29 
30 [Install]
31 WantedBy=multi-user.target

 

4、拷贝etcd目录到etcd01,etcd02,etcd03机器上

1 [root@k8s-master01 ~]# scp -r /opt/etcd/ etcd01:/opt/
2 [root@k8s-master01 ~]# scp -r /opt/etcd/ etcd02:/opt/
3 [root@k8s-master01 ~]# scp -r /opt/etcd/ etcd03:/opt/

 


5、分别修改3台etcd的cfg/etcd.conf文件,IP为自己的IP
#etcd01

[root@etcd01 ~]# cat /opt/etcd/cfg/etcd.conf 

#[Member]
ETCD_NAME="etcd-1"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://10.16.8.161:2380"
ETCD_LISTEN_CLIENT_URLS="https://10.16.8.161:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://10.16.8.161:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://10.16.8.161:2379"
ETCD_INITIAL_CLUSTER="etcd-1=https://10.16.8.161:2380,etcd-2=https://10.16.8.162:2380,etcd-3=https://10.16.8.163:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

 

#etcd02

#[Member]
ETCD_NAME="etcd-2"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://10.16.8.162:2380"
ETCD_LISTEN_CLIENT_URLS="https://10.16.8.162:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://10.16.8.162:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://10.16.8.162:2379"
ETCD_INITIAL_CLUSTER="etcd-1=https://10.16.8.161:2380,etcd-2=https://10.16.8.162:2380,etcd-3=https://10.16.8.163:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

 


#etcd03

[root@etcd03 ~]# cat /opt/etcd/cfg/etcd.conf

#[Member]
ETCD_NAME="etcd-3"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://10.16.8.163:2380"
ETCD_LISTEN_CLIENT_URLS="https://10.16.8.163:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://10.16.8.163:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://10.16.8.163:2379"
ETCD_INITIAL_CLUSTER="etcd-1=https://10.16.8.161:2380,etcd-2=https://10.16.8.162:2380,etcd-3=https://10.16.8.163:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

 


6、3台etcd机器上分别拷贝etcd.service到/usr/lib/systemd/system

[root@etcd01 ~]# mv /opt/etcd/etcd.service /usr/lib/systemd/system
[root@etcd02 ~]# mv /opt/etcd/etcd.service /usr/lib/systemd/system
[root@etcd03 ~]# mv /opt/etcd/etcd.service /usr/lib/systemd/system

 

7、启动和开机启动etcd

[root@etcd01 ~]# systemctl daemon-reload
[root@etcd01 ~]# systemctl start etcd
[root@etcd01 ~]# systemctl enable etcd

 

8、查看集群状态

[root@etcd01 ~]# /opt/etcd/bin/etcdctl \
 --ca-file=/opt/etcd/ssl/ca.pem --cert-file=/opt/etcd/ssl/server.pem --key-file=/opt/etcd/ssl/server-key.pem \
 --endpoints="https://10.16.8.161:2379,https://10.16.8.162:2379,https://10.16.8.163:2379" \
 cluster-health

member 592bed4fa345de89 is healthy: got healthy result from https://10.16.8.163:2379
member 7fc93466fcfffccf is healthy: got healthy result from https://10.16.8.162:2379
member d83d38380a38f404 is healthy: got healthy result from https://10.16.8.161:2379
cluster is healthy

 

发布了468 篇原创文章 · 获赞 163 · 访问量 72万+
展开阅读全文

etcd交予systemd管理,start时状态217不成功

02-05

日志信息如下: ``` Feb 06 05:04:48 master-15 systemd[1]: Unit etcd.service entered failed state. Feb 06 05:04:48 master-15 systemd[1]: etcd.service failed. Feb 06 05:04:54 master-15 systemd[1]: etcd.service holdoff time over, scheduling restart. Feb 06 05:04:54 master-15 systemd[1]: Starting Etcd Server... -- Subject: Unit etcd.service has begun start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit etcd.service has begun starting up. Feb 06 05:04:54 master-15 systemd[16498]: Failed at step USER spawning /usr/bin/etcd: No such pr -- Subject: Process /usr/bin/etcd could not be executed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- The process /usr/bin/etcd could not be executed and failed. -- -- The error number returned by this process is 3. Feb 06 05:04:54 master-15 systemd[1]: etcd.service: main process exited, code=exited, status=217 Feb 06 05:04:54 master-15 systemd[1]: Failed to start Etcd Server. -- Subject: Unit etcd.service has failed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit etcd.service has failed. -- -- The result is failed. Feb 06 05:04:54 master-15 systemd[1]: Unit etcd.service entered failed state. Feb 06 05:04:54 master-15 systemd[1]: etcd.service failed. ``` etcd.service如下: ``` [Unit] Description=Etcd Server After=network.target After=network-online.target Wants=network-online.target [Service] Type=notify WorkingDirectory=/var/lib/etcd/ User=etcd # set GOMAXPROCS to number of processors ExecStart=/usr/bin/etcd \ --name=etcd1 \ --cert-file=/etc/kubernetes/ssl/etcd.pem \ --key-file=/etc/kubernetes/ssl/etcd-key.pem \ --peer-cert-file=/etc/kubernetes/ssl/etcd.pem \ --peer-key-file=/etc/kubernetes/ssl/etcd-key.pem \ --trusted-ca-file=/etc/kubernetes/ssl/ca.pem \ --peer-trusted-ca-file=/etc/kubernetes/ssl/ca.pem \ --initial-advertise-peer-urls=https://192.168.230.15:2380 \ --listen-peer-urls=https://192.168.230.15:2380 \ --listen-client-urls=https://192.168.230.15:2379,http://127.0.0.1:2379 \ --advertise-client-urls=https://192.168.230.15:2379 \ --initial-cluster-token=k8s-etcd-cluster \ --initial-cluster=etcd1=https://192.168.230.15:2380 \ --initial-cluster-state=new \ --data-dir=/var/lib/etcd Restart=on-failure RestartSec=5 LimitNOFILE=65536 [Install] WantedBy=multi-user.target ``` 问答

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

©️2019 CSDN 皮肤主题: 精致技术 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览