如何使用Ansible一键部署MinIO集群?

由于测试环境资源有限,本文旨在利用ansible实现4节点单硬盘MinIO集群一键部署。多节点多硬盘在MINIO_VOLUMES环境变量指定多个驱动器路径就行了,没啥区别。

hosts 文件定义

复制代码
[root@ansible ansible]# cat inventory/hosts
[all:vars]

# ansible_ssh_pass: 主机密码
# ansible_user: 主机账号

ansible_become=true
ansible_ssh_pass=123456
ansible_ssh_user=weihu
ansible_become_pass=123456
ansible_become_user=root
ansible_become_method=sudo

[minio]
192.168.10.150 
192.168.10.151
192.168.10.152
192.168.10.131

全局变量文件定义

复制代码
192.168.10.131[root@ansible ansible]# cat inventory/all.yml 
all:
    vars:
        minio_root_user: "admin"
        minio_root_password: "Rb992334%"

systemd服务配置文件定义

复制代码
[root@ansible ansible]# cat roles/minio/files/minio.service 
[Unit]
Description=MinIO
Documentation=https://minio.org.cn/docs/minio/linux/index.html
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/usr/local/bin/minio

[Service]
WorkingDirectory=/usr/local

User=minio-user
Group=minio-user
ProtectProc=invisible

EnvironmentFile=-/etc/default/minio
ExecStartPre=/bin/bash -c "if [ -z \"${MINIO_VOLUMES}\" ]; then echo \"Variable MINIO_VOLUMES not set in /etc/default/minio\"; exit 1; fi"
ExecStart=/usr/local/bin/minio server $MINIO_OPTS $MINIO_VOLUMES

# MinIO RELEASE.2023-05-04T21-44-30Z adds support for Type=notify (https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type=)
# This may improve systemctl setups where other services use `After=minio.server`
# Uncomment the line to enable the functionality
# Type=notify

# Let systemd restart this service always
Restart=always

# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536

# Specifies the maximum number of threads this process can create
TasksMax=infinity

# Disable timeout logic and wait until process is stopped
TimeoutStopSec=infinity
SendSIGKILL=no

[Install]
WantedBy=multi-user.target

# Built for ${project.name}-${project.version} (${project.name})

MinIO集群服务配置文件定义

复制代码
[root@ansible ansible]# cat roles/minio/templates/minio_environment 
# Set the hosts and volumes MinIO uses at startup
# The command uses MinIO expansion notation {x...y} to denote a
# sequential series.
#
# The following example covers four MinIO hosts
# with 4 drives each at the specified hostname and drive locations.
# The command includes the port that each MinIO server listens on
# (default 9000)

MINIO_VOLUMES="http://{{ play_hosts[0] }}:9000/data/minio http://{{ play_hosts[1] }}:9000/data/minio http://{{ play_hosts[2] }}:9000/data/minio http://{{ play_hosts[3] }}:9000/data/minio"

# Set all MinIO server options
#
# The following explicitly sets the MinIO控制台 listen address to
# port 9001 on all network interfaces. The default behavior is dynamic
# port selection.

MINIO_OPTS="--console-address :9001"

# Set the root username. This user has unrestricted permissions to
# perform S3 and administrative API operations on any resource in the
# deployment.
#
# Defer to your organizations requirements for superadmin user name.

MINIO_ROOT_USER={{ minio_root_user }}

# Set the root password
#
# Use a long, random, unique string that meets your organizations
# requirements for passwords.

MINIO_ROOT_PASSWORD={{ minio_root_password }}

MinIO集群环境部署安装

复制代码
[root@ansible ansible]# cat roles/minio/tasks/install.yml 
---
- name: 下发minio安装包到/usr/local/bin/目录并授权
  copy:
    src: minio
    dest: /usr/local/bin/
    mode: 0755
    
- name: 下发systemd配置文件
  copy:
    src: minio.service  
    dest: /usr/lib/systemd/system/
    mode: 0644
    
- name: 配置minio开机自启动
  systemd: 
    name: minio
    enabled: yes
    daemon_reload: yes
    
- name: 为minio服务创建minio-user组
  group:
    name: minio-user
    state: present
    system: yes
    
- name: 为minio服务创建minio-user用户
  user:
    name: minio-user
    group: minio-user
    state: present
    system: yes
    create_home: no
    
- name: 为minio服务创建驱动器路径并授权
  file:
    path: /data/minio
    state: directory
    mode: '0755'
    owner: minio-user
    group: minio-user

- name: 下发minio集群服务配置文件到/etc/default/目录
  template:
    src: minio_environment
    dest: /etc/default/minio
    mode: 0644

- import_tasks: start.yml

脚本执行

复制代码
#MinIO集群环境部署
ansible-playbook -i inventory/ -e operation=install minio.yml

配置检查

复制代码
#针对minio集群,进行服务的启停,节点状态检查
ansible-playbook -i inventory/ -e operation=start|stop|status minio.yml
相关推荐
广目软件2 天前
HA分布式架构采集节点变更操作手册20261029
运维·服务器·ansible·zabbix·prometheus
Moshow郑锴2 天前
Ansible 批量部署 Node.js 服务:ZIP 直解与共享目录分发两种方案对比
node.js·ansible
垚垚学技术_聚焦云原生2 天前
Ansible Playbook 进阶:when 条件、loop 循环、handlers 触发器落地
linux·ansible·自动化运维·devops
Moshow郑锴3 天前
GCP MIG 重建后 Ansible 初始化实战:PowerShell + NSSM 挂载 Windows 服务
windows·ansible
承渊政道5 天前
新增一台服务器时还要重新装Nginx?Ansible只改hosts目标列表,同一份Playbook继续执行
运维·nginx·ansible·内网穿透·cpolar
Helix2506 天前
Ansible混合环境自动化:Windows与Linux统一配置管理实战
windows·自动化·ansible·playbook·配置管理·winrm·混合环境
垚垚学技术_聚焦云原生8 天前
Ansible 变量体系详解:主机变量、组变量、全局变量优先级实战
ansible·自动化运维·devops·变量优先级
I'mChloe17 天前
不再逐台装Docker:我用Ansible Playbook批量统一服务器环境
服务器·docker·ansible
筑梦之路17 天前
Alibaba Cloud Linux 4 制作 Ansible RPM包实践(离线可复用)——筑梦之路
linux·运维·ansible
张洛闻Eren17 天前
Ansible【第一课】:Ansible介绍
运维·数据库·云原生·kubernetes·github·ansible