CentOS 7 ETCD集群部署

一、前言
Etcd 是 CoreOS 基于 Raft 开发的分布式 key-value 存储,可用于服务发现、共享配置以及一致性保障(如数据库选主、分布式锁等)

Etcd 集群配置分为三种:
静态发现
Etcd 动态发现
DNS 动态发现 通过DNS的SRV解析动态发现集群

二、环境准备

主机名ip系统版本
etcd0192.168.1.85Centos 7
etcd1192.168.1.86Centos 7
etcd2192.168.1.87Centos 7

1.1、在三台机器上均执行

[root@etcd0 ~]# yum install etcd -y
[root@etcd0 ~]# rpm -qa etcd
etcd-3.3.11-2.el7.centos.x86_64

1.2、创建Etcd所需目录,在三台机器上均执行

mkdir /data/k8s/etcd/{data,wal} -p
chown -R etcd.etcd /data/k8s/etcd

三、配置集群
3.1、etcd0 配置文件

ETCD_DATA_DIR="/data/k8s/etcd/data"
ETCD_WAL_DIR="/data/k8s/etcd/wal"
ETCD_LISTEN_PEER_URLS="http://192.168.1.85:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.1.85:2379"
ETCD_MAX_SNAPSHOTS="5"
ETCD_MAX_WALS="5"
ETCD_NAME="etcd1"
ETCD_SNAPSHOT_COUNT="100000"
ETCD_HEARTBEAT_INTERVAL="100"
ETCD_ELECTION_TIMEOUT="1000"

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.85:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.85:2379"

ETCD_INITIAL_CLUSTER="etcd1=http://192.168.1.85:2380,etcd2=http://192.168.1.86:2380,etcd3=http://192.168.1.87:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

3.2、etcd1 配置文件

ETCD_DATA_DIR="/data/k8s/etcd/data"
ETCD_WAL_DIR="/data/k8s/etcd/wal"
ETCD_LISTEN_PEER_URLS="http://192.168.1.86:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.1.86:2379"
ETCD_MAX_SNAPSHOTS="5"
ETCD_MAX_WALS="5"
ETCD_NAME="etcd2"
ETCD_SNAPSHOT_COUNT="100000"
ETCD_HEARTBEAT_INTERVAL="100"
ETCD_ELECTION_TIMEOUT="1000"

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.86:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.86:2379"

ETCD_INITIAL_CLUSTER="etcd1=http://192.168.1.85:2380,etcd2=http://192.168.1.86:2380,etcd3=http://192.168.1.87:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

3.3、etcd2 配置文件

ETCD_DATA_DIR="/data/k8s/etcd/data"
ETCD_WAL_DIR="/data/k8s/etcd/wal"
ETCD_LISTEN_PEER_URLS="http://192.168.1.87:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.1.87:2379"
ETCD_MAX_SNAPSHOTS="5"
ETCD_MAX_WALS="5"
ETCD_NAME="etcd3"
ETCD_SNAPSHOT_COUNT="100000"
ETCD_HEARTBEAT_INTERVAL="100"
ETCD_ELECTION_TIMEOUT="1000"

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.87:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.87:2379"

ETCD_INITIAL_CLUSTER="etcd1=http://192.168.1.85:2380,etcd2=http://192.168.1.86:2380,etcd3=http://192.168.1.87:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

四、启动测试(三个节点都需要操作)

