如何使用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
相关推荐
Freed&6 小时前
Ansible 生产级自动化指南:Playbook、Handlers、Jinja2 全解析
运维·自动化·ansible
m0_464608268 小时前
Ansible实现自动化运维
运维·自动化·ansible
✎﹏赤子·墨筱晗♪8 小时前
Ansible Playbook 入门指南:从基础到实战
linux·服务器·ansible
小白不想白a8 小时前
【Ansible】使用ansible部署k8s集群前的准备工作脚本
容器·kubernetes·ansible
m0_464608268 小时前
Ansible Playbook:自动化配置管理的利器
运维·自动化·ansible
红尘客栈21 天前
Ansible Playbook 编写指南:从入门到 Roles 模块化
ansible
红尘客栈21 天前
Ansible 入门到实战:自动化运维的瑞士军刀
运维·自动化·ansible
小闫BI设源码2 天前
Ansible自动化运维平台部署
运维·自动化·ansible·批量管理·devops工具·持续集成ci/cd·ssh协议
我好饿12 天前
自动化运维工具 Ansible 集中化管理服务器
运维·自动化·ansible
東雪蓮☆2 天前
Ansible 自动化运维:集中化管理服务器实战指南
linux·运维·自动化·ansible