7. 安装MinIO
7.1. 说明
可以做集群的文件服务器,安装使用的是Linux的二进制包,下载地址为https://dl.min.io/server/minio/release/linux-amd64/minio。
7.2. yml脚本
---
- hosts: minioservers
remote_user: root
vars_files:
- ../vars.yml
tasks:
- name: enforce env #刷新环境变量
shell: source ~/.bashrc
- name: Create minio group
group:
name: minio
state: present
- name: Create minio user
user:
name: minio
group: minio
shell: /bin/bash
createhome: yes
- name: Copy binary
copy:
src: "{{ PLAYBOOK_DIR }}/files/minio"
dest: /usr/local/bin/minio
owner: root
group: root
mode: 0755
- name: Copy env
template:
src: "{{ PLAYBOOK_DIR }}/minio/templates/env.j2"
dest: /etc/default/minio
owner: minio
group: minio
mode: 0755
- name: make minio permission
file: path=/etc/default/minio owner=minio group=minio mode=0755 state=file
- name: Copy service
template:
src: "{{ PLAYBOOK_DIR }}/minio/templates/minio.service.j2"
dest: /etc/systemd/system/minio.service
owner: minio
group: minio
mode: 0755
- name: reload systemctl
shell: systemctl daemon-reload
- name: Create data dir
file:
path: "{{ MINIO_DATA_DIR }}/data1"
state: directory
owner: minio
group: minio
mode: 0755
recurse: true
- name: Create data dir2
file:
path: "{{ MINIO_DATA_DIR }}/data2"
state: directory
owner: minio
group: minio
mode: 0755
recurse: true
- name: Create data dir3
file:
path: "{{ MINIO_DATA_DIR }}/data3"
state: directory
owner: minio
group: minio
mode: 0755
recurse: true
- name: Create data dir4
file:
path: "{{ MINIO_DATA_DIR }}/data4"
state: directory
owner: minio
group: minio
mode: 0755
recurse: true
- name: firewarld add 5601
firewalld:
port: 9199/tcp
permanent: true
immediate: true
zone: public
state: enabled
- name: start minio
service:
name: minio.service
state: started
enabled: true
tags:
- start minio
7.3. 配置模板
7.3.1 env.j2
需要注意的是,MinIO的文件存储目录至少需要4个,如果有两个节点的话,可以每个节点创建两个目录,但这次安装只用了1个节点,因为在/home/data/minio
路径下创建了4个目录。路径的指向可以在j2模板里MINIO_VOLUMES
配置。如果有两个节点的话,每个节点两个目录即可。
# Local export path.
MINIO_VOLUMES="{%- for item in groups['minioservers'] -%}
http://{{ hostvars[item].ansible_default_ipv4.address }}:9199{{ MINIO_DATA_DIR }}/data1 \
http://{{ hostvars[item].ansible_default_ipv4.address }}:9199{{ MINIO_DATA_DIR }}/data2 \
http://{{ hostvars[item].ansible_default_ipv4.address }}:9199{{ MINIO_DATA_DIR }}/data3 \
http://{{ hostvars[item].ansible_default_ipv4.address }}:9199{{ MINIO_DATA_DIR }}/data4 {% if not loop.last %}\ {% endif %}
{% endfor -%}"
# Use if you want to run Minio on a custom port.
MINIO_OPTS="--address :9199"
# Access Key of the server.
MINIO_ACCESS_KEY={{ MINIO_USERNAME }}
# # Secret key of the server.
MINIO_SECRET_KEY={{ MINIO_SECRET_KEY }}
7.3.2 minio.service.j2
启动服务
[Unit]
Description=Minio
Documentation=https://docs.minio.io
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/usr/local/bin/minio
[Service]
WorkingDirectory=/usr/local
User=minio
Group=minio
PermissionsStartOnly=true
EnvironmentFile=-/etc/default/minio
ExecStartPre=/bin/bash -c "[ -n \"${MINIO_VOLUMES}\" ] || echo \"Variable MINIO_VOLUMES not set in /etc/default/minio\""
ExecStart=/usr/local/bin/minio server $MINIO_OPTS $MINIO_VOLUMES
# Let systemd restart this service only if it has ended with the clean exit code or signal.
Restart=on-success
StandardOutput=journal
StandardError=inherit
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536
# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0
# SIGTERM signal is used to stop Minio
KillSignal=SIGTERM
SendSIGKILL=no
SuccessExitStatus=0
[Install]
WantedBy=multi-user.target
# Built for ${project.name}-${project.version} (${project.name})
7.4. 运行ansible-playbook
ansible-playbook -i /etc/ansible/hosts minio/main.yml
7.5. 安装成功
MinIO的登录用户名和密码可以在vars.yml
文件中找到,MINIO_USERNAME
和MINIO_SECRET_KEY
,登录地址是http://192.168.0.250:9199/minio/login
登录成功后需要给项目创建使用的bucket即可
image.png
网友评论