ElasticSearch6.x 安装配置启动

x33g5p2x  于2021-03-14 发布在 ElasticSearch  
字(3.6k)|赞(0)|评价(0)|浏览(364)

安装配置JDK8

Elastic 需要 Java 8 环境。如果你的机器还没安装 Java,必须先安装Java环境。

  1. 下载并解压
[root@node1 ~]# tar -zxvf jdk-8u112-linux-x64.tar.gz -C /opt
  1. 编辑环境变量
    vi /etc/profile.d/custom.sh
[root@cyj ~]# vi /etc/profile.d/custom.sh
[root@cyj ~]# cat /etc/profile.d/custom.sh
#!/bin/bash
#java path
export JAVA_HOME=/opt/jdk1.8.0_112
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib
  1. 生效
[root@cyj ~]# source /etc/profile.d/custom.sh
  1. 查看JDK版本
[root@cyj ~]# java -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

创建用户

从5.0开始,ElasticSearch 安全级别提高了,不允许采用root帐号启动,所以我们要添加一个用户。

  1. 创建elastic 用户组
[root@cyj ~]# groupadd elastic 
  1. 创建用户es
[root@cyj ~]# useradd es
[root@cyj ~]# passwd es
Changing password for user es.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
  1. 将es用户添加到elastic 组
[root@cyj~]# usermod -G bigdata es
  1. 设置sudo权限
[root@cyj~]# visudo

找到root ALL=(ALL) ALL一行,添加es用户,如下。

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
es      ALL=(ALL)       ALL
  1. 切换用户
[root@cyj~]# su es
[es@cyj root]$ cd
[es@cyj~]$ 

ElasticSearch 6.x 软件包下载

  1. ElasticSearch官网
    https://www.elastic.co/cn/downloads
  2. 下载ElasticSearch
    https://www.elastic.co/downloads/elasticsearch
 [es@cyj~]$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.2.tar.gz
  1. 解压缩
[es@cyj~]$ tar -zxvf elasticsearch-6.4.2.tar.gz
  1. 修改目录权限
    更改elasticsearch-6.4.2文件夹以及内部文件的所属用户为es, 用户组组为bigdata,-R表示逐级(N层目录)
[es@cyj~]$ sudo chown -R es:elastic  /elasticsearch-6.4.2
[es@cyj~]$ ll /elasticsearch-6.4.2
total 220
drwxr-xr-x  2 es bigdata   4096 Jan  6 08:35 bin
drwxr-xr-x  2 es bigdata     75 Dec 17 15:24 config
drwxr-xr-x  2 es bigdata   4096 Dec 17 15:24 lib
-rw-r--r--  1 es bigdata  11358 Dec 17 15:22 LICENSE.txt
drwxr-xr-x 15 es bigdata    272 Dec 17 15:24 modules
-rw-r--r--  1 es bigdata 191887 Dec 17 15:24 NOTICE.txt
drwxr-xr-x  2 es bigdata      6 Dec 17 15:24 plugins
-rw-r--r--  1 es bigdata   9326 Dec 17 15:22 README.textile

ElasticSearch 配置

  1. 修改elasticsearch.yml文件
[es@cyj elasticsearch-6.4.2]$ vi config/elasticsearch.yml

修改network.host和http.port(设置ip地址以及端口号)

# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: xxx.xxx.xxx.xxx 
#
# Set a custom port for HTTP:
#
http.port: 9200
  1. 修改/etc/sysctl.conf
    切换到root用户
[root@cyj elasticsearch-6.4.2]# vi /etc/sysctl.conf

添加内容如下:

vm.max_map_count=262144

用命令sysctl -p 生效

[root@cyj ~]# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
vm.max_map_count = 262144
[root@cyj ~]# 
  1. 修改文件/etc/security/limits.conf
[root@cyj logs]# vi /etc/security/limits.conf

添加如下内容:

* hard nofile 65536
* soft nofile 65536

* soft nproc 2048
* hard nproc 4096

# End of file
  1. ElasticSearch启动与停止
    elasticsearch不能直接以root身份启动,必须切换回es用户启动
[es@cyj elasticsearch]$ ./bin/elasticsearch

注:后台启动加 -d

  1. 查询进程
[elsearch@cyj elasticsearch]$ lsof -i:9200
COMMAND  PID     USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
java    2429 elsearch  196u  IPv4 22910313      0t0  TCP 172.16.0.14:wap-wsp (LISTEN)
  1. 验证
[elsearch@cyj elasticsearch]$ curl http://xxxx.xxxx.xxxx.xxx:9200
{
  "name" : "master",
  "cluster_name" : "jiqun",
  "cluster_uuid" : "7b6GqaWyRsS8938Z8F7Exg",
  "version" : {
    "number" : "6.4.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "595516e",
    "build_date" : "2018-08-17T23:18:47.308994Z",
    "build_snapshot" : false,
    "lucene_version" : "7.4.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

相关文章