Skip to content

Commit c90a91c

Browse files
committed
Migrate from ddev-contrib
1 parent e6f6266 commit c90a91c

File tree

4 files changed

+351
-0
lines changed

4 files changed

+351
-0
lines changed

README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Apache Solr (Cloud) Integration for DDEV-Local
2+
3+
Running Solr in single core mode is not the recommended way anymore. The "Solr
4+
Cloud" mode is the preferred way and offers many additional features like
5+
Streaming Expressions and APIs that make management easier. These APIs allow to
6+
create and modify collections (cores), manage stopwords, synonyms etc.
7+
All from Drupal via UI or drush, via the Solarium library or your custom code.
8+
That’s a huge difference compared to Solr maintenance like you know it before!
9+
10+
In a production environment it is recommended to have at least three Solr nodes
11+
that build that "cloud". In a development environment you can choose to only run
12+
a single node in standalone mode to require less memory or CPU. DDEV offers both
13+
options. You choose to run three nodes or a single node in standalone mode by
14+
copying either `docker-compose.solr.yaml` or
15+
`docker-compose.solr-standalone.yaml` to your project's `.ddev` folder.
16+
17+
Solr Cloud provides a lot of APIs to manage your collections, cores, schemas
18+
etc. Some of these APIs require a so-called "trusted" context. Solr therefore
19+
supports different technologies for authentication and authorization. The
20+
easiest one to configure is "Basic Authentication". This DDEV service comes with
21+
a simple pre-configured `security.json` to provide such a trusted context based
22+
on basic authentication. It creates a single administrative account full access
23+
rights:
24+
* user: `solr`
25+
* password: `SolrRocks`
26+
27+
Just copy the `solr` directory (including `security.json`) to your
28+
project's `.ddev` folder. If required, you can adjust the username and the
29+
password by editing the `security.json` file and restarting the service. But be
30+
aware that the password is stored as a hash. Please consult the Solr
31+
documentation for details. On the other hand our recommendation for a local
32+
development environment is to just stay with the default.
33+
34+
Once up and running you can access Solr's UI within your browser by opening
35+
`http://<projectname>.ddev.site:8983`. For example, if the project is named
36+
"myproject" the hostname will be `http://myproject.ddev.site:8983`. To access
37+
the Solr container from the web container use `ddev-<project>-solr:8983`.
38+
39+
Solr Cloud depends on Zookeeper to share configurations between the Solr nodes.
40+
Therefore this service starts a single Zookeeper server on port 2181, too. It is
41+
also required if you decide to run this service in standalone mode using a
42+
single node only. But there's nothing you need to care about. This is just for
43+
your information in case you wonder what that service is.
44+
45+
## Drupal and Search API Solr
46+
47+
For Drupal and Search API Solr you need to configure a Search API server using
48+
Solr as backend and `Solr Cloud with Basic Auth` as its connector. As mentioned
49+
above, username "solr" and password "SolrRocks" are the pre-configured
50+
credentials for Basic Authentication in `.ddev/solr/security.json`.
51+
52+
Solr requires a Drupal-specific configset for any collection that should be used
53+
to index Drupal's content. (In Solr Cloud "collections" are the equivalent to
54+
"cores" in classic Solr installations. Actually a collection consists of
55+
multiple cores sharded across all server nodes.)
56+
Starting from Search API Solr module version 4.2.1 you don't need to deal with
57+
configsets manually anymore. Just enable the `search_api_solr_admin` sub-module
58+
which is part of Search API Solr. Now you create or update your "collections" at
59+
any time by clicking the "Upload Configset" button on the Search API server
60+
details page, or automate things using
61+
```
62+
ddev drush search-api-solr:upload-configset SERVER_ID NUMBER_OF_SHARDS
63+
```
64+
65+
Note: If you choose to run Solr Cloud using a single node in standalone mode,
66+
you need to limit the number of "shards" to "1" when uploading the
67+
configset. There's a corresponding option in the UI and a parameter for
68+
the drush command.
69+
70+
## Installation step by step
71+
72+
1. Copy `docker-compose.solr.yaml` **or** `docker-compose.solr-standalone.yaml` to your project's `.ddev` directory.
73+
2. Copy the `solr` folder (`including security.json`) to your project's `.ddev` directory.
74+
3. Configure your application to connect Solr at `http://ddev-<project>-solr:8983`.
75+
4. If you want to use Solr's APIs that require a trusted context configure Basic Auth with username `solr` and password `SolrRocks`.
76+
5. (Re-)start your DDEV project.
77+
78+
## Solarium
79+
80+
[Solarium](https://github.com/solariumphp/solarium) is the leading Solr
81+
integration library for PHP. It is used by the modules and integrations of many
82+
PHP frameworks and CMS like Drupal, Typo3, Wordpress, Symfony, Laravel, ...
83+
If you build your own PHP application and want to use Solarium directly, here is
84+
an example of how to configure the connection in DDEV.
85+
86+
```php
87+
use Solarium\Core\Client\Adapter\Curl;
88+
use Symfony\Component\EventDispatcher\EventDispatcher;
89+
90+
$adapter = new Curl();
91+
$eventDispatcher = new EventDispatcher();
92+
$config = [
93+
'endpoint' => [
94+
'localhost' => [
95+
// Replace <project> by your project's name:
96+
'host' => 'ddev-<project>-solr',
97+
'port' => 8983,
98+
'path' => '/',
99+
// Use your collection name here:
100+
'collection' => 'techproducts',
101+
'username' => 'solr',
102+
'password' => 'SolrRocks',
103+
)
104+
)
105+
);
106+
107+
$client = new Solarium\Client($adapter, $eventDispatcher, $config);
108+
```
109+
110+
## Drupal and Search API Solr (>= 4.2.1)
111+
112+
* Enable the `search_api_solr_admin` module. (This sub-module is included in Search API Solr >= 4.2.1)
113+
* Create a search server using the Solr backend and select `Solr Cloud with Basic Auth` as connector:
114+
* HTTP protocol: `http`
115+
* Solr node: `ddev-<project>-solr` (Replace <project> by your project's name.)
116+
* Solr port: `8983`
117+
* Solr path: `/`
118+
* Default Solr collection: `techproducts` (You can define any name here. The collection will be created automatically.)
119+
* Username: `solr`
120+
* Password: `SolrRocks`
121+
* Press the `Upload Configset` button on the server's view and check the "Upload (and overwrite) configset" checkbox.
122+
* Set the number of shards to _3_ if you use `docker-compose.solr.yaml` or _1_ if you use `docker-compose.solr-standalone.yaml`.
123+
* Press `Upload`.
124+
125+
### Drupal and Search API Solr 4.1 and older
126+
127+
It is highly recommended to upgrade to the 4.2 version. But if you're required
128+
to use an older versions of the Search API Solr module you have to deploy the
129+
configset manually and create a collection using this configset afterwards.
130+
Therefore you need to use the `Download config.zip` function of Search API Solr.
131+
Please consult the Solr documention about the different ways about how to deploy
132+
configset archive and how to create a collection using it.
133+
134+
135+
**Contributed by [@mkalkbrenner](https://github.com/mkalkbrenner)**
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# DDev Solr Cloud service file.
2+
#
3+
# This is a variation of docker-compose.solr.yaml that only creates one Solr node and runs a single zookeeper in
4+
# standalone mode. This setup is not recommended for a production environment but requires less ressources in a
5+
# development environment.
6+
#
7+
# To access Solr after it is installed:
8+
# - The Solr admin interface will be accessible at:
9+
# http://<projectname>.ddev.site:8983
10+
# For example, if the project is named "myproject" the hostname will be:
11+
# http://myproject.ddev.site:8983
12+
# - To access the Solr container from the web container use:
13+
# ddev-<project>-solr:8983
14+
#
15+
# To use this in your own project:
16+
# 1. Copy this file and the solr (including security.json) directory to your project's ".ddev" directory.
17+
# 2. For Drupal:
18+
# - enable the search_api_solr_admin (this sub-module included in Search API Solr >= 4.2.1)
19+
# - create a search server using the Solr Cloud Connector with Basic Auth using username "solr" and password
20+
# "SolrRocks".
21+
# - press the "Upload Configset" button.
22+
# - select the checkbox "Upload (and overwrite) configset to Solr Server."
23+
# - set the number of shards to "1" and press "Upload"
24+
25+
version: '3.6'
26+
services:
27+
solr:
28+
image: solr:8
29+
container_name: ddev-${DDEV_SITENAME}-solr
30+
expose:
31+
- 8983
32+
# These labels ensure this service is discoverable by ddev.
33+
labels:
34+
com.ddev.site-name: ${DDEV_SITENAME}
35+
com.ddev.approot: $DDEV_APPROOT
36+
environment:
37+
SOLR_HOST: ddev-${DDEV_SITENAME}-solr
38+
SOLR_PORT: 8983
39+
# The pre-trained OpenNLP models require a much bigger buffer.
40+
SOLR_OPTS: -Djute.maxbuffer=50000000
41+
#SOLR_HEAP: 1g
42+
ZK_HOST: ddev-${DDEV_SITENAME}-zoo:2181
43+
VIRTUAL_HOST: $DDEV_HOSTNAME
44+
HTTP_EXPOSE: 8983:8983
45+
depends_on:
46+
- zoo
47+
volumes:
48+
- .:/mnt/ddev_config
49+
- solr:/var/solr
50+
command: bash -c "docker-entrypoint.sh solr zk cp file:/mnt/ddev_config/solr/security.json zk:/security.json && exec solr-foreground"
51+
52+
zoo:
53+
image: bitnami/zookeeper:3.7
54+
container_name: ddev-${DDEV_SITENAME}-zoo
55+
hostname: ddev-${DDEV_SITENAME}-zoo
56+
expose:
57+
- 2181
58+
labels:
59+
com.ddev.site-name: ${DDEV_SITENAME}
60+
com.ddev.approot: $DDEV_APPROOT
61+
environment:
62+
# The pre-trained OpenNLP models require a much bigger buffer.
63+
JVMFLAGS: -Djute.maxbuffer=50000000
64+
ZOO_MY_ID: 1
65+
ZOO_SERVERS: server.1=ddev-${DDEV_SITENAME}-zoo1:2888:3888
66+
ZOO_4LW_COMMANDS_WHITELIST: mntr, conf, ruok
67+
ALLOW_ANONYMOUS_LOGIN: "yes"
68+
volumes:
69+
- .:/mnt/ddev_config
70+
- zoo:/bitnami/zookeeper
71+
72+
# This links the Solr service to the web service defined in the main
73+
# docker-compose.yml, allowing applications running inside the web container to
74+
# access the Solr service at http://solr:8983
75+
web:
76+
links:
77+
- solr:solr
78+
79+
volumes:
80+
solr:
81+
zoo:

docker-compose.solr.yaml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# DDev Solr Cloud service file.
2+
#
3+
# To access Solr after it is installed:
4+
# - The Solr admin interface will be accessible at:
5+
# http://<projectname>.ddev.site:8983
6+
# For example, if the project is named "myproject" the hostname will be:
7+
# http://myproject.ddev.site:8983
8+
# - To access the Solr container from the web container use:
9+
# ddev-<project>-solr:8983
10+
#
11+
# To use this in your own project:
12+
# 1. Copy this file and the solr (including security.json) directory to your project's ".ddev" directory.
13+
# 2. For Drupal:
14+
# - enable the search_api_solr_admin (this sub-module included in Search API Solr >= 4.2.1)
15+
# - create a search server using the Solr Cloud Connector with Basic Auth using username "solr" and password
16+
# "SolrRocks".
17+
# - press the "Upload Configset" button.
18+
19+
version: '3.6'
20+
services:
21+
solr1:
22+
image: solr:8
23+
container_name: ddev-${DDEV_SITENAME}-solr1
24+
expose:
25+
- 8983
26+
# These labels ensure this service is discoverable by ddev.
27+
labels:
28+
com.ddev.site-name: ${DDEV_SITENAME}
29+
com.ddev.approot: $DDEV_APPROOT
30+
environment:
31+
SOLR_HOST: ddev-${DDEV_SITENAME}-solr1
32+
SOLR_PORT: 8983
33+
# The pre-trained OpenNLP models require a much bigger buffer.
34+
SOLR_OPTS: -Djute.maxbuffer=50000000
35+
#SOLR_HEAP: 1g
36+
ZK_HOST: ddev-${DDEV_SITENAME}-zoo:2181
37+
VIRTUAL_HOST: $DDEV_HOSTNAME
38+
HTTP_EXPOSE: 8983:8983
39+
depends_on:
40+
- zoo
41+
volumes:
42+
- .:/mnt/ddev_config
43+
- solr1:/var/solr
44+
command: bash -c "docker-entrypoint.sh solr zk cp file:/mnt/ddev_config/solr/security.json zk:/security.json && exec solr-foreground"
45+
46+
solr2:
47+
image: solr:8
48+
container_name: ddev-${DDEV_SITENAME}-solr2
49+
expose:
50+
- 8984
51+
labels:
52+
com.ddev.site-name: ${DDEV_SITENAME}
53+
com.ddev.approot: $DDEV_APPROOT
54+
environment:
55+
SOLR_HOST: ddev-${DDEV_SITENAME}-solr2
56+
SOLR_PORT: 8984
57+
# The pre-trained OpenNLP models require a much bigger buffer.
58+
SOLR_OPTS: -Djute.maxbuffer=50000000
59+
#SOLR_HEAP: 1g
60+
ZK_HOST: ddev-${DDEV_SITENAME}-zoo:2181
61+
VIRTUAL_HOST: $DDEV_HOSTNAME
62+
HTTP_EXPOSE: 8984:8984
63+
depends_on:
64+
- solr1
65+
volumes:
66+
- .:/mnt/ddev_config
67+
- solr2:/var/solr
68+
69+
solr3:
70+
image: solr:8
71+
container_name: ddev-${DDEV_SITENAME}-solr3
72+
expose:
73+
- 8985
74+
labels:
75+
com.ddev.site-name: ${DDEV_SITENAME}
76+
com.ddev.approot: $DDEV_APPROOT
77+
environment:
78+
SOLR_HOST: ddev-${DDEV_SITENAME}-solr3
79+
SOLR_PORT: 8985
80+
# The pre-trained OpenNLP models require a much bigger buffer.
81+
SOLR_OPTS: -Djute.maxbuffer=50000000
82+
#SOLR_HEAP: 1g
83+
ZK_HOST: ddev-${DDEV_SITENAME}-zoo:2181
84+
VIRTUAL_HOST: $DDEV_HOSTNAME
85+
HTTP_EXPOSE: 8985:8985
86+
depends_on:
87+
- solr1
88+
volumes:
89+
- .:/mnt/ddev_config
90+
- solr3:/var/solr
91+
92+
zoo:
93+
image: bitnami/zookeeper:3.7
94+
container_name: ddev-${DDEV_SITENAME}-zoo
95+
hostname: ddev-${DDEV_SITENAME}-zoo
96+
expose:
97+
- 2181
98+
labels:
99+
com.ddev.site-name: ${DDEV_SITENAME}
100+
com.ddev.approot: $DDEV_APPROOT
101+
environment:
102+
# The pre-trained OpenNLP models require a much bigger buffer.
103+
JVMFLAGS: -Djute.maxbuffer=50000000
104+
ZOO_MY_ID: 1
105+
ZOO_SERVERS: server.1=ddev-${DDEV_SITENAME}-zoo:2888:3888
106+
ZOO_4LW_COMMANDS_WHITELIST: mntr, conf, ruok
107+
ALLOW_ANONYMOUS_LOGIN: "yes"
108+
volumes:
109+
- .:/mnt/ddev_config
110+
- zoo:/bitnami/zookeeper
111+
112+
# This links the Solr service to the web service defined in the main
113+
# docker-compose.yml, allowing applications running inside the web container to
114+
# access the Solr service at http://solr:8983
115+
web:
116+
links:
117+
- solr1:solr
118+
119+
volumes:
120+
solr1:
121+
solr2:
122+
solr3:
123+
zoo:

solr/security.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"authentication":{
3+
"class":"solr.BasicAuthPlugin",
4+
"credentials":{"solr":"IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c="}
5+
},
6+
"authorization":{
7+
"class":"solr.RuleBasedAuthorizationPlugin",
8+
"permissions":[{"name":"security-edit",
9+
"role":"admin"}],
10+
"user-role":{"solr":"admin"}
11+
}
12+
}

0 commit comments

Comments
 (0)