预置剧本
如何使用预置的 ansible 剧本来管理 INFRA 集群,常用管理命令速查。
Module:
Categories:
Pigsty 提供了三个与 INFRA 模块相关的剧本:
infra.yml
:在 infra 节点上初始化 pigsty 基础设施infra-rm.yml
:从 infra 节点移除基础设施组件install.yml
:在当前节点上一次性完整安装 Pigsty
infra.yml
INFRA 模块剧本 infra.yml
用于在配置文件的 infra
分组所定义的 Infra节点 上初始化基础设施模块
执行该剧本将完成以下任务
- 配置 Infra节点 的目录与环境变量
- 下载并创建本地软件仓库,加速后续安装。(若使用离线软件包,或检测到已经存在本地软件源,则跳过本阶段)
- 将当前 Infra节点 作为一个 普通节点 纳入 Pigsty 管理
- 部署基础设施组件,包括 Prometheus, Grafana, Loki, Alertmanager, PushGateway,Blackbox Exporter 等
该剧本默认在 infra
分组上执行
- Pigsty 会在配置文件中固定名为
infra
的分组上安装INFRA
模块 - Pigsty 会在 configure 过程中默认将当前安装节点标记为 Infra节点,并使用 当前节点首要IP地址 替换配置模板中的占位IP地址
10.10.10.10
。 - 该节点除了可以发起管理,部署有基础设施,与一个部署普通托管节点并无区别。
剧本注意事项
- 本剧本为幂等剧本,重复执行会 抹除 Infra节点 上的基础设施组件。
- 除非设置
prometheus_clean
为false
,否则 Prometheus 监控指标时序数据会丢失。 - 除非设置
loki_clean
为false
,否则 Loki 日志数据会丢失, - 除非设置
grafana_clean
为false
,否则 Grafana 监控面板与配置修改会丢失
- 除非设置
- 当本地软件仓库
/www/pigsty/repo_complete
存在时,本剧本会跳过从互联网下载软件的任务。- 完整执行该剧本耗时约1~3分钟,视机器配置与网络条件而异。
- 不使用离线软件包而直接从互联网原始上游下载软件时,可能耗时5-10分钟,根据您的网络条件而异。
执行演示
可用任务
以下为 infra.yml
剧本中可用的任务列表:
#--------------------------------------------------------------#
# Tasks
#--------------------------------------------------------------#
# ca : create self-signed CA on localhost files/pki
# - ca_dir : create CA directory
# - ca_private : generate ca private key: files/pki/ca/ca.key
# - ca_cert : signing ca cert: files/pki/ca/ca.crt
#
# id : generate node identity
#
# repo : bootstrap a local yum repo from internet or offline packages
# - repo_dir : create repo directory
# - repo_check : check repo exists
# - repo_prepare : use existing repo if exists
# - repo_build : build repo from upstream if not exists
# - repo_upstream : handle upstream repo files in /etc/yum.repos.d
# - repo_remove : remove existing repo file if repo_remove == true
# - repo_add : add upstream repo files to /etc/yum.repos.d
# - repo_url_pkg : download packages from internet defined by repo_url_packages
# - repo_cache : make upstream yum cache with yum makecache
# - repo_boot_pkg : install bootstrap pkg such as createrepo_c,yum-utils,...
# - repo_pkg : download packages & dependencies from upstream repo
# - repo_create : create a local yum repo with createrepo_c & modifyrepo_c
# - repo_use : add newly built repo into /etc/yum.repos.d
# - repo_nginx : launch a nginx for repo if no nginx is serving
#
# node/haproxy/docker/monitor : setup infra node as a common node (check node.yml)
# - node_name, node_hosts, node_resolv, node_firewall, node_ca, node_repo, node_pkg
# - node_feature, node_kernel, node_tune, node_sysctl, node_profile, node_ulimit
# - node_data, node_admin, node_timezone, node_ntp, node_crontab, node_vip
# - haproxy_install, haproxy_config, haproxy_launch, haproxy_reload
# - docker_install, docker_admin, docker_config, docker_launch, docker_image
# - haproxy_register, node_exporter, node_register, promtail
#
# infra : setup infra components
# - infra_env : env_dir, env_pg, env_pgadmin, env_var
# - infra_pkg : infra_pkg_yum, infra_pkg_pip
# - infra_user : setup infra os user group
# - infra_cert : issue cert for infra components
# - dns : dns_config, dns_record, dns_launch
# - nginx : nginx_config, nginx_cert, nginx_static, nginx_launch, nginx_certbot, nginx_reload, nginx_exporter
# - prometheus : prometheus_clean, prometheus_dir, prometheus_config, prometheus_launch, prometheus_reload
# - alertmanager : alertmanager_config, alertmanager_launch
# - pushgateway : pushgateway_config, pushgateway_launch
# - blackbox : blackbox_config, blackbox_launch
# - grafana : grafana_clean, grafana_config, grafana_launch, grafana_provision
# - loki : loki clean, loki_dir, loki_config, loki_launch
# - infra_register : register infra components to prometheus
#--------------------------------------------------------------#
infra-rm.yml
INFRA模块剧本 infra-rm.yml
用于从配置文件 infra
分组定义的 Infra节点 上移除 Pigsty 基础设施
常用子任务包括:
./infra-rm.yml # 移除 INFRA 模块
./infra-rm.yml -t service # 停止 INFRA 上的基础设施服务
./infra-rm.yml -t data # 移除 INFRA 上的存留数据
./infra-rm.yml -t package # 卸载 INFRA 上安装的软件包
install.yml
INFRA模块剧本 install.yml
用于在 所有节点 上一次性完整安装 Pigsty。
该剧本在 剧本:一次性安装 中有更详细的介绍。