Ansible部署系列:(七)安裝MinIO

7. 安裝MinIO

7.1. 說明

可以做集群的文件服務(wù)器,安裝使用的是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  #刷新環(huán)境變量
      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個,如果有兩個節(jié)點的話,可以每個節(jié)點創(chuàng)建兩個目錄,但這次安裝只用了1個節(jié)點,因為在/home/data/minio路徑下創(chuàng)建了4個目錄。路徑的指向可以在j2模板里MINIO_VOLUMES配置。如果有兩個節(jié)點的話,每個節(jié)點兩個目錄即可。

# 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

啟動服務(wù)

[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_USERNAMEMINIO_SECRET_KEY,登錄地址是http://192.168.0.250:9199/minio/login

登錄成功后需要給項目創(chuàng)建使用的bucket即可


image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請通過簡信或評論聯(lián)系作者。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容