linux搭建elasticsearch2.2.1

Scroll Down

1.下载安装包

[root@localhost es]# wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.2.1/elasticsearch-2.2.1.tar.gz

2.解压

[root@localhost es]# tar -xvzf elasticsearch-2.2.1.tar.gz

3.创建一个普通用户,elasticsearch-2.x版本以后就不允许使用root账户启动
创建账号:

[root@localhost es]# useradd dd

设置密码:

[root@localhost es]# passwd 123456

4.给用户设置文件夹的权限,不然切换用户后运行会提示权限不足

[root@localhost es]# chown -R dd elasticsearch-2.2.1/
[root@localhost es]# chgrp -R dd elasticsearch-2.2.1/

5.切换用户

[root@localhost es]# su dd

6.进入bin文件夹启动服务

[dd@localhost es]$ cd elasticsearch-2.2.1/bin/
[dd@localhost bin]$ ./elasticsearch
[2017-11-15 17:03:29,777][INFO ][node                     ] [Madame Hydra] version[2.2.1], pid[8123], build[d045fc2/2016-03-09T09:38:54Z]
[2017-11-15 17:03:29,784][INFO ][node                     ] [Madame Hydra] initializing ...
[2017-11-15 17:03:30,974][INFO ][plugins                  ] [Madame Hydra] modules [lang-expression, lang-groovy], plugins [], sites []
[2017-11-15 17:03:31,024][INFO ][env                      ] [Madame Hydra] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [21.9gb], net total_space [45.8gb], spins? [unknown], types [rootfs]
[2017-11-15 17:03:31,024][INFO ][env                      ] [Madame Hydra] heap size [990.7mb], compressed ordinary object pointers [true]
[2017-11-15 17:03:31,025][WARN ][env                      ] [Madame Hydra] max file descriptors [65535] for elasticsearch process likely too low, consider increasing to at least [65536]
[2017-11-15 17:03:33,957][INFO ][node                     ] [Madame Hydra] initialized
[2017-11-15 17:03:33,957][INFO ][node                     ] [Madame Hydra] starting ...
[2017-11-15 17:03:34,177][INFO ][transport                ] [Madame Hydra] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2017-11-15 17:03:34,183][INFO ][discovery                ] [Madame Hydra] elasticsearch/2_rsoks7SUCkniSHfy7ipQ
[2017-11-15 17:03:37,218][INFO ][cluster.service          ] [Madame Hydra] new_master {Madame Hydra}{2_rsoks7SUCkniSHfy7ipQ}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-join(elected_as_master, [0] joins received)
[2017-11-15 17:03:37,235][INFO ][http                     ] [Madame Hydra] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2017-11-15 17:03:37,235][INFO ][node                     ] [Madame Hydra] started
[2017-11-15 17:03:37,308][INFO ][gateway                  ] [Madame Hydra] recovered [0] indices into cluster_state

或后台启动

[dd@localhost bin]$ ./elasticsearch -d -p pid
[dd@localhost bin]$ 

7.检查是否启动

[dd@localhost bin]$ curl localhost:9200
{
  "name" : "Morg",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.2.1",
    "build_hash" : "d045fc29d1932bce18b2e65ab8b297fbf6cd41a1",
    "build_timestamp" : "2016-03-09T09:38:54Z",
    "build_snapshot" : false,
    "lucene_version" : "5.4.1"
  },
  "tagline" : "You Know, for Search"
}

8.注意:此时用外网或者局域网ip是不能访问的,如果要访问,按以下修改:

[dd@localhost bin]$ vim ../config/elasticsearch.yml 

修改配置:

network.host: 0.0.0.0

注意配置项的冒号后要有空格,不然会报错

端口可以手动指定,也可以不指定,使用默认端口。

http.port: 9200
transport.tcp.port: 9300

9.安装head插件
插件安装格式为:./plugin install [org]/[user|component]/[version]

[root@localhost bin]# ./plugin install mobz/elasticsearch-head
-> Installing mobz/elasticsearch-head...
Trying https://github.com/mobz/elasticsearch-head/archive/master.zip ...
Downloading .............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................DONE
Verifying https://github.com/mobz/elasticsearch-head/archive/master.zip checksums if available ...
NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .md5 file to verify)
Installed head into /opt/es/elasticsearch-2.2.1/plugins/head

10.关闭

在运行的时候如果加了-p参数,那es进程的pid会写入参数指定的文件里面,然后kill pid即可
还可以通过jps命令找到es的pid

[dd@localhost bin]$ ls
elasticsearch      elasticsearch.in.bat  elasticsearch-service-mgr.exe  elasticsearch-service-x86.exe  plugin      service.bat
elasticsearch.bat  elasticsearch.in.sh   elasticsearch-service-x64.exe  pid                            plugin.bat
[dd@localhost bin]$ cat pid
8406[dd@localhost bin]$ 

[dd@localhost bin]$ jps
8406 Elasticsearch
8796 Jps

[dd@localhost bin]$ kill -9 8406

11.外网访问要打开端口,CentOS7使用firewalld防火墙,无法使用iptables命令控制端口
查询端口是否打开:

[root@localhost elasticsearch-2.2.1]# firewall-cmd --query-port=9200/tcp
no

打开端口:

[root@localhost elasticsearch-2.2.1]# firewall-cmd --add-port=9200/tcp
success

9200和9300都要打开

查看规则:

[root@localhost elasticsearch-2.2.1]# iptables -L -n

外网就可以访问了

访问192.168.195.130:9200
可以看到一串json,说明访问成功

{
  "name" : "Stegron",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.2.1",
    "build_hash" : "d045fc29d1932bce18b2e65ab8b297fbf6cd41a1",
    "build_timestamp" : "2016-03-09T09:38:54Z",
    "build_snapshot" : false,
    "lucene_version" : "5.4.1"
  },
  "tagline" : "You Know, for Search"
}

访问http://192.168.195.130:9200/_plugin/head 可以看到管理界面

elasticsearch的名字每次启动都会变化,都是漫威漫画里的角色。。。