Elasticsearch安装(一)

Elasticsearch安装(一)

1.环境准备
1.Centos6.5 64位
2.jdk-8u144-linux-x64.tar.gz
3.elasticsearch-6.5.4.tar.gz
2.安装
1.解压jdk-8u144-linux-x64.tar.gz
2.配置jdk环境变量
3.解压elasticsearch-6.5.4.tar.gz
3.创建用户(es不可以使用root用户启动)
1.groupadd elsearch #创建用户组
2.useradd elsearch -g elsearch #创建用户并加入用户组
3.chown -R elsearch:elsearch elasticsearch-6.5.4 #更改es所属的用户组权限
4.passwd elsearch #设置用户密码
5.su - elsearch #切换用户
4.启动
1.cd elasticsearch-6.5.4/bin #进入es的bin目录
2…/elasticesrarch -d #后台启动 ./elasticesrarch启动占用终端
5.关闭
1.jps查看进程
2.kill -9 进程id
6.验证结果
1.通过Linux浏览器
访问:http://localhost:9200/ ,显示信息如下:
{
“name” : “rZBzwAw”,
“cluster_name” : “elasticsearch”,
“cluster_uuid” : “r8j2ND62T2yY4fPerpuSgg”,
“version” : {
“number” : “6.5.4”,
“build_flavor” : “default”,
“build_type” : “tar”,
“build_hash” : “d2ef93d”,
“build_date” : “2018-12-17T21:17:40.758843Z”,
“build_snapshot” : false,
“lucene_version” : “7.5.0”,
“minimum_wire_compatibility_version” : “5.6.0”,
“minimum_index_compatibility_version” : “5.0.0”
},
“tagline” : “You Know, for Search”
}
2.通过终端命令访问
curl http://localhost:9200 ,显示内容同上
7.常用命令
1.创建索引
curl -XPUT http://localhost:9200/music/ #music为索引名称
2.查看全部索引

	curl -XGET http://localhost:9200/_cat/indices?v
3.插入文档
	curl -H "Content-Type:application/json" -XPUT http://localhost:9200/music/songs/1 -d '{"name":"Deck the Halls","year":1885,"lyrics":"Fa la la la la"}'
4.查看文档
	curl -XGET http://localhost:9200/music/songs/1
5.更新文档
	ID相同则更新,不同则新增
6.删除文档
	curl -XDELETE http://localhost:9200/music/songs/1
7.查看索引下全部记录
	curl http://localhost:9200/music/songs/_search
8.删除索引
	curl -XDELETE http://localhost:9200/music
9.删除全部索引
	curl -XDELETE http://localhost:9200/_all 或者 curl -XDELETE http://localhost:9200/*

8.java连接es
1.开放端口 或者 永久关闭防火墙
开放端口
1./sbin/iptables -I INPUT -p tcp --dport 9200 -j ACCEPT
2./etc/rc.d/init.d/iptables save
3./etc/rc.d/init.d/iptables restart
4./etc/rc.d/init.d/iptables status
永久关闭防火墙
1.service iptables stop
2.chkconfig iptables off
3.service iptables status
2.修改es的config目录中的elasticsearch.yml
在该文件中增加一行如下内容,允许所有IP访问也可以指定IP
----------------Memory----------------
bootstrap.memory_lock: false #此处是取消注释,修改值为false
bootstrap.system_call_filter: false #此处是新增一行,注意冒号后面有一个空格
----------------Network----------------
network.host: 0.0.0.0 #此处是取消注释,修改IP
http.host: 0.0.0.0 #此处是新增一行,注意冒号后面有一个空格
3.用前端启动方式重新启动es,此时会出现3个错误
1.max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
解决方案:
vi /etc/security/limits.conf
增加如下内容:
* soft nofile 65536
* hard nofile 65536
2.max number of threads [1024] for user [es] is too low, increase to at least [4096]
vi /etc/security/limits.conf
增加如下内容:
* soft nproc 4096
* hard nproc 4096
3.max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
vi /etc/sysctl.conf
vm.max_map_count=262144
4.重启电脑重新启动es,继续报以下错误
1.max number of threads [1024] for user [es] is too low, increase to at least [4096]
vi /etc/security/limits.d/90-nproc.conf
* soft nproc 1024
#修改为
* soft nproc 4096
9.安装IK中文分词
1.下载分词器插件
地址:https://github.com/medcl/elasticsearch-analysis-ik/releases
版本与es版本对应
2.解压IK分词器,重命名为analysis-ik
3.将IK文件夹放入es的plugins目录,然后重启es
4.使用命令查看IK分词效果
curl -H “Content-Type: application/json” -XPOST ‘http://192.168.242.144:9200/users/_analyze?&pretty=true’ -d ‘{“analyzer”:“ik_max_word”,“text”:“中华人民”}’

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值