搭建windows的solr6服务器(二)
首先搭建solr环境,如:solr6.0学习(一)环境搭建
修改各种配置文件。
1、修改solrhome下的solr.xml文件
注解掉zookeeper搭建集群配置,我们后面会采用master-slave的形式。
至于zookeeper的形式可以阅读以下这篇文章【solrCloud集群配置指导】:http://www.aboutyun.com/thread-9432-1-1.html
- <!-- 结合zookeeper配置solrColound start -->
- <!-- 采用master-slave的方式
- <solrcloud>
- <str name="host">${host:}</str>
- <int name="hostPort">${jetty.port:8983}</int>
- <str name="hostContext">${hostContext:solr}</str>
- <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>
- <int name="zkClientTimeout">${zkClientTimeout:30000}</int>
- <int name="distribUpdateSoTimeout">${distribUpdateSoTimeout:600000}</int>
- <int name="distribUpdateConnTimeout">${distribUpdateConnTimeout:60000}</int>
- </solrcloud>
- <shardHandlerFactory name="shardHandlerFactory"
- class="HttpShardHandlerFactory">
- <int name="socketTimeout">${socketTimeout:600000}</int>
- <int name="connTimeout">${connTimeout:60000}</int>
- </shardHandlerFactory>
- -->
- <!-- 结合zookeeper配置solrColound end -->
2、在sorlhome文件夹下创建【my_solr】文件夹。
3、在【my_solr】文件夹中添加core.properties配置,内容如下:
- name=my_solr
这个name的值实际上就core的名称,可以任意命名,为了保证统一和方便阅读,个人觉得最好和文件夹名称一致。
4、将【solr-6.0.0\example\example-DIH\solr\solr】下的conf文件夹拷贝到【my_solr】文件夹下。包含如下文件:
【conf】中文件目录如下:
5、solr-5.0 以上默认对schema的管理是使用managed-schema,不能手动修改,需要使用Schema Restful的API操作。
如果要想手动修改配置,把【conf】文件夹中managed-schema拷贝一份修改为schema.xml,在solrconfig.xml中修改如下:
- <codecFactory class="solr.SchemaCodecFactory"/>
- <!-- 解除managed-schema管理模式 start -->
- <schemaFactory class="ClassicIndexSchemaFactory"/>
- <!-- 解除managed-schema管理模式 end -->
重启tomcat8,可能会报错,查看tomcat日志发现,比喻:
缺少DataImportHandler的jar等,那么将【solr-6.0.0\dist】下的solr-dataimporthandler-6.0.0.jar和solr-dataimporthandler-extras-6.0.0.jar
拷贝到【apache-tomcat-8.0.33\webapps\solr\WEB-INF\lib】下。
重启tomcat8。如果缺少其他jar包,根据报错信息添加即可。没有异常,
访问:【http://localhost:8080/solr/index.html#/】
会出现如下界面:
选择my_solr,会出现如下界面:
至此其实由于没有索引数据,其实solr是个空壳,那么下面写一个应用程序插入solr索引数据。
参考:http://www.open-open.com/lib/view/open1452062296995.html
1、首先需要修改schema.xml文件,添加
- <field name="content_test" type="text_general" indexed="true" stored="true" multiValued="true"/>
field的属性和配置,可以google一下schema.xml 说明很多,用法也很多,这里就不赘述。
2、添加索引数据,代码如下:
编写过程中可能会报错,最简便的方法是将web-inf下lib里所有jar包添加进来,然后运行,出什么错,就添加什么jar包即可。
- package com.solr.insertData;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import org.apache.solr.client.solrj.SolrClient;
- import org.apache.solr.client.solrj.SolrServerException;
- import org.apache.solr.client.solrj.impl.HttpSolrClient;
- import org.apache.solr.common.SolrInputDocument;
- public class InsertProgarm {
- //solr 服务器地址
- public static final String solrServerUrl = "http://localhost:8080/solr";
- //solrhome下的core
- public static final String solrCroeHome = "my_solr";
- //待索引、查询字段
- public static String[] docs = {"Solr是一个独立的企业级搜索应用服务器",
- "它对外提供类似于Web-service的API接口",
- "用户可以通过http请求",
- "向搜索引擎服务器提交一定格式的XML文件生成索引",
- "也可以通过Http Get操作提出查找请求",
- "并得到XML格式的返回结果"};
- public static void main(String[] args) {
- SolrClient client = getSolrClient();
- int i=0;
- List<SolrInputDocument> solrDocs = new ArrayList<SolrInputDocument>();
- for (String content : docs) {
- SolrInputDocument doc = new SolrInputDocument();
- doc.addField("id", i++);
- doc.addField("content_test", content);
- solrDocs.add(doc);
- }
- try {
- client.add(solrDocs);
- client.commit();
- } catch (SolrServerException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public static SolrClient getSolrClient(){
- return new HttpSolrClient(solrServerUrl+"/"+solrCroeHome);
- }
- }
3、运行成功后,会在【solrhome/my_solr】文件夹下创建一个【data】的文件夹,这个文件夹中的内容就是我们的solr索引。
其实其对于的是solconfig.xml中如下配置:
- <!-- Data Directory
- Used to specify an alternate directory to hold all index data
- other than the default ./data under the Solr home. If
- replication is in use, this should match the replication
- configuration.
- -->
- <dataDir>${solr.data.dir:}</dataDir>
4、访问http://localhost:8080/solr/index.html选择【my_solr】core,选择query得到如下界面:
红色区域是针对不同的ui,因为浏览器版本问题,我这里面选择使用【Use original
UI】,会跳转到http://localhost:8080/solr/old.html#/
选择【my_solr】core,选择query,点击【Execute Query】查询结果如下:
其实其访问的url实际为:http://localhost:8080/solr/my_solr/select?q=*%3A*&wt=json&indent=true
至于q、wt、indent等参数,代表的含义,可以搜索solr查询语法。
那么至此,我们就将solr插件完毕,结合了core和创建索引、查询程序,完成!
搭建windows的solr6服务器(二)的更多相关文章
- 搭建windows的solr6服务器
准备工作: 目前最新版本6.0.下载solr 6.0:Solr6.0下载 JDK8 下载jdk1.8:jdk1.8[solr6.0是基于jdk8开发的] tomcat8.0 下载:tomcat8 ## ...
- Git-gitblit-Tortoisegit 搭建Windows Git本地服务器
1.Gitblit安装 1.1.Gitblit简介 Git在版本控制领域可谓是深受程序员喜爱.对于开源的项目,可以免费托管到GitHub上面,相当的方便.但是私有项目托管到GitHub会收取相当昂贵的 ...
- office web apps 部署-搭建office web apps服务器
二.搭建office web apps服务器 相关文件可以去焰尾迭分享的百度网盘下载,下载地址:http://pan.baidu.com/s/1o6tCo8y#path=%252Foffice%252 ...
- Windows下Git服务器搭建[转]
Windows下Git服务器搭建 作为对前两天Git服务器搭建的一个整理,我想分别从服务端和客户端两个角度来记录下整个搭建过程,为了达到目标,我们需要哪些操作. (一)服务端软件和账号的安装配置 ...
- 搭建Windows SVN服务器及TortoiseSVN使用帮助和下载
搭建Windows SVN服务器: 用的SVN服务器通常为外部,例如Google Code的服务器,不过,做为一个程序开发人员,就算自己一个人写程序,也应该有一个SVN版本控制系统,以便对开发代码进行 ...
- 本地windows下搭建git的本地服务器
本地windows下搭建git的本地服务器 准备工作: 本地安装java环境,配置环境变量(略) 下载gitblit文件,百度一大堆 开始第一步: 减压gitblit压缩包到某个目录下,比如我在:H: ...
- Windows平台下搭建自己的Git服务器
该文章转自:http://www.codeceo.com/article/windows-git-server.html Gitblit 是一个纯 Java 库用来管理.查看和处理 Git 资料库,相 ...
- Windows下SVN服务器搭建方法整理(apache)
http://skydream.iteye.com/blog/437959 http://www.cnblogs.com/liuke209/archive/2009/09/23/1572858.htm ...
- 使用Gitblit 搭建Windows Git服务器
使用Gitblit 搭建Windows Git服务器 整理使用Gitblit搭建Git服务器的步骤. 目录 使用Gitblit 搭建Windows Git服务器 目录 下载安装 配置 运行 客户端运行 ...
随机推荐
- JS 获取服务器时间
function getSevertime(){ var xmlHttp = new XMLHttpRequest(); xmlHttp.open("get",location.h ...
- [Linux技巧]固定Vmware下CentOS的IP
1. 首先取消使用Vmware动态主机设置服务 [Edit] -> [Virtual Network Editor ...] 打开面板,选中[VMnet8]. 如下,取消对[ Use local ...
- [MongoDB]Mongodb攻略
-------------------------------------------------------------------------------------------- [基础] 1. ...
- iOS支持图文混排的按钮(UIButton)
创建UIButton子类 直接上代码了 .h文件 创建UIButton子类 直接上代码了 .h文件 #import <UIKit/UIKit.h> @interface GraphicBt ...
- C/C++字符串函数之复制函数
突然发现对字符串函数缺乏系统的了解,所以花了一点时间专门整理下,在此记录之,以方便自己及有需要的人使用. C/C++字符串函数的头文件:string.h 复制函数主要有4个,如下: 1.char * ...
- 关于最近在做的一个js全屏轮播插件
最近去面试了,对方要求我在一个星期内用原生的js代码写一个全屏轮播的插件,第一想法就是跟照片轮播很相似,只是照片轮播是有定义一个宽高度大小已经确定了的容器用来存储所有照片,然后将照片全部左浮动,利用m ...
- c#winform如何通过控件名查找控件
//根据控件名称查找控件 //作用根据控件的配置项目, Control[] myfindcs = this.Controls.Find("button4", true); if ( ...
- 使用语句查询mssql死锁
select spid, blocked, loginame, last_batch, status, cmd, hostname, program_name from sys.sysprocesse ...
- Delete characters
Description In this exercise, you will get two strings A and B in each test group and the length of ...
- Druid的使用步骤
一.关于Druid Druid是一个JDBC组件,它包括三部分: DruidDriver 代理Driver,能够提供基于Filter-Chain模式的插件体系. DruidDataSource 高效可 ...