美文网首页
Linux(Centos7)安装Elasticsearch

Linux(Centos7)安装Elasticsearch

作者: 盼旺 | 来源:发表于2020-08-13 13:52 被阅读0次

练手环境:

jdk环境


版本参考
版本对应很重要 我的是
springboot 2.1.3.RELEASE
es 6.2.2
spring data es 3.1.16.RELEASE

1.下载elasticsearch6.2.2

官网地址https://www.elastic.co/cn/downloads/past-releases#elasticsearch

在/usr/local目录下执行命令
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.2.tar.gz

[root@iZ2zee6a7ou2z7nc3kzgzrZ local]# pwd
/usr/local
[root@iZ2zee6a7ou2z7nc3kzgzrZ local]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.2.tar.gz

2.解压 elasticsearch

先创建目录用来存放elasticsearch
mkdir /usr/local/elasticsearch
然后解压到es目录
tar -xvf elasticsearch-6.2.2.tar.gz -C /usr/local/elasticsearch/

3.修改解压后的目录名称 变为节点名称

cd /usr/local/elasticsearch/
mv elasticsearch-6.2.2 node-wg

4.创建一个专门的用户组来运行elasticsearch(elasticsearch不能用root用户启动)

##创建用户组
groupadd esgroup
##创建用户esuser 指定到esgroup 用户组 并设置用户esuser 的密码为espassword
useradd esuser -g esgroup -p espassword
##给用户esuser 授权可操作的目录
chown -R esuser:esgroup /usr/local/elasticsearch

5.创建elasticsearch 的数据存放目录data 日志存放目录

su esuser 
mkdir /usr/local/elasticsearch/node-wg/data
mkdir /usr/local/elasticsearch/node-wg/logs (已经存在就不建了)

6.修改用户esuser文件最大打开数

系统默认文件句柄65535,但是ElasticSearch要求最低为65536,所以需改为65536

添加语句
esuser soft nofile 65536
esuser hard nofile 65536
esuser soft nproc 4096
esuer hard nproc 4096

另一个文件

vim /etc/security/limits.d/20-nproc.conf
添加语句
esuser soft nproc 4096

修改内核参数设置单进程最多内存映射大小

vim /etc/sysctl.conf
添加语句
vm.max_map_count = 655360

配置生效
sysctl -p

7.启动ES

切换用户
su esuser
进入安装目录启动
cd /usr/local/elasticsearch/node-wg/bin/
./elasticsearch
如果要后台启动 在启动的时候后面加 -d参数即可


启动成功

打开另一个客户端,进行测试连接curl 127.0.0.1:9200,可看到返回一串json串

8.实现远程访问 (我其实不需要这个)

杀死es进程

ps -ef | grep elasticsearch
kill 10691 10675

在esuser用户身份下编辑/usr/local/es/node-wg/config/elasticsearch.yml文件


##集群名称
cluster.name: my-cluster
##节点名称
node.name: node-wg
##网络监听地址
network.host: (私网IP)
http.port: 9200
path.data: /usr/local/elasticsearch/node-wg/data
# Path to log files:
path.logs: /usr/local/elasticsearch/node-wg/logs

##使用head等插件监控集群信息,需要打开以下配置项
#http.cors.enabled: true
#http.cors.allow-origin: "*"
#http.cors.allow-credentials: true

切记 阿里云是私网ip

修改 network.host 后的参数,即安装elasticsearch的机器的ip地址
http.port 可进行修改,也可不进行修改,不修改的话,默认端口就是9200

9.阿里云开放安全组端口9200


再次启动es
http访问

相关文章

网友评论

      本文标题:Linux(Centos7)安装Elasticsearch

      本文链接:https://www.haomeiwen.com/subject/ysepdktx.html