一.安装
1.先前条件:
- 安装java8
- 下载es安装包
2.上传到linux:/opt/software
3.解压
cd /opt/software
tar -zxvf elasticsearch-5.6.2.tar.gz -C /opt/module
4.新建data,logs文件夹
cd /opt/module/elasticsearch-5.6.2
mkdir data
mkdir logs
5.修改配置文件(root用户)
(1).修改elasticsearch.yml文件
vi /opt/module/elasticsearch-5.6.2/conf/elasticsearch.yml
修改内容如下:
# ---------------------------------- Cluster -------------------------------------
cluster.name: my-application
# ------------------------------------ Node --------------------------------------
node.name: JBS
# ----------------------------------- Paths ---------------------------------------
path.data: /opt/module/elasticsearch-5.6.1/data
path.logs: /opt/module/elasticsearch-5.6.1/logs
# ----------------------------------- Memory -----------------------------------
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
# ---------------------------------- Network ------------------------------------
network.host: 192.168.127.121
# --------------------------------- Discovery ------------------------------------
discovery.zen.ping.unicast.hosts: ["bigdata121"]
说明:
- cluster.name :如果要配置集群需要两个节点上的 elasticsearch 配置的 cluster.name 相同,都启动可以自动组成集群,这里如果不改 cluster.name 则默认是 cluster.name=my-application。
- nodename 随意取但是集群内的各节点不能相同
(2).修改limits.conf文件
vi /etc/security/limits.conf
//在文件末尾添加如下内容
* soft nofile 655360
* hard nofile 131072
* soft nproc 4096
* hard nproc 4096
(3).修改limits.d文件
vi /etc/security/limits.d/20-nproc.conf
//修改内容如下
* soft nproc 1024
//改为
* soft nproc 4096
(4).修改配置sysctl.conf
vi /etc/sysctl.conf
//添加内容
vm.max_map_count=655360
5.新建linux用户:es不能以root用户启动
useradd kai
passwd kai
输入密码
cd /opt/module/elasticsearch-5.6.2 //进入的elasticsearch目录
chown -R kai:users * //修改权限
su kai //切换到kai用户,启动es
6.重启linux,因为修改linux配置文件后需要重启后才生效
二.启动:
su kai //切换到kai用户
cd /opt/module/elasticsearch-5.6.2
bin/elasticsearch //启动
注意:can not run elasticsearch as root
三.验证:
curl 'http://192.168.127.121:9200'
curl -XGET '192.168.127.121:9200/_cat/health?v&pretty'
当看到status是green时,证明启动成功
- Green - 一切运行正常(集群功能齐全)
- Yellow - 所有数据是可以获取的,但是一些复制品还没有被分配(集群功能齐全)
- Red - 一些数据因为一些原因获取不到(集群部分功能不可用)
四.当启动es,报错:
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max number of threads [1024] for user [hduser] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[4]: system call filters failed to install; check the logs and fix your configuration or disable system
1.配置linux系统环境:
2.切换到 root 用户,编辑 limits.conf 添加类似如下内容
vi /etc/security/limits.conf
新增内容如下:
* soft nofile 65536
* hard nofile 131072
* soft nproc 4096
* hard nproc 4096
3.进入 limits.d 目录下修改配置文件。
vi /etc/security/limits.d/90-nproc.conf
把 * soft nproc 1024 改成4096
5.修改配置 sysctl.conf
vi /etc/sysctl.conf
添加内容如下:
vm.max_map_count=655360
执行命令:
sysctl -p
6.重新登录kai用户,重新启动es,如果还有报错,则需重启虚拟机
- 查看集群状态命令:
curl -XGET 'http://192.168.127.121:9200/_cat/health?v&pretty'
- 查看所有数据命令:
curl -XGET 'ip地址:9200/index名称/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} }
}'