Skip to content

Commit

Permalink
Fixes geerlingguy#299: Move Gluster example into this repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
geerlingguy committed Jul 24, 2020
1 parent ab9b2aa commit 5e1b717
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ env:
- playbook: first-ansible-playbook.yml
distro: centos7

# TODO: Not easy to test in CI at this time.
# - playbook: gluster.yml
# distro: ubuntu2004

- playbook: https-self-signed.yml
distro: ubuntu2004

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Here is an outline of all the examples contained in this repository, by chapter:

- [`lamp-infrastructure`](lamp-infrastructure/): A multi-server LAMP-based web application infrastructure focused on high-availability and performance for a LAMP-stack app.
- [`elk`](elk/): A two-server example of the Elasticsearch-Logstash-Kibana stack, which uses one server to store and visualize logs centrally, and another server to send logs via Filebeat.
- [`gluster`](gluster/): A two-server example of building a fast networked storage setup using Gluster.

### Chapter 10

Expand Down
35 changes: 35 additions & 0 deletions gluster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# GlusterFS Distributed Filesystem Configuration

This project creates a distributed filesystem on two servers using [GlusterFS](http://www.gluster.org/).

## Building the VMs

1. Download and install [VirtualBox](https://www.virtualbox.org/wiki/Downloads).
2. Download and install [Vagrant](http://www.vagrantup.com/downloads.html).
3. [Mac/Linux only] Install [Ansible](http://docs.ansible.com/ansible/latest/intro_installation.html).
4. Run `ansible-galaxy install -r requirements.yml` in this directory to get the required Ansible roles.
5. Run `vagrant up` to build the VMs and configure the infrastructure.

When Vagrant is finished provisioning the VMs with Ansible, run the following two commands to confirm that Gluster is operating nominally:

```
# Get status for the Gluster cluster.
$ ansible gluster -i inventory -a "gluster peer status" -b
# Get volume info for the Gluster cluster.
ansible gluster -i inventory -a "gluster volume info" -b
```

You can also do the following to confirm that files are being replicated/distributed correctly:

1. Log into the first server: `vagrant ssh gluster1`
2. Create a file in the mounted gluster volume: `sudo touch /mnt/gluster/test`
3. Log out of the first server: `exit`
4. Log into the second server: `vagrant ssh gluster2`
5. List the contents of the gluster directory: `ls /mnt/gluster`

You should see the `test` file you created in step 2; this means Gluster is working correctly!

## About the Author

This project was created by [Jeff Geerling](https://www.jeffgeerling.com/) as an example for [Ansible for DevOps](https://www.ansiblefordevops.com/).
38 changes: 38 additions & 0 deletions gluster/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
# Base VM OS configuration.
config.vm.box = "geerlingguy/ubuntu2004"
config.vm.synced_folder '.', '/vagrant', disabled: true
config.ssh.insert_key = false

config.vm.provider :virtualbox do |v|
v.memory = 512
v.cpus = 1
end

# Define two VMs with static private IP addresses.
boxes = [
{ :name => "gluster1", :ip => "192.168.29.2" },
{ :name => "gluster2", :ip => "192.168.29.3" }
]

# Provision each of the VMs.
boxes.each do |opts|
config.vm.define opts[:name] do |config|
config.vm.hostname = opts[:name]
config.vm.network :private_network, ip: opts[:ip]

# Provision both VMs using Ansible after the last VM is booted.
if opts[:name] == "gluster2"
config.vm.provision "ansible" do |ansible|
ansible.playbook = "playbooks/provision.yml"
ansible.inventory_path = "inventory"
ansible.limit = "all"
end
end
end
end

end
7 changes: 7 additions & 0 deletions gluster/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[gluster]
192.168.29.2
192.168.29.3

[gluster:vars]
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key
39 changes: 39 additions & 0 deletions gluster/playbooks/provision.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
- hosts: gluster
become: yes

vars_files:
- vars.yml

roles:
- geerlingguy.firewall
- geerlingguy.glusterfs

tasks:
- name: Ensure Gluster brick and mount directories exist.
file:
path: "{{ item }}"
state: directory
mode: 0775
with_items:
- "{{ gluster_brick_dir }}"
- "{{ gluster_mount_dir }}"

- name: Configure Gluster volume.
gluster_volume:
state: present
name: "{{ gluster_brick_name }}"
brick: "{{ gluster_brick_dir }}"
replicas: 2
cluster: "{{ groups.gluster | join(',') }}"
host: "{{ inventory_hostname }}"
force: yes
run_once: true

- name: Ensure Gluster volume is mounted.
mount:
name: "{{ gluster_mount_dir }}"
src: "{{ inventory_hostname }}:/{{ gluster_brick_name }}"
fstype: glusterfs
opts: "defaults,_netdev"
state: mounted
25 changes: 25 additions & 0 deletions gluster/playbooks/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# Firewall configuration.
firewall_allowed_tcp_ports:
- 22
# For Gluster.
- 111
# Port-mapper for Gluster 3.4+.
# - 2049
# Gluster Daemon.
- 24007
# 24009+ for Gluster <= 3.3; 49152+ for Gluster 3.4+ (one port per server).
- 24009
- 24010
- 49152
- 49153
# Gluster inline NFS server.
- 38465
- 38466
firewall_allowed_udp_ports:
- 111

# Gluster configuration.
gluster_mount_dir: /mnt/gluster
gluster_brick_dir: /srv/gluster/brick
gluster_brick_name: gluster
3 changes: 3 additions & 0 deletions gluster/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- src: geerlingguy.firewall
- src: geerlingguy.glusterfs

0 comments on commit 5e1b717

Please sign in to comment.