练手环境:
jdk环境
![](https://img.haomeiwen.com/i12058546/ed95131c873b6ab0.png)
版本参考
版本对应很重要 我的是
springboot 2.1.3.RELEASE
es 6.2.2
spring data es 3.1.16.RELEASE
![](https://img.haomeiwen.com/i12058546/b2aa8de49ae5c2b8.png)
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/
![](https://img.haomeiwen.com/i12058546/4669a134d2665d63.png)
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参数即可
![](https://img.haomeiwen.com/i12058546/b6dccbf63ac1d2a5.png)
![](https://img.haomeiwen.com/i12058546/7aa66a9be2d98df3.png)
打开另一个客户端,进行测试连接curl 127.0.0.1:9200
,可看到返回一串json串
![](https://img.haomeiwen.com/i12058546/f792feb85e3cbd04.png)
8.实现远程访问 (我其实不需要这个)
杀死es进程
ps -ef | grep elasticsearch
kill 10691 10675
![](https://img.haomeiwen.com/i12058546/187e897f43bf0aff.png)
在esuser用户身份下编辑/usr/local/es/node-wg/config/elasticsearch.yml
文件
![](https://img.haomeiwen.com/i12058546/9991a4775d4f89ef.png)
##集群名称
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
![](https://img.haomeiwen.com/i12058546/802917ce4a69b97f.png)
再次启动es
http访问
![](https://img.haomeiwen.com/i12058546/653925559c80173c.png)
网友评论