如何使用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
相关推荐
粥周粥10 小时前
ANSIBLE
ansible
码农101号11 小时前
Linux中ansible模块补充和playbook讲解
linux·运维·ansible
码农101号11 小时前
Linux的Ansible软件基础使用讲解和ssh远程连接
ansible
烟雨书信2 天前
ANSIBLE运维自动化管理端部署
运维·自动化·ansible
碎碎-li2 天前
ANSIBLE(运维自动化)
运维·自动化·ansible
@donshu@5 天前
Linux运维-ansible-python开发-获取inventroy信息
linux·运维·ansible
Kendra9198 天前
Ansible
ansible
꧁༺朝花夕逝༻꧂11 天前
Ansible小试牛刀
ansible
꧁༺朝花夕逝༻꧂11 天前
Ansible+Zabbix-agent2快速实现对多主机监控
运维·ansible