Linux安装Elasticsearch服务

15 篇文章 2 订阅

操作系统版本:CentOS 7 64位

Elasticsearch 版本: 6.4.2

JDK 版本:open JDK 8

java环境已经配置好了。 如何配置java环境?请您看这篇博文

1.下载安装包

登录官方网站,下载链接: https://www.elastic.co/cn/downloads/past-releases#elasticsearch ,本实例中,使用的版本是elasticsearch 6.4.2 ,如图:

2.安装elasticsearch

解压文件到 /usr/local/ ,并使用vim修改config文件夹下elasticsearch.yml文件,操作步骤如下所示

#  编辑elasticsearch配置文件
[root@localhost config]#  vim  /usr/local/elasticsearch-6.4.2/config/elasticsearch.yml

# 修改位置约为 33行和37行,放开注释,配置data和log日志路径
path.data: /usr/local/elasticsearch-6.4.2/data
path.logs: /usr/local/elasticsearch-6.4.2/logs

# 修改位置约为55行和59行,放开注释,配置网络和端口
network.host: 0.0.0.0
http.port: 9200
修改完成后,保存退出vim
# 修改用户权限
[root@localhost ~]# visudo
在配置文件约100行,在“root ALL=(ALL) ALL”配置下方新增一行配置:

elasticsearch  ALL=(ALL)  ALL
保存并退出

3.修改启动问题

由于elasticsearch的策略问题,不允许超级用户root启动,此处需要解决的是elasticsearch使用普通用户启动的配置更改:如下所示

# 创建一个普通用户elasticsearch ,用户组指向aoto用户组,家目录指向aoto家目录(aoto用户是安装操作系统时创建的一个普通用户)
[root@localhost ~]# useradd elasticsearch 
# 重置用户密码(需要连续输入两次,本实例使用的是aoto@123)
[root@localhost ~]# passwd elasticsearch
# 修改文件权限
[root@localhost ~]# chown  -R  elasticsearch  /usr/local/elasticsearch-6.4.2

4.解决启动报错

此时,切换到elasticsearch启动依然会报错,报错信息如图所示:

首先解决报错1]“max file descritor [4096] for ...”,配置linux系统线程和文件参数

# 打开配置文件
[root@localhost ~]# vim  /etc/security/limits.conf

# 在 #End of file 之前 加入以下配置

* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
保存并退出

解决第二个错误2] “max virtual memory areas ...”,配置系统允许的软件允许内存

# 打开配置文件
[root@localhost ~]# vi  /etc/sysctl.conf
# 在文件末尾添加以下配置项
vm.max_map_count = 655360
fs.file-max=655360
保存并退出
[root@localhost ~]# sysctl  -p   # 加载参数
# 切换到elasticsearch用户
[root@localhost ~]#  su elasticsearch
# 启动elasticsearch服务(后台启动,后面加参数 -d)
[root@localhost ~]#   /usr/local/elasticsearch-6.4.2/bin/elasticsearch 

启动后,显示“publish_address {192.168.1.105:9200}”,如图所示

5.使用本地curl指令校验

重新打开一个terminal窗口,键入curl 127.0.0.1:9200,查看输出信息,如下所示:

[root@localhost ~]# curl 127.0.0.1:9200
{
  "name" : "whLftvS",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "66ZoA9keQC6kEG4whr8yyg",
  "version" : {
    "number" : "6.4.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "04711c2",
    "build_date" : "2018-09-26T13:34:09.098244Z",
    "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"
}

显示上述信息,表示elasticsearch已经部署到本地,本地访问成功,接下来需要配置远程访问。

6.配置远程访问

elasticsearch之所以无法进行远程访问,是因为9200端口被防火墙规则阻挡,此时有两种选择,关闭防火墙或添加端口访问防火墙规则,推荐使用后者,因为实际的生产环境中,出于安全考虑,不允许粗鲁的直接关闭防火墙。

# 简单介绍一下防火墙关闭方法,不推荐使用
[root@localhost ~]# systemctl  status  firewalld   # 查看防火墙状态
#如果上一步输出的信息中含有绿色字体Active: active (running),则需要关闭防火墙
[root@localhost ~]# systemctl  stop  firewalld.service   # 关闭防火墙
[root@localhost ~]# systemctl  disable  firewalld.service   # 禁止防火墙开机自启动

#第二种,添加防火墙规则,推荐使用
# 添加9200端口访问规则
[root@localhost ~]# firewall-cmd --zone=public --add-port=9200/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload  # 重新加载防火墙规则
success

此时,在其他设备上访问http://serverip:9200,即可得到配置信息,如图所示

至此,elasticsearch服务安装与环境访问配置完成

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值