elasticsearch安装

1、环境

主机名 IP
ELK-1 10.0.0.51

2、ELK-1上安装 elasticsearch

# 安装java环境变量
yum install -y java-1.8.0-openjdk.x86_64

# 下载安装软件
mkdir  -p /data/es_soft/
cd /data/es_soft/
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.0.rpm
#yum localinstall elasticsearch-6.6.0.rpm -y
rpm -ivh elasticsearch-6.6.0.rpm

# 启动服务
systemctl daemon-reload
systemctl enable elasticsearch.service
systemctl start elasticsearch.service
systemctl status elasticsearch.service
#systemctl is-active elasticsearch.service

#检查是否启动成功
ps -ef|grep elastic
lsof -i:9200
curl localhost:9200
elasticsearch安装_第1张图片
效果图.png
# 调整jvm配置
vim /etc/elasticsearch/jvm.options

-Xms1g
-Xmx1g
 
注释:根据物理内存调,生产不要超过30G,这里我是在虚拟机里面所以只给1G

# 修改elasticsearch.yml配置文件
vim /etc/elasticsearch/elasticsearch.yml
#自定义节点名称
node.name: node-1
#索引数据存储位置
path.data: /data/elasticsearch
#日志路径
path.logs: /var/log/elasticsearch
#锁定物理内存地址,防止elasticsearch内存被交换出去,也就是避免es使用swap交换分区
bootstrap.memory_lock: true
#当前es节点绑定的ip地址
network.host: 10.0.0.51 
#启动的es对外访问的http端口,默认9200
http.port: 9200

#创建索引数据存储位置目录
mkdir /data/elasticsearch/ -p 
chown -R elasticsearch:elasticsearch /data/elasticsearch/
systemctl restart elasticsearch

# 启动报错1
[2019-11-23T22:26:16,759][ERROR][o.e.b.Bootstrap          ] [node-1] node validation exception
[1] bootstrap checks failed
[1]: memory locking requested for elasticsearch process but memory is not locked
[2019-11-23T22:26:16,812][INFO ][o.e.n.Node               ] [node-1] stopping ...
[2019-11-23T22:26:16,822][INFO ][o.e.n.Node               ] [node-1] stopped
[2019-11-23T22:26:16,822][INFO ][o.e.n.Node               ] [node-1] closing ...
[2019-11-23T22:26:16,848][INFO ][o.e.n.Node               ] [node-1] closed

# 解决方法:
systemctl edit elasticsearch
[Service]
LimitMEMLOCK=infinity

systemctl daemon-reload
systemctl start elasticsearch

# 启动有点慢,建议等会再测试
curl 10.0.0.51:9200

# 启动报错总结
1.配置文件没有任何修改
2.配置文件没有修改IP地址
3.系统内存只有1G,启动失败
4.配置文件参数拼写错误,启动失败
5.忘记修改内存锁定,启动失败

3、ELK-1上安装es-head

# 安装步骤
yum install nodejs npm openssl screen -y
node -v
npm  -v
npm install -g cnpm --registry=https://registry.npm.taobao.org
#上传es-head软件包
tar zxvf elasticsearch-head.tar.gz -C /opt/
cd /opt/elasticsearch-head
npm run start & 

# 修改es配置文件
cat >>/etc/elasticsearch/elasticsearch.yml<

插入数据

elasticsearch安装_第2张图片
image.png

curl -XPUT  'localhost:9200/vipinfo/user/2?pretty' -H 'Content-Type: application/json' -d' {
    "first_name": "Jane",
    "last_name" : "Smith",
    "age" : 32,
    "about" : "I like to collect rock albums", "interests": [ "music" ]
}'


curl -XPUT  'localhost:9200/vipinfo/user/3?pretty' -H 'Content-Type: application/json' -d' {
    "first_name": "Jane",
    "last_name" : "Smith",
    "age" : 32,
    "about" : "I like to collect rock albums", "interests": [ "music" ]
}'


curl -XPOST  'localhost:9200/vipinfo/user?pretty' -H 'Content-Type: application/json' -d' {
    "first_name": "Jane",
    "last_name" : "Smith",
    "age" : 32,
    "about" : "I like to collect rock albums", "interests": [ "music" ]
}'

4、查询
查询所有

image.png

查询id为3

elasticsearch安装_第3张图片
image.png
elasticsearch安装_第4张图片
image.png
elasticsearch安装_第5张图片
image.png

shell窗口执行

curl -XGET 'localhost:9200/vipinfo/user/_search?q=last_name:ya&pretty'
curl -XGET 'localhost:9200/vipinfo/user/_search?q=age:28&pretty'

 
使用Query-string查询 
curl -XGET 'localhost:9200/vipinfo/user/_search?pretty' -H 'Content-Type: application/json' -d'           
{
  "query" : { 
    "match" : {
        "last_name" : "ya"
     }
  } 
}
'

curl -XGET 'localhost:9200/vipinfo/user/_search?pretty' -H 'Content-Type: application/json' -d'{ 
  "query" : { 
    "bool": { 
      "must": { 
        "match" : { 
          "last_name" : "smith" 
          } 
     }, 
     "filter": { 
        "range" : {"age" : { "gt" : 30 }  
          } 
        } 
      } 
    } 
 }'

更新数据

curl -XPOST  'localhost:9200/linux58/linux?pretty' -H 'Content-Type: application/json' -d' {
    "id" : 1 ,
    "first_name": "zhang",
    "last_name" : "ya",
    "age" : 18,
    "group" : 1
}'


curl -XPOST  'localhost:9200/linux58/linux?pretty' -H 'Content-Type: application/json' -d' {
    "id" : 2 ,
    "first_name": "li",
    "last_name" : "banzhang",
    "age" : 18,
    "group" : 10
}'

curl -XPOST  'localhost:9200/linux58/linux?pretty' -H 'Content-Type: application/json' -d' {
    "id" : 3 ,
    "first_name": "what",
    "last_name" : "ao",
    "age" : 17,
    "group" : 13
}'

删除

elasticsearch安装_第6张图片
删除.png

你可能感兴趣的:(elasticsearch安装)