2019.1.22 springboot+elasticsearch+docker

首先先用docker 搭建 es

搜索 es+springboot 大都又是 在本地 搭建的es。。于是觉得自己边搜边写一篇博客 作为记录使用

docker:
首先安装
docker pull elasticsearch
docker run -d --name es -p 9200:9200 -e "discovery.type=single-node" id
打开 服务器ip:9200 可以正常打开
docker exec -it es /bin/bash
cd plugins/
plugin install mobz/elasticsearch-head
服务器ip:9200/_plugin/head/ 打开管理插件
但登陆elasticsearch-head点击连接9200 没反应
docker exec -it /bin/bash
cd config
vi elsaticsearch.yml
增加以下两行
http.cors.enabled: true
http.cors.allow-origin: "*"即可
点击连接 解决问题
整合springboot过程及其痛苦 搜了无数博客 都不行 就是愣连接不上9300端口 。。 于是乎 暂停dockr部署 转为命令启动方式以后有时间在去看看



命令:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.8.tar.gz
tar -zxvf elasticsearch-5.6.8.tar.gz
外网:
config目录下面elasticsearch.yml
修改为 network.host: 0.0.0.0
启动
bin/.elasticsearch
Spring Data 9300端口集成
Restful API 9200端口集成



springboot整合es
实体类
indexName为索引库
type为表
@Document(indexName = "blog", type = "article")
public class Article implements Serializable {br/>dao层
@Component
public interface ArticleRepository extends ElasticsearchRepository<Article, Long> {
保存
articleRepository.save(new Article());
查询
QueryBuilder queryBuilder = QueryBuilders.matchQuery("title",title);
Iterable<Article> list = articleRepository.search(queryBuilder);



报错解决方案:
ERROR: [2] bootstrap checks failed
[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
编辑 /etc/security/limits.conf,追加以下内容;

  • soft nofile 65536
  • hard nofile 65536
    此文件修改后需要重新登录用户,才会生效
    [2]: 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
    重新启动,成功。
    1、问题一
    Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error=‘Cannot allocate memory‘ (errno=12)
    #

    There is insufficient memory for the Java Runtime Environment to continue.

        #Native memory allocation (mmap) failed to map 986513408 bytes for committing reserved memory.
        #An error report file with more information is saved as:
        #/usr/local/software/temp/elasticsearch-6.2.2/hs_err_pid1912.log
    解决:内存不够,购买阿里云的机器可以动态增加内存
    
    2、问题二
        [[email protected] bin]# ./elasticsearch
        [2018-02-22T20:14:04,870][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
        org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.2.2.jar:6.2.2]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.2.2.jar:6.2.2]
    解决:用非root用户
        添加用户:useradd -m 用户名  然后设置密码  passwd 用户名
    
    3、问题三
        ./elasticsearch
        Exception in thread "main" java.nio.file.AccessDeniedException: /usr/local/software/temp/elasticsearch-6.2.2/config/jvm.options
       解决:权限不够 chmod 777 -R 当前es目录


项目起不来

启动的时候报错:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘controller‘: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘goodsRepository‘: Cannot resolve reference to bean ‘elasticsearchTemplate‘ while setting bean property ‘elasticsearchOperations‘; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘elasticsearchTemplate‘ defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfiguration.class]: Unsatisfied dependency expressed through method ‘elasticsearchTemplate‘ parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘elasticsearchClient‘ defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.transport.TransportClient]: Factory method ‘elasticsearchClient‘ threw exception; nested exception is java.lang.IllegalStateException: availableProcessors is already set to [12], rejecting [12]



docker vim

继续搜索解决方案 也没其他好办法 挨个博客试呗, 有的博客是让添加配置的 可是vim elasticsearch.yml 的时候报错:bash: vim: command not found
在使用docker容器时,有时候里边没有安装vim,敲vim命令时提示说:vim: command not found,这个时候就需要安装vim,可是当你敲apt-get install vim命令时,提示:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package vim
1)这时候需要敲:apt-get update,这个命令的作用是:同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引,这样才能获取到最新的软件包。
2)等更新完毕以后再敲命令:apt-get install vim命令即可。



es redis
好像是加了redis冲突了??ok 去掉redis配置
adding transport node : 60.205.217.216:9200特别慢 然后error 崩溃啊!
failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{jU1jEJLVTweRhMI98Kgf8A}{60.205.217.216}{60.205.217.216:9200}]

崩溃了。。弄了一天了,把项目中关于es的都删了,找个教程重新走一遍



