-
Notifications
You must be signed in to change notification settings - Fork 20
/
README
276 lines (231 loc) · 11.1 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
MediaWiki extension: CirrusSearch
---------------------------------
Installation
------------
Get Elasticsearch or OpenSearch up and running somewhere. Both Elasticsearch
v7.10 and OpenSearch v1.3 are supported. Support for Elasticsearch will be
removed in a future version of CirrusSearch, but is currently better tested
than integration with OpenSearch. If you will be running Elasticsearch on a
host separate from the mediawiki installation see
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html.
Be careful with the network configuration, never expose an unprotected node to
the internet.
Place the CirrusSearch extension in your extensions directory.
You also need to install the Elastica MediaWiki extension.
Add this to LocalSettings.php:
wfLoadExtension( 'Elastica' );
wfLoadExtension( 'CirrusSearch' );
$wgDisableSearchUpdate = true;
Configure your search servers in LocalSettings.php if you aren't running Elasticsearch on localhost:
$wgCirrusSearchServers = [ 'elasticsearch0', 'elasticsearch1', 'elasticsearch2', 'elasticsearch3' ];
There are other $wgCirrusSearch variables that you might want to change from their defaults.
Now run this script to generate your elasticsearch index:
php $MW_INSTALL_PATH/extensions/CirrusSearch/maintenance/UpdateSearchIndexConfig.php
Now remove $wgDisableSearchUpdate = true from LocalSettings.php. Updates should start heading to Elasticsearch.
Next bootstrap the search index by running:
php $MW_INSTALL_PATH/extensions/CirrusSearch/maintenance/ForceSearchIndex.php --skipLinks --indexOnSkip
php $MW_INSTALL_PATH/extensions/CirrusSearch/maintenance/ForceSearchIndex.php --skipParse
Note that this can take some time. For large wikis read "Bootstrapping large wikis" below.
Once that is complete add this to LocalSettings.php to funnel queries to ElasticSearch:
$wgSearchType = 'CirrusSearch';
Bootstrapping large wikis
-------------------------
Since most of the load involved in indexing is parsing the pages in php we provide a few options to split the
process into multiple processes. Don't worry too much about the database during this process. It can generally
handle more indexing processes then you are likely to be able to spawn.
General strategy:
0. Make sure you have a good job queue setup. It'll be doing most of the work. In fact, Cirrus won't work
well on large wikis without it.
1. Generate scripts to add all the pages without link counts to the index.
2. Execute them any way you like.
3. Generate scripts to count all the links.
4. Execute them any way you like.
Step 1:
In bash I do this:
export PROCS=5 #or whatever number you want
rm -rf cirrus_scripts
mkdir cirrus_scripts
mkdir cirrus_log
pushd cirrus_scripts
php extensions/CirrusSearch/maintenance/ForceSearchIndex.php --queue --maxJobs 10000 --pauseForJobs 1000 \
--skipLinks --indexOnSkip --buildChunks 250000 |
sed -e 's/$/ | tee -a cirrus_log\/'$wiki'.parse.log/' |
split -n r/$PROCS
for script in x*; do sort -R $script > $script.sh && rm $script; done
popd
Step 2:
Just run all the scripts that step 1 made. Best to run them in screen or something and in the directory above
cirrus_scripts. So like this:
bash cirrus_scripts/xaa.sh
Step 3:
In bash I do this:
pushd cirrus_scripts
rm *.sh
php extensions/CirrusSearch/maintenance/ForceSearchIndex.php --queue --maxJobs 10000 --pauseForJobs 1000 \
--skipParse --buildChunks 250000 |
sed -e 's/$/ | tee -a cirrus_log\/'$wiki'.parse.log/' |
split -n r/$PROCS
for script in x*; do sort -R $script > $script.sh && rm $script; done
popd
Step 4:
Same as step 2 but for the new scripts. These scripts put more load on Elasticsearch so you might want to run
them just one at a time if you don't have a huge Elasticsearch cluster or you want to make sure not to cause load
spikes.
If you don't have a good job queue you can try the above but lower the buildChunks parameter significantly and
remove the --queue parameter.
Handling elasticsearch outages
------------------------------
If for some reason in process updates to elasticsearch begin failing you can immediately
set "$wgDisableSearchUpdate = true;" in your LocalSettings.php file to
stop trying to update elasticsearch. Once you figure out what is wrong with elasticsearch you
should turn those updates back on and then run the following:
php ./maintenance/ForceSearchIndex.php --from <whenever the outage started in ISO 8601 format> --deletes
php ./maintenance/ForceSearchIndex.php --from <whenever the outage started in ISO 8601 format>
The first command picks up all the deletes that occurred during the outage and
should complete quite quickly. The second command picks up all the updates
that occurred during the outage and might take significantly longer.
Changing $wgNamespacesToBeSearchedDefault
-----------------------------------------
When changing wgNamespacesToBeSearchedDefault you might need to reindex some pages from the source documents.
For achieving this you have two options:
- Blow away the search index and rebuild it from scratch. (see the Upgrading section, option A)
- Use the "Saneitizer": php Saneitize.php
Both options have drawbacks, the first one might incur a downtime making some pages unfindable while
they are indexed, the second option might take time if the wiki is large.
PoolCounter
-----------
CirrusSearch can leverage the PoolCounter extension to limit the number of concurrent searches to
elasticsearch. You can do this by installing the PoolCounter extension and then configuring it in
LocalSettings.php like so:
wfLoadExtension( 'PoolCounter');
// Configuration for standard searches.
$wgPoolCounterConf[ 'CirrusSearch-Search' ] = [
'class' => 'MediaWiki\PoolCounter\PoolCounterClient',
'timeout' => 30,
'workers' => 25,
'maxqueue' => 50,
];
// Configuration for prefix searches. These are usually quite quick and
// plentiful.
$wgPoolCounterConf[ 'CirrusSearch-Prefix' ] = [
'class' => 'MediaWiki\PoolCounter\PoolCounterClient',
'timeout' => 10,
'workers' => 50,
'maxqueue' => 100,
];
// Configuration for expensive full text searches such as regex and deepcat.
// These are slow and use lots of resources so we only allow a few at a time.
$wgPoolCounterConf[ 'CirrusSearch-ExpensiveFullText' ] = [
'class' => 'MediaWiki\PoolCounter\PoolCounterClient',
'timeout' => 30,
'workers' => 10,
'maxqueue' => 10,
];
// Configuration for funky namespace lookups. These should be reasonably fast
// and reasonably rare.
$wgPoolCounterConf[ 'CirrusSearch-NamespaceLookup' ] = [
'class' => 'MediaWiki\PoolCounter\PoolCounterClient',
'timeout' => 10,
'workers' => 20,
'maxqueue' => 20,
),
];
Upgrading
---------
When you upgrade there four possible cases for maintaining the index:
1. You must update the index configuration and reindex from source documents.
2. You must update the index configuration and reindex from already indexed documents.
3. You must update the index configuration but no reindex is required.
4. No changes are required.
If you must do (1) you have two options:
A. Blow away the search index and rebuild it from scratch. Marginally faster and uses less disk space on
in elasticsearch but empties the index entirely and rebuilds it so search will be down for a while:
php updateSearchIndexConfig.php --startOver
php forceSearchIndex.php
B. Build a copy of the index, reindex to it, and then force a full reindex from source documents. Uses
more disk space but search should be up the entire time:
php updateSearchIndexConfig.php --reindexAndRemoveOk --indexIdentifier now
php forceSearchIndex.php
If you must do (2) really have only one option:
A. Build of a copy of the index and reindex to it:
php updateSearchIndexConfig.php --reindexAndRemoveOk --indexIdentifier now
php forceSearchIndex.php --from <time when you started updateSearchIndexConfig.php in YYYY-mm-ddTHH:mm:ssZ> --deletes
php forceSearchIndex.php --from <time when you started updateSearchIndexConfig.php in YYYY-mm-ddTHH:mm:ssZ>
or for the Bash inclined:
TZ=UTC export REINDEX_START=$(date +%Y-%m-%dT%H:%m:%SZ)
php updateSearchIndexConfig.php --reindexAndRemoveOk --indexIdentifier now
php forceSearchIndex.php --from $REINDEX_START --deletes
php forceSearchIndex.php --from $REINDEX_START
If you must do (3) you again only have one option:
A. Same as (2.A)
4 is easy!
The safest thing if you don't know what is required for your update is to execute (1.B).
Production suggestions
----------------------
Elasticsearch
All the general rules for making Elasticsearch production ready apply here. So you don't have to go
round them up below is a list. Some of these steps are obvious, others will take some research.
** NOTE: this list was written for 0.90 so it may not work well for 1.0. It'll be revised when I have
more experience with 1.0. --Nik
1. Have >= 3 nodes.
2. Configure Elasticsearch for memlock.
3. Change each node's elasticsearch.yml file in a few ways.
3a. Change node name to the real host name.
3b. Turn off auto creation and some other scary stuff by adding this (tested with 0.90.4):
################################### Actions #################################
## Modulo some small changes to comments this section comes directly from the
## wonderful Elasticsearch mailing list, specifically Dan Everton.
##
# Require explicit index creation. ES never auto creates the indexes the way we
# like them.
##
action.auto_create_index: false
##
# Protect against accidental close/delete operations on all indices. You can
# still close/delete individual indices.
##
action.disable_close_all_indices: true
action.disable_delete_all_indices: true
##
# Disable ability to shutdown nodes via REST API.
##
action.disable_shutdown: true
Testing
-------
See tests
Job Queue
---------
Cirrus makes heavy use of the job queue. You can run it without any job queue customization but
if you switch the job queue to Redis with checkDelay enabled then Cirrus's results will be more
correct. The reason for this is that this configuration allows Cirrus to delay link counts
until Elasticsearch has appropriately refreshed. This is an example of configuring it:
$redisPassword = '<password goes here>';
$wgJobTypeConf['default'] = [
'class' => 'JobQueueRedis',
'order' => 'fifo',
'redisServer' => 'localhost',
'checkDelay' => true,
'redisConfig' => [
'password' => $redisPassword,
],
];
Note: some MediaWiki setups have trouble running the job queue. It can be finicky. The most
sure fire way to get it to work is also the slowest. Add this to your LocalSettings.php:
$wgRunJobsAsync = false;
Development
-----------
The fastest way to get started with CirrusSearch development is to use MediaWiki-Vagrant.
1. Follow steps here: https://www.mediawiki.org/wiki/MediaWiki-Vagrant#Quick_start
2. Now execute the following:
vagrant enable-role cirrussearch
vagrant provision
This can take some time but it produces a clean development environment in a virtual machine
that has everything required to run Cirrus.
Hooks
-----
See docs/hooks.txt.
Licensing information
---------------------
CirrusSearch makes use of the Elastica extension containing the Elastica library to connect
to Elasticsearch <http://elastica.io/>. It is Apache licensed and you can read the license
Elastica/LICENSE.txt.