docker安装Elasticsearch 6.2.2

1.拉取镜像

docker pull docker.elastic.co/elasticsearch/elasticsearch:6.2.2

2.启动容器,设置部分参数是为了支持跨域访问。

docker run -d --name elasticsearch  -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e http.cors.enabled=true -e http.cors.allow-origin="*" -e http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization -e http.cors.allow-credentials=true docker.elastic.co/elasticsearch/elasticsearch:6.2.2

3.通过ip:9200 访问,会返回集群状态信息,证明安装成功。

{
  "name" : "2pH4SYF",
  "cluster_name" : "es-test",
  "cluster_uuid" : "wvB794uYQ0OJVBAkRshU0w",
  "version" : {
    "number" : "6.2.2",
    "build_hash" : "10b1edd",
    "build_date" : "2018-02-16T19:01:30.685723Z",
    "build_snapshot" : false,
    "lucene_version" : "7.2.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

5.此刻你会发现Elasticsearch是裸奔的,现在添加基本安全验证。

5.1 进入容器

docker ps
docker exec -it 容器ID bash

5.2 进入到Elasticsearch安装目录

cd /usr/share/elasticsearch

5.3使用下列命令生成证书,证书生成后在config下

bin/elasticsearch-certutil cert -out config/elastic-certificates.p12 -pass ""

此时/usr/share/elasticsearch/config目录下会多出2个文件:elastic-certificates.p12 和 elasticsearch.keystore。
修改文件所属用户和权限:

chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/config/

5.4 修改配置,打开config/elasticsearch.yml,添加以下内容:

vi /usr/share/elasticsearch/config/elasticsearch.yml
cluster.name: es-test
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
xpack.license.self_generated.type: basic

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12

5.5 重启容器

docker restart 容器ID

5.6 进入容器

docker exec -it 容器ID bash

6.安装分词器

进入到docker容器内

elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.0/elasticsearch-analysis-ik-6.2.2.zip

安装完成后查看

elasticsearch-plugin list

删除分词器

elasticsearch-plugin remove analysis-ik

7安装kabana

7.1拉取kabana镜像

docker pull docker.elastic.co/elasticsearch/elasticsearch:6.2.2

7.2启动kibana

docker run --name kibana -p 5601:5601 -d --privileged=true docker.elastic.co/kibana/kibana:6.2.2

7.3修改elasticsearch配置

进入到容器

docker exec -it ac016117a18d bash

修改/usr/share/kibana/config/kibana.yml

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

退出重启kibana
然后浏览器访问ip:5601就能进入kibana,账号密码为elsticsearch的账号密码

7.4验证IK分词器是否配置成功

在elk的dev-tools输入,提示如下

POST /_analyze
{
  "analyzer": "ik_max_word",
  "text": "我是Joey"
}

注意使用spring-data-elasticsearch,spring-boot版本是2.1.5,yml配置如下:

spring:
  data:
    elasticsearch:
      cluster-nodes: x.x.x.141:9300
      repositories:
        enabled: true
      properties:
        transport:
          tcp:
            connect_timeout: 120s
      # 集群名称
      cluster-name: es-test

注意端口好事9300而不是9200,cluster-name要合elasticsearch.yml里面设置一样

你可能感兴趣的:(docker安装Elasticsearch 6.2.2)