docker一键部署elasticsearch搜索服务器只要3分钟

Posted docker核心技术中文网

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker一键部署elasticsearch搜索服务器只要3分钟相关的知识,希望对你有一定的参考价值。

什么是elasticsearch?

Elasticsearch是一个实时的分布式搜索和分析引擎。它可以帮助你用前所未有的速度去处理大规模数据。

ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。

主要优点:

  1. Elasticsearch是分布式的。不需要其他组件,分发是实时的,被叫做”Push replication”。

  2. Elasticsearch 完全支持 Apache Lucene 的接近实时的搜索。

  3. 处理多租户(multitenancy)不需要特殊配置,而Solr则需要更多的高级设置。

  4. Elasticsearch 采用 Gateway 的概念,使得完备份更加简单。

  5. 各节点组成对等的网络结构,某些节点出现故障时会自动分配其他节点代替其进行工作。


   废话不多说请看dockerfile代码吧

目录结构如下:

dockerfile

FROM docker.io/centos:latest
MAINTAINER huzailingcom <huzailingcom@gmail.com>

RUN yum clean all
RUN yum install -y yum-plugin-fastestmirror yum-utils epel-release
RUN yum update -y

# utils
RUN yum install -y git hostname sudo less iproute psmisc net-tools \
bash unzip which tar passwd ed m4 patch rsync wget curl tcpdump telnet \
tar bzip2 unzip strace supervisor openssl openssh openssh-server \
openssh-clients util-linux inotify-tools

# dev
RUN yum install -y gcc-c++ libtool make gdb mariadb-devel snappy-devel \
boost-devel lz4-devel zlib-devel libcurl-devel libevent-devel \
libesmtp-devel libuuid-devel libcsv-devel cyrus-sasl-devel \
bzip2-devel libpqxx-devel libxml2-devel libxslt-devel libxslt-python \
libpng-devel jemalloc-devel fontconfig-devel pcre-devel

# deps
RUN yum install -y redis sqlite mariadb mariadb-server postgresql

# python
RUN yum install -y python-pip python-devel python-lxml python-setuptools

RUN mkdir /var/run/sshd
RUN ssh-keygen -t rsa -q -f /etc/ssh/ssh_host_rsa_key -P ""
RUN ssh-keygen -t dsa -q -f /etc/ssh/ssh_host_dsa_key -P ""
RUN ssh-keygen -t rsa -q -f /root/.ssh/id_rsa -P ""
RUN cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys && chmod 600 /root/.ssh/authorized_keys

RUN echo 'root:123qwe' | chpasswd
RUN sed -i 's/.*session.*required.*pam_loginuid.so.*/session optional pam_loginuid.so/g' /etc/pam.d/sshd
RUN echo -e "LANG=\"en_US.UTF-8\"" > /etc/default/local
RUN localedef -i en_US -f UTF-8 en_US.UTF-8
RUN cp /usr/lib64/mysql/libmysqlclient* /usr/lib64/
RUN rm -rf etc/localtime && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

RUN echo "bind '\"\e[A\":history-search-backward'" >> /root/.bashrc
RUN echo "bind '\"\e[B\":history-search-forward'" >> /root/.bashrc
RUN echo "export HISTTIMEFORMAT='%F %T '" >> /root/.bashrc

EXPOSE 22
RUN chmod u+s /usr/bin/ping

ENV JDK_VERSION 8u91
RUN mkdir -p /opt/jdk
COPY ./jdk-${JDK_VERSION}-linux-x64.tar.gz /opt/jdk/
RUN cd /opt/jdk && tar xvf jdk-${JDK_VERSION}-linux-x64.tar.gz --strip-components=1

RUN /bin/echo 'JAVA_HOME=/opt/jdk' >> /etc/profile
RUN /bin/echo 'PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile
RUN /bin/echo 'CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH' >> /etc/profile
RUN /bin/echo 'export JAVA_HOME CLASSPATH PATH' >> /etc/profile

