linux 安装elasticSearch

elasticSearch · Fecmall · 于 2年前 发布 · 1472 次阅读

ElasticSearch 是一款优秀的搜索引擎,用java编写,restful接口的方式进行对接。

1.安装ElasticSearch

安装Java环境

首先检测是否安装java

java -version  
echo $JAVA_HOME

如果java的版本过低,建议安装高版本,下面安装的是java 1.8

cd /opt/    
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u66-b17/jdk-8u66-linux-x64.tar.gz"    
tar xzf jdk-8u66-linux-x64.tar.gz

上面的下载,如果失效,您可以在我的百度网盘中下载jdk: https://pan.baidu.com/s/1kVwRD2Z 下载文件:jdk-8u66-linux-x64.tar.gz

cd /opt/jdk1.8.0_66/    
alternatives --install /usr/bin/java java /opt/jdk1.8.0_66/bin/java 2    
alternatives --config java

运行了上面的,会初选一个选择的地方,我的机器显示:

There are 3 programs which provide 'java'.    
    
  Selection    Command    
-----------------------------------------------    
*  1           /opt/jdk1.7.0_71/bin/java    
 + 2           /opt/jdk1.8.0_45/bin/java    
   3           /opt/jdk1.8.0_51/bin/java    
   4           /opt/jdk1.8.0_66/bin/java    
    
Enter to keep the current selection[+], or type selection number: 4

我们安装的是jdk1.8.0.66 所以,我选择的是4,这个看具体情况,jdk1.8.0.66 是第几个,就选择那个数字。

alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_66/bin/jar 2    
alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_66/bin/javac 2    
alternatives --set jar /opt/jdk1.8.0_66/bin/jar    
alternatives --set javac /opt/jdk1.8.0_66/bin/javac

安装完成,检查版本

java -version    
    
java version "1.8.0_66"    
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)    
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

保存到文件 /etc/environment中,当服务器重启的时候加载:

vi /etc/profile  
  
export JAVA_HOME=/opt/jdk1.8.0_66    
export JRE_HOME=/opt/jdk1.8.0_66/jre    
export PATH=$PATH:/opt/jdk1.8.0_66/bin:/opt/jdk1.8.0_66/jre/bin

重启linux: reboot , 查看是否安装成功

java -version  
echo $JAVA_HOME

安装ElasticSearch

cd /tools  
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.3.zip 
unzip elasticsearch-6.1.3.zip 
mv ./elasticsearch-6.1.3 /usr/local/elasticsearch  
cd /usr/local  
groupadd elasticsearch  
useradd -g elasticsearch  elasticsearch  
chown elasticsearch:elasticsearch -R elasticsearch

上面安装的是es6.

1.设置开机启动: 我是本地,直接把iptables 关掉了

vim /etc/rc.d/rc.local  

service iptables stop  
su elasticsearch  -c "/usr/local/elasticsearch/bin/elasticsearch -d"

一定要注意,elasticSearch不能用root账户启动,elasticSearch不能用root账户启动,elasticSearch不能用root账户启动,重要的说三遍,我这里用的是我新建的elasticsearch账户开机启动

报错:

$./bin/elasticsearch
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /data/elasticsearch-5.2.2/hs_err_pid26945.log

解决方案:调小启动内存

# vi /usr/local/elasticsearch/config/jvm.options

#-Xms2g
#-Xmx2g
-Xms256m
-Xmx64m

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms128m
-Xmx128m

上面设置的分配的内存的最大值为256MB和最小值64mb,您可以根据自己的机器情况设置内存大小。

上面的内存一定要修改设置,除非你的机器内存很大,2G的机器,建议按照上面的修改内存大小,否则将启动失败

下面是一个使用默认配置启动失败的log

[root@vultr local]# su elasticsearch  -c "/usr/local/elasticsearch/bin/elasticsearch "
[2018-06-23T05:31:43,284][INFO ][o.e.n.Node               ] [] initializing ...
[2018-06-23T05:31:43,458][INFO ][o.e.e.NodeEnvironment    ] [3NDH7pj] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [30.2gb], net total_space [39.3gb], types [rootfs]
[2018-06-23T05:31:43,458][INFO ][o.e.e.NodeEnvironment    ] [3NDH7pj] heap size [1015.6mb], compressed ordinary object pointers [true]
[2018-06-23T05:31:43,461][INFO ][o.e.n.Node               ] node name [3NDH7pj] derived from node ID [3NDH7pjFRkqGJK-esxelQw]; set [node.name] to override
[2018-06-23T05:31:43,461][INFO ][o.e.n.Node               ] version[6.1.3], pid[1566], build[af51318/2018-01-26T18:22:55.523Z], OS[Linux/3.10.0-862.3.2.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_66/25.66-b17]
[2018-06-23T05:31:43,461][INFO ][o.e.n.Node               ] JVM arguments [-Xms256m, -Xmx64m, -Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/usr/local/elasticsearch, -Des.path.conf=/usr/local/elasticsearch/config]
[2018-06-23T05:31:45,916][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [aggs-matrix-stats]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [analysis-common]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [ingest-common]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [lang-expression]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [lang-mustache]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [lang-painless]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [mapper-extras]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [parent-join]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [percolator]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [reindex]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [repository-url]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [transport-netty4]
[2018-06-23T05:31:45,917][INFO ][o.e.p.PluginsService     ] [3NDH7pj] loaded module [tribe]
[2018-06-23T05:31:45,918][INFO ][o.e.p.PluginsService     ] [3NDH7pj] no plugins loaded
Killed

重新启动即可。

2.配置

vim /usr/local/elasticsearch/config/elasticsearch.yml

修改如下:

cluster.name: TA-application  
node.name: node-210  
network.host: 192.168.0.210

其中cluster.name 是集群名称,这个不要使用默认的,要修改,去掉注释,如果有多个机器,加入同一个集群,那么这个值必须一样

noide.name 是集群里面每个节点的值,也就是当前机器的节点的值,这个值,每个节点要不一样。

network host 改成当前的内网ip

共收到 1 条回复
Fecmall#12个月前 0 个赞

elasticSearch启动后,查看版本curl -XGET localhost:9200

[root@iZ942k2d5ezZ fecbbc]# curl -XGET localhost:9200
{
  "name" : "VRV7sNu",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "QEStHWtpShy4TtgTrMMTfA",
  "version" : {
    "number" : "6.1.3",
    "build_hash" : "af51318",
    "build_date" : "2018-01-26T18:22:55.523Z",
    "build_snapshot" : false,
    "lucene_version" : "7.1.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics