Authored by root

新增role:高可用非持久化redis集群

Redis
=========
安装Redis server(不持久化), 并使用twemproxy支持Redis高可用集群
Redis 默认端口: 6379
twemproxy 默认端口: 22121
Author Information
------------------
tiexin.yang@yoho.cn
... ...
No preview for this file type
---
# handlers file for redis
- name: stop redis
shell: /Data/local/redis/bin/redis-cli -h "{{ ansible_default_ipv4['address'] }}" -p 6379 shutdown
ignore_errors: True
- name: start redis
shell: /Data/local/redis/bin/redis-server /Data/local/redis/conf/redis.conf
- name: start nutcracker
shell: /Data/local/twemproxy/sbin/nutcracker -d -c /Data/local/twemproxy/conf/nutcracker.yml
... ...
galaxy_info:
author: tiexin.yang@yoho.cn
description: install redis with twemproxy supported HA available
company: yohobuy.com
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: license (GPLv2, CC-BY, etc)
min_ansible_version: 1.2
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If Travis integration is configured, only notifications for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:
#
# platforms is a list of platforms, and each platform has a name and a list of versions.
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
... ...
---
# tasks file for redis-cluster
# install redis server
- name: Ensure libselinux-python is installed
yum:
name: libselinux-python
state: installed
update_cache: yes
- name: Check if redis already installed
stat: path=/Data/local/redis/bin/redis-server
register: redis_binary
- name: Upload redis source package
copy:
src: "redis-3.2.12.tar.gz"
dest: "/root/redis-3.2.12.tar.gz"
mode: 0755
when: redis_binary.stat.exists == False
- name: Decompress and install redis
shell: cd /root/ && mkdir -p /Data/local/ && tar -zxvf redis-3.2.12.tar.gz && cd redis-3.2.12 && make && 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:
- start redis
- name: Make sure autoconf268 utils installed
yum:
name: autoconf268,automake,libtool
state: installed
update_cache: yes
- name: Check if twemproxy already installed
stat: path=/Data/local/twemproxy/sbin/nutcracker
register: nutcracker_binary
- name: Download latest twemproxy
git:
repo: https://github.com/twitter/twemproxy.git
dest: /root/twemproxy
accept_hostkey: true
when: nutcracker_binary.stat.exists == False
- name: Install twemproxy
shell: cd /root/twemproxy && autoreconf268 -ivf && ./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
... ...
alpha:
listen: 0.0.0.0:22121
hash: fnv1a_64
distribution: ketama
auto_eject_hosts: true
redis: true
server_retry_timeout: 2000
server_failure_limit: 2
servers:
{% for host in play_hosts %}
- {{ host }}:6379:1
{% endfor %}
... ...
daemonize yes
pidfile /Data/local/redis/redis.pid
bind "{{ ansible_default_ipv4['address'] }}"
port 6379
tcp-backlog 511
timeout 300
tcp-keepalive 60
loglevel notice
logfile "/Data/logs/redis/redis.log"
databases 16
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename redis01.rdb
dir /Data/local/redis/data
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
maxclients 2048
maxmemory {{ ansible_memtotal_mb*0.8 }}M
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
... ...