centos7+docker+elasticsearch 安装记录+踩坑

版本:

  cenos7 :3.10.0-957.21.3.el7.x86_64  (内核需>=3.10 才可以安装)

  docker: yum安装版本为1.13.1

  elasticsearch: 6.8.5

安装:

  网上的安装步骤很多,主要参考这篇文章 https://juejin.im/post/5ca0d12c518825550b35be6d,大致说一下不同点

  1. 此文是内网环境,需外网访问参看下文异常处理3、4
  2. 注意应用docker logs containerid  命令查看docker日志,分析错误原因
  3. 安装es-head:  
  • docker pull mobz/elasticsearch-head:5
  • docker run -d -p 9100:9100 docker.io/mobz/elasticsearch-head:5
  • ps:注意提前开9100端口
  • oh shit,没想到这个官方镜像是有bug的,由于es6.0+修改了检测contenttype的机制,而es-head5没有手动设置content-type,造成所有查询都报406.  目前es-head5已经修复了这个bug,但是官方docker镜像没有同步修复。建议不要安装docker版本https://github.com/mobz/elasticsearch-head/issues/361

  4.zipkin设置存储方式为es时,查看docker日志有报错,启动命令为:

  

docker run -d  -p 9411:9411 \
           -e "STORAGE_TYPE=elasticsearch" \
           -e "ES_HOSTS=http://x.x.x.x:9200" \
           -e "ES_INDEX=zipkin" \
           -e "ES_INDEX_SHARDS=1" \
           -e "ES_INDEX_REPLICAS=1" \
           openzipkin/zipkin

  发现只要加上STORAGE_TYPE=elasticsearch,就在zipkin中无数据,去掉就可以正常写入数据

  改为zipkin-slim后正常写入zipkin和es (上面命令最后一行改为openzipkin/zipkin-slim)

  ps:zipkin-slim只能连接es,不能连接mysql

 

启动

  

es启动:
docker run -e xpack.security.enabled=true -e xpack.security.transport.ssl.enabled=true -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 -v /dockerdata/es/config/master.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /dockerdata/es/master:/usr/share/elasticsearch/data --name es-master elasticsearch:6.8.5

ps:master.yml
cluster.name: elasticsearch-cluster
node.name: master
network.bind_host: 0.0.0.0
network.publish_host: x.x.x.x
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["x.x.x.x:9300","x.x.x.x:9301"]
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

最后一行为添加xpack后运行head插件访问使用,访问时http://x.x.x.x:9100/?auth_user=elastic&auth_password=123456

head启动:
定位到head目录后 nohup npm run start &
            disown (不加disown的话,node进程会在shell断开后结束)
没有使用docker版本的原因是官方docker镜像没有同步git主版本,所以存在一个bug:所有接口调用都报406错误,原因是es新版更新了请求机制,需要指定content-type

zipkin启动:
docker run -d -p 9411:9411 \
-e "STORAGE_TYPE=elasticsearch" \
-e "ES_HOSTS=http://x.x.x.x:9200" \
-e "ES_INDEX=zipkin" \
-e "ES_INDEX_SHARDS=1" \
-e "ES_INDEX_REPLICAS=1" \
-e "ES_USERNAME=elastic" \
-e "ES_PASSWORD=123456" \
openzipkin/zipkin-slim


kibana启动:
//docker run --link es-master:elasticsearch -p 5601:5601 --name kibana -d kibana:6.8.5
docker run -l es-master:elasticsearch -p 5601:5601 -v /dockerdata/es/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml -d kibana:6.8.5

ps:kibana.yml

server.name: kibana
server.host: "0"
elasticsearch.url: http://x.x.x.x:9200
xpack.monitoring.ui.container.elasticsearch.enabled: true
elasticsearch.username: "kibana"
elasticsearch.password: "123456"



修改xpack默认用户名密码:
docker exec -it 'containerid' bash
进入 /usr/share/elasticsearch/bin 输入 elasticsearch-setup-passwords interactive
然后依次修改所有账户密码

 

异常处理:

  1. 启动容器时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen   解决:重启docker后再启动容器
  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=262144  (大于等于此数字)
  3. 无法外网访问:修改config/master.yml/slave.yml 中的network.host: 0.0.0.0 (我有两个节点,所以修改两个配置文件;如果非docker环境,直接修改elasticsearch.yml)
  4. 外网依然访问不了,可能是防火墙没有开放端口,防火墙和端口相关命令参看 https://blog.csdn.net/u011846257/article/details/54707864

 

ps: es工具https://github.com/elastic/curator

 

posted @ 2019-11-29 17:24  喵了个汪的2371  阅读(1352)  评论(0编辑  收藏  举报