-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathredis-cluster-ansible.yaml
205 lines (163 loc) · 7.15 KB
/
redis-cluster-ansible.yaml
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
---
- hosts: test
vars:
# - redis_port: "{{ port|default(6379) }}"
- redis_port: ['6379','6380','6381']
- redis_home: '/app/redis'
- redis_version: 'redis-4.0.11'
- redis_url: "http://download.redis.io/releases/{{ redis_version }}.tar.gz"
- IP: "{{ ansible_ens33['ipv4']['address'] }}"
- ruby_version: '2.5.1'
- rvm_path: "/usr/local/rvm/gems/ruby-{{ ruby_version }}/bin:/usr/local/rvm/gems/ruby-{{ ruby_version }}@global/bin:/usr/local/rvm/rubies/ruby-{{ ruby_version }}/bin:/usr/local/rvm/bin"
tasks:
- name: prepare the environment
yum: name={{ item }} state=present
with_items:
- gcc
- gcc-*
- automake
- autoconf
- libtool
- make
- zlib
- zlib-devel
- glibc-*
- tcl
- name: Download Redis package
get_url: url={{ redis_url }} dest=/tmp/{{ redis_version }}.tar.gz
- name: Untar Redis file
command: tar zxf /tmp/{{ redis_version }}.tar.gz -C /tmp
- name: Build Redis file
command: make -C /tmp/{{ redis_version }}
- name: Create Redis group
group: name=redis state=present gid=2000
- name: Create Redis user
user: name=redis uid=2000 group=redis createhome=no shell=/bin/bash state=present
# - name: Create the dir
# file: path={{ item }} state=directory group=redis owner=redis mode=0750
# with_items:
# - "{{ redis_home }}"
# - "{{ redis_home }}/{{ redis_port }}"
# - "{{ redis_home }}/{{ redis_port }}/data"
# - "{{ redis_home }}/{{ redis_port }}/conf"
# - "{{ redis_home }}/{{ redis_port }}/logs"
- name: Create the Redis dir
file: path={{ redis_home }}/{{ item[0] }}/{{ item[1] }} state=directory group=redis owner=redis mode=0750
with_nested:
- "{{ redis_port }}"
- ['data','conf','logs']
# - name: copy redis.conf file
# command: cp /tmp/redis-4.0.11/redis.conf {{ redis_home }}/{{ redis_port }}/conf/redis-{{ redis_port }}.conf
- name: Copy Redis conf file
command: cp /tmp/{{ redis_version }}/redis.conf {{ redis_home }}/{{ item }}/conf/redis-{{ item }}.conf
with_items:
- "{{ redis_port }}"
- name: Installing Redis binaries
command: cp /tmp/{{ redis_version }}/src/{{ item }} /usr/local/bin
with_items:
- redis-server
- redis-cli
- redis-check-aof
- redis-trib.rb
- redis-benchmark
- redis-check-rdb
- name: Modifying Redis Conf -> "bind"
lineinfile: dest={{ redis_home }}/{{ item }}/conf/redis-{{ item }}.conf regexp="^bind" line="bind {{IP}}"
with_items:
- "{{ redis_port }}"
- name: Modifying Redis Conf -> "pidfile"
lineinfile: dest={{ redis_home }}/{{ item }}/conf/redis-{{ item }}.conf regexp="^pidfile" line="pidfile {{ redis_home }}/{{ item }}/logs/redis-{{ item }}.pid"
with_items:
- "{{ redis_port }}"
- name: Modifying Redis Conf -> "logfile"
lineinfile: dest={{ redis_home }}/{{ item }}/conf/redis-{{ item }}.conf regexp="^logfile" line="logfile {{ redis_home }}/{{ item }}/logs/redis-{{ item }}.log"
with_items:
- "{{ redis_port }}"
- name: Modifying Redis Conf -> "dir"
lineinfile: dest={{ redis_home }}/{{ item }}/conf/redis-{{ item }}.conf regexp="^dir" line="dir {{ redis_home }}/{{ item }}/data"
with_items:
- "{{ redis_port }}"
- name: Modifying Redis Conf -> "port"
lineinfile: dest={{ redis_home }}/{{ item }}/conf/redis-{{ item }}.conf regexp="^port" line="port {{ item }}"
with_items:
- "{{ redis_port }}"
- name: Modifying Redis Conf -> "daemonize"
lineinfile: dest={{ redis_home }}/{{ item }}/conf/redis-{{ item }}.conf regexp="^daemonize" line="daemonize yes"
with_items:
- "{{ redis_port }}"
- name: Modifying Redis Conf -> "maxmemory"
lineinfile: dest={{ redis_home }}/{{ item }}/conf/redis-{{ item }}.conf regexp='# maxmemory <bytes>' line="maxmemory 200000000"
with_items:
- "{{ redis_port }}"
- name: Modifying Redis Conf -> "maxmemory-policy"
lineinfile: dest={{ redis_home }}/{{ item }}/conf/redis-{{ item }}.conf regexp='# maxmemory-policy noeviction' line="maxmemory-policy volatile-lru"
with_items:
- "{{ redis_port }}"
- name: Modifying Redis Conf -> "cluster-enabled"
lineinfile: dest={{ redis_home }}/{{ item }}/conf/redis-{{ item }}.conf regexp='# cluster-enabled yes' line="cluster-enabled yes"
with_items:
- "{{ redis_port }}"
- name: Modifying Redis Conf -> "cluster-node-timeout"
lineinfile: dest={{ redis_home }}/{{ item }}/conf/redis-{{ item }}.conf regexp='# cluster-node-timeout 15000' line="cluster-node-timeout 10000"
with_items:
- "{{ redis_port }}"
- name: copy init script
copy: src=redis_init_script dest=/etc/init.d/redis_{{ item }}
with_items:
- "{{ redis_port }}"
- name: Modifying Redis init script -> "REDISPORT"
lineinfile: dest=/etc/init.d/redis_{{ item }} regexp="^REDISPORT" line="REDISPORT={{ item }}"
with_items:
- "{{ redis_port }}"
- name: Modifying Redis init script -> "PIDFILE"
lineinfile: dest=/etc/init.d/redis_{{ item }} regexp="^PIDFILE" line="PIDFILE={{ redis_home }}/{{ item }}/logs/redis-{{ item }}.pid"
with_items:
- "{{ redis_port }}"
- name: Modifying Redis init script -> "CONF"
lineinfile: dest=/etc/init.d/redis_{{ item }} regexp="^CONF" line='CONF="{{ redis_home }}/{{ item }}/conf/redis-{{ item }}.conf"'
with_items:
- "{{ redis_port }}"
- name: Modifying Redis init script -> "CLIEXEC"
lineinfile: dest=/etc/init.d/redis_{{ item }} regexp="^CLIEXEC" line="CLIEXEC='/usr/local/bin/redis-cli -h {{IP}} ' "
with_items:
- "{{ redis_port }}"
- name: chkconfig Redis
command: chmod +x /etc/init.d/redis_{{ item }}
with_items:
- "{{ redis_port }}"
- name: chkconfig Redis
command: chkconfig --add redis_{{ item }}
with_items:
- "{{ redis_port }}"
- name: chkconfig Redis
command: chkconfig --level 345 redis_{{ item }} on
with_items:
- "{{ redis_port }}"
- name: prepare the environment
yum: name={{ item }} state=present
with_items:
- ruby
- ruby-devel
- rubygems
- rpm-build
- name: import rvm gpg2
shell: " curl -sSL https://rvm.io/mpapis.asc | gpg2 --import - "
- name: install rvm 2.5
shell: " curl -sSL https://get.rvm.io | bash "
args:
creates: /usr/local/rvm
- name: install ruby-{{ ruby_version }}
command: "rvm install ruby-{{ ruby_version }}"
environment:
PATH: "{{ rvm_path }}:{{ ansible_env.PATH }}"
args:
creates: "/usr/local/rvm/gems/ruby-{{ ruby_version }}"
- name: gem install ruby
command: "gem install redis"
environment:
PATH: "{{ rvm_path }}:{{ ansible_env.PATH }}"
- name: Cleaning up build files
file: path= /tmp/{{ item }} state=absent
with_items:
- "{{ redis_version }}"
- "{{ redis_version }}".tar.gz