搭建windows的solr6服务器(二)

本文涉及的产品
云原生网关 MSE Higress,422元/月
注册配置 MSE Nacos/ZooKeeper,118元/月
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
简介:

首先搭建solr环境,如:solr6.0学习(一)环境搭建

修改各种配置文件。

1、修改solrhome下的solr.xml文件

注解掉zookeeper搭建集群配置,我们后面会采用master-slave的形式。

至于zookeeper的形式可以阅读以下这篇文章【solrCloud集群配置指导】:http://www.aboutyun.com/thread-9432-1-1.html

[html]  view plain  copy 在CODE上查看代码片派生到我的代码片
  1. <!-- 结合zookeeper配置solrColound start -->  
  2.   <!-- 采用master-slave的方式  
  3.   <solrcloud>  
  4.   
  5.     <str name="host">${host:}</str>  
  6.     <int name="hostPort">${jetty.port:8983}</int>  
  7.     <str name="hostContext">${hostContext:solr}</str>  
  8.   
  9.     <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>  
  10.   
  11.     <int name="zkClientTimeout">${zkClientTimeout:30000}</int>  
  12.     <int name="distribUpdateSoTimeout">${distribUpdateSoTimeout:600000}</int>  
  13.     <int name="distribUpdateConnTimeout">${distribUpdateConnTimeout:60000}</int>  
  14.   
  15.   </solrcloud>  
  16.   
  17.   <shardHandlerFactory name="shardHandlerFactory"  
  18.     class="HttpShardHandlerFactory">  
  19.     <int name="socketTimeout">${socketTimeout:600000}</int>  
  20.     <int name="connTimeout">${connTimeout:60000}</int>  
  21.   </shardHandlerFactory>  
  22.   -->  
  23. <!-- 结合zookeeper配置solrColound end -->  
2、在sorlhome文件夹下创建【my_solr】文件夹。

3、在【my_solr】文件夹中添加core.properties配置,内容如下:

[html]  view plain  copy 在CODE上查看代码片派生到我的代码片
  1. 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中修改如下:

 

[html]  view plain  copy 在CODE上查看代码片派生到我的代码片
  1. <codecFactory class="solr.SchemaCodecFactory"/>  
  2.   <!-- 解除managed-schema管理模式 start -->  
  3.   <schemaFactory class="ClassicIndexSchemaFactory"/>  
  4.   <!-- 解除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文件,添加

 

[html]  view plain  copy 在CODE上查看代码片派生到我的代码片
  1. <field name="content_test" type="text_general" indexed="true" stored="true" multiValued="true"/>  
field的属性和配置,可以google一下 schema.xml 说明很多,用法也很多,这里就不赘述。

2、添加索引数据,代码如下:

编写过程中可能会报错,最简便的方法是将web-inf下lib里所有jar包添加进来,然后运行,出什么错,就添加什么jar包即可。

 

[java]  view plain  copy 在CODE上查看代码片派生到我的代码片
  1. package com.solr.insertData;  
  2.   
  3.   
  4. import java.io.IOException;  
  5. import java.util.ArrayList;  
  6. import java.util.List;  
  7.   
  8. import org.apache.solr.client.solrj.SolrClient;  
  9. import org.apache.solr.client.solrj.SolrServerException;  
  10. import org.apache.solr.client.solrj.impl.HttpSolrClient;  
  11. import org.apache.solr.common.SolrInputDocument;  
  12.   
  13. public class InsertProgarm {  
  14.     //solr 服务器地址  
  15.     public static final String solrServerUrl = "http://localhost:8080/solr";  
  16.     //solrhome下的core  
  17.     public static final String solrCroeHome = "my_solr";  
  18.     //待索引、查询字段  
  19.     public static String[] docs = {"Solr是一个独立的企业级搜索应用服务器",  
  20.                                     "它对外提供类似于Web-service的API接口",  
  21.                                     "用户可以通过http请求",  
  22.                                      "向搜索引擎服务器提交一定格式的XML文件生成索引",  
  23.                                     "也可以通过Http Get操作提出查找请求",  
  24.                                     "并得到XML格式的返回结果"};  
  25.     public static void main(String[] args) {  
  26.         SolrClient client = getSolrClient();  
  27.         int i=0;  
  28.         List<SolrInputDocument> solrDocs = new ArrayList<SolrInputDocument>();  
  29.         for (String content : docs) {  
  30.             SolrInputDocument doc = new SolrInputDocument();  
  31.             doc.addField("id", i++);  
  32.             doc.addField("content_test", content);  
  33.             solrDocs.add(doc);  
  34.         }  
  35.         try {  
  36.             client.add(solrDocs);  
  37.             client.commit();  
  38.         } catch (SolrServerException e) {  
  39.             // TODO Auto-generated catch block  
  40.             e.printStackTrace();  
  41.         } catch (IOException e) {  
  42.             // TODO Auto-generated catch block  
  43.             e.printStackTrace();  
  44.         }  
  45.           
  46.     }  
  47.     public static SolrClient getSolrClient(){  
  48.         return new HttpSolrClient(solrServerUrl+"/"+solrCroeHome);  
  49.     }  
  50.   
  51. }  
