Thank you for reading this post, don't forget to subscribe!
данная роль будет устанавливать glusterfs сервер и клиентов.
после первого прогона будут ошибки при создании вольюма и добавления пиров, Необходимо 2 раза запустить эту роль
Для корректной работы рекомендованы 3 сервера чтобы был кворум, так же можно использовать 2 сервера и 1 арбитр. Можно но не рекомендуется использовать 2 сервера без арбитра
все хосты перечисляем в файле:
/etc/ansible/hosts
в моём случае содержимое следующее:
[glusterfs:children]
glustermaster
glusterclient
[glustermaster]
192.168.1.20
192.168.1.21
192.168.1.24
[glusterclient]
192.168.1.22
192.168.1.23
3 мастер сервера и 2 клиента
создаём структуру директорий:
mkdir -p /etc/ansible/{playbooks/roles_play,roles/glusterfs/{handlers,tasks,templates}}
cat /etc/ansible/roles/glusterfs/handlers/main.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 |
--- - name: Start gluster service: name=glusterd state=restarted enabled=yes |
[/codesyntax]
cat /etc/ansible/roles/glusterfs/tasks/add-peer.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
- name: Check if Gluster volumes already exist. shell: cmd: gluster volume info run_once: true changed_when: false register: gluster_volume_info when: inventory_hostname in groups['glustermaster'] - name: Connect to Gluster peers. shell: cmd: "gluster peer probe {{ item }}" run_once: true register: gluster_peer_probe changed_when: "'already in peer list' not in gluster_peer_probe.stdout" failed_when: false with_items: "{{groups.glustermaster}}" when: "'Volume Name: {{ name_of_gluster_tom }}' not in gluster_volume_info.stdout and inventory_hostname in groups['glustermaster']" |
[/codesyntax]
cat /etc/ansible/roles/glusterfs/tasks/add-to-hosts.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
- name: Add all hosts and ip to /etc/hosts lineinfile: dest: /etc/hosts regexp: '{{ hostvars[item].ansible_default_ipv4.address }}.*{{ item }}$' line: "{{ hostvars[item].ansible_default_ipv4.address }} {{ hostvars[item].ansible_hostname }}" state: present become: yes with_items: "{{ groups.glusterfs }}" - name: save only uniq in /etc/hosts to /etc/hosts2 shell: "/usr/bin/cat /etc/hosts | /usr/bin/awk '!a[$0]++' > /etc/hosts2" - name: save only uniq shell: "mv /etc/hosts2 /etc/hosts" |
[/codesyntax]
cat /etc/ansible/roles/glusterfs/tasks/add-tom.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
- name: Create Gluster volume "{{ name_of_gluster_tom }}". gluster_volume: state: present name: "{{ name_of_gluster_tom }}" brick: "{{ dir_gluster_master }}/gv01" replicas: "{{ replica_number }}" cluster: "{{ groups.glustermaster | join(',') }}" transport: tcp rebalance: yes force: yes become: true become_user: root become_method: sudo run_once: true ignore_errors: true when: inventory_hostname in groups['glustermaster'] - name: start gluster volume "{{ name_of_gluster_tom }}" gluster_volume: state: started name: "{{ name_of_gluster_tom }}" run_once: true when: inventory_hostname in groups['glustermaster'] |
[/codesyntax]
cat /etc/ansible/roles/glusterfs/tasks/create-gluster-dir.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
--- - name: Create directory "{{ dir_gluster_master }}" on nfsmaster file: path: "{{ dir_gluster_master }}" state: directory mode: 0755 owner: root group: root when: inventory_hostname in groups['glustermaster'] - name: Create directory "{{ dir_gluster_master }}/gv01" on nfsmaster file: path: "{{ dir_gluster_master }}/gv01" state: directory mode: 0755 owner: root group: root when: inventory_hostname in groups['glustermaster'] - name: Create directory "{{ dir_gluster_client }}" on nfsclient file: path: "{{ dir_gluster_client }}" state: directory mode: 0755 owner: root group: root |
[/codesyntax]
cat /etc/ansible/roles/glusterfs/tasks/install-gluster-client.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 |
- name: install grlusterfs client yum: name: "{{item}}" state: present with_items: - glusterfs-client |
[/codesyntax]
cat /etc/ansible/roles/glusterfs/tasks/install-gluster-server.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 |
- name: install grlusterfs server yum: name: "{{item}}" state: present with_items: - glusterfs - glusterfs-libs - glusterfs-server notify: - Start gluster when: inventory_hostname in groups['glustermaster'] |
[/codesyntax]
cat /etc/ansible/roles/glusterfs/tasks/install-repo-gluster.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 |
- name: install repo grlusterfs yum: name: "{{item}}" state: present with_items: - centos-release-gluster5.noarch |
[/codesyntax]
cat /etc/ansible/roles/glusterfs/tasks/mount.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
- name: get ip brick. shell: cmd: gluster volume info | grep -i brick1 | awk -F ':' '{print $2}' | tr -d ' ' run_once: true changed_when: false register: gluster_brick_ip when: inventory_hostname in groups['glustermaster'] - name: Ensure Gluster volume is mounted. become: yes become_user: root mount: name: "{{ dir_gluster_client }}" src: "localhost:/{{name_of_gluster_tom}}" path: "{{dir_gluster_client}}" fstype: glusterfs opts: "defaults,_netdev" state: mounted when: inventory_hostname in groups['glustermaster'] - name: Ensure Gluster volume is mounted to client become: yes become_user: root mount: name: "{{ dir_gluster_client }}" src: "{{ gluster_brick_ip.stdout }}:/{{name_of_gluster_tom}}" path: "{{dir_gluster_client}}" fstype: glusterfs opts: "defaults,_netdev" state: mounted when: inventory_hostname in groups['glusterclient'] |
[/codesyntax]
cat /etc/ansible/roles/glusterfs/tasks/proxy-install-gluster-client.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 |
- name: install grlusterfs client yum: name: "{{item}}" state: present with_items: - glusterfs-client environment: http_proxy: "{{ http_proxy }}" https_proxy: "{{ https_proxy }}" |
[/codesyntax]
cat /etc/ansible/roles/glusterfs/tasks/proxy-install-gluster-server.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
- name: install grlusterfs server yum: name: "{{item}}" state: present with_items: - glusterfs - glusterfs-libs - glusterfs-server environment: http_proxy: "{{ http_proxy }}" https_proxy: "{{ https_proxy }}" notify: - Start gluster when: inventory_hostname in groups['glustermaster'] |
[/codesyntax]
cat /etc/ansible/roles/glusterfs/tasks/proxy-install-repo-gluster.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 |
- name: install repo grlusterfs yum: name: "{{item}}" state: present with_items: - centos-release-gluster5.noarch environment: http_proxy: "{{ http_proxy }}" https_proxy: "{{ https_proxy }}" |
[/codesyntax]
cat /etc/ansible/roles/glusterfs/tasks/main.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
--- - import_tasks: proxy-install-repo-gluster.yml tags: proxy gluster repo when: proxy - import_tasks: install-repo-gluster.yml tags: gluster repo - import_tasks: create-gluster-dir.yml tags: create-dir - import_tasks: add-to-hosts.yml tags: add-hostname-to-hosts - import_tasks: proxy-install-gluster-server.yml tags: proxy install-gluster-serer when: proxy - import_tasks: install-gluster-server.yml tags: install-gluster-serer - import_tasks: proxy-install-gluster-client.yml tags: proxy install-gluster-serer when: proxy - import_tasks: install-gluster-client.yml tags: install-gluster-serer - import_tasks: add-peer.yml tags: add-peer - import_tasks: add-tom.yml tags: add-tom - import_tasks: mount.yml tags: mount |
[/codesyntax]
cat /etc/ansible/playbooks/roles_play/glusterfs.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
--- - hosts: glusterfs become: true ignore_errors: yes become_method: sudo gather_facts: yes vars: - dir_gluster_master: /gluster - dir_gluster_client: /var/gluster - name_of_gluster_tom: gluster-tom - replica_number: "{{ groups['glustermaster'] | length }}" - proxy: false # here use true/false - http_proxy: "http://192.168.1.170:3128" - https_proxy: "http://192.168.1.170:3128" roles: - glusterfs |
[/codesyntax]
dir_gluster_master - здесь указываем директорию на мастере которв которой будут хранится данные
dir_gluster_client - здесь указываем директорию для клиентов(на мастерах она тоже будет создана), с ней и будем работать в дальнейшем
name_of_gluster_tom - имя создаваемого/используемого тома
replica_number - авоматически посчитаем количество мастеров добавленных в инвентори файле
proxy - указываем true/false если необходимо чтобы установка шла через прокси сервер
http_proxy https_proxy соответственно адрес прокси
запускаем:
ansible-playbook -u ansible /etc/ansible/playbooks/roles_play/glusterfs.yml
после первого прогона будут ошибки при создании вольюма и добавления пиров, Необходимо 2 раза запустить эту роль