|
|
# Elasticsearch Setup
|
|
|
|
|
|
## Installing
|
|
|
|
|
|
To install Elasticsearch, run the following commands:
|
|
|
|
|
|
```plaintext
|
|
|
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
|
|
|
sudo apt-get install apt-transport-https
|
|
|
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list
|
|
|
sudo apt-get update && sudo apt-get install elasticsearch
|
|
|
```
|
|
|
|
|
|
## Configuring
|
|
|
|
|
|
#### Max Memory Usage
|
|
|
|
|
|
For development purposes, it is sufficient to limit Elasticsearch to 1GB RAM. You can set this in `/etc/elasticsearch/jvm.options.d/lowram.jvm.options`using your editor of choice:
|
|
|
|
|
|
```
|
|
|
-Xms1g
|
|
|
-Xmx1g
|
|
|
```
|
|
|
|
|
|
Or as a one-time use command:
|
|
|
|
|
|
```
|
|
|
sudo echo -e "-Xms1g\n-Xmx1g" > /etc/elasticsearch/jvm.options.d/lowram.jvm.options"
|
|
|
```
|
|
|
|
|
|
#### Authentication for Development
|
|
|
|
|
|
Open the configuration file at `/etc/elasticsearch/elasticsearch.yml` with your favourite editor (requires `sudo`) and add the options:
|
|
|
|
|
|
```
|
|
|
discovery.type: single-node
|
|
|
xpack.security.enabled: false
|
|
|
```
|
|
|
|
|
|
Or as a one-time use command:
|
|
|
|
|
|
```
|
|
|
sudo echo -e "discovery.type: single-node\nxpack.security.enabled: false" > /etc/elasticsearch/elasticsearch.yml"
|
|
|
```
|
|
|
|
|
|
Now, start/restart Elasticsearch with `sudo service elasticsearch restart` .
|
|
|
|
|
|
#### Authentication for Production
|
|
|
|
|
|
For production, you will probably want to set `xpack.security.enabled: true` . See <https://www.elastic.co/guide/en/elasticsearch/reference/7.13/security-minimal-setup.html> .
|
|
|
|
|
|
Configure passwords by running the following command:
|
|
|
|
|
|
```
|
|
|
/usr/share/elasticsearch/elasticsearch-setup-passwords auto
|
|
|
```
|
|
|
|
|
|
This will automatically generate passwords for the cluster which you can configure in Project Forum in `(shared/)config/initializers/elastic_search.rb`.
|
|
|
|
|
|
## Starting and Stopping Elasticsearch
|
|
|
|
|
|
You can start elasticsearch with `sudo service elasticsearch start` and stop it again with `sudo service elasticsearch stop`.
|
|
|
|
|
|
## Sync databases
|
|
|
|
|
|
Whenever the database is reset or changed without Elasticsearch being informed (i.e. due to an error), the Elasticsearch database must also be brought back into sync. Use
|
|
|
|
|
|
```
|
|
|
bundle exec rake elasticsearch:sync
|
|
|
```
|
|
|
|
|
|
to sync it. You can prepend `RAILS_ENV=production` in case you want to do this with the production database. |
|
|
\ No newline at end of file |