igor_nikiforov.etcd
Ansible角色:etcd
该角色在目标主机上配置etcd和etcdctl。支持所有etcd配置选项,并力求尽可能灵活。
要求
该角色是在以下Ansible版本上开发和测试的:
名称 | 版本 |
---|---|
ansible | >= 2.9.13 |
ansible-base | >= 2.10.1 |
其他Ansible版本未经过测试,但可能会工作。
安装
使用 ansible-galaxy install igor_nikiforov.etcd
安装该角色的最新稳定版本。
您也可以通过要求文件安装 ansible-galaxy install -r requirements.yml
:
# requirements.yml
---
roles:
- name: igor_nikiforov.etcd
version: v1.0.0
平台
名称 | 版本 |
---|---|
Debian | buster, bullseye |
Ubuntu | focal, jammy |
CentOS | 7.4+, stream8 |
RedHat | 7.4+, 8 |
其他操作系统发行版未经过测试,但可能会工作。如有问题,请提交PR!
变量
名称 | 描述 | 默认值 |
---|---|---|
etcd_version | 要安装的etcd版本 | 3.4.13 |
etcd_user | etcd用户 | etcd |
etcd_group | etcd组 | etcd |
etcd_config | etcd配置参数的键值列表。 | {} |
etcd_service_enabled | 服务是否在启动时启动。 | True |
etcd_service_state | etcd服务状态。 | started |
etcdctl_output_format | 在etcdctl中使用的输出格式。 | table |
用法
该角色支持可以通过 etcd_config
变量传递的所有etcd配置参数。您可以在etcd官方库中找到YAML配置格式的示例,并在etcd官方文档中找到所有可用标志及其描述。
etcd支持两种主要方法来构建集群:
-
在剧本执行后,您应该手动使用
etcdctl member add
命令从其中一个主机添加每个成员。假设您会手动执行此操作或在单独的Ansible任务中自动化。 -
此处的主要前提是您的DNS本地域中必须准备好SRV和A记录。请仔细检查DNS记录的要求,这些记录应该提前创建。如果一切创建得当,则需要将以下与DNS发现相关的属性添加到
etcd_config
:etcd_config: discovery-srv: "company.local" discovery-srv-name: "dev" # 可选
在剧本执行后,etcd集群将自动创建。强烈建议在生产环境中使用此方法。
重要提示:
- 不要忘记在第一次执行后在剧本中将
etcd_config.initial-cluster-state
从new
修改为existing
。 - 在构建集群后,在您的剧本中使用
serial: 1
以安全更新配置更改。更多信息请见这里。
示例
静态
# playbook.yml
---
- hosts: all
become: True
gather_facts: False
pre_tasks:
- wait_for_connection: {timeout: 300}
- setup:
tasks:
- name: 安装etcd
import_role:
name: etcd
vars:
etcd_version: "3.4.13"
etcd_config:
name: "{{ ansible_facts.hostname }}"
data-dir: "/var/lib/etcd/data"
wal-dir: "/var/lib/etcd/wal"
initial-advertise-peer-urls: "https://{{ ansible_facts.fqdn }}:2380"
initial-cluster-token: "token"
initial-cluster-state: "new"
advertise-client-urls: "https://{{ ansible_facts.fqdn }}:2379"
listen-client-urls: "https://{{ ansible_default_ipv4.address }}:2379,https://127.0.0.1:2379"
listen-peer-urls: "https://{{ ansible_default_ipv4.address }}:2380"
client-transport-security:
trusted-ca-file: "{{ etcd_conf_dir }}/certs/ca.crt"
cert-file: "{{ etcd_conf_dir }}/certs/server.crt"
key-file: "{{ etcd_conf_dir }}/certs/server.key"
peer-transport-security:
trusted-ca-file: "{{ etcd_conf_dir }}/certs/ca.crt"
cert-file: "{{ etcd_conf_dir }}/certs/server.crt"
key-file: "{{ etcd_conf_dir }}/certs/server.key"
log-level: "debug"
logger: "zap"
DNS发现
# playbook.yml
---
- hosts: all
become: True
gather_facts: False
pre_tasks:
- wait_for_connection: {timeout: 300}
- setup:
tasks:
- name: 安装etcd
import_role:
name: etcd
vars:
etcd_version: "3.4.13"
etcd_config:
name: "{{ ansible_facts.hostname }}"
data-dir: "/var/lib/etcd/data"
wal-dir: "/var/lib/etcd/wal"
discovery-srv: "company.local"
initial-advertise-peer-urls: "https://{{ ansible_facts.fqdn }}:2380"
initial-cluster-token: "token"
initial-cluster-state: "new"
advertise-client-urls: "https://{{ ansible_facts.fqdn }}:2379"
listen-client-urls: "https://{{ ansible_default_ipv4.address }}:2379,https://127.0.0.1:2379"
listen-peer-urls: "https://{{ ansible_default_ipv4.address }}:2380"
client-transport-security:
trusted-ca-file: "{{ etcd_conf_dir }}/certs/ca.crt"
cert-file: "{{ etcd_conf_dir }}/certs/server.crt"
key-file: "{{ etcd_conf_dir }}/certs/server.key"
peer-transport-security:
trusted-ca-file: "{{ etcd_conf_dir }}/certs/ca.crt"
cert-file: "{{ etcd_conf_dir }}/certs/server.crt"
key-file: "{{ etcd_conf_dir }}/certs/server.key"
log-level: "debug"
logger: "zap"
许可证
MIT