《docker+k8s教程》

安装docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

在/etc/sysctl.conf中添加vm.max_map_count=262144
vim /etc/sysctl.conf
vm.max_map_count=262144

#使配置生效
sysctl -p

创建volume挂载目录,并修改目录用户和用户组。由于elasticsearch6之后不允许使用root启用,所以需要修改/usr/share/elasticsearch/data的权限为1000
mkdir -pv /usr/share/elasticsearch/data
chown 1000:1000 /usr/share/elasticsearch/data

编写部署文件
mkdir /usr/local/elasticsearch-kibana
cd elasticsearch-kibana/
vim docker-compose.yml

version: '2.2'
services:
  elasticsearch:
    image: elasticsearch:6.6.2
    container_name: elasticsearch
    environment:
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    volumes:
      - /usr/share/elasticsearch/data:/usr/share/elasticsearch/data
      - ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
    ports:
      - 9200:9200
      - 9300:9300
    mem_limit: 1024m
    restart: always
  kibana:
    image: kibana:6.6.2
    container_name: kibana
    ports:
      - 5601:5601
    depends_on:
      - elasticsearch
    mem_limit: 512m
    restart: always

vim elasticsearch.yml

#集群名
cluster.name: "elasticsearch"
# 允许外部网络访问
network.host: 0.0.0.0
#支持跨域
http.cors.enabled: true
#支持所有域名
http.cors.allow-origin: "*"
# 关闭xpack安全校验,在kibana中使用就不需要输入账号密码
xpack.security.enabled: false

后台启动elasticsearch和kibana容器  

docker-compose up -d


停止      docker-compose down
停止并卸载volumes      docker-compose down -v

检查elasticsearch是否启动成功

curl 127.0.0.1:9200 

访问kibana

http://主机ip:5601

点击 Dev Tools菜单

再点击下图中的三角形运行查询语句

 

官方安装教程https://www.elastic.co/guide/en/elasticsearch/reference/6.4/docker.html

 

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