阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS7下Solr6.6+ZooKeeper 集群安装部署

155次阅读
没有评论

共计 7037 个字符,预计需要花费 18 分钟才能阅读完成。

CentOS7 下 ZooKeeper 集群安装部署

安装 JDK

yum install -y java-1.8.0-openjdk

安装 ZooKeeper

下载

wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
tar -zxvf zookeeper-3.4.10.tar.gz

官方地址:http://www.apache.org/dyn/closer.cgi/zookeeper/

配置 zoo.cfg

cp conf/zoo_sample.cfg conf/zoo.cfg
vi conf/zoo.cfg

修改(本)

# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/data/solr/zookeeper
# the port at which the clients will connect
clientPort=2181
server.211=dt211.corp:2888:3888
server.212=0.0.0.0:2888:3888
server.214=dt214.corp:2888:3888

创建数据目录和 myid

mkdir /data/solr/zookeeper
vi /data/solr/zookeeper/myid

myid 文件中只有一个数字,与 server id 对应

212

防火墙配置

firewall-cmd --permanent --add-port=2181/tcp
firewall-cmd --permanent --add-port=2888/tcp
firewall-cmd --permanent --add-port=3888/tcp
firewall-cmd --reload

同步到其它机器

————————————– 分割线 ————————————–

CentOS7 NFS 共享设置

安装 nfs 工具

yum install -y nfs-utils

配置共享目录

创建共享目录

mkdir /home/share

目录授权

chmod 766 /home/share

编辑 exports

vi /etc/exports

添加内容

/home/share 192.168.1.0/24(rw,sync)

先启动 rpcbind

systemctl start rpcbind

在启动 nfs

systemctl start nfs

查看本机共享目录

exportfs

防火墙设置

firewall-cmd --permanent --add-service=nfs
firewall-cmd --reload

挂载共享目录

安装 nfs,同上
创建挂载目录

mkdir /mnt/share

添加挂载

mount 192.168.1.212:/home/share /mnt/share

异常处理

1.mount.nfs: requested NFS version or transport protocol is not supported
启动顺序不对,先启动 rpcbind,在启动 nfs

2.mount.nfs: access denied by server while mounting

————————————– 分割线 ————————————–

修改 zoo.cfg,本机 IP 地址:0.0.0.0

启动集群

启动

bin/zkServer.sh start

查看状态

bin/zkServer.sh status

停止

bin/zkServer.sh stop

异常处理

1.java.net.ConnectException: 拒绝连接 (Connection refused)
本机 IP 要改成 0.0.0.0,无法识别别名,127.0.0.1 也只能有一台

CentOS7 下 Solr6.6 集群安装部署

Solr

添加 zk 地址

vi bin/solr.in.sh
# Set the ZooKeeper connection string if using an external ZooKeeper ensemble
# e.g. host1:2181,host2:2181/chroot
# Leave empty if not using SolrCloud
ZK_HOST="hbase201:2181,hbase202:2181,hbase203:2181/solr"

# Set the ZooKeeper client timeout (for SolrCloud mode)
ZK_CLIENT_TIMEOUT="15000"

上传配置文件

./zkcli.sh -zkhost hbase201,hbase202,hbase203:2181/solr -cmd upconfig -confdir /usr/solr/solr-6.6.0/server/solr/configsets/data_driven_schema_configs/conf -confname solr

同步到其它服务器

scp -r /usr/solr hbase201:/usr/
scp -r /usr/solr hbase202:/usr/

分别启动 solr 服务

bin/solr start -force

集群操作

查看状态

http://hbase203:8983/solr/#/~cloud

创建集群

http://hbase203:8983/solr/admin/collections?action=CREATE&name=test&numShards=3&replicationFactor=3&maxShardsPerNode=3&collection.configName=solr

删除集群

http://hbase203:8983/solr/admin/collections?action=DELETE&name=test

重新加载

http://hbase203:8983/solr/admin/collections?action=RELOAD&name=test

更新配置文件,添加 DIH

修改 solrconfig.xml

vi solrconfig.xml
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-.*\.jar" />  
<requestHandler name="/dataimport" class="solr.DataImportHandler">  
  <lst name="defaults">  
    <str name="config">data-config.xml</str>  
  </lst>  
</requestHandler>

创建 data-config.xml

vi data-config.xml
<dataConfig>  
  <dataSource type="JdbcDataSource"  
              driver="com.mysql.jdbc.Driver"  
              convertType="true"  
              url="jdbc:mysql://127.0.0.1:3306/db_name"  
              user="sa"  
              password="123456"/>  
  <document>  
    <entity name="query_news" query="SELECT id, title, content, tags FROM news" >  
    </entity>  
  </document>  
</dataConfig>

创建 schema.xml

