elastic安装过程-Ubuntu

elastic安装过程-Ubuntu

直接下载jdk压缩包方式安装(这里只介绍jdk7的,jdk8 的原理完全一致)

分为下面5个步骤

官网下载JDK

地址: http://www.oracle.com/technetwork/articles/javase/index-jsp-138363.html , 选择相应的 .gz包下载

解压缩,放到指定目录(以jdk-7u60-linux-x64.gz为例)

  1. 创建目录:

    sudo mkdir /usr/lib/jvm

  2. 解压缩到该目录:

    sudo tar -zxvf jdk-7u60-linux-x64.gz -C /usr/lib/jvm

修改环境变量

sudo vim ~/.bashrc

  1. 文件的末尾追加下面内容:

    1
    2
    3
    4
    5
    #set oracle jdk environment
    export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_60 ## 这里要注意目录要换成自己解压的jdk 目录
    export JRE_HOME=${JAVA_HOME}/jre
    export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
    export PATH=${JAVA_HOME}/bin:$PATH
  2. 使环境变量马上生效
    source ~/.bashrc

设置系统默认jdk 版本

1
2
3
4
5
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_60/bin/java 300  
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_60/bin/javac 300
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.7.0_60/bin/jar 300
sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk1.7.0_60/bin/javah 300
sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk1.7.0_60/bin/javap 300

 然后执行:sudo update-alternatives --config java

若是初次安装jdk,会有下面的提示
1
2
There is only one alternative in link group java (providing /usr/bin/java): 
/usr/lib/jvm/jdk1.7.0_60/bin/java
否则,选择合适的jdk

测试jdk

1
2
3
4
5
java -version
#显示如下
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
jdk 安装成功

下载elasticsearch

1
2
3
4
5
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz.sha512
shasum -a 512 -c elasticsearch-6.2.4.tar.gz.sha512
tar -xzf elasticsearch-6.2.4.tar.gz
cd elasticsearch-6.2.4/

启动elasticsearch

1
2
3
4
5
6
# Running Elasticsearch from the command line
./bin/elasticsearch
# Running as a daemon
./bin/elasticsearch -d -p pid
#To shut down Elasticsearch, kill the process ID recorded in the pid file:
kill `cat pid`

安装错误

  • max file descriptors [4096] for elasticsearch process is too low

    解决办法:

    1
    2
    3
    4
    5
    sudo vim /etc/security/limits.conf

    # 在最后面追加下面内容
    *** - nofile 65536
    *** 是启动ES的用户

    Ubuntu ignores the limits.conf file for processes started by init.d. To enable the limits.conf file, edit /etc/pam.d/su and uncomment the following line:

    #session required pam_limits.so

  • max virtual memory areas vm.max_count [65530] likely too low,increase to at least [26244]

    解决办法

    sudo sysctl -w vm.max_map_count=262144

  • 默认情况下,Elastic 只允许本机访问,如果需要远程访问,可以修改 Elastic 安装目录的config/elasticsearch.yml文件,去掉network.host的注释,将它的值改成0.0.0.0,然后重新启动 Elastic。

安装中文分词器

  1. 执行命令

    ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.4/elasticsearch-analysis-ik-6.2.4.zip

  2. 配置IK[仅供v5.0以下版本使用]

    执行以下CURL

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    curl -XPOST 'http://localhost:9200/_all/_close' 
    curl -XPUT 'http://localhost:9200/_all/_settings?preserve_existing=true' -d '{
    "index.analysis.analyzer.default.type" : "ik_max_word",
    "index.analysis.analyzer.ik.alias" : [
    "ik_analyzer"
    ],
    "index.analysis.analyzer.ik.type" : "org.elasticsearch.index.analysis.IkAnalyzerProvider",
    "index.analysis.analyzer.ik_max_word.type" : "ik_max_word",
    "index.analysis.analyzer.ik_max_word.use_smart" : "false",
    "index.analysis.analyzer.ik_smart.type" : "ik_max_word",
    "index.analysis.analyzer.ik_smart.use_smart" : "true"
    }'