linux 添加用户 并设置密码
因为es不能root用户起(root权限太大,危险)所以新建了用户
useradd -r 添加系统用用户
passwd 用户名 进入设置密码

2019.1.22 springboot+elasticsearch+docker

原文地址:http://blog.51cto.com/12005608/2346290

时间: 2024-08-02 14:45:08

2019.1.22 springboot+elasticsearch+docker的相关文章

springboot elasticsearch 集成注意事项

文章来源: http://www.cnblogs.com/guozp/p/8686904.html 一 elasticsearch基础 这里假设各位已经简单了解过elasticsearch,并不对es进入更多的,更深层次的解释,如有必要,会在写文章专门进行es讲解. Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎.无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进.性能最好的.功能最全的搜索引擎库. 但是,Lucene只是一个库.想要使用它,你必

Springboot 生成docker image

前段日子搭建了一个kubenetes集群,kubenetes是需要载入docker image来运行应用的. 我使用的是Springboot框架,因此向大家分享一下Springboot生成docker image的一个方法.不对的地方请指教- 一.Springboot生成jar包 docker image生成需要用到项目build生成的jar包,因此第一步你需要生成一个jar包.maven项目,命令是: mvn clean package 二.Dockerfile 1.jar生成完毕后,需要创建

2019.6.22刷题统计

今日写统计如此早的原因是:下午回老家,无法刷题. 今天完成了普及组的100道题,但还未进入USACO. 通过数:9 通过题目编号:1061/1072/1085/1090/1103/1109/1113/1125/1132 排名:暂居第一 本网站开始时间:2019/6/15 15:02:09 结束时间:2019/6/22 12:58:30 共计6天21小时56分21秒. 完成题目(见图片): 通过普及组100题的练习,我发现了自己普及组的知识点仍然掌握不全面,还需要继续复习. 另外,已经完成了入门+

springboot集成elk 一: springboot + Elasticsearch

1.ELK介绍 1> Elasticsearch是实时全文搜索和分析引擎, 提供搜集.分析.存储数据三大功能: 是一套开放REST和JAVA API等结构提供高效搜索功能,可扩展的分布式系统. 2> Logstash是一个用来搜集.分析.过滤日志的工具. 它支持几乎任何类型的日志,包括系统日志.错误日志和自定义应用程序日志. 它可以从许多来源接收日志,这些来源包括 syslog.消息传递(例如 RabbitMQ)和JMX,它能够以多种方式输出数据,包括电子邮件.websockets和Elast

SpringBoot 部署 docker 打包镜像

SpringBoot 部署 docker 打包镜像 环境: 1.代码编写工具:IDEA 2.打包:maven 3.docker 4.linux 7.JDK1.8 8.Xshell 9.Xftp 第一步:使用idea创建简单的springboot项目 引用一篇别人文章:https://blog.csdn.net/u013777094/article/details/78580710/ 第二步:设置项目生成jar包(两种方式) 1.修改pom文件 <?xml version="1.0"

springboot之docker启动参数传递

这几天有网友问,如何在使用docker的情况下传递spring.profiles.active=test,也就是说springboot切换配置文件.以往我们直接通过java启动jar的时候,直接跟上--spring.profiles.active=test或者利用jvm参数-Dspring.profiles.active=test来传递.我写一些命令吧. 非docker下springboot切换配置文件 java -jar test.jar --spring.profiles.active=te

springboot+elasticsearch + rabbitMQ实现全文检索(springboot+ES整合)

springboot 2.X  能用 springboot-data-ES 5.X的 用特殊方式引入 5.X的ES 配置 bootstrap.xml 因为在调试,所以暂时写死了,具体的路径按照上面的配置 @Configuration public class ElasticSearchConfig { /** * * @Title: transportClient * @Description: 配置elasticsearch * @return * @throws UnknownHostExc

java版spring cloud+spring boot 社交电子商务平台 (二十四)springboot整合docker

这篇文篇介绍,怎么为 springboot程序构建一个docker镜像.docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源.Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销极低. 准备工作 环境: linux环境或mac,不要用windows jdk 8 mave

Springboot使用docker容器部署

本文基于ubuntu 16 1.安装openjdk8(略) 2.创建Dockerfile文件 cd ~vi Dockerfile Dockerfile内容 FROM openjdk:8MAINTAINER Lee <[email protected]> WORKDIR /homeVOLUME /home/logsENV java_opts '-XX:+PrintGCDetails -XX:+PrintGCTimeStamps'#ADD package/pinpoint-agent /pinpo