ENV ES_VERSION 5.1.1
RUN mkdir -p /opt/elasticsearch
COPY ./elasticsearch-${ES_VERSION}.tar.gz /opt/elasticsearch/
RUN cd /opt/elasticsearch && tar xvf elasticsearch-${ES_VERSION}.tar.gz --strip-components=1

RUN /bin/echo 'ES_HOME=/opt/elasticsearch' >> /etc/profile
RUN /bin/echo 'PATH=$PATH:$ES_HOME/bin' >> /etc/profile
RUN /bin/echo 'export ES_HOME PATH' >> /etc/profile

ENV JAVA_HOME /opt/jdk
ENV PATH $PATH:$JAVA_HOME/bin

RUN yum install -y nodejs npm
RUN npm config set strict-ssl false && npm config set registry http://registry.cnpmjs.org
RUN npm install -g gulp grunt-cli bower browser-sync && \
    echo -e "    StrictHostKeyChecking no" >> /etc/ssh/ssh_config

RUN mkdir -p /opt/elasticsearch/data /opt/elasticsearch/logs
VOLUME ["/opt/elasticsearch/data"]
VOLUME ["/opt/elasticsearch/logs"]
VOLUME ["/opt/elasticsearch/config"]

RUN useradd elasticsearch
RUN mkdir -p /opt/elasticsearch/plugins
ADD elasticsearch-analysis-ik-${ES_VERSION}.zip /tmp/
RUN mkdir -p /opt/elasticsearch/plugins/ik
RUN cd /opt/elasticsearch/plugins/ik && unzip /tmp/elasticsearch-analysis-ik-${ES_VERSION}.zip
RUN chown -R elasticsearch:elasticsearch /opt/elasticsearch/*

ADD ./elasticsearch.yml /opt/elasticsearch/config/elasticsearch.yml
RUN cd /opt/elasticsearch/ && wget -c https://github.com/mobz/elasticsearch-head/archive/master.zip \
    && unzip master.zip && mv elasticsearch-head-master elasticsearch-head \
    && cd /opt/elasticsearch/elasticsearch-head && npm install

ADD Gruntfile.js /opt/elasticsearch/elasticsearch-head/Gruntfile.js
ADD ssh_config /root/.ssh/config
RUN chmod 600 /root/.ssh/config
RUN chown root:root /root/.ssh/config

EXPOSE 9100 9200 9300

RUN yum clean all

ADD container-files /

RUN chmod +x /config/bootstrap.sh
RUN chmod +x -f /config/init/*.sh; exit 0

ENTRYPOINT ["/config/bootstrap.sh"]

docker-compose的书写格式如下 docker-compose.yml

version: '2'
services:
    elasticsearch:
        build: .
        image: zailing/elasticsearch
        container_name: elasticsearch
        hostname: elasticsearch
        privileged: true
        read_only: false
        tty: false
        network_mode: "bridge"

        ulimits:
            nofile:
                soft: 102400
                hard: 102400
            memlock:
                soft: -1
                hard: -1

        ports:
            - "123.56.116.82:2228:22"
            - "9100:9100"
            - "9200:9200"
            - "9300:9300"

        volumes:
            - /data/docker/elasticsearch/data:/opt/elasticsearch/data
            - /data/docker/elasticsearch/logs:/opt/elasticsearch/logs
            - /data/docker/elasticsearch/conf:/opt/elasticsearch/config

最好只需要           docker-compose up -d 即可完成部署喔



以上是关于docker一键部署elasticsearch搜索服务器只要3分钟的主要内容,如果未能解决你的问题,请参考以下文章

Docker 简单部署 ElasticSearch

Docker 简单部署 ElasticSearch

Docker 简单部署 ElasticSearch

转Docker 简单部署 ElasticSearch

Docker安装部署ELK教程 (Elasticsearch+Kibana+Logstash+Filebeat)

Docker安装部署ELK教程 (Elasticsearch+Kibana+Logstash+Filebeat)