Linux安装elasticsearch

本文详细介绍了在CentOS上从下载、解压到配置及启动Elasticsearch的全过程,包括解决启动异常的方法和用户组权限配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

.首先到官网下载最新版本的ElasticSearch的zip压缩包,也可以复制下载地址在终端中使用wget命令直接下载到CentOS中。例如在终端中执行以下命令:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.tar.gz

下载过程可能比较慢,可以使用自己电脑下载后使用ftp工具上传到/soft目录。

2.下载完成后,解压elasticsearch-6.0.0.tar.gz

tar -vxf elasticsearch-6.0.0.tar.gz

解压完成后内容如下

[king@localhost soft]$ ls
elasticsearch-6.0.0  elasticsearch-6.0.0.tar.gz

3.进入elasticsearch-5.5.2,并启动elasticsearch

[king@localhost soft]$ cd elasticsearch-6.0.0
[king@localhost elasticsearch-6.0.0]$ sh ./bin/elasticsearch
## 会有一堆日志输出,还报了一个异常java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ ...不过这个异常不影响启动,是因为我们的内核版本太低了,新版本系统应该没这个问题。

4.让启动不提示这个异常可以在config/elasticsearch.yml添加如下两行内容,其中:号后面要加上一个空格,因为这是yaml文件的格式要求,yaml是一种新的属性文件的写法,更简洁,不懂的可以自行查查。

bootstrap.memory_lock: false
bootstrap.system_call_filter: false

5.添加用户组(因为elasticsearch不能用root用户启动)

1)创建 elasticsearch 用户组

1

[root@localhost ~]# groupadd elasticsearch

2) 创建用户 es 并设置密码为es

1

2

[root@localhost ~]# useradd es

[root@localhost ~]# passwd es

3 )用户es 添加到 elasticsearch 用户组

1

[root@localhost ~]# usermod -G elasticsearch es

6..这时重新启动,不会提示任何错误了。新打开一个窗口,输入curl localhost:9200,如果有以下输出则说明启动成功。

[king@localhost ~]$ curl localhost:9200
{
  "name" : "ZGws7ZX",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "yeYDTLbNQ--rmDXMi2xO-g",
  "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"
}

 

<think>我们正在安装Elasticsearch,根据引用[1]和引用[4],我们可以使用包管理工具安装。注意,引用[1]提到了导入GPG密钥,引用[4]提到了配置yum仓库。由于用户没有指定Linux发行,我们将分别提供基于Debian/Ubuntu和基于RHEL/CentOS的安装方法。 步骤: 1. 导入Elasticsearch的GPG密钥(用于验证软件包) 2. 添加Elasticsearch仓库 3. 安装Elasticsearch 4. 启动并设置开机自启 注意:根据引用[4],Elasticsearch有开源本(OSS),我们这里使用官方仓库。 对于Debian/Ubuntu系统(参考引用[1]): - 导入GPG密钥:`wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -` - 添加仓库:`echo "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list` - 更新并安装:`sudo apt update && sudo apt install elasticsearch-oss` 对于RHEL/CentOS系统(参考引用[4]): - 创建仓库文件:`/etc/yum.repos.d/elasticsearch.repo`,内容如下: [elasticsearch-7.x] name=Elasticsearch repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/oss-7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md - 安装:`sudo yum install elasticsearch-oss` 注意:以上安装的是开源本(不带商业功能)。如果需要默认的本(包含商业功能,但需要遵守许可),可以去掉`-oss`,但注意许可证问题。 5. 配置Elasticsearch:编辑配置文件`/etc/elasticsearch/elasticsearch.yml`,主要设置集群名称、节点名称、网络绑定等。 6. 启动服务:`sudo systemctl start elasticsearch` 并设置开机自启:`sudo systemctl enable elasticsearch` 另外,引用[3]提到了一些生产环境的注意事项,例如数据存储和日志记录,在安装后需要根据实际情况调整。 现在,根据用户要求,我们生成相关问题。</think>### 在Linux系统上安装Elasticsearch的步骤 #### 1. **导入GPG密钥(安全验证)** ```bash wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - ``` > 此命令下载Elasticsearch的公钥并添加到APT信任列表中,确保软件包来源可信[^1]。 --- #### 2. **添加Elasticsearch仓库** - **Debian/Ubuntu系统**: ```bash echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list ``` - **RHEL/CentOS系统**: 创建仓库文件 `/etc/yum.repos.d/elasticsearch.repo` 并写入: ```ini [elasticsearch-7.x] name=Elasticsearch repository baseurl=https://artifacts.elastic.co/packages/oss-7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 ``` > 仓库配置指定了软件包下载源和验证方式[^4]。 --- #### 3. **安装Elasticsearch** - **APT系统(Debian/Ubuntu)**: ```bash sudo apt update && sudo apt install elasticsearch ``` - **YUM系统(RHEL/CentOS)**: ```bash sudo yum install elasticsearch-oss # 安装开源本 ``` --- #### 4. **配置与启动服务** 1. **编辑配置文件**: ```bash sudo nano /etc/elasticsearch/elasticsearch.yml ``` 关键配置项: ```yaml cluster.name: my-cluster # 集群名称 node.name: node-1 # 节点名称 network.host: 0.0.0.0 # 允许远程访问(生产环境需设具体IP) discovery.type: single-node # 单节点模式 ``` 2. **启动并设置开机自启**: ```bash sudo systemctl daemon-reload sudo systemctl enable elasticsearch sudo systemctl start elasticsearch ``` --- #### 5. **验证安装** ```bash curl -X GET "localhost:9200" ``` 成功响应示例: ```json { "name" : "node-1", "cluster_name" : "my-cluster", "version" : { ... } } ``` --- ### 关键注意事项 1. **存储配置**: - 默认数据目录:`/var/lib/elasticsearch` - 生产环境需挂载独立存储卷,避免使用Docker默认存储驱动(性能差)[^3] 2. **日志管理**: - 日志路径:`/var/log/elasticsearch` - 建议使用专用日志驱动(如`journald`),避免`json-file`默认驱动[^3] 3. **防火墙规则**: ```bash sudo ufw allow 9200/tcp # 开放API端口 sudo ufw allow 9300/tcp # 开放集群通信端口 ``` > **重要提示**:生产环境需额外配置安全组、TLS加密和用户认证。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值