vi schema.xml
<schema name="query_news">
  <uniqueKey>id</uniqueKey>
  <field name="id" type="int" indexed="true" stored="true" required="true" multiValued="false" />
  <field name="title" type="string" indexed="true" stored="true" required="true" multiValued="false" />
  <field name="content" type="string" indexed="true" stored="true" required="false" multiValued="false" />
  <field name="tags" type="string" indexed="true" stored="false" required="false" multiValued="false" />
  <field name="_version_" type="long" indexed="true" stored="true"/>

  <field name="info_text" type="text_general" indexed="true" stored="false" multiValued="true" />

  <copyField source="title" dest="info_text" />
  <copyField source="content" dest="info_text" />
  <copyField source="tags" dest="info_text" />

  <fieldType name="string" class="solr.StrField" sortMissingLast="true" />
  <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
  <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
  </fieldType>
</schema>

上传配置文件

./zkcli.sh -zkhost hbase201,hbase202,hbase203:2181/solr -cmd putfile /configs/solr/solrconfig.xml /usr/solr/solr-6.6.0/server/solr/configsets/data_driven_schema_configs/conf/solrconfig.xml
./zkcli.sh -zkhost hbase201,hbase202,hbase203:2181/solr -cmd putfile /configs/solr/data-config.xml /usr/solr/solr-6.6.0/server/solr/configsets/data_driven_schema_configs/conf/data-config.xml
./zkcli.sh -zkhost hbase201,hbase202,hbase203:2181/solr -cmd putfile /configs/solr/schema.xml /usr/solr/solr-6.6.0/server/solr/configsets/data_driven_schema_configs/conf/schema.xml

更新配置文件

http://hbase201:8983/solr/admin/collections?action=RELOAD&name=test

备份和恢复

备份

http://hbase201:8983/solr/test/replication?command=backup&location=/home/test_bak

恢复

  1. 停止 Solr 服务
  2. Copy 备份文件到 CoreIndex 目录
  3. 启动 Solr 服务

Index 存储为 HDFS

修改 solrconfig.xml

vi solrconfig.xml
<directoryFactory name="DirectoryFactory" class="solr.HdfsDirectoryFactory">
  <str name="solr.hdfs.home">hdfs://hbase201:9000/solr</str>
  <bool name="solr.hdfs.blockcache.enabled">true</bool>
  <int name="solr.hdfs.blockcache.slab.count">1</int>
  <bool name="solr.hdfs.blockcache.direct.memory.allocation">true</bool>
  <int name="solr.hdfs.blockcache.blocksperbank">16384</int>
  <bool name="solr.hdfs.blockcache.read.enabled">true</bool>
  <bool name="solr.hdfs.nrtcachingdirectory.enable">true</bool>
  <int name="solr.hdfs.nrtcachingdirectory.maxmergesizemb">16</int>
  <int name="solr.hdfs.nrtcachingdirectory.maxcachedmb">192</int>
</directoryFactory>

 

<lockType>${solr.lock.type:hdfs}</lockType>

上传配置文件到 zookeeper

./zkcli.sh -zkhost hbase201,hbase202,hbase203:2181/solr -cmd putfile /configs/solr/data-config.xml /usr/solr/solr-6.6.0/server/solr/configsets/data_driven_schema_configs/conf/data-config.xml

更新 Hadoop 处理 jar 包(solr 自带版本不一致)

rm -f server/solr-webapp/webapp/WEB-INF/lib/hadoop-*
rm -f server/solr-webapp/webapp/WEB-INF/lib/protobuf-java-*
cd /usr/hadoop/hadoop-2.7.4/share
cp hadoop/common/hadoop-common-2.7.4.jar /usr/solr/solr-6.6.0/server/solr-webapp/webapp/WEB-INF/lib/
cp hadoop/common/lib/hadoop-* /usr/solr/solr-6.6.0/server/solr-webapp/webapp/WEB-INF/lib/
cp hadoop/common/lib/protobuf-java-2.5.0.jar /usr/solr/solr-6.6.0/server/solr-webapp/webapp/WEB-INF/lib/
cp hadoop/hdfs/hadoop-hdfs-2.7.4.jar /usr/solr/solr-6.6.0/server/solr-webapp/webapp/WEB-INF/lib/

更多 Solr 相关教程见以下内容

CentOS7 下搭建 Solr 6.6 全文检索服务器及 IK 分词器配置  http://www.linuxidc.com/Linux/2017-12/149897.htm

Apache Solr: 安装和运行 http://www.linuxidc.com/Linux/2016-12/138527.htm

Solr 实现 Low Level 查询解析(QParser)http://www.linuxidc.com/Linux/2012-05/59755.htm

Solr6.0.0 + Tomcat8 配置问题 http://www.linuxidc.com/Linux/2016-05/131845.htm

CentOS 6.7 下单机部署 Solr 7.1.0  http://www.linuxidc.com/Linux/2017-12/149889.htm

Solr 的详细介绍:请点这里
Solr 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-12/149902.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计7037字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中