由于elasticsearch由Java实现,所以需要Java环境,请自行百度安装。
elasticsticsearch不能用root用户去启动,否则会报错,所以在这里我将会单独创建一个名为elasticsearch的用户,去运行elasticsearch程序,当前用户是root,所以无需切换,直接运行如下命令:
创建密码,这里会有两次密码输入提示,确保一致即可创建完成!
[root@localhost soft]# useradd elasticsearch
[root@localhost soft]# passwd elasticsearch
Changing password for user elasticsearch.
New password: elasticsearch
Retype new password: elasticsearch
passwd: all authentication tokens updated successfully.
[root@localhost soft]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.2.tar.gz
--2017-10-19 14:22:31-- https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.2.tar.gz
Resolving artifacts.elastic.co... 54.235.82.130, 184.72.218.26, 23.21.118.61, ...
Connecting to artifacts.elastic.co|54.235.82.130|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 33485703 (32M) [application/x-gzip]
Saving to: “elasticsearch-5.5.2.tar.gzâ€
100%[======================================>] 33,485,703 445K/s in 74s
2017-10-19 14:23:46 (440 KB/s) - “elasticsearch-5.5.2.tar.gz†saved [33485703/33485703]
[root@localhost soft]# sha1sum elasticsearch-5.5.2.tar.gz
91b3b3c823fafce54609ed5c9075d9cf50b2edff elasticsearch-5.5.2.tar.gz
[root@localhost soft]# tar xf elasticsearch-5.5.2.tar.gz
[root@localhost soft]# ll
total 32708
drwxr-xr-x. 7 root root 4096 Aug 14 05:35 elasticsearch-5.5.2
-rw-r--r--. 1 root root 33485703 Aug 17 07:42 elasticsearch-5.5.2.tar.gz
[root@localhost soft]# mkdir /usr/local/elasticsearch-5.5.2
[root@localhost soft]# mv elasticsearch-5.5.2/* /usr/local/elasticsearch-5.5.2
[root@localhost soft]# chown -R elasticsearch /usr/local/elasticsearch-5.5.2
[root@localhost soft]# cd /usr/local/elasticsearch-5.5.2
[root@localhost elasticsearch-5.5.2]# ll
total 236
drwxr-xr-x. 2 elasticsearch root 4096 Oct 19 14:25 bin
drwxr-xr-x. 2 elasticsearch root 4096 Aug 14 05:35 config
drwxr-xr-x. 2 elasticsearch root 4096 Aug 14 05:35 lib
-rw-r--r--. 1 elasticsearch root 11358 Aug 14 05:30 LICENSE.txt
drwxr-xr-x. 13 elasticsearch root 4096 Aug 14 05:35 modules
-rw-r--r--. 1 elasticsearch root 194187 Aug 14 05:35 NOTICE.txt
drwxr-xr-x. 2 elasticsearch root 4096 Aug 14 05:35 plugins
-rw-r--r--. 1 elasticsearch root 9549 Aug 14 05:30 README.textile
[root@localhost elasticsearch-5.5.2]# cd ..
[root@localhost local]# chmod -R 777 elasticsearch-5.5.2
[root@localhost local]# ll
total 44
drwxr-xr-x. 2 root root 4096 Sep 23 2011 bin
drwxrwxrwx. 7 elasticsearch root 4096 Oct 19 14:26 elasticsearch-5.5.2
drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 games
drwxr-xr-x. 2 root root 4096 Sep 23 2011 include
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64
drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec
drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin
drwxr-xr-x. 5 root root 4096 Sep 22 00:45 share
drwxr-xr-x. 2 root root 4096 Sep 23 2011 src
[root@localhost local]# cd elasticsearch-5.5.2/
[root@localhost elasticsearch-5.5.2]# ll
total 236
drwxrwxrwx. 2 elasticsearch root 4096 Oct 19 14:25 bin
drwxrwxrwx. 2 elasticsearch root 4096 Aug 14 05:35 config
drwxrwxrwx. 2 elasticsearch root 4096 Aug 14 05:35 lib
-rwxrwxrwx. 1 elasticsearch root 11358 Aug 14 05:30 LICENSE.txt
drwxrwxrwx. 13 elasticsearch root 4096 Aug 14 05:35 modules
-rwxrwxrwx. 1 elasticsearch root 194187 Aug 14 05:35 NOTICE.txt
drwxrwxrwx. 2 elasticsearch root 4096 Aug 14 05:35 plugins
-rwxrwxrwx. 1 elasticsearch root 9549 Aug 14 05:30 README.textile
elasticsearch5.5版本默认是需要分配2G内存,否则启动时会报错,类似如下:
INFO: os::commit_memory(0x00000000ea660000, 362414080, 0) failed; error='Cannot allocate memory' (errno=12)
如果你的内存不够,打开并编辑/usr/local/elasticsearch-5.5.2/config/jvm.options文件,将文件开始位置的配置修改,则可以解决,例如我将2G的默认配置修改称为512M,只需要删除或者使用#注释掉原来配置再添加自己的配置项即可,类似如下:
# 注释掉的原来的2G配置
#-Xms2g
#-Xmx2g
# 修改称为512M内存大小
-Xms512m
-Xmx512m
[root@localhost elasticsearch-5.5.2]# su elasticsearch
[elasticsearch@localhost elasticsearch-5.5.2]$ who -m
elasticsearch pts/0 2017-10-19 14:16 (192.168.174.1)
确保当前用户为elasticsearch后,编辑~/.bash_profile文件,在export $PATH之前加入如下行,保存退出即可:
export PATH=/usr/local/elasticsearch-5.5.2/bin:$PATH
[elasticsearch@localhost elasticsearch-5.5.2]$ source ~/.bash_profile
[elasticsearch@localhost elasticsearch-5.5.2]$ elasticsearch
新开一个登录窗口,任何用户登录都行,这里需要使用到curl,如果没有,以centos为例自行yum安装即可,确保没问题后,最终执行如下命令:
[elasticsearch@localhost ~]$ curl http://localhost:9200
{
"name" : "JiJUcOE",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "4gwlK6HLSs68pZI6uXv6bg",
"version" : {
"number" : "5.5.2",
"build_hash" : "b2f0c09",
"build_date" : "2017-08-14T12:33:14.154Z",
"build_snapshot" : false,
"lucene_version" : "6.6.0"
},
"tagline" : "You Know, for Search"
}