设为首页 收藏本站
查看: 1127|回复: 0

[经验分享] SOLR 5.0安装 使用内置脚本安装

[复制链接]

尚未签到

发表于 2015-11-12 10:09:31 | 显示全部楼层 |阅读模式
solr 安装脚本(bin/install_solr_service.sh) thescript only supports Red Hat, Ubuntu, Debian, and SUSE Linux distributions.
建议将使用中的solr文件  例如logs 文件  索引文件 从Solr分布式中分离出来,以方便系统升级Solr 安装目录默认的Solr脚本会将分布式文件copy 到/opt 目录中
可以使用  参数-i改变安装目录,如果你运行的是Solr5.0.0的脚本则一下的目录结构可能用上/opt/solr-5.0.0/opt/solr ->/opt/solr-5.0.0使用特殊的目录链接来区分不同Solr版本的独立的运行脚本,假设在一段时间过后你需要升级你的Solr你只需要将目录链接指定到最新的Solr的目录版本。接下来的部分中将演示:使用/opt/solr 来关联solr的安装目录的安装方法。
需要将可写目录分开来放,脚本运行默认目录是 /var/solr  可以使用 参数-d  来指定目录这样solr在/var/solr 运行时说做出的改变将不会影响/opt/solr目录
创建Solr用户
以root身份运行Solr是不安全的。所以你需要指定系统用户名 来运行solr可以是用 参数-u 来设置solr用户

运行Solr 安装脚本将install_solr_service.sh文件从solr-5.0.0.tgz 中解压出来tar -xzf solr-5.0.0.tgz solr-5.0.0/bin/install_solr_service.sh --strip-component=2如果安装在小红帽服务器上需要确保安装了lsof 命令
安装solr需要root权限干的事在/etc/init.d目录下创建solr目录安装solr服务将solr 加入服务
需要删除install_solr_service.sh 中的root用户认证  /opt 是默认的安装目录 通过-i参数指定/var/solr 是默认的写数据的默认 通过-d参数指定-u参数用于指定solr用户-s 表示指定服务名称-p表示指定端口号sudo bash ./install_solr_service.sh solr-5.0.0.tgz-i /opt -d /var/solr -u solr -s solr -p 8983查看install_solr_service.sh可用账号sudo bash ./install_solr_service.sh -help


Solr Home Directory 家目录和Solr 安装目录不同安装默认的家目录为 /var/solr/dataSolr家目录就是包含solr.xml和索引的目录
Solr启动时solr脚本会使用 -Dsolr.solr.home系统参数传递家目录的路径Environment overrides include file
include file 也就是启动脚本 solr.in.sh首先使用的安装更具你的系统重写的include file修改运行环境配置文件在solr.in.sh 可以修改SOLR_HOME 和SOLR_PID_DIR目录SOLR_PID_DIR=/var/sSOLR_HOME=/var/solr/data
配置日志copies /opt/solr/server/resources/log4j.properties to /var/solr/log4j.properties自定义日志格式
在solr.in.sh 中修改日志LOG4J_PROPS=/var/solr/log4j.propertiesSOLR_LOGS_DIR=/var/solr/logs更多日志格式配置信息查看https://cwiki.apache.org/confluence/display/solr/Configuring+Logging

/etc/init.d 脚本
如果想将solr作为Linux的一个服务。需要配置init.d文件这样系统管理员才能使用service命令工具控制solr 例如service solr start/etc/init.d/solr 需要注意下这些变量设置:SOLR_INSTALL_DIR=/opt/solrSOLR_ENV=/var/solr/solr.in.shRUNAS=solr
RUNAS 设置solr线程的所属者如果你不设置此值这Solr将会以root权限运行,这在生产环境中是不允许的。
启动命令 service solr start
service命令还支持     stop、restart、status参数
微调生产环境设置内存和GC设置修改bin/solr SOLR_JAVA_MEM参数SOLR_JAVA_MEM="-Xms10g -Xmx10g"
通过/var/solr/solr.in.sh 中的 GC_TUNE 参数修改来及回收策略详细查看 Solr 垃圾回收策略https://cwiki.apache.org/confluence/display/solr/JVM+Settings

