Skip to content

Commit 4e8444b

Browse files
authored
Generic solr role (#901)
* Generic solr role * Update solr options for OpenJDK > 8
1 parent 8045e5f commit 4e8444b

7 files changed

Lines changed: 615 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Allow dynamic solr fields in the biocache
2+
dynamic_solr_schema_biocache: false
3+
dynamic_solr_schema_biocache_el_cl: false
4+
# By default bind the solr jetty server to a single interface/IP for security
5+
# Only set this to true if access to solr is required for other servers and you know the access is well firewalled
6+
solr_bind_jetty_host: true
7+
solr_version: "8.11.4"

ansible/roles/solr/tasks/main.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
---
2+
- include_tasks: ../../common/tasks/setfacts.yml
3+
tags:
4+
- solr
5+
- solr_create_cores
6+
- properties
7+
- solr_check_running
8+
9+
- name: Select JTS version
10+
set_fact:
11+
jts_version: >-
12+
{% if solr_version is version('7', '>=') and solr_version is version('8', '<') %}1.15.0
13+
{% elif solr_version is version('8', '>=') and solr_version is version('9', '<') %}1.19.0
14+
{% elif solr_version is version('9', '>=') %}1.19.0{% endif %}
15+
solr_in: >-
16+
{% if solr_version is version('7', '>=') and solr_version is version('8', '<') %}solr.in.sh.solr7
17+
{% elif solr_version is version('8', '>=') and solr_version is version('9', '<') %}solr.in.sh.solr8
18+
{% elif solr_version is version('9', '>=') %}solr.in.sh.solr8{% endif %}
19+
20+
- name: Download SOLR {{ solr_version }}
21+
get_url: url="https://archive.apache.org/dist/lucene/solr/{{ solr_version }}/solr-{{ solr_version }}.tgz" dest=/tmp/solr-{{ solr_version }}.tgz
22+
tags:
23+
- solr
24+
25+
- name: Extract the install script
26+
shell: "tar xzf /tmp/solr-{{ solr_version }}.tgz solr-{{ solr_version }}/bin/install_solr_service.sh --strip-components=2"
27+
tags:
28+
- solr
29+
30+
- name: ensure target directories exist [data subdirectories etc.
31+
file: path={{item}} state=directory
32+
with_items:
33+
- "{{data_dir}}/solr/"
34+
tags:
35+
- solr
36+
- properties
37+
38+
- name: Run install script
39+
shell: "./install_solr_service.sh /tmp/solr-{{ solr_version }}.tgz -d /data/solr -f"
40+
become: yes
41+
tags:
42+
- solr
43+
44+
- name: Download and install jts-core
45+
ansible.builtin.get_url:
46+
url: "https://repo1.maven.org/maven2/org/locationtech/jts/jts-core/{{ jts_version | trim }}/jts-core-{{ jts_version | trim }}.jar"
47+
dest: "/opt/solr/server/lib/ext/jts-core-{{ jts_version | trim }}.jar"
48+
mode: '0644'
49+
validate_certs: yes
50+
timeout: 30
51+
52+
- name: Download and install jst-io
53+
ansible.builtin.get_url:
54+
url: "https://repo1.maven.org/maven2/org/locationtech/jts/io/jts-io-common/{{ jts_version | trim }}/jts-io-common-{{ jts_version | trim }}.jar"
55+
dest: "/opt/solr/server/lib/ext/jts-io-common-{{ jts_version | trim }}.jar"
56+
mode: '0644'
57+
validate_certs: yes
58+
timeout: 30
59+
60+
- name: set SOLR directory ownership [all data is owned by solr]
61+
file: path=/opt/solr/ owner=solr group=solr recurse=true
62+
tags:
63+
- solr
64+
65+
- name: Stop solr
66+
shell: "service solr stop"
67+
tags:
68+
- solr
69+
- solr_restart
70+
71+
- name: copy SOLR config
72+
template: src={{ solr_in | trim }} dest=/opt/solr/bin/solr.in.sh force=yes
73+
tags:
74+
- solr
75+
- properties
76+
77+
- name: copy SOLR config /etc/default
78+
template: src={{ solr_in | trim }} dest=/etc/default/solr.in.sh force=yes
79+
tags:
80+
- solr
81+
- properties
82+
83+
- name: ensure target directories exist [data subdirectories etc.
84+
file: path={{item}} state=directory owner=solr group=solr
85+
with_items:
86+
- "{{data_dir}}/solr/data/biocache/conf"
87+
- "{{data_dir}}/solr/data/bie/conf"
88+
- "{{data_dir}}/solr/data/bie-offline/conf"
89+
- "{{data_dir}}/solr/data/biocache/data"
90+
- "{{data_dir}}/solr/data/bie/data"
91+
- "{{data_dir}}/solr/data/bie-offline/data"
92+
tags:
93+
- solr
94+
- properties
95+
96+
- name: copy SOLR config files for BIE and Biocache
97+
copy: src={{ role_path }}/../solrcloud_config/files/{{ item }}/conf dest={{ data_dir }}/solr/data/{{ item }}/ owner=solr group=solr
98+
with_items:
99+
- "biocache"
100+
- "bie"
101+
- "bie-offline"
102+
tags:
103+
- solr
104+
- properties
105+
- solr_create_cores
106+
107+
- name: Set up SOLR Biocache schema (non doc values)
108+
template: src={{ role_path }}/../solrcloud_config/templates/biocache_schema.xml dest={{ data_dir }}/solr/data/biocache/conf/schema.xml owner=solr group=solr
109+
when: use_docvalues is not defined or use_docvalues|bool == false
110+
tags:
111+
- solr
112+
- properties
113+
- solr_create_cores
114+
115+
- name: Set up SOLR Biocache schema (with doc values)
116+
template: src={{ role_path }}/../solrcloud_config/templates/biocache_schema_docvalues.xml dest={{ data_dir }}/solr/data/biocache/conf/schema.xml owner=solr group=solr
117+
when: use_docvalues is defined and use_docvalues|bool == true
118+
tags:
119+
- solr
120+
- properties
121+
- solr_create_cores
122+
123+
- name: Set up SOLR Biocache schema
124+
template: src={{ role_path}}//../solrcloud_config/templates/biocache_schema.xml dest={{ data_dir }}/solr/data/biocache/conf/biocache_schema_docvalues.xml owner=solr group=solr
125+
tags:
126+
- solr
127+
- properties
128+
- solr_create_cores
129+
130+
- name: set data ownership [all data is owned by the unix user solr]
131+
file: path="{{ data_dir }}/solr/" owner=solr group=solr recurse=true
132+
tags:
133+
- solr
134+
- properties
135+
136+
- name: Start solr
137+
service:
138+
name: solr
139+
state: restarted
140+
enabled: "yes"
141+
tags:
142+
- solr
143+
- solr_restart
144+
- solr_create_cores
145+
146+
- name: Ensure SOLR is running
147+
wait_for: host="{{ solr_host }}" port="{{ solr_port }}" delay=1 timeout=300
148+
tags:
149+
- solr
150+
- solr_check_running
151+
152+
- name: Create SOLR cores
153+
get_url: url="{{ solr_base_url }}/solr/admin/cores?action=CREATE&name={{ item }}&instanceDir={{data_dir}}/solr/data/{{ item }}&config=solrconfig.xml&dataDir=data" force=yes timeout=30 dest=/tmp/solr-output-{{ item }}
154+
with_items:
155+
- "biocache"
156+
- "bie"
157+
- "bie-offline"
158+
tags:
159+
- solr
160+
- solr_create_cores
161+
162+
163+
164+
165+
166+
167+
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# By default the script will use JAVA_HOME to determine which java
17+
# to use, but you can set a specific path for Solr to use without
18+
# affecting other Java applications on your server/workstation.
19+
#SOLR_JAVA_HOME=""
20+
21+
# Increase Java Heap as needed to support your indexing / query needs
22+
SOLR_HEAP="{{ solr_heap | default('512m') }}"
23+
24+
# Expert: If you want finer control over memory options, specify them directly
25+
# Comment out SOLR_HEAP if you are using this though, that takes precedence
26+
#SOLR_JAVA_MEM="-Xms512m -Xmx512m"
27+
28+
# Enable verbose GC logging
29+
{% if use_openjdk11 or use_openjdk17 %}
30+
GC_LOG_OPTS='-Xlog:gc*'
31+
{% else %}
32+
GC_LOG_OPTS="-verbose:gc -XX:+PrintHeapAtGC -XX:+PrintGCDetails \
33+
-XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime"
34+
{% endif %}
35+
36+
# These GC settings have shown to work well for a number of common Solr workloads
37+
GC_TUNE="-XX:NewRatio=3 \
38+
-XX:SurvivorRatio=4 \
39+
-XX:TargetSurvivorRatio=90 \
40+
-XX:MaxTenuringThreshold=8 \
41+
-XX:+UseConcMarkSweepGC \
42+
{% if use_openjdk8 %}
43+
-XX:+UseParNewGC \
44+
{% endif %}
45+
-XX:ConcGCThreads=4 -XX:ParallelGCThreads=4 \
46+
-XX:+CMSScavengeBeforeRemark \
47+
-XX:PretenureSizeThreshold=64m \
48+
-XX:+UseCMSInitiatingOccupancyOnly \
49+
-XX:CMSInitiatingOccupancyFraction=50 \
50+
-XX:CMSMaxAbortablePrecleanTime=6000 \
51+
-XX:+CMSParallelRemarkEnabled \
52+
-XX:+ParallelRefProcEnabled"
53+
54+
# Set the ZooKeeper connection string if using an external ZooKeeper ensemble
55+
# e.g. host1:2181,host2:2181/chroot
56+
# Leave empty if not using SolrCloud
57+
ZK_HOST="{{ solr_zk_host | default('127.0.0.1:2181') }}"
58+
59+
# Set the ZooKeeper client timeout (for SolrCloud mode)
60+
ZK_CLIENT_TIMEOUT="{{ solr_zk_client_timeout | default('15000') }}"
61+
62+
# By default the start script uses "localhost"; override the hostname here
63+
# for production SolrCloud environments to control the hostname exposed to cluster state
64+
SOLR_HOST="{{ solr_host }}"
65+
66+
# By default the start script uses UTC; override the timezone if needed
67+
#SOLR_TIMEZONE="UTC"
68+
69+
# CVE-2021-44228 mitigation
70+
SOLR_OPTS="$SOLR_OPTS -Dlog4j2.formatMsgNoLookups=true"
71+
72+
# Set to true to activate the JMX RMI connector to allow remote JMX client applications
73+
# to monitor the JVM hosting Solr; set to "false" to disable that behavior
74+
# (false is recommended in production environments)
75+
{% if solr_jmx_port is defined %}
76+
# The usual solr method includes the instruction "-Dcom.sun.management.jmxremote.local.only=false" which may be hampering zabbix connecting to JMX
77+
#ENABLE_REMOTE_JMX_OPTS="true"
78+
#RMI_PORT="{{ solr_jmx_port }}"
79+
# Alternative to the above is to manually include the necessary JMX properties
80+
ENABLE_REMOTE_JMX_OPTS="false"
81+
SOLR_OPTS="$SOLR_OPTS -Djava.rmi.server.hostname={{ solr_host }}"
82+
SOLR_OPTS="$SOLR_OPTS -Dcom.sun.management.jmxremote"
83+
SOLR_OPTS="$SOLR_OPTS -Dcom.sun.management.jmxremote.port={{ solr_jmx_port }}"
84+
SOLR_OPTS="$SOLR_OPTS -Dcom.sun.management.jmxremote.rmi.port={{ solr_jmx_port }}"
85+
SOLR_OPTS="$SOLR_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
86+
SOLR_OPTS="$SOLR_OPTS -Dcom.sun.management.jmxremote.ssl=false"
87+
# JMX monitoring needs IPV4 preferred
88+
SOLR_OPTS="$SOLR_OPTS -Djava.net.preferIPv4Stack=true"
89+
{% else %}
90+
ENABLE_REMOTE_JMX_OPTS="false"
91+
# The script will use SOLR_PORT+10000 for the RMI_PORT or you can set it here
92+
# RMI_PORT=18983
93+
{% endif %}
94+
95+
# Set the thread stack size
96+
SOLR_OPTS="$SOLR_OPTS -Xss256k"
97+
98+
# Anything you add to the SOLR_OPTS variable will be included in the java
99+
# start command line as-is, in ADDITION to other options. If you specify the
100+
# -a option on start script, those options will be appended as well. Examples:
101+
#SOLR_OPTS="$SOLR_OPTS -Dsolr.autoSoftCommit.maxTime=3000"
102+
#SOLR_OPTS="$SOLR_OPTS -Dsolr.autoCommit.maxTime=60000"
103+
#SOLR_OPTS="$SOLR_OPTS -Dsolr.clustering.enabled=true"
104+
105+
{% if solr_bind_jetty_host is defined and solr_bind_jetty_host | bool == true %}
106+
# Only listen on the defined interface
107+
# This may not be necessary if you are using firewalls or VLANs/VPCs to limit access to the port
108+
SOLR_OPTS="$SOLR_OPTS -Djetty.host=${SOLR_HOST}"
109+
{% endif %}
110+
111+
# turn off config editing for security
112+
SOLR_OPTS="$SOLR_OPTS -Ddisable.configEdit=true"
113+
114+
# Location where the bin/solr script will save PID files for running instances
115+
# If not set, the script will create PID files in $SOLR_TIP/bin
116+
#SOLR_PID_DIR=
117+
118+
# Path to a directory for Solr to store cores and their data. By default, Solr will use server/solr
119+
# If solr.xml is not stored in ZooKeeper, this directory needs to contain solr.xml
120+
SOLR_HOME={{ solr_home | default('/data/solr/data') }}
121+
122+
# Solr provides a default Log4J configuration properties file in server/resources
123+
# however, you may want to customize the log settings and file appender location
124+
# so you can point the script to use a different log4j.properties file
125+
#LOG4J_PROPS={{ solr_log4j_props | default('/data/solr/log4j.properties') }}
126+
127+
# Location where Solr should write logs to; should agree with the file appender
128+
# settings in server/resources/log4j.properties
129+
#SOLR_LOGS_DIR={{ solr_logs_dir | default('/data/solr/logs') }}
130+
131+
# Sets the port Solr binds to, default is 8983
132+
SOLR_PORT={{ solr_port| default('8983') }}
133+
134+
# Uncomment to set SSL-related system properties
135+
# Be sure to update the paths to the correct keystore for your environment
136+
#SOLR_SSL_KEY_STORE=etc/solr-ssl.keystore.jks
137+
#SOLR_SSL_KEY_STORE_PASSWORD=secret
138+
#SOLR_SSL_TRUST_STORE=etc/solr-ssl.keystore.jks
139+
#SOLR_SSL_TRUST_STORE_PASSWORD=secret
140+
#SOLR_SSL_NEED_CLIENT_AUTH=false
141+
#SOLR_SSL_WANT_CLIENT_AUTH=false
142+
143+
# Uncomment if you want to override previously defined SSL values for HTTP client
144+
# otherwise keep them commented and the above values will automatically be set for HTTP clients
145+
#SOLR_SSL_CLIENT_KEY_STORE=
146+
#SOLR_SSL_CLIENT_KEY_STORE_PASSWORD=
147+
#SOLR_SSL_CLIENT_TRUST_STORE=
148+
#SOLR_SSL_CLIENT_TRUST_STORE_PASSWORD=
149+
150+
# Settings for authentication
151+
#SOLR_AUTHENTICATION_CLIENT_CONFIGURER=
152+
#SOLR_AUTHENTICATION_OPTS=
153+
154+
SOLR_MODE="{{ solr_mode | default('solrcloud') }}"

0 commit comments

Comments
 (0)