Skip to content

Commit

Permalink
Migrate from ddev-contrib
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed Jan 12, 2022
1 parent e6f6266 commit c90a91c
Show file tree
Hide file tree
Showing 4 changed files with 351 additions and 0 deletions.
135 changes: 135 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Apache Solr (Cloud) Integration for DDEV-Local

Running Solr in single core mode is not the recommended way anymore. The "Solr
Cloud" mode is the preferred way and offers many additional features like
Streaming Expressions and APIs that make management easier. These APIs allow to
create and modify collections (cores), manage stopwords, synonyms etc.
All from Drupal via UI or drush, via the Solarium library or your custom code.
That’s a huge difference compared to Solr maintenance like you know it before!

In a production environment it is recommended to have at least three Solr nodes
that build that "cloud". In a development environment you can choose to only run
a single node in standalone mode to require less memory or CPU. DDEV offers both
options. You choose to run three nodes or a single node in standalone mode by
copying either `docker-compose.solr.yaml` or
`docker-compose.solr-standalone.yaml` to your project's `.ddev` folder.

Solr Cloud provides a lot of APIs to manage your collections, cores, schemas
etc. Some of these APIs require a so-called "trusted" context. Solr therefore
supports different technologies for authentication and authorization. The
easiest one to configure is "Basic Authentication". This DDEV service comes with
a simple pre-configured `security.json` to provide such a trusted context based
on basic authentication. It creates a single administrative account full access
rights:
* user: `solr`
* password: `SolrRocks`

Just copy the `solr` directory (including `security.json`) to your
project's `.ddev` folder. If required, you can adjust the username and the
password by editing the `security.json` file and restarting the service. But be
aware that the password is stored as a hash. Please consult the Solr
documentation for details. On the other hand our recommendation for a local
development environment is to just stay with the default.

Once up and running you can access Solr's UI within your browser by opening
`http://<projectname>.ddev.site:8983`. For example, if the project is named
"myproject" the hostname will be `http://myproject.ddev.site:8983`. To access
the Solr container from the web container use `ddev-<project>-solr:8983`.

Solr Cloud depends on Zookeeper to share configurations between the Solr nodes.
Therefore this service starts a single Zookeeper server on port 2181, too. It is
also required if you decide to run this service in standalone mode using a
single node only. But there's nothing you need to care about. This is just for
your information in case you wonder what that service is.

## Drupal and Search API Solr

For Drupal and Search API Solr you need to configure a Search API server using
Solr as backend and `Solr Cloud with Basic Auth` as its connector. As mentioned
above, username "solr" and password "SolrRocks" are the pre-configured
credentials for Basic Authentication in `.ddev/solr/security.json`.

Solr requires a Drupal-specific configset for any collection that should be used
to index Drupal's content. (In Solr Cloud "collections" are the equivalent to
"cores" in classic Solr installations. Actually a collection consists of
multiple cores sharded across all server nodes.)
Starting from Search API Solr module version 4.2.1 you don't need to deal with
configsets manually anymore. Just enable the `search_api_solr_admin` sub-module
which is part of Search API Solr. Now you create or update your "collections" at
any time by clicking the "Upload Configset" button on the Search API server
details page, or automate things using
```
ddev drush search-api-solr:upload-configset SERVER_ID NUMBER_OF_SHARDS
```

Note: If you choose to run Solr Cloud using a single node in standalone mode,
you need to limit the number of "shards" to "1" when uploading the
configset. There's a corresponding option in the UI and a parameter for
the drush command.

## Installation step by step

1. Copy `docker-compose.solr.yaml` **or** `docker-compose.solr-standalone.yaml` to your project's `.ddev` directory.
2. Copy the `solr` folder (`including security.json`) to your project's `.ddev` directory.
3. Configure your application to connect Solr at `http://ddev-<project>-solr:8983`.
4. If you want to use Solr's APIs that require a trusted context configure Basic Auth with username `solr` and password `SolrRocks`.
5. (Re-)start your DDEV project.

## Solarium

