centos服务器配置elasticsearch

1.下载

官网下载地址:
https://www.elastic.co/cn/downloads/elasticsearch
选择版本下载地址:
https://www.elastic.co/cn/downloads/past-releases
https://www.elastic.co/cn/downloads/past-releases/elasticsearch-6-2-2

2.安装(也可以直接下载zip包解压安装)

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.2.tar.gz

3.解压文件(我是将包移动到/usr/local下再解压)

cd /usr/local
tar -zxvf elasticsearch-6.2.2.tar.gz

4.在 Linux 环境中,elasticsearch 不允许以 root 权限来运行!所以需要创建一个非root用户,以非root用户来启动es

groupadd elk # 创建用户组elk
useradd elk -g elk -p 111111 # 创建新用户elk,-g elk 设置其用户组为 elk,-p 111111 设置其密码6个1
chown -R elk:elk /usr/local/elasticsearch-6.2.2 # 更改 /usr/loacal/elasticsearch-6.2.2 文件夹及内部文件的所属用户及组为 elk:elk

5.打开外网(如果外网访问不了,请检查安全组或者firewalld防火墙是否打开了端口)

修改 vi ./config/elasticsearch.yml
network.host: 0.0.0.0

6.启动

su elk
前台启动  ./elasticsearch
后台启动  ./elasticsearch  -d

7.(打开外网启动会报几个错误)错误解决方法

 (1) max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

此错误出现在修改config/elasticsearch.yml中的network.host为network.host: 0.0.0.0以便让外网任何IP都能来访问时。

解决方法:

切换到root用户,然后
vim /etc/security/limits.conf
* soft nofile 300000
* hard nofile 300000
* soft nproc 102400
* soft memlock unlimited
* hard memlock unlimited

注意:!!!!!!!一定要用户退出后重新登录生效

(2)  max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

先要切换到root用户;
然后可以执行以下命令,设置 vm.max_map_count ,但是重启后又会恢复为原值。
sysctl -w vm.max_map_count=262144

持久性的做法是在 /etc/sysctl.conf 文件中修改 vm.max_map_count 参数:
echo "vm.max_map_count=262144" > /etc/sysctl.conf
sysctl -p 查看是否生效

8.安装ik分词器插件

插件:ik
https://github.com/medcl/elasticsearch-analysis-ik
输入
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.2/elasticsearch-analysis-ik-6.2.2.zip

9.es常用命令

1.查看索引
curl localhost:9200/_cat/indices

2.新建索引
curl -XPUT localhost:9200/example1

3.新建文档
curl -H "Content-Type: application/json"  -XPUT localhost:9200/example1/tp1/1?pretty -d '
{
"name":"hello"
}'

4.删除文档
curl -H "Content-Type: application/json" -XDELETE localhost:9200/product?pretty

5.查询索引
curl -H "Content-Type: application/json" -XGET localhost:9200/product?pretty

curl -H "Content-Type: application/json" -XGET localhost:9200/example1?pretty

6.查询具体文档
curl -XGET localhost:9200/example1/_search?pretty

7.查询文档具体数据
curl -XGET localhost:9200/example1/tp1/1?pretty

8.更新文档数据
1.1.利用POST直接覆盖
curl -H "Content-Type: application/json" -XPOST localhost:9200/example1/tp1/1?pretty -d '
{
"name":"hello hello"
}'
这种方法会使得版本号+1。

1.2用_update子命令和”doc”属性来更新:
curl -H "Content-Type: application/json" -XPOST localhost:9200/example1/tp1/1/_update?pretty -d '
{
"doc":{"name":"hello3"}
}'
看到_version=2,说明这种方法更新数据不会创建新的版本。

9.删除记录
curl -XDELETE localhost:9200/example1/tp1/1?pretty

10.查询记录
1.1查询文档所有数据
curl -XGET localhost:9200/product/docs/_search?pretty

1.2带参数查询文档
curl -H "Content-Type: application/json" -XGET localhost:9200/example1/tp1/_search?pretty -d'
 {
 "query":{"match":{"name":"hello"}}
 }'

11.用_all查询所有索引
curl -XGET localhost:9200/_all?pretty

curl -H "Content-Type: application/json" -XPUT http://127.0.0.1:9200/product/_settings -d '{ "index" : { "max_result_window" : 100000000}}'

发布了49 篇原创文章 · 获赞 17 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/unhejing/article/details/103565510