linux下源码安装elasticsearch-5.5.2

来源:互联网 发布:淘宝发空包平台 编辑:程序博客网 时间:2024/05/17 23:52

环境准备

由于elasticsearch由Java实现,所以需要Java环境,请自行百度安装。

创建用户和密码(root用户下)

elasticsticsearch不能用root用户去启动,否则会报错,所以在这里我将会单独创建一个名为elasticsearch的用户,去运行elasticsearch程序,当前用户是root,所以无需切换,直接运行如下命令:
创建密码,这里会有两次密码输入提示,确保一致即可创建完成!

[root@localhost soft]# useradd elasticsearch[root@localhost soft]# passwd elasticsearchChanging password for user elasticsearch.New password: elasticsearchRetype new password: elasticsearchpasswd: all authentication tokens updated successfully.

下载和安装elasticsearch

[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.gzResolving 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 OKLength: 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.gz91b3b3c823fafce54609ed5c9075d9cf50b2edff  elasticsearch-5.5.2.tar.gz[root@localhost soft]# tar xf elasticsearch-5.5.2.tar.gz[root@localhost soft]# lltotal 32708drwxr-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]# lltotal 236drwxr-xr-x.  2 elasticsearch root   4096 Oct 19 14:25 bindrwxr-xr-x.  2 elasticsearch root   4096 Aug 14 05:35 configdrwxr-xr-x.  2 elasticsearch root   4096 Aug 14 05:35 lib-rw-r--r--.  1 elasticsearch root  11358 Aug 14 05:30 LICENSE.txtdrwxr-xr-x. 13 elasticsearch root   4096 Aug 14 05:35 modules-rw-r--r--.  1 elasticsearch root 194187 Aug 14 05:35 NOTICE.txtdrwxr-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]# lltotal 44drwxr-xr-x. 2 root root 4096 Sep 23  2011 bindrwxrwxrwx. 7 elasticsearch  root 4096 Oct 19 14:26 elasticsearch-5.5.2drwxr-xr-x. 2 root root 4096 Sep 23  2011 etcdrwxr-xr-x. 2 root root 4096 Sep 23  2011 gamesdrwxr-xr-x. 2 root root 4096 Sep 23  2011 includedrwxr-xr-x. 2 root root 4096 Sep 23  2011 libdrwxr-xr-x. 2 root root 4096 Sep 23  2011 lib64drwxr-xr-x. 2 root root 4096 Sep 23  2011 libexecdrwxr-xr-x. 2 root root 4096 Sep 23  2011 sbindrwxr-xr-x. 5 root root 4096 Sep 22 00:45 sharedrwxr-xr-x. 2 root root 4096 Sep 23  2011 src[root@localhost local]# cd elasticsearch-5.5.2/[root@localhost elasticsearch-5.5.2]# lltotal 236drwxrwxrwx.  2 elasticsearch root   4096 Oct 19 14:25 bindrwxrwxrwx.  2 elasticsearch root   4096 Aug 14 05:35 configdrwxrwxrwx.  2 elasticsearch root   4096 Aug 14 05:35 lib-rwxrwxrwx.  1 elasticsearch root  11358 Aug 14 05:30 LICENSE.txtdrwxrwxrwx. 13 elasticsearch root   4096 Aug 14 05:35 modules-rwxrwxrwx.  1 elasticsearch root 194187 Aug 14 05:35 NOTICE.txtdrwxrwxrwx.  2 elasticsearch root   4096 Aug 14 05:35 plugins-rwxrwxrwx.  1 elasticsearch root   9549 Aug 14 05:30 README.textile

elasticsearch内存配置

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

登录elasticsearch用户,并将程序目录加入环境变量

[root@localhost elasticsearch-5.5.2]# su elasticsearch[elasticsearch@localhost elasticsearch-5.5.2]$ who -melasticsearch      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

[elasticsearch@localhost elasticsearch-5.5.2]$ elasticsearch

测试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"}
原创粉丝点击