yorknong 发表于 2019-1-28 14:05:53

Elasticsearch安装篇

  Elasticsearch安装篇
  1.先去elasticsearch 官网
  https://www.elastic.co/
  Jar下载
  http://jcenter.bintray.com/org/elasticsearch/elasticsearch-hadoop
  下载好后 直接解压
  tar -zxvf   elasticsearch-2.4.3.tar.gz
  修改config下elasticsearch.yml
  cluster.name: gotop
  node.name: hadoop001
  http.port: 9200
  network.host: 192.168.1.101
  discovery.zen.ping.unicast.hosts: ["hadoop001", "hadoop003", "hadoop004"]
  
  
#集群名称,通过组播的方式通信,通过名称判断属于哪个集群
cluster.name: es
#节点名称,要唯一
node.name: es-1
#数据存放位置
path.data:/data/es/data
#日志存放位置
path.logs:/data/es/logs
#es绑定的ip地址
network.host:172.16.0.14
#初始化时可进行选举的节点(es集群节点)
discovery.zen.ping.unicast.hosts:["node-4", "node-5", "node-6"]

6.可以直接复制到其他服务器,只修改node.name和network.host就行了
7.启动es
  
  然后把整个目录修改权限为777或者更改用户组
  切换到普通频道执行:su gotop
启动:./bin/elasticsearch(前台运行)bin/elasticsearch-d(后台运行)

关闭elasticsearch
前台运行,可以通过"CTRL+C"组合键来停止运行
关闭:ps aux |grep elasticsearch找到pid    kill-9pid
后台运行,可以通过"kill -9 进程号"停止;也可以通过REST API接口"curl -XPOST http://主机IP:9200/_cluster/nodes/_shutdown"来关闭整个集群,"curl -XPOST http://主机IP:9200/_cluster/nodes/节点标示符(如Bjkhlujigopojhih)/_shutdown"来关闭单个节点
rpm安装,"sudo service elasticsearch stop"关闭服务

curl -XPOST 'http://localhost:9200/_shutdown'



注意问题:
1.elasticsearch不建议使用root用户,可以使用其他用户
       2.节点名称也是唯一(集群里不一样名)
       3.绑定ip地址也是不一样的
       4.启动es后,可以在线查看帮助文档 bin/elasticsearch-h
      5.数据和日志存放都是自定义的
  打开:
  http://192.168.1.101:9200
  证明安装成功!
  

  2.安装elasticsearch-head 插件
  ./bin/plugin install mobz/elasticsearch-head
  浏览器查看
  http://192.168.1.101:9200/_plugin/head/
  
  安装elasticsearch-sql 插件
  把插件上传到服务器,进入elasticsearch/bin启动./elasticsearch &,执行./plugin install file:/ 插件存放路径/elasticsearch-sql-2.4.1.0.zip
  浏览器查看
  http://192.168.1.101:9200/_plugin/sql/
  
  可以看到上面内容证明安装成功
  
  遇到的问题及解决方法:
问题一:ERROR: bootstrap checks failed
max file descriptors for elasticsearch process likely too low, increase to at least
max number of threads for user likely too low, increase to at least
解决:切换到root用户,编辑limits.conf 添加类似如下内容
vi /etc/security/limits.conf
添加如下内容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

问题二:max number of threads for user likely too low, increase to at least
解决:切换到root用户,进入limits.d目录下修改配置文件。
vi /etc/security/limits.d/90-nproc.conf
修改如下内容:
* soft nproc 1024
#修改为
* soft nproc 2048

问题三:max virtual memory areas vm.max_map_count likely too low, increase to at least
解决:切换到root用户修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并执行命令:
sysctl -p
然后,重新启动elasticsearch,即可启动成功。
  关于使用可一参考:http://blog.csdn.net/ebw123/article/details/46707559
  
  创建索引
  curl -XPUT 'http://192.168.0.111:9200/web01?pretty' -d'
  {
  "settings":{
  "number_of_shards":2,
  "number_of_replicas":1
  }
  }'
  为索引增加数据
  curl -XPUT 'http://192.168.1.101:9200/web01/table/1' -d '
  {
  
      "news": {
  
        "properties": {
  
        "id": {
  
            "analyzer": "ik",
  
            "type": "int"
  
        },
  
        "name": {
  
            "index": "not_analyzed",
  
            "type": "string"
  
        },
  
        "ip": {
  
            "analyzer": "ik",
  
            "type": "string"
  
        },
  
        "time": {
  
            "index": "not_analyzed",
  
            "type": "string"
  
        }
  
        
  
      }
  
  }
  
  }’
