安装elasticsearch
创建用户
useradd <username>
为新建用户添加 sudo 权限
修改 /etc/sudoers 文件,定位到107行,在下面添加以下内容
<username> ALL=(ALL) NOPASSWD:ALL
username 指的是要添加的用户名,NOPASSWD:ALL 表示每次在使用 sudo 的时候不需要输入当前用户的密码,否则需要每次都确认当前用户的密码
保存修改
集群搭建
- 修改 elasticsearch主目录/conf/elasticsearch.yml 文件,每个节点的名称保持唯一,集群名称保持一致
cluster.name: <集群名称>
node.name: <节点名称>
node.master: true # 参与主节点选举
node.data: true # 是否作为数据节点
bootstrap.memory_lock: true
network.host: <服务器ip>
http.port: 9200
transport.tcp.port: 9300
transport.tcp.compress: true
discovery.zen.ping.unicast.hosts: ["host1","host2","host3"] # 用于集群发现的elasticsearch的节点ip
discovery.zen.minimum_master_nodes: 2 # 节点数/2上取整,竞选主节点的最低节点数量,为了防止脑裂
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers: "X-Requested-With, Content-Type, Content-Length, X-User"
保存修改后启动
- 后台启动
bin/elasticsearch -d
启动时常见报错
- max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
修改 /etc/security/limits.conf 文件,添加以下内容
* soft nofile 65536
* hard nofile 65536
- max number of threads [3818] for user [es] is too low, increase to at least [4096]
修改 /etc/security/limits.conf 文件,添加以下内容
* soft nproc 4096
* hard nproc 4096
- memory locking requested for elasticsearch process but memory is not locked
修改 /etc/security/limits.conf 文件,添加以下内容
* soft memlock unlimited
* hard memlock unlimited
- max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
修改 /etc/sysctl.conf 文件,添加以下内容
vm.max_map_count=262144
执行以下命令使修改生效
sysctl -p