对应镜像版本:
registry.cn-hangzhou.aliyuncs.com/fugle/elasticsearch:v12
es官方提供的镜像docker.elastic.co/elasticsearch/elasticsearch:5.5.3是以elasticsearch用户作为bootstrap user,无法在容器启动时通过ulimit -l修改memlock为unlimited,导致设置bootstrap.memory_lock: true时启动失败。
需在dockerfile中使用USER root, 且在ENTRYPOINT中使用
chown -R elasticsearch:elasticsearch "$path"
exec gosu elasticsearch $@
关于镜像的source code: https://github.com/hy9418/elasticsearch.git
可直接使用我们的阿里云镜像地址
docker pull registry.cn-hangzhou.aliyuncs.com/fugle/elasticsearch:v12
对应镜像版本:
registry.cn-hangzhou.aliyuncs.com/fugle/elasticsearch:v13
RUN elasticsearch-plugin install x-pack && \
elasticsearch-plugin install analysis-icu && \
elasticsearch-plugin install analysis-phonetic && \
elasticsearch-plugin install analysis-smartcn
git clone https://github.com/medcl/elasticsearch-analysis-ik.git
git clone https://github.com/medcl/elasticsearch-analysis-pinyin.git
进入项目后切换到5.5.3版本tag下编译打包
git checkout v5.5.3
mvn clean package
解压jar包到镜像中
COPY pinyin /usr/share/elasticsearch/plugins/pinyin
COPY ik /usr/share/elasticsearch/plugins/ik
对应镜像版本:
registry.cn-hangzhou.aliyuncs.com/fugle/elasticsearch:v14
添加run.sh
ulimit -l unlimited
if [ -d /configmap ]; then
for z in /configmap/*.yml; do
cat $z >> /usr/share/elasticsearch/config/elasticsearch.yml
done
fi
set -- elasticsearch "$@"
/docker-entrypoint.sh "$@"
容器启动时自动修改memlock
configmap挂载至/configmap目录下,将*.yml文件中的值写至elasticsearch config path的yml中
使用elasticsearch用户启动进程
如master节点configmap:
apiVersion: v1
data:
elasticsearch.yml: |
cluster.name: elasticsearch-cluster
bootstrap.memory_lock: true
discovery.zen.ping.unicast.hosts: elasticsearch-cluster-discovery
node.master: true
node.data: false
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s
node.ingest: true
transport.tcp.port: 9300
transport.host: 0.0.0.0
kind: ConfigMap
metadata:
name: elasticsearch-master-configmap
namespace: ns-elastic
data节点configmap:
apiVersion: v1
data:
elasticsearch.yml: |
cluster.name: elasticsearch-cluster
bootstrap.memory_lock: true
discovery.zen.ping.unicast.hosts: elasticsearch-cluster-discovery
node.master: false
node.data: true
node.ingest: true
discovery.zen.ping_timeout: 5s
transport.host: 0.0.0.0
kind: ConfigMap
metadata:
name: elasticsearch-data-configmap
namespace: ns-elastic
kind: Deployment
apiVersion: apps/v1beta2
metadata:
labels:
elastic-app: elasticsearch-cluster
role: master
name: elasticsearch-master
namespace: ns-elastic
spec:
replicas: 3
revisionHistoryLimit: 10
selector:
matchLabels:
elastic-app: elasticsearch-cluster
role: master
template:
metadata:
labels:
elastic-app: elasticsearch-cluster
role: master
spec:
containers:
- name: elasticsearch-master
image: registry.cn-hangzhou.aliyuncs.com/fugle/elasticsearch:v14
volumeMounts:
- name: elasticsearch-master-configmap
mountPath: /configmap
ports:
- containerPort: 9200
protocol: TCP
- containerPort: 9300
protocol: TCP
env:
- name: "ES_JAVA_OPTS"
value: "-Xms512m -Xmx512m"
securityContext:
privileged: true
volumes:
- name: elasticsearch-master-configmap
configMap:
name: elasticsearch-master-configmap
---
kind: Service
apiVersion: v1
metadata:
labels:
elastic-app: elasticsearch-cluster
name: elasticsearch-cluster-discovery
namespace: ns-elastic
spec:
ports:
- port: 9300
targetPort: 9300
selector:
elastic-app: elasticsearch-cluster
role: master
---
kind: Deployment
apiVersion: apps/v1beta2
metadata:
labels:
elastic-app: elasticsearch-cluster
role: data
name: elasticsearch-data
namespace: ns-elastic
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
elastic-app: elasticsearch-cluster
template:
metadata:
labels:
elastic-app: elasticsearch-cluster
role: data
spec:
containers:
- name: elasticsearch-data
image: registry.cn-hangzhou.aliyuncs.com/fugle/elasticsearch:v14
ports:
- containerPort: 9200
protocol: TCP
- containerPort: 9300
protocol: TCP
volumeMounts:
- name: elasticsearch
mountPath: /usr/share/elasticsearch/data
- name: elasticsearch-data-configmap
mountPath: /configmap
env:
- name: "ES_JAVA_OPTS"
value: "-Xms512m -Xmx512m"
securityContext:
privileged: true
volumes:
- name: elasticsearch
emptyDir: {}
- name: elasticsearch-data-configmap
configMap:
name: elasticsearch-data-configmap
---
kind: Service
apiVersion: v1
metadata:
labels:
elastic-app: elasticsearch-cluster-nodeport
name: elasticsearch-cluster-nodeport
namespace: ns-elastic
spec:
ports:
- port: 9200
targetPort: 9200
selector:
elastic-app: elasticsearch-cluster
type: NodePort
kind: Deployment
apiVersion: apps/v1beta2
metadata:
labels:
elastic-app: elasticsearch-simple
name: elasticsearch-simple
namespace: ns-elastic
spec:
replicas: 1
revisionHistoryLimit: 4
selector:
matchLabels:
elastic-app: elasticsearch-simple
template:
metadata:
labels:
elastic-app: elasticsearch-simple
spec:
containers:
- name: elasticsearch-simple
image: registry.cn-hangzhou.aliyuncs.com/fugle/elasticsearch:v13
ports:
- containerPort: 9200
protocol: TCP
- containerPort: 9300
protocol: TCP
volumeMounts:
- name: elasticsearch-simple
mountPath: /usr/share/elasticsearch/data
env:
- name: "ES_JAVA_OPTS"
value: "-Xms512m -Xmx512m"
securityContext:
privileged: true
volumes:
- name: elasticsearch-simple
persistentVolumeClaim:
claimName: elasticsearch-simple
---
kind: Service
apiVersion: v1
metadata:
labels:
elastic-app: elasticsearch-simple
name: elasticsearch-simple
namespace: ns-elastic
spec:
ports:
- port: 9300
targetPort: 9300
selector:
elastic-app: elasticsearch-simple
---
kind: Service
apiVersion: v1
metadata:
labels:
elastic-app: elasticsearch-simple-nodeport
name: elasticsearch-simple-nodeport
namespace: ns-elastic
spec:
ports:
- port: 9200
targetPort: 9200
selector:
elastic-app: elasticsearch-simple
type: NodePort
注:imagePullSecret、namespace、pv等对象这里不再复述