我这里安装的是ElasticSearch2.x系列。ElasticSearch官方文档 1.检查系统是否已经安装了jdk
1 yum list installed |grep java
若有自带安装的JDK,如何卸载CentOS系统自带Java环境?
1 2 卸载JDK相关文件输入:yum -y remove java-1.7.0-openjdk* 卸载tzdata-java输入:yum -y remove tzdata-java.noarch
注 :“*”表示卸载掉java 1.7.0的所有openjdk相关文件 2.查看yum库中的Java安装包
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 yum -y list java* [root@iZwz99xkrnh5xy0cqp8aofZ ~] Loaded plugins: security Installed Packages java-1.8.0-openjdk.x86_64 1:1.8.0.151-1.b12.el6_9 @updates java-1.8.0-openjdk-debug.x86_64 1:1.8.0.151-1.b12.el6_9 @updates java-1.8.0-openjdk-demo.x86_64 1:1.8.0.151-1.b12.el6_9 @updates java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.151-1.b12.el6_9 @updates java-1.8.0-openjdk-devel.x86_64 1:1.8.0.151-1.b12.el6_9 @updates java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.151-1.b12.el6_9 @updates java-1.8.0-openjdk-headless.x86_64 1:1.8.0.151-1.b12.el6_9 @updates java-1.8.0-openjdk-headless-debug.x86_64 1:1.8.0.151-1.b12.el6_9 @updates java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.151-1.b12.el6_9 @updates java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.151-1.b12.el6_9 @updates java-1.8.0-openjdk-src.x86_64 1:1.8.0.151-1.b12.el6_9 @updates java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.151-1.b12.el6_9 @updates Available Packages java-1.5.0-gcj.x86_64 1.5.0.0-29.1.el6 base java-1.5.0-gcj-devel.x86_64 1.5.0.0-29.1.el6 base java-1.5.0-gcj-javadoc.x86_64 1.5.0.0-29.1.el6 base java-1.5.0-gcj-src.x86_64 1.5.0.0-29.1.el6 base java-1.6.0-openjdk.x86_64 1:1.6.0.41-1.13.13.1.el6_8 base java-1.6.0-openjdk-demo.x86_64 1:1.6.0.41-1.13.13.1.el6_8 base java-1.6.0-openjdk-devel.x86_64 1:1.6.0.41-1.13.13.1.el6_8 base java-1.6.0-openjdk-javadoc.x86_64 1:1.6.0.41-1.13.13.1.el6_8 base java-1.6.0-openjdk-src.x86_64 1:1.6.0.41-1.13.13.1.el6_8 base java-1.7.0-openjdk.x86_64 1:1.7.0.161-2.6.12.0.el6_9 updates java-1.7.0-openjdk-demo.x86_64 1:1.7.0.161-2.6.12.0.el6_9 updates java-1.7.0-openjdk-devel.x86_64 1:1.7.0.161-2.6.12.0.el6_9 updates java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.161-2.6.12.0.el6_9 updates java-1.7.0-openjdk-src.x86_64 1:1.7.0.161-2.6.12.0.el6_9 updates java-clearsilver.i686 0.10.5-16.el6 epel java-dirq.noarch 1.4-1.el6 epel java-dirq-javadoc.noarch 1.4-1.el6 epel java-service-wrapper.x86_64 3.2.5-23.el6 epel java-service-wrapper-javadoc.noarch 3.2.5-23.el6 epel java-sleep.noarch 2.1-6.el6 epel java-sleep-javadoc.noarch 2.1-6.el6 epel java_cup.x86_64 1:0.10k-5.el6 base java_cup-javadoc.x86_64 1:0.10k-5.el6 base java_cup-manual.x86_64 1:0.10k-5.el6 base javacc.x86_64 4.1-0.5.el6 base javacc-demo.x86_64 4.1-0.5.el6 base javacc-manual.x86_64 4.1-0.5.el6 base javassist.noarch 3.9.0-6.el6 base javassist-javadoc.noarch 3.9.0-6.el6 base javastroke.x86_64 0.5.1-33.el6 epel javatar.noarch 2.5-5.el6 epel javatar-javadoc.noarch
以yum库中的java-1.8为例,将java-1.8.0的所有相关Java程序都安装上。
1 yum -y install java-1.8.0-openjdk*
3.查看刚安装的Java版本信息
1 2 3 4 5 java -version 可查看Java版本 [root@iZwz99xkrnh5xy0cqp8aofZ ~] openjdk version "1.8.0_151" OpenJDK Runtime Environment (build 1.8.0_151-b12) OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
4.通过rpm安装ElasticSearch
1 2 3 4 5 6 7 8 9 先下载并安装公共签名密钥 rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch 再安装rpm的repository [elasticsearch-2.x] name=Elasticsearch repository for 2.x packages baseurl=https://packages.elastic.co/elasticsearch/2.x/centos gpgcheck=1 gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch enabled=1
安装ElasticSearch
1 2 3 4 5 6 7 8 9 10 11 12 13 sudo yum install elasticsearch sudo dnf install elasticsearch sudo zypper install elasticsearch 使用yum在CentOS和旧的基于Red Hat分发 使用dnf的Fedora和其他新的Red Hat分发 使用zypper基于分布的OpenSUSE 如果你嫌麻烦可以之前使用下面的方法安装: wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.4.2/elasticsearch-2.4.2.rpm sha1sum elasticsearch-5.6.5.rpm sudo rpm --install elasticsearch-5.6.5.rpm
5.使用chkconfig命令将Elasticsearch配置为在系统启动时自动启动
1 2 3 4 5 6 sudo chkconfig --add elasticsearch 下面的命令启动或者关闭elasticsearch服务 sudo -i service elasticsearch start sudo -i service elasticsearch stop
6.启动elasticsearch服务报错
1 2 3 4 5 6 7 8 9 [root@iZwz99xkrnh5xy0cqp8aofZ src] Starting elasticsearch: OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12) [FAILED]
这是因为机器的内存不足,可用内存少于1G,解决方法如下:
1 2 3 4 5 6 7 vim /etc/elasticsearch/jvm.options -Xms4g -Xmx4g
7.配置外网可用访问
1 2 3 修改配置文件 vim/etc/elasticsearch/elasticsearch.yml 修改成:network.host: 0.0.0.0
至此,elasticsearch的基本配置完成!