当出现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 安装
ZooKeeper下载http://zookeeper.apache.org/releases.html
文章链接https://cwiki.apache.org/confluence/display/solr/Setting+Up+an+External+ZooKeeper+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
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 :监听客户端连接的端口
下面是我们所配置的集群伪分布模式,通过 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