linux 安装elasticsearch 以及踩过的坑

1.查看是否安装了jdk
 
java -version
 
2.建立文件夹
cd usr      mkdir java
 
3.下载sdk
http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz?AuthParam=1496819635_e2e721ae219bea46228786d51756bdcc (时间稍长)
 
 
4.安装jdk
重命名并解压文件
tar zxvf jdk....
 
5.配置环境变量
 
$  vi /etc/profile
 
文件最后添加
#Java Env
export JAVA_HOME=/usr/java/jdk1.8.0_131    
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
 
6.环境变量设置立即生效
 
$ source /etc/profile
 
7.java -version
 
8.安装elasticsearch
git clone git://github.com/medcl/elasticsearch-rtf.git -b master --depth 1
 
9.解压
 
 
 
10. cd elasticsearch   ./bin/elasticsearch 
ps:如果报权限错误
 
(由于root 用户不安全 需要新建用户组elsearch 以及用户elsearch  密码设置elel123
groupadd elsearch  
useradd elsearch -g elsearch -p elel123
ps: useradd用户名–g组名–p密码 )
 
 
11设置模板
 
curl -XPUT http://elastic:changeme@localhost:9200/_template/rtf -d'{"template":"*","settings":{"number_of_shards":1},"mappings":{"_default_":{"_all":{"enabled":true},"dynamic_templates":[{"strings":{"match_mapping_type":"string","mapping":{"type":"text","analyzer":"ik_smart","ignore_above":256,"fields":{"keyword":{"type":"keyword"}}}}}]}}}'
 
ps:这个粗体的之前是string 在windows 上可以用,但是linux上报错误,所以换做text
 
 curl -XPUT  http://elastic:changeme@localhost:9200/we-media -d'{"settings":{"refresh_interval":"5s","number_of_shards":1,"number_of_replicas":0},"mappings":{"_default_":{"_all":{"enabled":true}}}}'
 
12,运行添加数据,
 
 
 
ps:
检查索引是否存在
curl -i -XHEAD http://elastic:changeme@localhost:9200/we-media/news/551
 
删除所有索引
curl -XDELETE http://elastic:changeme@localhost:9200/_all
 
获取索引
curl -XGET http://elastic:changeme@localhost:9200/we-media/news/
 
导入索引
php artisan scout:import "App\News"
 
获取mapping
 
curl -XGET http://elastic:changeme@localhost:9200/_mappings?pretty"
查看索引
curl -XGET http://elastic:changeme@localhost:9200/_cat/indices?v
 
curl -XPUT http://elastic:changeme@localhost:9200/we-media/_mapping/news -d '
{    "news" : {        "properties" : {            "message" : {"type" : "string", "store" : true }      }  }}'
 
 
添加测试数据
 
curl -XPUT http://elastic:changeme@localhost:9200/we-media/news/1?pretty -d '
{
   "title" : "John Doe"
}'
 
查看状态
curl -XGET http://elastic:changeme@localhost:9200/_cluster/health/?level=shards
 
如果报 not mapping field[**] not order  
 
改索引名字,更新删除模板,
记得删除 elasticsearch 里面的data 文件夹 ,并且要重启服务
 
 
另外建议安装kibana 比较简单,也比较好用
posted @ 2022-08-10 11:20  PHP01  阅读(52)  评论(0)    收藏  举报