安装环境 centos7.2 64位 openJDK1.8
要求非root用户运行 ./elasticsearch
报错:
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
解决办法:
修改配置文件:
sudo vim /etc/sysctl.conf
vm.max_map_count=262144
或:sudo sysctl -w vm.max_map_count=655360
sudo vim /etc/security/limits.conf
加入两行:
username hard nofile 65536
username soft nofile 65536
集群配置:
修改配置文件config/elasticsearch.yml
假设配置2台服务器
cluster.name: my-application
node.name: node-1
network.host: 192.168.10.141
network.bind_host: 192.168.10.141
network.publish_host: 192.168.10.141
node.master: true
node.data: true
http.port: 9200
http.enabled: true
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.ping.unicast.hosts: ["192.168.10.1","192.168.10.2"]
----------------------------------------------------------------------
cluster.name: my-application
node.name: node-2
network.host: 192.168.10.2
network.bind_host: 192.168.10.2
network.publish_host: 192.168.10.2
http.port: 9201
node.master: false
node.data: true
http.enabled: true
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.ping.unicast.hosts: ["192.168.10.1","192.168.10.2"]
由于es5对head支持不友好,所以只能通过API来观察服务器状态了。别安装x-pack了,如果安装了以后就需要你输入用户名密码,java api里面还不知道如何输入
http://192.168.0.x:9201/_nodes/stats?pretty
maven依赖:
https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/_maven_repository.html
Java api 调用代码:
public class ElasticsearchTools {
private static String clustername="my-application";//es集群
private static String ip = "192.168.0.x";
private static String ip2 = "192.168.0.x";
private static int port = 9300;
public static boolean addDocument(JSONObject object, String index, String type, String id) {
TransportClient client = null;
try {
Settings settings = Settings.builder()
.put("cluster.name", clustername).put("client.transport.sniff", true).build();
client = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ip), port)).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ip2), port));