ElasticSearch 5.1.1 安装开发部署总结 集群配置

安装环境 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));    



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值