当出现Out-of-Memory 是关闭机制out of memory shutdown hook(拦截)
The bin/solr scriptregisters the bin/oom_solr.sh script tobe called by the JVM if an OutOfMemoryError occurs. The oom_solr.sh scriptwill issue a kill -9 to the Solr processthat experiences the OutOfMemoryError.This behavior is recommended when running in SolrCloud mode so that ZooKeeper is immediately notified that a node has experienced a non-recoverable error. Take a moment to inspect the contents of the /opt/solr/bin/oom_solr.sh scriptso that you are familiar with the actions the script will perform if it is invoked by the JVM.
SolrCloud
修改includefile  ini.d/solr如果以SolrCloud 模式运行solr需要在文件头设置ZK_HOST变量指定Zookeeper集并设置SOLR_MODE=solrcloud.内嵌的ZooKeeper不支持生产环境,作为实例如果你有Zookeeper群组,在一下三个主机上使用默认端口2181端口的主机地址(zk1,zk2,zk3)然后可以设置配置变量为SOLR_MODE=solrcloudZK_HOST=zk1,zk2,zk3通过这个配置可以使脚本以cloud模式启动。

ZooKeeper chroot
ZooKeeper跟目录如果你的Zookeeper实例与其他系统共用,建议你使用ZooKeeper更目录的支持分离SolrCloud节点树,例如在SolrCloud 所创建的节点存储在/solr目录下可以在配置ZK_HOST时加上ZK_HOST=zk1,zk2,zk3/solr
如果是第一次使用chroot,你需要使用脚本zkcli.sh,在ZooKeeper中引导Solr节点树例如:server/scripts/cloud-scripts/zkcli.sh -zkhost ZK_HOST -cmd bootstrap -solrhome /var/solr/data
Solr Hostname设置Solr主机名称使用SOLR_HOST 变量在Solr Server 中指定Solr的 主机名称SOLR_HOST=solr1.example.com设置Solr server主机名称是推荐设置,特别是以SolrCloud模式运行。当它在ZooKeeper中注册时,它便决定了节点的地址
Override settings in solrconfig.xmlSolr允许配置属性在启动时使用java的系统属性 -Dproperty=value 方式传入例如:在solrconfig.xml中默认的软提交设置为:<autoSoftCommit>     <maxTime>${solr.autoSoftCommit.maxTime:-1}</maxTime></autoSoftCommit>使用java system property 在启动时的配置方式为 -Dsolr.autoSoftCommit.maxTime=10000例如bin/solr start -Dsolr.autoSoftCommit.maxTime=100000

bin/solr脚本简单的通过 以-D开头先JVM启动期间向其传入选项。在生产环境是推荐使用在头文件中 使用 变量SOLR_OPTS 代替在/var/solr/sorl.in.sh 中SOLR_OPTS=&quot;$SOLR_OPTS -Dsolr.autoSoftCommit.maxTime=10000&quot;


Enable Remote JMX Access启用远程JMX访问
启用远程JMX java 性能解析工具例如JConsole 或VisualVM 检测远程Solr服务需要将ENABLE_REMOTE_JMX_OPTS属性设置为true,还需要为JMX设置端口用于JMX RMI连接绑定像18983ENABLE_REMOTE_JMX_OPTS=trueRMI_PORT=18983
JMX RMI将会允许java性能剖析工具尝试连接18983.当可用时,在Solr启动时以下属性将会传到JVM-Dcom.sun.management.jmxremote \-Dcom.sun.management.jmxremote.local.only=false\-Dcom.sun.management.jmxremote.ssl=false\-Dcom.sun.management.jmxremote.authenticate=false\-Dcom.sun.management.jmxremote.port=18983\-Dcom.sun.management.jmxremote.rmi.port=18983该设置主要用于性能调试
每个主机运行多个Solr节点每个节点需要有不懂的Solr家目录,理想状态下每个家目录需要在不懂的物理硬盘上,这样Solr节点才不会相互竞争磁盘空间。每个节点都有独立的solr文件。如果需要将solr加入系统服务,则需要分别使用脚本指定。如:sudo bash ./install_solr_service.shsolr-5.0.0.tgz -s solr2 -p 8984

