1.下载
镜像地址:https://thans.cn/mirror/elasticsearch.html
找自己喜欢的下载,我选择的是7.3.2-linux-x86_64.tar.gz
2.解压
tar -zxvf elasticsearch-7.3.2-linux-x86_64.tar.gz
3.启动
到安装路径下 输入./bin/elasticsearch (这个一退出客户端就关闭了)
后台启动的用 ./bin/elasticsearch -d
启动会报错:can not run elasticsearch as root
4.创建新用户
第一步:liunx创建新用户:"adduser yjclsx",然后给创建的用户加密码:"passwd yjclsx",输入两次密码。
第二步:切换刚才创建的用户:"su yjclsx",然后启动elasticsearch。如果显示Permission denied权限不足,则继续进行第三步。
第三步:给新用户赋权限,因为这个用户本身就没有权限,肯定自己不能给自己付权限。所以要用root用户登录并赋予权限,chown -R yjclsx/你的elasticsearch安装目录。
通过上面三步就可以启动elasticsearch了。
5.启动远程访问
进入安装目录下的conf文件夹
vim elasticsearch.yml
- node.name: node-1 前面的#打开
- network.host: 0.0.0.0 签名#记得去掉
- cluster.initial_master_nodes: ["node-1"] 这里一定要这样设置
-
在最后加上这两句,要不然,外面浏览器就访问不了哈
http.cors.enabled: true
http.cors.allow-origin: "*" -
# # Lock the memory on startup: # #bootstrap.memory_lock: true # # Make sure that the heap size is set to about half the memory available # on the system and that the owner of the process is allowed to use this # limit. # # Elasticsearch performs poorly when the system is swapping the memory. # # ---------------------------------- Network ----------------------------------- # # Set the bind address to a specific IP (IPv4 or IPv6): # #network.host: 192.168.0.1 network.host: 192.168.136.110 #network.host: 0.0.0.0 #network.host: localhost #network.host: 127.0.0.1 # # Set a custom port for HTTP: # #http.port: 9200 #http.port: 9200 # # For more information, consult the network module documentation. # # --------------------------------- Discovery ---------------------------------- # # Pass an initial list of hosts to perform discovery when this node is started: # The default list of hosts is ["127.0.0.1", "[::1]"] # #discovery.seed_hosts: ["host1", "host2"] #discovery.seed_hosts:["my-application"] # # Bootstrap the cluster using an initial set of master-eligible nodes: # #cluster.initial_master_nodes: ["node-1", "node-2"] cluster.initial_master_nodes: ["node-1"] # # For more information, consult the discovery and cluster formation module documentation. # # ---------------------------------- Gateway ----------------------------------- # # Block initial recovery after a full cluster restart until N nodes are started: # #gateway.recover_after_nodes: 3 # # For more information, consult the gateway module documentation. # # ---------------------------------- Various ----------------------------------- # # Require explicit names when deleting indices: # #action.destructive_requires_name: true http.cors.enabled: true http.cors.allow-origin: "*"
ps -ef|grep elasticsearch 看进程
把进程杀了
kill -9 进程id
重启就好了
6.如果启动报错 “max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]”
解决:
切换到root用户
执行命令:
sysctl -w vm.max_map_count=262144
查看结果:
sysctl -a|grep vm.max_map_count
显示:
vm.max_map_count = 262144
上述方法修改之后,如果重启虚拟机将失效,所以:
解决办法:
在 /etc/sysctl.conf文件最后添加一行
vm.max_map_count=262144
即可永久修改
7.最后kill进程重启elasticsearch
8.验收效果
浏览器输入:ip:9200
9200如果被防火墙拦住或者阿里云安全组没有配置,请自行百度
效果: