ElasticSearch8.2.3 + CentOs 7 安装

注: ES 不能使用 root 用户来启动,必须使用 普通用户来安装启动。

1、 创建一个es 专用的用户

复制代码
# 先创建组, 在创建用户
#1、 创建 elasticsearch 用户组
groupadd elasticsearch

#2、 创建用户 elastic 
useradd elastic

#3、 设置密码
passwd elastic
123456(自定)

#4、创建es 文件夹
mkdir -p /usr/local/es

#5、用户es 添加到elasticsearch 用户组
usermod -G elasticsearch elastic

#6、 设置 sudo 权限
visudo
# 在 root ALL=(ALL) ALL 一行下面添加如下:
elastic ALL=(ALL) ALL

#7、 在 es 文件夹下载压缩包
cd /usr/local/es/
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.2.3-linux-x86_64.tar.gz

#8、 解压文件
tar -zxvf elasticsearch-8.2.3-linux-x86_64.tar.gz

#9、 修改文件夹 owner
chown -R elastic /usr/local/es/elasticsearch-8.2.3
复制代码

2、修改es配置文件

  切换到 elastic 用户

  2.1 修改 elasticsearch.yml 文件

复制代码
#1、 进入配置文件路径
cd /usr/local/es/elasticsearch-8.2.3/config

#2、创建 日志 和 数据目录
mkdir -p /usr/local/es/elasticsearch-8.2.3/log
mkdir -p /usr/local/es/elasticsearch-8.2.3/data

#3、 修改配置文件
vim elasticsearch.yml

cluster.name: douger-es
node.name: node-1
path.data: /usr/local/es/elasticsearch-8.2.3/data
path.log: /usr/local/es/elasticsearch-8.2.3/log
network.host: 0.0.0.0 
http.port:9200
bootstrap.memory_lock:true
discovery.seed_hosts:["192.168.1.103"] #服务器IP
cluster.initial_master_nodes: ["node-1"] #节点名
 
复制代码

  2.2 修改 jvm.options

  修改 jvm.options 配置文件,调整jvm 堆内存大小,jvm 比较吃内存  

vim jvm.options

-Xms2g
-Xmx2g

3、 启动es, 常见错误如下, 需修改部分配置

  3.1、错误描述:

    max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
  ES 因为需要大量的创建索引文件,需要大量的打开系统的文件,所以我们需要解除 linux 系统当中打开文件最大数目的限制, 否则会抛上述错误
sudo vim /etc/security/limits.conf

# 添加如下内容

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

  3.2、 错误描述

    max virtual memory areas vm.max_map_count [65530] likely too low,increase to at least [262144]
  调大系统虚拟内存, 原因: 虚拟内存太小
vim /etc/sysctl.conf

# 追加以下内容 
vm.max_map_count=262144

  保存后, 执行  sysctl -p 生效。

  3.3、 错误描述

     memory locking requested for elasticsearch process but memory is not locked   

sudo vim /ect/security/limits.conf

# 添加如下内容
* soft memlock unlimited
* hard memlock unlimited

  3.4、 错误描述,此错误未遇到,先做记录

    max number of threads [1024] for user [es] likely too low, increase to at least [4096]

    修改普通用户可以创建的最大线程数, 原因: 无法创建本地线程问题,用户最大可创建线程数太小。

  修改 nproc.conf 配置文件

复制代码
#CentOS 6
sudo vim /etc/security/limits.d/90-nproc.conf

#CentOS 7
sudo vim /etc/security/limits.d/20-nproc.conf

#找到如下内容 
* soft nproc 1024 修改为 
* soft nproc 4096
复制代码

问题解决后,重新链接 xshell 生效

   3.5、 错误描述, 启动后, 访问 http://xxxx.9200/?pretty 后台日志如下

    received plaintext http traffic on an https channel, closing connection Netty4HttpChannel{localAddress=/192.168.1.103:9200, remoteAddress=/192.168.1.124:51561}

  原因是Elasticsearch在Windows下开启了安全认证,虽然started成功,但访问http://localhost:9200/失败

  找到config/目录下面的elasticsearch.yml配置文件,把安全认证开关从原先的true都改成false,实现免密登录访问即可,修改这两处都为false后:

复制代码
# Enable security features
xpack.security.enabled: false

xpack.security.enrollment.enabled: true

# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
  enabled: false
  keystore.path: certs/http.p12

# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
  enabled: true
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12
复制代码

 

启动成功后, 可以 通过 请求 http://xxxx.9200/?pretty 看到浏览器信息 如下

复制代码
{
  "name" : "node-1",
  "cluster_name" : "leapstack-es",
  "cluster_uuid" : "XpgEC3DuRKyk09f5_og7hA",
  "version" : {
    "number" : "8.2.3",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "9905bfb62a3f0b044948376b4f607f70a8a151b4",
    "build_date" : "2022-06-08T22:21:36.455508792Z",
    "build_snapshot" : false,
    "lucene_version" : "9.1.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}
复制代码

 

注: 如果是启动集群, 在每启动一个 节点后, 进入对应的 data 目录下删除 nodes 文件,再进行启动

# 查看集群状态
GET   _cat/nodes?v
GET   _cat/health?v
posted @   长弓射大狗  阅读(877)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 三行代码完成国际化适配,妙~啊~
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
点击右上角即可分享
微信分享提示