ZooKeeper 安装
ZooKeeper下载http://zookeeper.apache.org/releases.html
文章链接https://cwiki.apache.org/confluence/display/solr/Setting&#43;Up&#43;an&#43;External&#43;ZooKeeper&#43;EnsembleSetting Up a Single ZooKeeper


Create the instance


Configure the instance
<ZOOKEEPER_HOME>/conf/zoo.cfg
tickTime=2000dataDir=/var/lib/zookeeper端口clientPort=2181
Run the instance
ZOOKEEPER_HOME/bin/zkServer.sh
zkServer.sh start其他配置:http://zookeeper.apache.org/doc/r3.4.5/zookeeperStarted.html
Point Solr at the instance

使用-z参数将solr参数添加到ZooKeeper中bin/solr start -e cloud -z localhost:2181-noprompt

Add a node pointing to an existing ZooKeeper at port 2181:添加节点到ZooKeeper中bin/solr start -cloud -s <新solr节点的home目录> -p8987 -z localhost:2181
如果启动的不是使用solr example ,那需要自己去配置创建集群
Shut down ZooKeeper
zkServer.sh stop.

Setting up a ZooKeeper Ensemble
创建ZooKeeper集群
zoo.cfgdataDir=/var/lib/zookeeperdata/1clientPort=2181initLimit=5syncLimit=2server.1=localhost:2888:3888server.2=localhost:2889:3889server.3=localhost:2890:3890这一行配置中,第一个端口( port )是从( follower )机器连接到主( leader )机器的端口,第二个端口是用来进行 leader 选举的端口。在这个例子中,每台机器使用三个端口,分别是: clientPort 2181 port 2888 port 3888 initLimit ,允许节点链接主服务器所需的时间和次数,如果等于5的话表示有5次链接尝试,每次2000毫秒,所以服务器需要等待10秒时间来连接和与主服务器同步Amount of time, in ticks, to allow followers to connect and sync toa leader. In this case, you have 5 ticks, each of which is 2000 milliseconds long, so the server will wait as long as 10 seconds to connect and sync with the leader.syncLimit:节点与主服务器同步所允许的时长,如果节点服务器远远落后于主服务器那么,该节点有可能会被抛弃Amount of time, in ticks, to allow followers to sync with ZooKeeper.If followers fall too far behind a leader, they will be dropped.server.X 设置服务集群的ID和地址,服务器id必须单独的存储在<dataDir>/myid文件中,需要手动创建1/var/lib/zookeeperdata/myid鉴于需要运行多个solr实例,你需要为每个实例创建独立的目录,同样也需要创建一个新的ZooKeeper实例。即使在同一台机器上。所以需要为每一个实例创建配置文件 <ZOOKEEPER_HOME>/conf/zoo2.cfgtickTime=2000dataDir=c:/sw/zookeeperdata/2clientPort=2182initLimit=5syncLimit=2server.1=localhost:2888:3888server.2=localhost:2889:3889server.3=localhost:2890:3890<ZOOKEEPER_HOME>/conf/zoo3.cfg:tickTime=2000dataDir=c:/sw/zookeeperdata/3clientPort=2183initLimit=5syncLimit=2server.1=localhost:2888:3888server.2=localhost:2889:3889server.3=localhost:2890:3890tickTime :基本事件单元,以毫秒为单位。它用来指示心跳,最小的 session 过期时间为两倍的 tickTime. 。
dataDir :存储内存中数据库快照的位置,如果不设置参数,更新事务日志将被存储到默认位置。
clientPort :监听客户端连接的端口

最后在每一个dataDir中创建myid文件,用于区分实例。通过server.x的设置来匹配每个机器的ZooKeeper实例,因此ZooKeeper实例会被命名成server.1,在上述例子中myid的中的&#20540;为1 myid的&#20540;可以是1到255
指定特定的配置文件启动ZooKeeper
d<ZOOKEEPER_HOME>bin/zkServer.shstart zoo.cfgbin/zkServer.shstart zoo2.cfgbin/zkServer.shstart zoo3.cfg
一旦这些服务都起来了之后就可以将Solr实例关联ZooKeeper
bin/solr start -e cloud -z localhost:2181,localhost:2182,localhost:2183 -noprompt115.182.66.179:2181,118.244.192.244:2181,118.244.192.245:2181solr start -e cloud -z 115.182.66.179:2181,118.244.192.244:2181,118.244.192.245:2181 -noprompt1)单机模式

