Centos7部署Elasticsearch遇到的问题

1、部署ES不能用root用户

需要用useradd es添加一个叫es的用户,来启动es

2、max file错误

max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]

解决办法:

在文件:/etc/security/limits.conf 添加:

* soft nofile 165535
* hard nofile 365535

*是指所有用户,文件数可以根据需要自己定义

然后sysctl -p 重新登录es用户就可以解决max file的问题了

3、max virtual memory错误

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决办法:

在文件:/etc/sysctl.conf 添加:

vm.max_map_count=655360

数字根据需要进行调整

然后sysctl -p重新登录es用户就可以解决max virtual memory的问题了

 

4、局域网访问问题

首先,打开防火墙对应端口9200,9300

然后,配置config文件夹下的elasticsearch.yml对应的network.bind_host为es的本机局域网地址,如:network.bind_host: [‘10.51.x.x’]

如果使用云服务,需要考虑到安全组、安全规则的配置

 

ES-MatchQuery

1、加载依赖

<!--ES搜索依赖-->
<dependency>
 <groupId>org.elasticsearch.client</groupId>
 <artifactId>transport</artifactId>
 <version>5.4.0</version>
</dependency>

<dependency>
 <groupId>org.apache.logging.log4j</groupId>
 <artifactId>log4j-api</artifactId>
 <version>2.8.2</version>
</dependency>
<dependency>
 <groupId>org.apache.logging.log4j</groupId>
 <artifactId>log4j-core</artifactId>
 <version>2.8.2</version>
</dependency>


2、初始化Client

public class MyTransportClient {
 private static Logger logger = LoggerFactory.getLogger(MyTransportClient.class);
 private static TransportClient client;
 public MyTransportClient() {
 init();
 }
 protected void init() {
 // on startup
 try {
 client = new PreBuiltTransportClient(Settings.EMPTY)
 .addTransportAddress(new InetSocketTransportAddress(
 InetAddress.getByName("localhost"), 9300));
 } catch (UnknownHostException e) {
 e.printStackTrace();
 }
 }

 public static TransportClient getTransportClient(){
 if(client==null){
 new MyTransportClient();
 }
 return client;
 }
}

3、高亮查询
 HighlightBuilder hiBuilder=new HighlightBuilder();
 hiBuilder.preTags("<h2>");
 hiBuilder.postTags("</h2>");
 hiBuilder.field("tweet");
 QueryBuilder matchQuery = QueryBuilders.matchQuery("tweet", "IS");
 SearchResponse response2 = MyTransportClient.getTransportClient().prepareSearch("us")
 .setTypes("tweet")
 .setQuery(matchQuery)
 .setFrom(2)
 .setSize(2)
 .highlighter(hiBuilder)
 .get();
 log.info(response2);
 log.info(response2.getHits());
 //获取查询结果集
 SearchHits searchHits = response2.getHits();
 System.out.println("共搜到:"+searchHits.getTotalHits()+"条结果!");
 //遍历结果
 for(SearchHit hit:searchHits){
 System.out.println("String方式打印文档搜索内容:");
 System.out.println(hit.getSourceAsString());
 System.out.println("Map方式打印高亮内容");
 System.out.println(hit.getHighlightFields());

 System.out.println("遍历高亮集合,打印高亮片段:");
 Text[] text = hit.getHighlightFields().get("tweet").getFragments();
 for (Text str : text) {
 System.out.println(str.string());
 }
 }
 }

unblock with ‘mysqladmin flush-hosts’

上午突然断网,恢复的过程中多次链接mysql数据库,导致创建链接过多,出现host被锁的问题,查了一下

1、找到mysqladmin

whereis mysqladmin,看到对应的路径,然后cd进入所在目录

比如/usr/local/mysql/bin

2、执行修复命令

./mysqladmin flush-hosts -h127.0.0.1 -p3308 -uroot -p

然后输入密码

-h127.0.0.1是-h加上mysql服务的host地址

-p3308是-p加上mysql服务的port端口号

-uroot是-u加速mysql服务的user,root用户

这里的最后一个p是指password的,mysql的root用户的密码

执行之后,输入密码就可以修复了

参考:http://www.cnblogs.com/susuyu/archive/2013/05/28/3104249.html