Update elasticsearch index playbooks (#892)
* Update elasticsearch index swapping playbooks * Add ansible syntax check * Document index swapping * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml
Cette révision appartient à :
Parent
6c0735607f
révision
991fc73c4e
6 fichiers modifiés avec 69 ajouts et 22 suppressions
|
@ -3,11 +3,15 @@ go:
|
|||
- 1.x
|
||||
gobuild_args: -x -ldflags "-X main.buildversion=$(date -u +.%Y%m%d.%H%M%S)"
|
||||
before_install:
|
||||
- sudo apt-get install gcc-mingw-w64 gcc-mingw-w64-i686 gcc-mingw-w64-x86-64 binutils-mingw-w64-i686 binutils-mingw-w64-x86-64
|
||||
- sudo apt-add-repository ppa:ansible/ansible -y
|
||||
- sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
|
||||
- sudo apt-get update
|
||||
- sudo apt-get install gcc-mingw-w64 gcc-mingw-w64-i686 gcc-mingw-w64-x86-64 binutils-mingw-w64-i686 binutils-mingw-w64-x86-64 ansible
|
||||
- go get -u github.com/tools/godep
|
||||
before_script:
|
||||
- go vet
|
||||
- go test -v ./...
|
||||
- cd deploy/ansible/ && for playbook in *.yml; do ansible-playbook -i hosts $playbook --syntax-check; done && cd ../..
|
||||
install:
|
||||
# Add Godeps dependencies to GOPATH and PATH
|
||||
- export GOPATH="${TRAVIS_BUILD_DIR}/vendor:$GOPATH"
|
||||
|
|
|
@ -109,28 +109,40 @@ $ ansible-playbook -i hosts restore_database.yml
|
|||
```
|
||||
|
||||
|
||||
### Create Elasticsearch Index Playbook
|
||||
### Elasticsearch Index Playbooks
|
||||
|
||||
This playbook creates the elasticsearch index for our database from
|
||||
[ansible/roles/elasticsearch/files/elasticsearch_settings.yml](ansible/roles/elasticsearch/files/elasticsearch_settings.yml)
|
||||
We are using index aliases for a zero downtime and index hotswapping. You can
|
||||
find more information [here](https://www.elastic.co/guide/en/elasticsearch/guide/current/index-aliases.html).
|
||||
|
||||
I'll assume you already have an index named `nyaapantsu_old` that is aliased to
|
||||
`nyaapantsu` and you want to create a new index to become the new `nyaapantsu`.
|
||||
|
||||
First you'll need to modify the variables in the [group_vars/all](group_vars/all)
|
||||
file.
|
||||
|
||||
The new index will be called `nyaapantsu_new`.
|
||||
|
||||
```yaml
|
||||
nyaapantsu_elasticsearch_alias: nyaapantsu
|
||||
nyaapantsu_elasticsearch_index: nyaapantsu_new
|
||||
nyaapantsu_elasticsearch_old_index: nyaapantsu_old
|
||||
```
|
||||
|
||||
Now you need to run three playbooks.
|
||||
|
||||
```bash
|
||||
# Creates the new index
|
||||
$ ansible-playbook -i hosts create_elasticsearch_index.yml
|
||||
```
|
||||
|
||||
|
||||
### Populate Elasticsearch Index Playbook
|
||||
|
||||
This playbook uses a python script to populate the elasticsearch index from all
|
||||
the data inside the database.
|
||||
|
||||
> WARNING: Make sure the python script is in sync with the mapping defined in
|
||||
> the elasticsearch index configuration.
|
||||
|
||||
```
|
||||
# Populate the new index and disable the reindexing cron job. This avoid
|
||||
# losing new entries.
|
||||
$ ansible-playbook -i hosts populate_elasticsearch_index.yml
|
||||
# Remove the alias nyaapantsu from nyaapantsu_old and adds it to nyaapantsu_new
|
||||
$ ansible-playbook -i hosts swap_elasticsearch_index.yml
|
||||
```
|
||||
|
||||
Nyaa can now access the new index `nyaapantsu_new` by using the alias
|
||||
`nyaapantsu`.
|
||||
|
||||
## Playbook Testing
|
||||
|
||||
You can easily test these playbooks by using vagrant. Once you have vagrant
|
||||
|
@ -138,7 +150,7 @@ installed:
|
|||
|
||||
```
|
||||
# Download centos/7 image
|
||||
$ vagrant init centos/7
|
||||
$ vagrant init centos/7
|
||||
|
||||
# Create and boot the vm
|
||||
$ vagrant up
|
||||
|
|
|
@ -16,8 +16,3 @@
|
|||
url: "http://localhost:9200/{{ nyaapantsu_elasticsearch_index }}"
|
||||
method: PUT
|
||||
body: "{{ config.stdout }}"
|
||||
|
||||
- name: Create alias
|
||||
uri:
|
||||
url: "http://localhost:9200/{{ nyaapantsu_elasticsearch_index }}/_alias/{{ nyaapantsu_elasticsearch_alias }}"
|
||||
method: PUT
|
||||
|
|
|
@ -9,6 +9,7 @@ nyaapantsu_elasticsearch_alias: nyaapantsu
|
|||
# nyaapantsu_elasticsearch_alias: sukebei
|
||||
nyaapantsu_elasticsearch_index: nyaapantsu_v1
|
||||
# nyaapantsu_elasticsearch_index: nyaapantsu_sukebei_v1
|
||||
nyaapantsu_elasticsearch_old_index: CHANGETHIS
|
||||
nyaapantsu_torrent_tablename: torrents
|
||||
# nyaapantsu_torrent_tablename: torrents_sukebei
|
||||
nyaapantsu_max_open_files: 200000
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
- elasticsearch
|
||||
|
||||
tasks:
|
||||
# Needed otherwise we'll lose information when people upload when we're
|
||||
# populating to the new index.
|
||||
# DONT FORGET TO RE-ENABLE THE CRON JOB AFTER
|
||||
- name: Disable reindex cron job
|
||||
command: mv "/etc/cron.d/reindex_{{ nyaapantsu_torrent_tablename }}" /tmp/
|
||||
become: true
|
||||
|
||||
- name: Index the database into elasticsearch
|
||||
command: python "{{ nyaapantsu_directory }}/index_nyaapantsu.py"
|
||||
environment:
|
||||
|
|
28
deploy/ansible/swap_elasticsearch_index.yml
Fichier normal
28
deploy/ansible/swap_elasticsearch_index.yml
Fichier normal
|
@ -0,0 +1,28 @@
|
|||
# We're not putting elasticsearch role because we don't want to re-enable the
|
||||
# reindexing cron job before we've actually made the swap
|
||||
- name: Populate elasticsearch index from database
|
||||
hosts: dbs
|
||||
roles:
|
||||
- common
|
||||
- postgresql
|
||||
|
||||
tasks:
|
||||
- name: Swap elasticsearch index
|
||||
uri:
|
||||
url: "http://localhost:9200/_aliases"
|
||||
method: POST
|
||||
body_format: json
|
||||
body:
|
||||
actions:
|
||||
- remove:
|
||||
index: "{{ nyaapantsu_elasticsearch_old_index }}"
|
||||
alias: "{{ nyaapantsu_elasticsearch_alias }}"
|
||||
- add:
|
||||
index: "{{ nyaapantsu_elasticsearch_index }}"
|
||||
alias: "{{ nyaapantsu_elasticsearch_alias }}"
|
||||
|
||||
- name: Re-enable reindex cron job
|
||||
command: mv "/tmp/reindex_{{ nyaapantsu_torrent_tablename }}" /etc/cron.d/
|
||||
become: true
|
||||
ignore_errors: yes # Can ignore error here if the file had previously been
|
||||
# moved.
|
Référencer dans un nouveau ticket