首先,从Apache官方网站下载一个ZooKeeper 的最近稳定版本。


http://hadoop.apache.org/zookeeper/releases.html

作为国内用户来说,选择最近的的源文件服务器所在地,能够节省不少的时间。


http://labs.renren.com/apache-mirror//hadoop/zookeeper/

ZooKeeper 要求 JAVA 的环境才能运行,并且需要 JAVA6 以上的版本,可以从 SUN 官网上下载,并对JAVA 环境变量进行设置。除此之外,为了今后操作的方便,我们需要对 ZooKeeper 的环境变量进行配置,方法如下,在 /etc/profile 文件中加入如下的内容:



#Set ZooKeeper Enviroment
export ZOOKEEPER_HOME=/root/hadoop-0.20.2/zookeeper-3.3.1
export PATH=$PATH:$ZOOKEEPER_HOME/bin:$ZOOKEEPER_HOME/conf


ZooKeeper 服务器包含在单个 JAR 文件中,安装此服务需要用户创建一个配置文档,并对其进行设置。我们在 ZooKeeper-*.*.* 目录(我们以当前 ZooKeeper 的最新版 3.3.1 为例,故此下面的“ ZooKeeper-*.*.* ”都将写为“ ZooKeeper-3.3.1” )的 conf 文件夹下创建一个 zoo.cfg 文件,它包含如下的内容:


tickTime=2000
dataDir=/var/zookeeper
clientPort=2181

在这个文件中,我们需要指定 dataDir 的&#20540;,它指向了一个目录,这个目录在开始的时候需要为空。下面是每个参数的含义:

tickTime :基本事件单元,以毫秒为单位。它用来指示心跳,最小的 session 过期时间为两倍的 tickTime. 。
dataDir :存储内存中数据库快照的位置,如果不设置参数,更新事务日志将被存储到默认位置。
clientPort :监听客户端连接的端口

使用单机模式时用户需要注意:这种配置方式下没有 ZooKeeper 副本,所以如果 ZooKeeper 服务器出现故障, ZooKeeper 服务将会停止。


以下代码清单 A 是我们的根据自身情况所设置的 zookeeper 配置文档: zoo.cfg
代码清单 A : zoo.cfg
# The number of milliseconds of each tick
tickTime=2000

# the directory where the snapshot is stored.
dataDir=/root/hadoop-0.20.2/zookeeper-3.3.1/snapshot/data

# the port at which the clients will connect
clientPort=2181




2)集群模式


为了获得可靠的 ZooKeeper 服务,用户应该在一个集群上部署 ZooKeeper 。只要集群上大多数的ZooKeeper 服务启动了,那么总的 ZooKeeper 服务将是可用的。另外,最好使用奇数台机器。 如果 zookeeper拥有 5 台机器,那么它就能处理 2 台机器的故障了。


之后的操作和单机模式的安装类&#20284;,我们同样需要对 JAVA 环境进行设置,下载最新的 ZooKeeper 稳定版本并配置相应的环境变量。不同之处在于每台机器上 conf/zoo.cfg 配置文件的参数设置,参考下面的配置:


tickTime=2000
dataDir=/var/zookeeper/
clientPort=2181
initLimit=5
syncLimit=2
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888