[Solarium](https://github.com/solariumphp/solarium) is the leading Solr
integration library for PHP. It is used by the modules and integrations of many
PHP frameworks and CMS like Drupal, Typo3, Wordpress, Symfony, Laravel, ...
If you build your own PHP application and want to use Solarium directly, here is
an example of how to configure the connection in DDEV.

```php
use Solarium\Core\Client\Adapter\Curl;
use Symfony\Component\EventDispatcher\EventDispatcher;

$adapter = new Curl();
$eventDispatcher = new EventDispatcher();
$config = [
'endpoint' => [
'localhost' => [
// Replace <project> by your project's name:
'host' => 'ddev-<project>-solr',
'port' => 8983,
'path' => '/',
// Use your collection name here:
'collection' => 'techproducts',
'username' => 'solr',
'password' => 'SolrRocks',
)
)
);

$client = new Solarium\Client($adapter, $eventDispatcher, $config);
```

## Drupal and Search API Solr (>= 4.2.1)

* Enable the `search_api_solr_admin` module. (This sub-module is included in Search API Solr >= 4.2.1)
* Create a search server using the Solr backend and select `Solr Cloud with Basic Auth` as connector:
* HTTP protocol: `http`
* Solr node: `ddev-<project>-solr` (Replace <project> by your project's name.)
* Solr port: `8983`
* Solr path: `/`
* Default Solr collection: `techproducts` (You can define any name here. The collection will be created automatically.)
* Username: `solr`
* Password: `SolrRocks`
* Press the `Upload Configset` button on the server's view and check the "Upload (and overwrite) configset" checkbox.
* Set the number of shards to _3_ if you use `docker-compose.solr.yaml` or _1_ if you use `docker-compose.solr-standalone.yaml`.
* Press `Upload`.

### Drupal and Search API Solr 4.1 and older

It is highly recommended to upgrade to the 4.2 version. But if you're required
to use an older versions of the Search API Solr module you have to deploy the
configset manually and create a collection using this configset afterwards.
Therefore you need to use the `Download config.zip` function of Search API Solr.
Please consult the Solr documention about the different ways about how to deploy
configset archive and how to create a collection using it.


**Contributed by [@mkalkbrenner](https://github.com/mkalkbrenner)**
81 changes: 81 additions & 0 deletions docker-compose.solr-standalone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# DDev Solr Cloud service file.
#
# This is a variation of docker-compose.solr.yaml that only creates one Solr node and runs a single zookeeper in
# standalone mode. This setup is not recommended for a production environment but requires less ressources in a
# development environment.
#
# To access Solr after it is installed:
# - The Solr admin interface will be accessible at:
# http://<projectname>.ddev.site:8983
# For example, if the project is named "myproject" the hostname will be:
# http://myproject.ddev.site:8983
# - To access the Solr container from the web container use:
# ddev-<project>-solr:8983
#
# To use this in your own project:
# 1. Copy this file and the solr (including security.json) directory to your project's ".ddev" directory.
# 2. For Drupal:
# - enable the search_api_solr_admin (this sub-module included in Search API Solr >= 4.2.1)
# - create a search server using the Solr Cloud Connector with Basic Auth using username "solr" and password
# "SolrRocks".
# - press the "Upload Configset" button.
# - select the checkbox "Upload (and overwrite) configset to Solr Server."
# - set the number of shards to "1" and press "Upload"

version: '3.6'
services:
solr:
image: solr:8
container_name: ddev-${DDEV_SITENAME}-solr
expose:
- 8983
# These labels ensure this service is discoverable by ddev.
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
environment:
SOLR_HOST: ddev-${DDEV_SITENAME}-solr
SOLR_PORT: 8983
# The pre-trained OpenNLP models require a much bigger buffer.
SOLR_OPTS: -Djute.maxbuffer=50000000
#SOLR_HEAP: 1g
ZK_HOST: ddev-${DDEV_SITENAME}-zoo:2181
VIRTUAL_HOST: $DDEV_HOSTNAME
HTTP_EXPOSE: 8983:8983
depends_on:
- zoo
volumes:
- .:/mnt/ddev_config
- solr:/var/solr
command: bash -c "docker-entrypoint.sh solr zk cp file:/mnt/ddev_config/solr/security.json zk:/security.json && exec solr-foreground"

zoo:
image: bitnami/zookeeper:3.7
container_name: ddev-${DDEV_SITENAME}-zoo
hostname: ddev-${DDEV_SITENAME}-zoo
expose:
- 2181
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
environment:
# The pre-trained OpenNLP models require a much bigger buffer.
JVMFLAGS: -Djute.maxbuffer=50000000
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=ddev-${DDEV_SITENAME}-zoo1:2888:3888
ZOO_4LW_COMMANDS_WHITELIST: mntr, conf, ruok
ALLOW_ANONYMOUS_LOGIN: "yes"
volumes:
- .:/mnt/ddev_config
- zoo:/bitnami/zookeeper

# This links the Solr service to the web service defined in the main
# docker-compose.yml, allowing applications running inside the web container to
# access the Solr service at http://solr:8983
web:
links:
- solr:solr

volumes:
solr:
zoo:
123 changes: 123 additions & 0 deletions docker-compose.solr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# DDev Solr Cloud service file.
#
# To access Solr after it is installed:
# - The Solr admin interface will be accessible at:
# http://<projectname>.ddev.site:8983
# For example, if the project is named "myproject" the hostname will be:
# http://myproject.ddev.site:8983
# - To access the Solr container from the web container use:
# ddev-<project>-solr:8983
#
# To use this in your own project:
# 1. Copy this file and the solr (including security.json) directory to your project's ".ddev" directory.
# 2. For Drupal:
# - enable the search_api_solr_admin (this sub-module included in Search API Solr >= 4.2.1)
# - create a search server using the Solr Cloud Connector with Basic Auth using username "solr" and password
# "SolrRocks".
# - press the "Upload Configset" button.

version: '3.6'
services:
solr1:
image: solr:8
container_name: ddev-${DDEV_SITENAME}-solr1
expose:
- 8983
# These labels ensure this service is discoverable by ddev.
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
environment:
SOLR_HOST: ddev-${DDEV_SITENAME}-solr1
SOLR_PORT: 8983
# The pre-trained OpenNLP models require a much bigger buffer.
SOLR_OPTS: -Djute.maxbuffer=50000000
#SOLR_HEAP: 1g
ZK_HOST: ddev-${DDEV_SITENAME}-zoo:2181
VIRTUAL_HOST: $DDEV_HOSTNAME
HTTP_EXPOSE: 8983:8983
depends_on:
- zoo
volumes:
- .:/mnt/ddev_config
- solr1:/var/solr
command: bash -c "docker-entrypoint.sh solr zk cp file:/mnt/ddev_config/solr/security.json zk:/security.json && exec solr-foreground"

solr2:
image: solr:8
container_name: ddev-${DDEV_SITENAME}-solr2
expose:
- 8984
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
environment:
SOLR_HOST: ddev-${DDEV_SITENAME}-solr2
SOLR_PORT: 8984
# The pre-trained OpenNLP models require a much bigger buffer.
SOLR_OPTS: -Djute.maxbuffer=50000000
#SOLR_HEAP: 1g
ZK_HOST: ddev-${DDEV_SITENAME}-zoo:2181
VIRTUAL_HOST: $DDEV_HOSTNAME
HTTP_EXPOSE: 8984:8984
depends_on:
- solr1
volumes:
- .:/mnt/ddev_config
- solr2:/var/solr

solr3:
image: solr:8
container_name: ddev-${DDEV_SITENAME}-solr3
expose:
- 8985
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
environment:
SOLR_HOST: ddev-${DDEV_SITENAME}-solr3
SOLR_PORT: 8985
# The pre-trained OpenNLP models require a much bigger buffer.
SOLR_OPTS: -Djute.maxbuffer=50000000
#SOLR_HEAP: 1g
ZK_HOST: ddev-${DDEV_SITENAME}-zoo:2181
VIRTUAL_HOST: $DDEV_HOSTNAME
HTTP_EXPOSE: 8985:8985
depends_on:
- solr1
volumes:
- .:/mnt/ddev_config
- solr3:/var/solr

zoo:
image: bitnami/zookeeper:3.7
container_name: ddev-${DDEV_SITENAME}-zoo
hostname: ddev-${DDEV_SITENAME}-zoo
expose:
- 2181
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
environment:
# The pre-trained OpenNLP models require a much bigger buffer.
JVMFLAGS: -Djute.maxbuffer=50000000
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=ddev-${DDEV_SITENAME}-zoo:2888:3888
ZOO_4LW_COMMANDS_WHITELIST: mntr, conf, ruok
ALLOW_ANONYMOUS_LOGIN: "yes"
volumes:
- .:/mnt/ddev_config
- zoo:/bitnami/zookeeper

# This links the Solr service to the web service defined in the main
# docker-compose.yml, allowing applications running inside the web container to
# access the Solr service at http://solr:8983
web:
links:
- solr1:solr

volumes:
solr1:
solr2:
solr3:
zoo:
12 changes: 12 additions & 0 deletions solr/security.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"authentication":{
"class":"solr.BasicAuthPlugin",
"credentials":{"solr":"IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c="}
},
"authorization":{
"class":"solr.RuleBasedAuthorizationPlugin",
"permissions":[{"name":"security-edit",
"role":"admin"}],
"user-role":{"solr":"admin"}
}
}

0 comments on commit c90a91c

Please sign in to comment.