3、运行成功后,会在【solrhome/my_solr】文件夹下创建一个【data】的文件夹,这个文件夹中的内容就是我们的solr索引。

其实其对于的是solconfig.xml中如下配置:

 

[html]  view plain  copy 在CODE上查看代码片派生到我的代码片
  1. <!-- Data Directory  
  2.   
  3.        Used to specify an alternate directory to hold all index data  
  4.        other than the default ./data under the Solr home.  If  
  5.        replication is in use, this should match the replication  
  6.        configuration.  
  7.     -->  
  8.   <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和创建索引、查询程序,完成!

分类:  java

本文转自快乐就好博客园博客,原文链接:http://www.cnblogs.com/happyday56/p/5728441.html,如需转载请自行联系原作者
相关实践学习
基于MSE实现微服务的全链路灰度
通过本场景的实验操作,您将了解并实现在线业务的微服务全链路灰度能力。
相关文章
|
7天前
|
SQL 关系型数据库 MySQL
Windows服务器的最佳数据库是什么?
【7月更文挑战第20天】Windows服务器的最佳数据库是什么?
21 5
|
7天前
|
Java Linux 应用服务中间件
Windows和Linux的最佳Web服务器
【7月更文挑战第20天】Windows和Linux的最佳Web服务器
19 3
|
8天前
|
弹性计算 持续交付 Docker
阿里云云效产品使用合集之如何部署到阿里云服务器上的 Windows Server 上的 IIS
云效作为一款全面覆盖研发全生命周期管理的云端效能平台,致力于帮助企业实现高效协同、敏捷研发和持续交付。本合集收集整理了用户在使用云效过程中遇到的常见问题,问题涉及项目创建与管理、需求规划与迭代、代码托管与版本控制、自动化测试、持续集成与发布等方面。
|
15天前
|
网络协议 Unix 网络安全
FTP服务器怎么搭建?Windows server搭建FPT服务器
FTP服务器是按照FTP协议提供文件传输服务的计算机。它用于在两台计算机间安全地传输文件,支持用户权限管理和跨平台操作。FTP使用控制连接处理命令,数据连接传输文件,有PORT和PASV模式。要搭建FTP服务器,首先在Windows Server 2008 R2上安装IIS,确保选中FTP服务。接着,创建FTP文件夹作为站点根目录,通过IIS管理器添加FTP站点,配置站点信息、身份验证和权限。测试客户端通过telnet和浏览器访问FTP服务器,确认能成功登录及浏览文件。FTP常用于文件共享和管理,可通过专用工具如FlashFXP上传下载文件。
42 0
FTP服务器怎么搭建?Windows server搭建FPT服务器
|
29天前
|
Linux 数据安全/隐私保护 Windows
pscp 将Linux服务器上的文件同步到Windows服务器上
【6月更文挑战第28天】pscp 将Linux服务器上的文件同步到Windows服务器上
50 0
|
XML JSON 负载均衡
Windows 安装solr 8版本并简单测试
Windows 安装solr 8版本并简单测试
410 0
Windows 安装solr 8版本并简单测试
|
21天前
|
前端开发 JavaScript 应用服务中间件
windows server + iis 部署若伊前端vue项目
5,配置url重写规则(重写后端请求) 注:如果没有Application Request Routing Cachefourcloudbdueclaim和URL重写,则是第二部的那两个插件没装上 打开iis,点击计算机->点击Application Request Routing Cache -> 打开功能
56 0
|
1月前
|
编解码 安全 网络安全
RealVNC的 VNC server在windows7系统下无法正确运行
在Windows 7上运行旧版VNC Server(如4.1.2)可能存在兼容性问题,但可通过调整配置解决。步骤包括:安装VNC Server,设置兼容性模式(选择Windows XP SP3),启动VNC Server,配置VNC连接参数。若遇到问题,检查防火墙设置,确保系统更新,并考虑升级到新版VNC Server以提高性能和兼容性。
|
2月前
|
开发框架 .NET API
在Windows Server 2008 R2上运行.Net 8应用
在Windows Server 2008 R2上成功运行.Net 8程序,需安装三个补丁:Windows Server 2008 R2 SP1 (KB976932)是基础更新;VC_redist.x64提供MSVC库支持;KB3063858解决.NET运行时加载`kernel.dll`的路径问题。KB3063858可能需要KB2533623。详细信息和下载链接在文中给出。
129 4
|
2月前
|
网络协议 Unix Linux
【技术分享】Server / Server Software / Unix Windows OS
Server / Server Software / Unix Windows OS
59 2

热门文章

最新文章