server.id=host:port:port. ”指示了不同的 ZooKeeper 服务器的自身标识,作为集群的一部分的机器应该知道 ensemble 中的其它机器。用户可以从“ server.id=host:port:port. ”中读取相关的信息。 在服务器的 data dataDir 参数所指定的目录)目录下创建一个文件名为 myid 的文件,这个文件中仅含有一行的内容,指定的是自身的 id &#20540;。比如,服务器“ 1 ”应该在 myid 文件中写入“ 1 ”。这个 id &#20540;必须是 ensemble 中唯一的,且大小在 1 255 之间。这一行配置中,第一个端口( port )是从( follower )机器连接到主( leader )机器的端口,第二个端口是用来进行 leader 选举的端口。在这个例子中,每台机器使用三个端口,分别是: clientPort 2181 port 2888 port 3888 我们在拥有三台机器的 Hadoop 集群上测试使用 ZooKeeper 服务,下面代码清单 B 是我们根据自身情况所设置的 ZooKeeper 配置文档:
代码清单 B : zoo.cfg
# The number of milliseconds of each tick
tickTime=2000

# The number of ticks that the initial
# synchronization phase can take
initLimit=10

# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5

# the directory where the snapshot is stored.
dataDir=/root/hadoop-0.20.2/zookeeper-3.3.1/snapshot/d1

# the port at which the clients will connect
clientPort=2181

server.1=IP1:2887:3887
server.2=IP2:2888:3888
server.3=IP3:2889:3889

清单中的 IP 分别对应的配置分布式 ZooKeeperIP 地址。当然,也可以通过机器名访问 zookeeper ,但是需要在ubuntuhosts 环境中进行设置。读者可以查阅 Ubuntu 以及 Linux 的相关资料进行设置。



3)集群伪分布


简单来说,集群伪分布模式就是在单机下模拟集群的ZooKeeper服务。


那么,如何对配置 ZooKeeper 的集群伪分布模式呢?其实很简单,在 zookeeper 配置文档中, clientPort参数用来设置客户端连接 zookeeper 的端口。 server.1=IP1:2887:3887 中, IP1 指示的是组成 ZooKeeper 服务的机器 IP 地址, 2887 为用来进行 leader 选举的端口, 3887 为组成 ZooKeeper 服务的机器之间通信的端口。集群伪分布模式我们使用每个配置文档模拟一台机器,也就是说,需要在单台机器上运行多个 zookeeper 实例。但是,我们必须要保证各个配置文档的 clientPort 不能冲突。


下面是我们所配置的集群伪分布模式,通过 zoo1.cfg , zoo2.cfg , zoo3.cfg 模拟了三台机器的 ZooKeeper集群。详见代码清单 C :

代码清单C : zoo1.cfg :
# The number of milliseconds of each tick
tickTime=2000

# The number of ticks that the initial
# synchronization phase can take
initLimit=10

# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5

# the directory where the snapshot is stored.
dataDir=/root/hadoop-0.20.2/zookeeper-3.3.1/d_1

# the port at which the clients will connect
clientPort=2181

server.1=localhost:2887:3887
server.2=localhost:2888:3888
server.3=localhost:2889:3889
zoo2.cfg :
# The number of milliseconds of each tick
tickTime=2000

# The number of ticks that the initial
# synchronization phase can take
initLimit=10

# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5

# the directory where the snapshot is stored.
dataDir=/root/hadoop-0.20.2/zookeeper-3.3.1/d_2

# the port at which the clients will connect
clientPort=2182

#the location of the log file
dataLogDir=/root/hadoop-0.20.2/zookeeper-3.3.1/logs

server.1=localhost:2887:3887
server.2=localhost:2888:3888
server.3=localhost:2889:3889

zoo3.cfg :
# The number of milliseconds of each tick
tickTime=2000

# The number of ticks that the initial
# synchronization phase can take
initLimit=10

# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5

# the directory where the snapshot is stored.
dataDir=/root/hadoop-0.20.2/zookeeper-3.3.1/d_2

# the port at which the clients will connect
clientPort=2183

#the location of the log file
dataLogDir=/root/hadoop-0.20.2/zookeeper-3.3.1/logs

server.1=localhost:2887:3887
server.2=localhost:2888:3888
server.3=localhost:2889:3889

从上述三个代码清单中可以看到,除了 clientPort 不同之外, dataDir 也不同。另外,不要忘记在 dataDir 所对应的目录中创建 myid 文件来指定对应的 zookeeper 服务器实例。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-138219-1-1.html 上篇帖子: Solr的配置及从数据库建立索引 下篇帖子: Solr部署配置(四)批量导入数据
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表