main.yml 3.01 KB
---
# tasks file for redis-cluster

# install redis server

- name: ensure a list of packages installed
  yum:
    name: "{{ packages }}"
  vars:
    packages:
    - gcc
    - gcc-c++
    - kernel-devel


#### sync files
- name: Check if redis already installed
  stat: path=/Data/local/redis/bin/redis-server
  register: redis_binary

- name: Check if twemproxy already installed
  stat: path=/Data/local/twemproxy/sbin/nutcracker
  register: nutcracker_binary

- name: Upload redis source package
  copy:
    src: "redis-4.0.14.tar.gz"
    dest: "/root/redis-4.0.14.tar.gz"
    mode: 0755
  when: redis_binary.stat.exists == False

- name: Upload twemproxy source package
  copy:
    src: "nutcracker-0.4.1.tar.gz"
    dest: "/root/nutcracker-0.4.1.tar.gz"
    mode: 0755
  when: nutcracker_binary.stat.exists == False


########################## modify for redis install ############################
# disable transparent_hugepage.
- name: disable transparent_hugepage
  shell: echo never > /sys/kernel/mm/transparent_hugepage/enabled

- name: Test exist disable transparent_hugepage in /etc/rc.local
  shell: 'grep "transparent_hugepage" /etc/rc.local'
  register: test_grep

- name: add disable transparent_hugepage to /etc/rc.local
  lineinfile:
    dest: /etc/rc.local
    line: 'echo never > /sys/kernel/mm/transparent_hugepage/enabled'
  when: test_grep.stdout != ""

# vm.overcommit_memory = 1
- name: Test exist overcommit_memory  in /etc/sysctl.conf
  shell: grep "overcommit_memory" /etc/sysctl.conf
  register: test_grep_overcommit
- name: modify overcommit_memory in /etc/sysctl.conf
  lineinfile:
    dest:  /etc/sysctl.conf
    line: 'vm.overcommit_memory = 1'
  when: test_grep_overcommit.stdout != ""

# net.core.somaxconn = 1024
- name: Test exist somaxconn  in /etc/sysctl.conf
  shell: grep "somaxconn" /etc/sysctl.conf
  register: test_grep_somaxconn
- name: modify somaxconn in /etc/sysctl.conf
  lineinfile:
    dest:  /etc/sysctl.conf
    line: 'net.core.somaxconn = 1024'
  when: test_grep_somaxconn.stdout != ""  

- name: make sysctl effective now
  shell: sysctl -p

########################## end modify for redis install ############################

- name: Decompress and install redis
  shell: cd /root/ && mkdir -p /Data/local/ && tar -zxvf redis-4.0.14.tar.gz && cd redis-4.0.14 && make PREFIX=/Data/local/redis install && mkdir -p /Data/local/redis/conf /Data/logs/redis/ /Data/local/redis/data
  when: redis_binary.stat.exists == False

- name: Update redis configuration file
  template:
    src: "redis.conf.j2"
    dest: "/Data/local/redis/conf/redis.conf"
  notify:
    - stop redis
    - start redis
 
 
- name: Install twemproxy
  shell: cd /root/ && tar -zxvf nutcracker-0.4.1.tar.gz && cd nutcracker-0.4.1 && ./configure --prefix=/Data/local/twemproxy && make && make install && mkdir -p /Data/local/twemproxy/conf
  when: nutcracker_binary.stat.exists == False

- name: Update twemproxy configuration file
  template:
    src: "nutcracker.yml.j2"
    dest: "/Data/local/twemproxy/conf/nutcracker.yml"
  notify:
    - start nutcracker