作者:友尔哥_398 | 来源:互联网 | 2023-05-19 17:23
众所周知,安装solr的时候需要配置一个solrhome参数,其实就是指定solr的根目录,solr在启动的时候会去这个根目录下加载配置信息。配置solrhome参数有如下几种方式:
众所周知,安装solr的时候需要配置一个solr/home参数,其实就是指定solr的根目录,solr在启动的时候会去这个根目录下加载配置信息。
配置solr/home参数有如下几种方式:
基于web.xml(不推荐)
solr/home
${the_path_to solr_home}
java.lang.String
基于JNDI 配置
基于环境变量
在${ tomcat_home}/bin/catalina.sh中添加如下环境变量:
export JAVA_OPTS="$JAVA_OPTS -Dsolr.solr.home=${the_path_to solr_home}"
基于当前路径
启动tomcat时需要cd(切换)到${the_path_to solr_home},然后执行sh ${tomcat_home}/bin/startup.sh
solr加载solr/home源码
(变量project定义===>static final String project = "solr";)
public static String locateSolrHome() {
String home = null;
// Try JNDI
try {
Context c = new InitialContext();
home = (String)c.lookup("java:comp/env/"+project+"/home");
log.info("Using JNDI solr.home: "+home );
} catch (NoInitialContextException e) {
log.info("JNDI not configured for "+project+" (NoInitialContextEx)");
} catch (NamingException e) {
log.info("No /"+project+"/home in JNDI");
} catch( RuntimeException ex ) {
log.warn("Odd RuntimeException while testing for JNDI: " + ex.getMessage());
}
// Now try system property
if( home == null ) {
String prop = project + ".solr.home";
home = System.getProperty(prop);
if( home != null ) {
log.info("using system property "+prop+": " + home );
}
}
// if all else fails, try
if( home == null ) {
home = project + '/';
log.info(project + " home defaulted to '" + home + "' (could not find system property or JNDI)");
}
return normalizeDir( home );
}