美文网首页Docker学习
Docker安装Elasticsearch和Kibana

Docker安装Elasticsearch和Kibana

作者: JBryan | 来源:发表于2021-01-14 16:17 被阅读0次

    Docker安装请参考:https://www.jianshu.com/p/64de448b637c

    1、安装Elasticsearch和Kibana

    1.1、安装Elasticsearch

    docker pull elasticsearch:7.10.1
    

    1.2、安装kibana,kibana的版本一定要和elasticsearch的版本一样。

    docker pull kibana:7.10.1
    

    1.3、创建Elasticsearch文件夹,以后会把配置文件放到config下,数据文件放到data下

    mkdir -p /usr/local/app/elasticsearch/config
    mkdir -p /usr/local/app/elasticsearch/data
    

    1.4、进入config文件夹,创建Elasticsearch配置文件

    cd /usr/local/app/elasticsearch/config/
    vi elasticsearch.yml
    

    elasticsearch.yml中添加“http.host: 0.0.0.0”,配置Elasticsearch可被任意主机连接

    [root@localhost config]# cat elasticsearch.yml 
    http.host: 0.0.0.0
    [root@localhost config]#
    
    2、启动Elasticsearch

    启动命令:
    --name 为容器起名字;
    -p 9200:9200 监听9200端口,接收http请求;
    -p 9300:9300 监听9300端口,集群间通信端口;
    -e "discovery.type=single-node" 以单节点运行;
    -e ES_JAVA_OPTS="-Xms64m -Xmx512m" 指定初始占用内存64m,最大占用512m;
    -v /usr/local/app/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml 将容器中的配置文件挂载到,刚才创建的config/elasticsearch.yml文件中;
    -v /usr/local/app/elasticsearch/data:/usr/share/elasticsearch/data 挂载data目录;
    -v /usr/local/app/elasticsearch/plugins:/usr/share/elasticsearch/plugins 挂载插件目录plugins;
    -d elasticsearch:7.10.1 使用刚才下载的镜像 ;

    [root@localhost config]# docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
    >  -e  "discovery.type=single-node" \
    >  -e ES_JAVA_OPTS="-Xms64m -Xmx512m" \
    >  -v /usr/local/app/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
    >  -v /usr/local/app/elasticsearch/data:/usr/share/elasticsearch/data \
    >  -v /usr/local/app/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
    >  -d elasticsearch:7.10.1
    e4fba7b5ba08f4c5096f7e7b670138aed86ad0396bab150778a638a918967829
    [root@localhost config]# docker ps
    CONTAINER ID   IMAGE                  COMMAND                  CREATED         STATUS         PORTS                                            NAMES
    e4fba7b5ba08   elasticsearch:7.10.1   "/tini -- /usr/local…"   3 seconds ago   Up 3 seconds   0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   elasticsearch
    [root@localhost config]#
    

    过一会,elasticsearch会错误退出,查看docker中elasticsearch日志,出现访问拒绝报错:

    [root@localhost config]# docker logs elasticsearch
    uncaught exception in thread [main]
    ElasticsearchException[failed to bind service]; nested: AccessDeniedException[/usr/share/elasticsearch/data/nodes];
    Likely root cause: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes
        at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
        at java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:388)
        at java.base/java.nio.file.Files.createDirectory(Files.java:694)
        at java.base/java.nio.file.Files.createAndCheckIsDirectory(Files.java:801)
        at java.base/java.nio.file.Files.createDirectories(Files.java:787)
        at org.elasticsearch.env.NodeEnvironment.lambda$new$0(NodeEnvironment.java:275)
        at org.elasticsearch.env.NodeEnvironment$NodeLock.<init>(NodeEnvironment.java:212)
        at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:272)
        at org.elasticsearch.node.Node.<init>(Node.java:362)
        at org.elasticsearch.node.Node.<init>(Node.java:289)
        at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:227)
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:227)
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:393)
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170)
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161)
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127)
        at org.elasticsearch.cli.Command.main(Command.java:90)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
    For complete error details, refer to the log at /usr/share/elasticsearch/logs/elasticsearch.log
    

    修改elasticsearch文件夹权限,-R递归修改所有子文件权限,777所有用户、分组均可读可写

    [root@localhost elasticsearch]# chmod -R 777 /usr/local/app/elasticsearch
    [root@localhost elasticsearch]# ll
    total 0
    drwxrwxrwx. 2 root root 31 Jan 13 16:00 config
    drwxrwxrwx. 2 root root  6 Jan 13 15:55 data
    drwxrwxrwx. 2 root root  6 Jan 13 16:14 plugins
    

    查看elasticsearch容器,并重启elasticsearch,docker start后面跟上自己elasticsearch容器id就可以了。

    [root@localhost elasticsearch]# docker ps -a
    CONTAINER ID   IMAGE                  COMMAND                  CREATED        STATUS                    PORTS     NAMES
    e4fba7b5ba08   elasticsearch:7.10.1   "/tini -- /usr/local…"   23 hours ago   Exited (1) 23 hours ago             elasticsearch
    [root@localhost elasticsearch]# docker start e4fba7b5ba08
    e4fba7b5ba08
    

    容器启动成功

    [root@localhost elasticsearch]# docker ps
    CONTAINER ID   IMAGE                  COMMAND                  CREATED        STATUS         PORTS                                            NAMES
    e4fba7b5ba08   elasticsearch:7.10.1   "/tini -- /usr/local…"   24 hours ago   Up 2 minutes   0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   elasticsearch
    

    此时访问虚拟机9200端口,返回成功


    docker2.jpg
    3、启动kibana

    --name kibana:给容器起名字kibana;
    -e ELASTICSEARCH_HOSTS=http://{自己的虚拟机地址}:9200:指定elasticsearch的地址和端口;
    -p 5601:5601:kibana的操作端口;
    -d kibana:7.10.1:kibana的版本;

    [root@localhost elasticsearch]# docker run --name kibana -e ELASTICSEARCH_HOSTS=http://192.168.43.129:9200 -p 5601:5601 -d kibana:7.10.1
    b4f383036f1b14ea0a6d6a8cf38a8ed636360652a9811899c5a60c16a86d9563
    [root@localhost elasticsearch]# docker ps
    CONTAINER ID   IMAGE                  COMMAND                  CREATED         STATUS          PORTS                                            NAMES
    b4f383036f1b   kibana:7.10.1          "/usr/local/bin/dumb…"   4 seconds ago   Up 4 seconds    0.0.0.0:5601->5601/tcp                           kibana
    e4fba7b5ba08   elasticsearch:7.10.1   "/tini -- /usr/local…"   24 hours ago    Up 15 minutes   0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   elasticsearch
    [root@localhost elasticsearch]#
    

    访问虚拟机5601端口,kibana启动成功


    docker3.jpg

    相关文章

      网友评论

        本文标题:Docker安装Elasticsearch和Kibana

        本文链接:https://www.haomeiwen.com/subject/hpnuaktx.html