Hive结合
  把elasticsearch-hadoop-2.4.3.jar /usr/hdp/2.2.6.0-2800/hive/lib
  把elasticsearch-hadoop-2.4.3.jar上传到hdfs的下面目录/tmp/
  然后运行
  beeline -u jdbc:hive2://hadoop001:10000 hive -p gotop123 -hiveconf hive.aux.jars.path=/opt/es/elasticsearch-hadoop-2.4.3.jar
  
  首先创建源数据表
  CREATE TABLE test01_source (
  id int,
  name string,
  ip string,)
  ROW FORMAT DELIMITED
  FIELDS TERMINATED BY ','
  STORED AS TEXTFILE;
  
  然后把自己的数据load进去
  
  LOAD DATA LOCAL INPATH '/usr/local/555.txt.lzo' OVERWRITE INTO TABLE lzowu;
  select * from web01_source;
  
  所需时间21秒
  
  建立视图表
  hive表中field类型为int时,映射到es中变成long,所以会报此错误。将hive表中int改为bigint即可。
  CREATE EXTERNAL TABLE web03(
  id bigint,
  name string,
  ip string,
  time string)
  STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
  TBLPROPERTIES('es.resource' = 'test1/table1', 'es.nodes'='192.168.0.111', 'es.port'='9200', 'es.nodes.wan.only'='true');
  
  CREATE EXTERNAL TABLE estwo(
  id bigint,
  name string,
  ip string,
  age string)
  STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
  TBLPROPERTIES('es.resource' = 'two/two', 'es.nodes'='192.168.1.101:9200,192.168.1.103:9200,192.168.1.95:9200', 'es.nodes.wan.only'='true');
  es.resource的two/two分别是索引名和索引的类型,这个是在es访问数据时候使用的。
然后建立源数据表
  
  
  只能用bigint类型 因为默认为long类型interesting类型可以被javaapi进行调用
  运行下面如果提示在目录下面elasticsearch-hadoop-2.4.3.jar不能写的权限问题 需要手动上传到hdfs里面 如果彻底解决这个问题需要改变目录权限即可
  
  
  insert overwrite table web select * from test01_source;
  insert into table web03 from web01_source;
  
  selece * from web03
  所需时间0.3秒以内
  Select * from web01_source
  所需时间0.2秒以内
  
  ES参考:http://blog.csdn.net/pilihaotian/article/details/52452014
  
  LZO参考:http://blog.csdn.net/zhangzhaokun/article/details/17595325#comments
        http://blog.csdn.net/slx_2011/article/details/44748613
  
  
LZO在线安装:
yum -y install *lzo*

修改hdfs 的 core-site.xml

io.compression.codecs=org.apache.hadoop.io.compress.GzipCodec,org.apache.hadoop.io.compress.DefaultCodec,org.apache.hadoop.io.compress.BZip2Codec,com.hadoop.compression.lzo.LzoCodec,com.hadoop.compression.lzo.LzopCodec

添加
io.compression.codec.lzo.class=com.hadoop.compression.lzo.LzoCodec


当使用insert语句往lzo表里插入数据时,需要加入下面两个参数,否则只能load(lzop 1.txt压缩成lzo格式):
SET hive.exec.compress.output=true;
SET mapred.output.compression.codec=com.hadoop.compression.lzo.LzopCodec;

4. 测试mapreduce读lzo
hive新建一张表lzoer
create table lzoer(id int,name string, ip string)ROW FORMAT DELIMITED
FIELDS TERMINATED BY ',' STORED AS INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat';


下载lzop工具,load一个lzo文件进lzoer表中,执行“select * fromlzoer"和"select count(1) from lzo_test"正确
LZOP安装:
1. 下载lzop包
# wget 'http://www.lzop.org/download/lzop-1.03.tar.gz'

2. 编译安装
# tar xzvf lzop-1.03.tar.gz
# cd lzop-1.03
# ./configure
# make
#make install

如果lzop提示找不到命令,尝试执行:
#ln -s /usr/local/bin/lzop /usr/bin/lzop

三、测试
# lzop -V
                        Lempel-Ziv-Oberhumer Packer
                           Copyright (C) 1996 - 2010
lzop v1.03         Markus Franz Xaver Johannes Oberhumer          Nov 1st 2010
lzop version: v1.03, Nov 1st 2010
lzop build date: Feb1 2013 12:37:12

命令使用帮助:
# lzop -h
  
  
  




页: [1]
查看完整版本: Elasticsearch安装篇