Hello
Welcome to the second part of the series DevOps for Databases, in this post we will see how to install Redis database along with HA (two slaves) , sentinel a HA solution to monitor the redis nodes and stunnel for managing SSL connections to Redis using Ansible playbook. In addition there is also a vagrant file in the repository where you can build virtualboxes with centos 7 and a playbook will run. If you do not want to run with vagrant simple run the playbook.
Here are the things you will need to understand before you start.
- Install vagrant and ansible in your machine, windows also do. Playbook will run on local mode if windows
- You can download the git repository from here.
- Look at variables in install/group_vars/redis_vars.yml for password, masternode, env etc
- By default the nodes that built in vagrant having stgredis01/02/03 you can change if you want
- If you want to use SSL and had readymade certificates copy them to install/roles/redis/files/ and mark ssl_mode: "Yes" in variable file install/group_vars/redis_vars.yml
Here is how it look like
If you want to build the machines on your laptop/machine for learning purpose. There's a file VagrantFile already in there. So run below, the following will build three boxes and provision playbook also.
cd <repositoryfolder>/
vagrant up
But if you want to run only playbook and you have machines built already
- Modify the variables in install/group_vars/redis_vars.yml
- Add the hostname in hosts file in <repositoryfolder>/hosts
Run the playbook
ansible-playbook install/redis.yml -i hosts
Log part of Vagrant
C:\Users\Sureshgandhi\Desktop\ansible-redis-sentinel-stunnel-master>vagrant up
Bringing machine 'stgredis01' up with 'virtualbox' provider...
Bringing machine 'stgredis02' up with 'virtualbox' provider...
Bringing machine 'stgredis03' up with 'virtualbox' provider...
==> stgredis01: Importing base box 'centos/7'...
Progress: 20%
==> stgredis01: Importing base box 'centos/7'...
==> stgredis01: Matching MAC address for NAT networking...
==> stgredis01: Checking if box 'centos/7' is up to date...
==> stgredis01: A newer version of the box 'centos/7' for provider 'virtualbox' is
==> stgredis01: available! You currently have version '1804.02'. The latest is version
==> stgredis01: '1812.01'. Run `vagrant box update` to update.
==> stgredis01: Setting the name of the VM: ansible-redis-sentinel-stunnel-master_stgredis01_1547554542974_39615
==> stgredis01: Clearing any previously set network interfaces...
==> stgredis01: Preparing network interfaces based on configuration...
stgredis01: Adapter 1: nat
stgredis01: Adapter 2: bridged
==> stgredis01: Forwarding ports...
stgredis01: 22 (guest) => 20122 (host) (adapter 1)
==> stgredis01: Running 'pre-boot' VM customizations...
==> stgredis01: Booting VM...
==> stgredis01: Waiting for machine to boot. This may take a few minutes...
stgredis01: SSH address: 127.0.0.1:20122
stgredis01: SSH username: vagrant
stgredis01: Inserting generated public key within guest...
stgredis01: Removing insecure key from the guest if it's present...
stgredis01: Key inserted! Disconnecting and reconnecting using new SSH key...
=> stgredis01: Machine booted and ready!==> stgredis02: Importing base box 'centos/7'...
==> stgredis02: Matching MAC address for NAT networking...
==> stgredis02: Checking if box 'centos/7' is up to date...
==> stgredis02: A newer version of the box 'centos/7' for provider 'virtualbox' is
==> stgredis02: available! You currently have version '1804.02'. The latest is version
==> stgredis02: '1812.01'. Run `vagrant box update` to update.
==> stgredis02: Setting the name of the VM: ansible-redis-sentinel-stunnel-master_stgredis02_1547554542974_39615
==> stgredis02: Clearing any previously set network interfaces...
==> stgredis02: Preparing network interfaces based on configuration...
stgredis02: Adapter 1: nat
stgredis02: Adapter 2: bridged
==> stgredis02: Forwarding ports...
stgredis02: 22 (guest) => 20122 (host) (adapter 1)
==> stgredis02: Running 'pre-boot' VM customizations...
==> stgredis02: Booting VM...
==> stgredis02: Waiting for machine to boot. This may take a few minutes...
stgredis02: SSH address: 127.0.0.1:20122
stgredis02: SSH username: vagrant
stgredis02: Inserting generated public key within guest...
stgredis02: Removing insecure key from the guest if it's present...
stgredis02: Key inserted! Disconnecting and reconnecting using new SSH key...
=> stgredis02: Machine booted and ready!==> stgredis03: Importing base box 'centos/7'...
==> stgredis03: Matching MAC address for NAT networking...
==> stgredis03: Checking if box 'centos/7' is up to date...
==> stgredis03: A newer version of the box 'centos/7' for provider 'virtualbox' is
==> stgredis03: available! You currently have version '1804.02'. The latest is version
==> stgredis03: '1812.01'. Run `vagrant box update` to update.
==> stgredis03: Setting the name of the VM: ansible-redis-sentinel-stunnel-master_stgredis03_1547554542974_39615
==> stgredis03: Clearing any previously set network interfaces...
==> stgredis03: Preparing network interfaces based on configuration...
stgredis03: Adapter 1: nat
stgredis03: Adapter 2: bridged
==> stgredis03: Forwarding ports...
stgredis03: 22 (guest) => 20122 (host) (adapter 1)
==> stgredis03: Running 'pre-boot' VM customizations...
==> stgredis03: Booting VM...
==> stgredis03: Waiting for machine to boot. This may take a few minutes...
stgredis03: SSH address: 127.0.0.1:20122
stgredis03: SSH username: vagrant
stgredis03: Inserting generated public key within guest...
stgredis03: Removing insecure key from the guest if it's present...
stgredis03: Key inserted! Disconnecting and reconnecting using new SSH key...
=> stgredis03: Machine booted and ready!
Log part of Playbook that is provisioned
PLAY [stgredis*] ***************************************************************
TASK [Gathering Facts] *********************************************************
ok: [stgredis01]TASK [redis : Obtain hostname] *************************************************
changed: [stgredis01]TASK [redis : Install dependencies] ********************************************
changed: [stgredis01]TASK [redis : Install Yum Package] *********************************************
changed: [stgredis01]TASK [redis : Download and install redis] **************************************
changed: [stgredis01]TASK [redis : Create user] *****************************************************
changed: [stgredis01]TASK [redis : Create Required Directories] *************************************
changed: [stgredis01]TASK [redis : Disable THP support scripts added to rc.local] *******************
changed: [stgredis01]TASK [redis : Change permissions of /etc/rc.local to make it run on boot] ******
changed: [stgredis01]TASK [redis : Add or modify nofile soft limit for all] *************************
changed: [stgredis01]TASK [redis : Add or modify fsize hard limit for the all. Keep or set the maximal value.] ***
changed: [stgredis01]TASK [redis : Add or modify memlock, both soft and hard, limit for the user root with a comment.] ***
changed: [stgredis01]TASK [redis : Add or modify hard nofile limits for wildcard *] *****************
changed: [stgredis01]TASK [redis : Copy Redis Conf file] ********************************************
changed: [stgredis01]TASK [redis : Copy Redis Conf file] ********************************************
changed: [stgredis01]TASK [redis : Copy Sentinel Conf file] *****************************************
changed: [stgredis01]TASK [redis : Copy Stunnel Conf file] ******************************************
changed: [stgredis01]TASK [redis : Copy Redis Failover Script] **************************************
changed: [stgredis01]TASK [redis : Change Failover Script Permissions] ******************************
TASK [redis : Create Permissions for Redis Conf Files] *************************
changed: [stgredis01]TASK [redis : Copy Redis Init Script] ******************************************
changed: [stgredis01]TASK [redis : Copy Sentinel Init Script] ***************************************
changed: [stgredis01]TASK [redis : Copy Sentinel Init Script] ***************************************
changed: [stgredis01]TASK [redis : Update redis clustername in sentinel conf] ***********************
changed: [stgredis01]TASK [redis : Update redis masternode name in sentinel conf] *******************
changed: [stgredis01]TASK [redis : Update redis masternode name in sentinel conf] *******************
changed: [stgredis01]TASK [redis : Update redis VIPADDRESS in stunnel conf] *************************
ok: [stgredis01]TASK [redis : Update redis VIPADDRES in failover script] ***********************
changed: [stgredis01]TASK [redis : Update redis masterauth in Redis conf] ***************************
changed: [stgredis01]TASK [redis : Update redis masterauth in Redis conf] ***************************
changed: [stgredis01]TASK [redis : Update redis masterauth in sentinel conf] ************************
changed: [stgredis01]TASK [redis : Update redis requirepass in Redis conf] **************************
changed: [stgredis01]TASK [redis : Update redis datadirect in Redis conf] ***************************
changed: [stgredis01]TASK [redis : Fix ASCII Characters issues in shell scripts] ********************
changed: [stgredis01]TASK [redis : Update stunnel file with right keys] *****************************
changed: [stgredis01]TASK [redis : Copy SSL Certificate to Stunnel] *********************************
skipping: [stgredis01]TASK [redis : Copy SSL Key to Stunnel] *****************************************
skipping: [stgredis01]TASK [redis : Update Stunnel stuff] ********************************************
skipping: [stgredis01]TASK [redis : Copy Hosts file] ************************************************
changed: [stgredis01]TASK [redis : Update hosts file with right environment Dev/QA/STG/PRD] *********
changed: [stgredis01]TASK [redis : Update hosts file with right environment Dev/QA/STG/PRD] *********
changed: [stgredis01]TASK [redis : Update hosts file with right subnet] *****************************
ok: [stgredis01]TASK [redis : Add Line for slaveof configuration] ******************************
ok : [stgredis01]TASK [redis : Start redis Service] *********************************************
changed: [stgredis01]TASK [redis : Start sentinel service] ******************************************
changed: [stgredis01]TASK [redis : Start Stunnel service] *******************************************
skipping: [stgredis01]PLAY RECAP *********************************************************************
stgredis01 : ok=41 changed=38 unreachable=0 failed=0
Redis Status once Boxes built and Provisioned
Note: There's lot of warnings and optimizations need for Playbook, feel free to modify the repository code and commit. When I find some time will do accordingly.
Happy Learning
-Suresh
Follow Me!!!