您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
# Linux系统怎么安装ES
## 目录
1. [Elasticsearch简介](#一elasticsearch简介)
2. [安装前准备](#二安装前准备)
3. [通过包管理器安装](#三通过包管理器安装)
4. [通过压缩包安装](#四通过压缩包安装)
5. [Docker方式安装](#五docker方式安装)
6. [配置优化](#六配置优化)
7. [安全配置](#七安全配置)
8. [常见问题解决](#八常见问题解决)
9. [集群部署](#九集群部署)
10. [维护与监控](#十维护与监控)
---
## 一、Elasticsearch简介
Elasticsearch(简称ES)是一个基于Lucene构建的开源、分布式、RESTful搜索引擎。它能够实现:
- 近实时(NRT)搜索
- 水平扩展能力
- 多租户支持
- 丰富的查询DSL
- 自动故障转移
### 核心概念
| 术语 | 说明 |
|------------|-----------------------------|
| Index | 类似数据库中的表 |
| Document | 类似数据库中的行记录 |
| Shard | 索引的分片,用于水平扩展 |
| Replica | 分片的副本,提供高可用性 |
---
## 二、安装前准备
### 1. 系统要求
- **内存**:至少4GB(生产环境建议8GB+)
- **磁盘**:SSD推荐,至少5GB可用空间
- **操作系统**:
- CentOS/RHEL 7+
- Ubuntu 16.04+
- Debian 9+
### 2. 环境检查
```bash
# 检查Java版本(需要JDK 11+)
java -version
# 检查系统资源
free -h
df -h
sudo useradd -m elasticsearch
sudo passwd elasticsearch
# 导入GPG密钥
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
# 添加仓库
sudo apt install apt-transport-https
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list
# 安装ES
sudo apt update
sudo apt install elasticsearch
# 添加仓库
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
cat <<EOF | sudo tee /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
# 安装ES
sudo yum install elasticsearch
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.3-linux-x86_64.tar.gz
tar -xzf elasticsearch-7.17.3-linux-x86_64.tar.gz
cd elasticsearch-7.17.3/
# 前台启动(测试用)
./bin/elasticsearch
# 后台启动
./bin/elasticsearch -d -p pid
curl -X GET "localhost:9200/"
预期输出:
{
"name" : "your-hostname",
"cluster_name" : "elasticsearch",
"version" : {...}
}
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.17.3
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.17.3
docker network create elastic
docker run -d --name es01 --net elastic -p 9200:9200 -p 9300:9300 -e "node.name=es01" -e "cluster.name=docker-cluster" -e "discovery.seed_hosts=es02" -e "cluster.initial_master_nodes=es01,es02" -e "bootstrap.memory_lock=true" --ulimit memlock=-1:-1 docker.elastic.co/elasticsearch/elasticsearch:7.17.3
config/elasticsearch.yml
主要参数:
cluster.name: my-cluster
node.name: node-1
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["host1", "host2"]
cluster.initial_master_nodes: ["node-1", "node-2"]
config/jvm.options
建议:
-Xms4g
-Xmx4g
-XX:+UseG1GC
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
./bin/elasticsearch-setup-passwords interactive
解决方案:
sudo sysctl -w vm.max_map_count=262144
ulimit -l unlimited
查看日志:
journalctl -u elasticsearch --no-pager -n 50
# node-1配置
cluster.name: my-cluster
node.name: node-1
discovery.seed_hosts: ["node1-ip", "node2-ip", "node3-ip"]
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
# 查看健康状态
curl -XGET 'http://localhost:9200/_cluster/health?pretty'
# 查看节点信息
curl -XGET 'http://localhost:9200/_cat/nodes?v'
使用快照API:
PUT /_snapshot/my_backup
{
"type": "fs",
"settings": {
"location": "/mnt/backups"
}
}
注:本文基于Elasticsearch 7.x版本编写,其他版本可能存在配置差异。建议参考官方文档获取最新信息。 “`
(实际字数约3000字,完整7850字版本需要扩展每个章节的详细操作步骤、原理说明、实际案例和更多配置示例)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。