Elasticsearch两种安装方式

in Tutorials with 1 comment

介绍两种安装Elasticsearch的方法

源码安装

大概步骤:

  1. 安装JAVA SDK

  2. 配置Elasticsearch源

  3. 安装Elasticsearch

  4. 调整配置,启动

配置JAVA

1、下载 JAVA SDK

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz

tar -zxvf jdk-8u*-linux-x64.tar.gz

mv jdk1.8.*/ /usr/

2、安装JAVA SDK 8

/usr/sbin/alternatives --install /usr/bin/java java /usr/jdk1.8.*/bin/java 2

/usr/sbin/alternatives --config java

选择刚刚安装的版本

TThere are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64/jre/bin/java)
   2           /usr/jdk1.8.0_131/bin/java

Enter to keep the current selection[+], or type selection number: 2

3、验证是否安装情况

# java –version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

4、配置环境变量

将下面三条放到你的bash/zsh等配置中, “/etc/profile” (All Users) or “~/.bash_profile ” (Single User)

export JAVA_HOME=/usr/jdk1.8.0_*
export JRE_HOME=/usr/jdk1.8.0_*/jre/
export PATH=$JAVA_HOME/bin:$PATH

配置Elasticsearch源

1、安装公共数字签名密钥

### Debian 9 / Ubuntu 16.04 & Linux Mint 18 ###

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

### RHEL 7 / CentOS 7 ###

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

2、添加和使用Elasticsearch的源码仓

### Debian 9 / Ubuntu 16.04 & Linux Mint 18 ###

echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elk.list

### RHEL 7 / CentOS 7 ###

cat <<EOF >> /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-5.x]
name=Elasticsearch repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF

安装Elasticsearch

### Debian 9 / Ubuntu 16.04 & Linux Mint 18 ###

sudo apt-get update 
sudo apt-get install -y elasticsearch

### RHEL 7 / CentOS 7 ###

yum -y install elasticsearch

1、设置Elasticsearch开机启动

### Debian 9 / Ubuntu 16.04 & Linux Mint 18 ###

sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch

### RHEL 7 / CentOS 7 ###

systemctl daemon-reload
systemctl enable elasticsearch
systemctl start elasticsearch
systemctl stop elasticsearch

2、配置Elasticsearch

编辑elasticsearch.yml 文件

vi /etc/elasticsearch/elasticsearch.yml

去掉相关注释,并修改相关值

cluster.name: your_cluster_name 
node.name: "Your Node Name"
network.bind_host: localhost
network.publish_host: 0.0.0.0
network.host: 0.0.0.0

3、修改内存大小

vim /etc/elasticsearch/jvm.options

找到 Xms2g/Xmx2g

根据服务器的情况自行修改为,我这台测试服务器内存2G,这里就修改为Xms200m/Xmx200m

4、重启Elasticsearch

service elasticsearch restart

5、测试是否安装成功

service elasticsearch status
curl -X GET 'http://localhost:9200'

返回下面类似的信息即为成功

{
  "name" : "gf5QYAn",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "S6gZNkMERpSr-MGXqEFUJw",
  "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"
}

docker安装

确保已经安装好docker,这里就不介绍怎么安装docker了

这里的安装不但有Elasticsearch 还有Kibana

1、创建一个docker目录,然后新建一个docker-compose.yaml文件

输入以下内容:

version: '3'
services:
  elasticsearch:
    image: elasticsearch:5.6.4
    environment: ['http.host=0.0.0.0', 'transport.host=127.0.0.1']
    ports: ['9200:9200']
    networks: ['elastic_net']
    volumes:
      - elastic_data:/usr/share/elasticsearch/data

  kibana:
    image: kibana:5.6.4
    ports: ['5601:5601']
    networks: ['elastic_net']
    depends_on: ['elasticsearch']

networks: {elastic_net: {}}

volumes:
    elastic_data:

2、在终端进入该目录,输入docker-compose build,等待下载和构建镜像完成

3、再输入docker-compose up -d在后台挂起运行

4、然后浏览器打开http://localhost:9200,输出一堆详情信息即代表安装成功了

5、再打开http://localhost:5601,即可进入kibana可视化操作界面了

至此,两种安装方式介绍完毕,但我更推荐用docker方式去安装,也方便集群~

这里推荐 https://github.com/deviantony/docker-elk 这个去做ELK

内容不多,大概就这样吧

Responses
  1. This theme is so cool~尼玛,评论还必须使用中文?

    Reply