[root@etcd0 etcd]# systemctl start etcd
[root@etcd0 etcd]# systemctl status etcd
● etcd.service - Etcd Server
   Loaded: loaded (/usr/lib/systemd/system/etcd.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2019-11-07 09:28:54 CST; 5s ago
 Main PID: 1546 (etcd)
    Tasks: 8
   Memory: 41.3M
   CGroup: /system.slice/etcd.service
           └─1546 /usr/bin/etcd --name=etcd1 --data-dir=/data/k8s/etcd/data --listen-client-urls=http://192.168.1.85:2379

Nov 07 09:28:54 etcd0.k8s.com etcd[1546]: 3b8b38de05e2c497 [term: 1] received a MsgVote message with higher term from 9c64fba479c5e94 [term: 2]
Nov 07 09:28:54 etcd0.k8s.com etcd[1546]: 3b8b38de05e2c497 became follower at term 2
Nov 07 09:28:54 etcd0.k8s.com etcd[1546]: 3b8b38de05e2c497 [logterm: 1, index: 3, vote: 0] cast MsgVote for 9c64fba479c5e94 [logterm: 1, index: 3] at term 2
Nov 07 09:28:54 etcd0.k8s.com etcd[1546]: raft.node: 3b8b38de05e2c497 elected leader 9c64fba479c5e94 at term 2
Nov 07 09:28:54 etcd0.k8s.com etcd[1546]: published {Name:etcd1 ClientURLs:[http://192.168.1.85:2379]} to cluster 19456f0bfd57284e
Nov 07 09:28:54 etcd0.k8s.com etcd[1546]: ready to serve client requests
Nov 07 09:28:54 etcd0.k8s.com etcd[1546]: serving insecure client requests on 192.168.1.85:2379, this is strongly discouraged!
Nov 07 09:28:54 etcd0.k8s.com systemd[1]: Started Etcd Server.
Nov 07 09:28:54 etcd0.k8s.com etcd[1546]: set the initial cluster version to 3.3
Nov 07 09:28:54 etcd0.k8s.com etcd[1546]: enabled capabilities for version 3.3

4.1、查看 /var/log/message 日志中,会有日下体现:

Nov  7 09:28:53 etcd1 etcd: added member 9c64fba479c5e94 [http://192.168.1.86:2380] to cluster 19456f0bfd57284e
Nov  7 09:28:53 etcd1 etcd: added member 3b8b38de05e2c497 [http://192.168.1.85:2380] to cluster 19456f0bfd57284e
Nov  7 09:28:53 etcd1 etcd: added member 76ea8679db7365b3 [http://192.168.1.87:2380] to cluster 19456f0bfd57284e

五、查看集群状态

[root@etcd0 etcd]# ETCDCTL_API=3 etcdctl --endpoints=http://192.168.1.85:2379,http://192.168.1.86:2379,http://192.168.1.87:2379 endpoint health
http://192.168.1.86:2379 is healthy: successfully committed proposal: took = 1.103545ms
http://192.168.1.87:2379 is healthy: successfully committed proposal: took = 2.122478ms
http://192.168.1.85:2379 is healthy: successfully committed proposal: took = 2.690215ms
[root@etcd0 etcd]# etcdctl --endpoints=http://192.168.1.85:2379,http://192.168.1.86:2379,http://192.168.1.87:2379 cluster-health
member 9c64fba479c5e94 is healthy: got healthy result from http://192.168.1.85:2379
member 3b8b38de05e2c497 is healthy: got healthy result from http://192.168.1.86:2379
member 76ea8679db7365b3 is healthy: got healthy result from http://192.168.1.87:2379
cluster is healthy
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是在两台 CentOS 7 服务器上部署 Apache APISIX 集群的步骤: 1. 安装必要的软件包。在两台服务器上分别运行以下命令: ``` sudo yum install -y gcc-c++ git make openssl openssl-devel pcre-devel zlib-devel ``` 2. 安装 etcd。在两台服务器上分别运行以下命令: ``` sudo curl -L https://github.com/etcd-io/etcd/releases/download/v3.5.0/etcd-v3.5.0-linux-amd64.tar.gz -o /tmp/etcd-v3.5.0-linux-amd64.tar.gz sudo tar xzf /tmp/etcd-v3.5.0-linux-amd64.tar.gz -C /usr/local/bin --strip-components=1 ``` 3. 克隆 Apache APISIX 代码。在一台服务器上运行以下命令: ``` git clone https://github.com/apache/apisix.git cd apisix/ ``` 4. 编译和安装 Apache APISIX。在一台服务器上运行以下命令: ``` sudo make deps sudo make sudo make install ``` 5. 修改 Apache APISIX 配置文件。在一台服务器上打开 `conf/config.yaml` 文件,修改以下配置: ``` node_listen: - 0.0.0.0:9080 ``` 这里将监听端口修改为 9080,因为默认的 9080、9081 端口会被 Kubernetes Ingress Controller 占用。 6. 启动 Apache APISIX。在一台服务器上运行以下命令: ``` sudo /usr/local/apisix/bin/apisix start ``` 7. 配置 etcd 集群。在另一台服务器上运行以下命令: ``` sudo /usr/local/bin/etcd --name=apisix-node2 \ --initial-advertise-peer-urls=http://<node2-ip>:2380 \ --listen-peer-urls=http://<node2-ip>:2380 \ --advertise-client-urls=http://<node2-ip>:2379 \ --listen-client-urls=http://<node2-ip>:2379 \ --initial-cluster-token=apisix-cluster \ --initial-cluster=apisix-node1=http://<node1-ip>:2380,apisix-node2=http://<node2-ip>:2380 \ --initial-cluster-state=new \ --data-dir=/var/lib/etcd ``` 这里将 `<node1-ip>` 替换为第一台服务器的 IP 地址,`<node2-ip>` 替换为第二台服务器的 IP 地址。 8. 修改 Apache APISIX 配置文件。在一台服务器上打开 `conf/config.yaml` 文件,修改以下配置: ``` etcd: host: - <node1-ip>:2379 - <node2-ip>:2379 prefix: "/apisix" ``` 这里将 `<node1-ip>` 和 `<node2-ip>` 分别替换为两台服务器的 IP 地址。 9. 启动 Apache APISIX。在一台服务器上运行以下命令: ``` sudo /usr/local/apisix/bin/apisix start ``` 10. 验证 Apache APISIX 集群是否正常工作。在任意一台服务器上运行以下命令: ``` curl -i http://<node1-ip>:9080/hello ``` 如果返回以下响应,则说明 Apache APISIX 集群已经部署成功: ``` HTTP/1.1 200 OK Content-Type: text/plain Content-Length: 5 Date: Tue, 21 Sep 2021 00:00:00 GMT Server: APISIX web server hello ``` 以上就是在两台 CentOS 7 服务器上部署 Apache APISIX 集群的步骤。希望能对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维那些事~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值