elasticsearh集群布署与调试

来源:互联网 发布:virtualbox拖拽文件mac 编辑:程序博客网 时间:2024/06/15 23:43
curl 'http://localhost:9200/?pretty'   查看elasticsearch状态


一、安装


1、安装jdk1.7


2、安装elasticsearch-1.4.1


下载地址:https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.1.zip


解压缩:tar xf elasticsearch-1.4.1.zip


3、安装elasticsearch插件


cd elasticsearch-1.4.1


集群管理插件:./bin/plugin --install(2.1直接用install没有--) mobz/elasticsearch-head


集群监控插件:./bin/plugin --install lukas-vlcek/bigdesk


mmseg分词插件:


1、手动打包elasticsearch-analysis-mmseg-1.2.0.jar,拷贝jar文件到新建目录plugins/mmseg下


2、拷贝mmseg词典文件(chars.dic  units.dic  words.dic  words-my.dic)到新建目录config/mmseg下


4、文档参考


http://www.elasticsearch.org/


http://www.chepoo.com/elasticsearcharticles


二、配置


配置elasticsearch.yml(默认为yaml格式,yaml格式不只支持Tab缩进;也可以为json格式)


cluster.name: beta-2.1
node.name: beta-2.1.node-1
#节点间交互端口、对外服务http端口,默认为9300、9200
transport.tcp.port: 9300
http.port: 9200
#数据,日志目录
path.data: /root/search/elasticsearch/data
path.logs: /root/search/elasticsearch/logs
#有资格选举为主结点,默认为true
node.master: true
#数据结点,即存储索引默认为true
node.data: true
#是否使用http协议对外提供服务,默认为true
http.enabled: true
#默认为支持所有river,不支持设置为_none_,支持某个或多个river设置为名称,逗号分隔
node.river: _none_ 
#分片数,默认为5,索引分片数=数据总量/单分片数(20G)
index.number_of_shards: 5
#副本数,默认为1, 索引过程中如果有副本存在,数据会马上同步到副本中去。建议在批量索引过程中将副本数设为0,待索引完成并且执行Optimize后,将副本数按需量改回来
index.number_of_replicas: 1
#刷新频率,默认为120ms,-1为关闭, 建议在批量索引过程中将刷新周期设置为-1,待索引完成后将副本数按需量改回来
index.refresh_interval: 120
#tranlog数据达到多少条进行平衡,-1为关闭,默认为5000
index.translog.flush_threshold_ops: 5000
#设置索引缓存(最大数量、过期时间)
index.cache.field.max_size: 50000
index.cache.field.expire: 10m
#默认类型为resident,表示常驻内存,直到内存耗尽
#soft就是当内存不足的时候,先clear掉占用的,然后再往内存中放
index.cache.field.type: soft
#确保使用物理内存,不使用linux swap
bootstrap.mlockall: true
#全局禁用动态mapping,默认为true
#"dynamic": "false"表示已创建的mapping中的字段类型必须一致,但可以动态添加新字段
#"dynamic": "strict"表示已创建的mapping中的字段类型必须一致,并且不可以动态添加新字段
index.mapper.dynamic: strict
#禁止索引自动创建
action.auto_create_index: false


network.host: 172.20.10.192


#分词器设置(也可以再创建索引时配置)
index:
  analysis:
    analyzer:
      mmseg_complex:
        type: org.elasticsearch.index.analysis.MMsegAnalyzerProvider
        seg_type: complex
      mmseg_max_word:
        type: org.elasticsearch.index.analysis.MMsegAnalyzerProvider
        seg_type: max_word


#字段使用分词器方式
#"list_name" : { "type" : "string", "store" : "yes", "index" : "analyzed", "index_analyzer" : "mmseg_max_word", "search_analyzer" : "mmseg_complex" }


三、运行


运行命令:./bin/elasticsearch -d -Xmx2g -Xms2g -Des.index.storage.type=memory --node.name=172.24.136.36_1 --cluster.name=ule.cse(ps:-d为后台运行参数,-X为指定jvm内存)


查看日志:tail -f /data/logs/cse/elasticsearch_1/ule.cse.log


集群管理:http://localhost:9200/_plugin/head/


集群监控:http://localhost:9200/_plugin/bigdesk


四、优化


1、提高elasticsearch占用内存,调大后,最小和最大一样,避免GC,一般设置为机器配置的一半,如16G内存机器:


./bin/elasticsearch -d -Xmx8g -Xms8g -Des.index.storage.type=memory


2、bulk操作前后优化


1)bulk操作前,禁用shard刷新频率,设置replicas数为0:


curl -XPUT 'http://localhost:9200/listing/_settings?pretty' -d '{"index":{"number_of_replicas":0}}'


curl -XPUT 'http://localhost:9200/listing/_settings?pretty' -d '{"index":{"refresh_interval":-1}}'


2)bulk操作后,优化索引,优化segments段为5,启用shard刷新频率,设置replicas为需要的数量,:


curl -XPUT 'http://localhost:9200/listing/_optimize?pretty'


curl -XPUT 'http://localhost:9200/listing/_optimize?pretty&max_num_segments=5'


curl -XPUT 'http://localhost:9200/listing/_settings?pretty' -d '{"index":{"number_of_replicas":2}}'


curl -XPUT 'http://localhost:9200/listing/_settings?pretty' -d '{"index":{"refresh_interval":120}}' 


 3、清除删除文档


curl -XPOST 'http://localhost:9200/listing/_optimize?pretty&only_expunge_deletes=true'


 
无  编辑标签