nodes.yml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. ---
  2. - hosts: nodes
  3. become: yes
  4. become_user: root
  5. become_method: sudo
  6. gather_facts: yes
  7. vars:
  8. raft_repo: "https://github.com/Redislabs/redisraft"
  9. raft_branch: "master"
  10. deb_packages:
  11. - build-essential
  12. - autoconf
  13. - cmake
  14. - automake
  15. - libbsd-dev
  16. - libltdl-dev
  17. - libltdl7
  18. - libtool
  19. - libevent-openssl-2.1-6
  20. - libpcre3-dev
  21. - libevent-dev
  22. - pkg-config
  23. - zlib1g-dev
  24. - libssl-dev
  25. - python3-pip
  26. redis_ports:
  27. - {"port": 19901, "start-hslot": 0, "end-hslot": 1365}
  28. - {"port": 19902, "start-hslot": 1366, "end-hslot": 2730}
  29. - {"port": 19903, "start-hslot": 2731, "end-hslot": 4096}
  30. - {"port": 19904, "start-hslot": 4097, "end-hslot": 5460}
  31. - {"port": 19905, "start-hslot": 5461, "end-hslot": 6826}
  32. - {"port": 19906, "start-hslot": 6827, "end-hslot": 8191}
  33. - {"port": 19907, "start-hslot": 8192, "end-hslot": 9557}
  34. - {"port": 19908, "start-hslot": 9558, "end-hslot": 10921}
  35. - {"port": 19909, "start-hslot": 10922, "end-hslot": 12287}
  36. - {"port": 19910, "start-hslot": 12288, "end-hslot": 13651}
  37. - {"port": 19911, "start-hslot": 13652, "end-hslot": 15017}
  38. - {"port": 19912, "start-hslot": 15018, "end-hslot": 16383}
  39. handlers:
  40. - name: reload_redis_services
  41. command: systemctl daemon-reload
  42. - name: restart_redis_services
  43. systemd:
  44. name: "redis-{{ item['port'] }}"
  45. state: restarted
  46. with_items: "{{ redis_ports }}"
  47. pre_tasks:
  48. - name: Update Apt Cache
  49. apt: update_cache=yes cache_valid_time=86400
  50. when: ansible_os_family == "Debian"
  51. - name: Ubuntu Packages
  52. package:
  53. name: "{{ deb_packages }}"
  54. - name: Set to Realistic Hostname
  55. hostname:
  56. name: "cpredisnode-{{ ansible_default_ipv4.address | replace('.', '-') }}"
  57. - name: Setup Hostsfile
  58. lineinfile:
  59. dest: /etc/hosts
  60. regexp: '^127\.0\.0\.1[ \t]+localhost'
  61. line: "127.0.0.1 localhost cpredisnode-{{ansible_default_ipv4.address | replace('.','-')}}"
  62. state: present
  63. - name: Disable THP
  64. shell: "echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled"
  65. - name: Disable Swap
  66. ansible.posix.sysctl:
  67. name: vm.swappiness
  68. value: '0'
  69. state: present
  70. - name: Enable RPS
  71. shell: "echo '3' > /sys/class/net/{{ ansible_default_ipv4.alias}}/queues/rx-0/rps_cpus"
  72. - name: Install Redis Python pip
  73. pip:
  74. name: redis
  75. executable: pip3
  76. - name: Install Redis Cluster Python pip
  77. pip:
  78. name: redis-py-cluster
  79. executable: pip3
  80. tasks:
  81. - name: load vars
  82. include_vars: default.yaml
  83. tags:
  84. - cluster
  85. - name: create redis user
  86. user:
  87. name: redis
  88. uid: 4001
  89. shell: /bin/bash
  90. state: present
  91. - name: raft - clone the github repo
  92. git:
  93. repo: "{{raft_repo}}"
  94. dest: /home/redis/redisraft
  95. version: "{{raft_branch}}"
  96. recursive: yes
  97. update: yes
  98. force: yes
  99. notify:
  100. - restart_redis_services
  101. - name: raft - make
  102. make:
  103. chdir: /home/redis/redisraft
  104. - name: create raft directories
  105. file:
  106. path: /redis/persistant/cpredis
  107. owner: redis
  108. group: redis
  109. mode: '0755'
  110. state: directory
  111. - name: create raft directories
  112. file:
  113. path: /var/log/cpredis
  114. owner: redis
  115. group: redis
  116. mode: '0755'
  117. state: directory
  118. - name: checkout redis git repo
  119. git:
  120. repo: 'https://github.com/redis/redis'
  121. dest: /home/redis/redis
  122. - name: redis - Build the default target
  123. make:
  124. chdir: /home/redis/redis
  125. - name: redis - Run 'install' target as root
  126. make:
  127. chdir: /home/redis/redis
  128. target: install
  129. become: yes
  130. - name: Redis Systemd
  131. template:
  132. src: systemd_redis.j2
  133. dest: /lib/systemd/system/redis-{{ item['port'] }}.service
  134. owner: root
  135. group: root
  136. mode: 0644
  137. with_items: "{{ redis_ports }}"
  138. notify:
  139. - reload_redis_services
  140. - restart_redis_services
  141. - name: Cluster Setup Script
  142. template:
  143. src: setup_raft_cluster.j2
  144. dest: /usr/local/bin/setup-raft-cluster
  145. owner: redis
  146. group: redis
  147. mode: 0755
  148. tags:
  149. - cluster
  150. - name: Enable Redis Services
  151. systemd:
  152. name: redis-{{ item['port'] }}
  153. enabled: yes
  154. state: started
  155. with_items: "{{ redis_ports }}"
  156. - name: Show RG script
  157. copy:
  158. src: rgshow.py
  159. dest: /usr/bin/rgshow
  160. owner: root
  161. group: root
  162. mode: "0755"