首页 > 数据库 >【container】【docker-compose】【mysql】【redis】【rabbit mq】【mongo】【elasticsearch】

【container】【docker-compose】【mysql】【redis】【rabbit mq】【mongo】【elasticsearch】

时间:2024-05-08 16:55:33浏览次数:24  
标签:compose container mongo xpack ca ssl certs security config

@

目录


写在前面

  • 相关博文
  • 个人博客首页
  • 免责声明:仅供学习交流使用!开源框架可能存在的风险和相关后果将完全由用户自行承担,本人不承担任何法律责任。

mysql

version: '3'
services:
  mysql:
    image: mysql:8.0.18
    restart: always
    container_name: mysql
    command:
      --default_authentication_plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
      --max_allowed_packet=128M
      --sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
    ports:
      - "3306:3306"
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - $PWD/var/lib/mysql:/var/lib/mysql
      - $PWD/mysqlBackup:/data/mysqlBackup
    environment:
      MYSQL_ROOT_PASSWORD: <root-pass> # mysql root 账户的密码
      MYSQL_DATABASE: <database-name>  # 新建 mysql 数据库名称
      MYSQL_USER: <user>         # 新建 mysql 用户
      MYSQL_PASSWORD: <pass>            # 新建 mysql 密码 

redis

version: '3'
services:
  redis:
    image: redis # 镜像名称以及版本号
    restart: always  # 失败后总是重启
    container_name: redis-6379 # 自定义容器名

    # 文件夹以及文件映射
    volumes:
      - $PWD/data:/data
      - $PWD/logs:/logs
      # 自定义 redis configuration file
    #  - $PWD/redis.conf:/usr/local/etc/redis/redis.conf 
    #command: [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
    command: redis-server --requirepass <pass> # redis 密码 
      # 端口号
    ports:
      - "6379:6379"

rabbit mq

version: '3'
services:
  rabbit-mq:
    hostname: rabbitmq
    # 镜像名称以及版本号
    image: rabbitmq:3-management
    # 失败后总是重启
    restart: always
    # 自定义容器名
    container_name: rabbitmq
    # 文件夹以及文件映射
    volumes:
      - $PWD/etc:/etc/rabbitmq
    #  - $PWD/lib:/var/lib/rabbitmq
      - $PWD/log:/var/log/rabbitmq
    ports:
      # 端口号
      - "5672:5672"
      - "15672:15672"
    environment:
      RABBITMQ_DEFAULT_USER: <user>  # rabbit mq user
      RABBITMQ_DEFAULT_PASS: <pass> # rabbit mq password

mongo

version: '3.1'

services:
  mongo:
    image: mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: <user> # mongo root 用户名 
      MONGO_INITDB_ROOT_PASSWORD: <pass> # mongo root 密码 
      MONGO_INITDB_DATABASE: <database> # mongo database
    ports:
      - "27017:27017"

elasticsearch

单节点

version: '3'
services:
  es:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.13.2
    container_name: es
    environment:
      - "discovery.type=single-node"
      #- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "ELASTIC_PASSWORD=elastic"
    #volumes:
    #  - ./plugins:/usr/share/elasticsearch/plugins #插件文件挂载
    #  - ./data:/usr/share/elasticsearch/data #数据文件挂载
    #  - ./log:/usr/share/elasticsearch/logs
    ports:
      - 9200:9200

多节点

  • .ven
# Password for the 'elastic' user (at least 6 characters)
ELASTIC_PASSWORD=elastic

# Password for the 'kibana_system' user (at least 6 characters)
KIBANA_PASSWORD=elastic

# Version of Elastic products
STACK_VERSION=8.13.2

# Set the cluster name
CLUSTER_NAME=docker-cluster

# Set to 'basic' or 'trial' to automatically start the 30-day trial
LICENSE=basic
#LICENSE=trial

# Port to expose Elasticsearch HTTP API to the host
ES_PORT=9200
#ES_PORT=127.0.0.1:9200

# Port to expose Kibana to the host
KIBANA_PORT=5601
#KIBANA_PORT=80

# Project namespace (defaults to the current folder name if not set)
#COMPOSE_PROJECT_NAME=myproject

# Increase or decrease based on the available host memory (in bytes)
MEM_LIMIT=1073741824
  • mem limit

设置为至少vm.max_map_count262144编辑
内核设置必须设置为至少用于生产用途。vm.max_map_count262144

[Linux]

1. 若要在实时系统上应用该设置,请运行:
sysctl -w vm.max_map_count=262144

2. 要永久更改设置的值,请更新 中的值。
vm.max_map_count/etc/sysctl.conf
vm.max_map_count=262144

[macOS with Docker] 

1. 在命令行中,运行:
screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty

2. 按回车键并使用配置:sysctlvm.max_map_count
sysctl -w vm.max_map_count=262144

[docker desktop]

1. sudo sysctl -w vm.max_map_count=262144

带有 Docker 桌面 WSL 2 后端的 Windows编辑
该设置必须在“docker-desktop”WSL 实例中设置,然后 Elasticsearch 容器将正确启动。有几种方法可以做到这一点,这取决于 在你的 Windows 版本和 WSL 版本上。vm.max_map_count

1.1 如果你使用的是版本 22H2 之前的 Windows 10,或者如果你使用的是 Windows 10 版本 22H2,请使用 WSL 的内置版本,每次重新启动 Docker 时都必须手动设置它,然后才能启动 您的 Elasticsearch 容器,或者(如果您不希望在每次重新启动时都这样做)您必须全局设置 每个 WSL2 实例都已更改。这是因为这些版本的 WSL 不要正确处理 /etc/sysctl.conf 文件。vm.max_map_count

若要在每次重新启动时手动设置它,必须在命令提示符下运行以下命令 或每次重启 Docker 时的 PowerShell 窗口:

wsl -d docker-desktop -u root
sysctl -w vm.max_map_count=262144

1.2 如果你使用的是这些版本的 WSL,并且你不希望每次都运行这些命令 重新启动 Docker 时,可以使用此设置全局更改每个 WSL 分配 通过修改 %USERPROFILE%\.wslconfig,如下所示:

[wsl2]
1. kernelCommandLine = "sysctl.vm.max_map_count=262144"
这将导致所有 WSL2 VM 在启动时分配该设置。

2. 如果你使用的是 Windows 11 或 Windows 10 版本 22H2 并已安装 Microsoft Store WSL 版本,可以在“docker-desktop”WSL 中修改 /etc/sysctl.conf 分发,也许使用这样的命令:

wsl -d docker-desktop -u root
vi /etc/sysctl.conf
并附上一行内容如下:

vm.max_map_count = 262144

  • docker-compose
version: "2.2"

services:
  setup:
    image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
    volumes:
      - ./certs:/usr/share/elasticsearch/config/certs
    user: "0"
    command: >
      bash -c '
        if [ x${ELASTIC_PASSWORD} == x ]; then
          echo "Set the ELASTIC_PASSWORD environment variable in the .env file";
          exit 1;
        elif [ x${KIBANA_PASSWORD} == x ]; then
          echo "Set the KIBANA_PASSWORD environment variable in the .env file";
          exit 1;
        fi;
        if [ ! -f config/certs/ca.zip ]; then
          echo "Creating CA";
          bin/elasticsearch-certutil ca --silent --pem -out config/certs/ca.zip;
          unzip config/certs/ca.zip -d config/certs;
        fi;
        if [ ! -f config/certs/certs.zip ]; then
          echo "Creating certs";
          echo -ne \
          "instances:\n"\
          "  - name: es01\n"\
          "    dns:\n"\
          "      - es01\n"\
          "      - localhost\n"\
          "    ip:\n"\
          "      - 127.0.0.1\n"\
          "  - name: es02\n"\
          "    dns:\n"\
          "      - es02\n"\
          "      - localhost\n"\
          "    ip:\n"\
          "      - 127.0.0.1\n"\
          "  - name: es03\n"\
          "    dns:\n"\
          "      - es03\n"\
          "      - localhost\n"\
          "    ip:\n"\
          "      - 127.0.0.1\n"\
          > config/certs/instances.yml;
          bin/elasticsearch-certutil cert --silent --pem -out config/certs/certs.zip --in config/certs/instances.yml --ca-cert config/certs/ca/ca.crt --ca-key config/certs/ca/ca.key;
          unzip config/certs/certs.zip -d config/certs;
        fi;
        echo "Setting file permissions"
        chown -R root:root config/certs;
        find . -type d -exec chmod 750 \{\} \;;
        find . -type f -exec chmod 640 \{\} \;;
        echo "Waiting for Elasticsearch availability";
        until curl -s --cacert config/certs/ca/ca.crt https://es01:9200 | grep -q "missing authentication credentials"; do sleep 30; done;
        echo "Setting kibana_system password";
        until curl -s -X POST --cacert config/certs/ca/ca.crt -u "elastic:${ELASTIC_PASSWORD}" -H "Content-Type: application/json" https://es01:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_PASSWORD}\"}" | grep -q "^{}"; do sleep 10; done;
        echo "All done!";
      '
    healthcheck:
      test: ["CMD-SHELL", "[ -f config/certs/es01/es01.crt ]"]
      interval: 1s
      timeout: 5s
      retries: 120

  es01:
    depends_on:
      setup:
        condition: service_healthy
    image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
    volumes:
      - ./certs:/usr/share/elasticsearch/config/certs
      - ./esdata01:/usr/share/elasticsearch/data
    ports:
      - ${ES_PORT}:9200
    environment:
      - node.name=es01
      - cluster.name=${CLUSTER_NAME}
      - cluster.initial_master_nodes=es01,es02,es03
      - discovery.seed_hosts=es02,es03
      - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
      - bootstrap.memory_lock=true
      - xpack.security.enabled=true
      - xpack.security.http.ssl.enabled=true
      - xpack.security.http.ssl.key=certs/es01/es01.key
      - xpack.security.http.ssl.certificate=certs/es01/es01.crt
      - xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
      - xpack.security.transport.ssl.enabled=true
      - xpack.security.transport.ssl.key=certs/es01/es01.key
      - xpack.security.transport.ssl.certificate=certs/es01/es01.crt
      - xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
      - xpack.security.transport.ssl.verification_mode=certificate
      - xpack.license.self_generated.type=${LICENSE}
    mem_limit: ${MEM_LIMIT}
    ulimits:
      memlock:
        soft: -1
        hard: -1
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
        ]
      interval: 10s
      timeout: 10s
      retries: 120

  es02:
    depends_on:
      - es01
    image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
    volumes:
      - ./certs:/usr/share/elasticsearch/config/certs
      - ./esdata02:/usr/share/elasticsearch/data
    environment:
      - node.name=es02
      - cluster.name=${CLUSTER_NAME}
      - cluster.initial_master_nodes=es01,es02,es03
      - discovery.seed_hosts=es01,es03
      - bootstrap.memory_lock=true
      - xpack.security.enabled=true
      - xpack.security.http.ssl.enabled=true
      - xpack.security.http.ssl.key=certs/es02/es02.key
      - xpack.security.http.ssl.certificate=certs/es02/es02.crt
      - xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
      - xpack.security.transport.ssl.enabled=true
      - xpack.security.transport.ssl.key=certs/es02/es02.key
      - xpack.security.transport.ssl.certificate=certs/es02/es02.crt
      - xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
      - xpack.security.transport.ssl.verification_mode=certificate
      - xpack.license.self_generated.type=${LICENSE}
    mem_limit: ${MEM_LIMIT}
    ulimits:
      memlock:
        soft: -1
        hard: -1
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
        ]
      interval: 10s
      timeout: 10s
      retries: 120

  es03:
    depends_on:
      - es02
    image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
    volumes:
      - ./certs:/usr/share/elasticsearch/config/certs
      - ./esdata03:/usr/share/elasticsearch/data
    environment:
      - node.name=es03
      - cluster.name=${CLUSTER_NAME}
      - cluster.initial_master_nodes=es01,es02,es03
      - discovery.seed_hosts=es01,es02
      - bootstrap.memory_lock=true
      - xpack.security.enabled=true
      - xpack.security.http.ssl.enabled=true
      - xpack.security.http.ssl.key=certs/es03/es03.key
      - xpack.security.http.ssl.certificate=certs/es03/es03.crt
      - xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
      - xpack.security.transport.ssl.enabled=true
      - xpack.security.transport.ssl.key=certs/es03/es03.key
      - xpack.security.transport.ssl.certificate=certs/es03/es03.crt
      - xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
      - xpack.security.transport.ssl.verification_mode=certificate
      - xpack.license.self_generated.type=${LICENSE}
    mem_limit: ${MEM_LIMIT}
    ulimits:
      memlock:
        soft: -1
        hard: -1
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
        ]
      interval: 10s
      timeout: 10s
      retries: 120

  kibana:
    depends_on:
      es01:
        condition: service_healthy
      es02:
        condition: service_healthy
      es03:
        condition: service_healthy
    image: docker.elastic.co/kibana/kibana:${STACK_VERSION}
    volumes:
      - ./certs:/usr/share/kibana/config/certs
      - ./kibanadata:/usr/share/kibana/data
    ports:
      - ${KIBANA_PORT}:5601
    environment:
      - SERVERNAME=kibana
      - ELASTICSEARCH_HOSTS=https://es01:9200
      - ELASTICSEARCH_USERNAME=kibana_system
      - ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD}
      - ELASTICSEARCH_SSL_CERTIFICATEAUTHORITIES=config/certs/ca/ca.crt
    mem_limit: ${MEM_LIMIT}
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'",
        ]
      interval: 10s
      timeout: 10s
      retries: 120


参考资料

docker

kubernetes

helm

k3s

标签:compose,container,mongo,xpack,ca,ssl,certs,security,config
From: https://www.cnblogs.com/nones/p/18174946

相关文章

  • MongoDB索引
    MongoDB索引概述索引支持在MongoDB中高效地执行查询。如果没有索引,MongoDB必须执行全集合扫描,即扫描集合中的每个文档,以选择与查询语句匹配的文档。这种扫描全集合的查询效率是非常低的,特别在处理大量的数据时,查询可以要花费几十秒甚至几分钟,这对网站的性能是非常致命的。如果......
  • pymongo:Python下 MongoDB 的存储操作
    1.连接mongodb#########方法一##########importpymongo#MongoClient()返回一个mongodb的连接对象clientclient=pymongo.MongoClient(host="localhost",port=27017)#########方法二##########importpymongo#MongoClient的第一个参数host还可以直接传MongoDB......
  • Golang gin 框架使用 MongoDB 进行多表联查,以及分组查询
    主要针对gin框架中如何使用假设两张表order表{"_id":ObjectId("65aa2b2203abce203bbe3c7a"),"name":"骆驼祥子","route":"/test/v2/desktop","bookshelf":"03"}orderRemark表{......
  • 使用 docker-compose 部署 nexus
    本篇博客主要介绍如何通过docker-compose快速搭建nexus服务,毕竟目前采用容器化部署是一件更加快速轻松的方案。之前的博客已经介绍过nexus的搭建,以及为IDEA和VisualStudio提供代理服务,这里就不详细介绍了,提供出之前博客的链接。nexus在windows上的搭建:https://www......
  • docker-compose 安装 harbor
     参考:https://blog.csdn.net/ladymorgana/article/details/1299450101、在https://github.com/goharbor/harbor/releases下载harbor-offline-installer-v2.10.1.tgz 2、将下载的包上传到/opt并解压,解压完成后,在当前目录生成harbor目录/opt//harbortar-zxvfharbor-offlin......
  • MongoDB基本常用命令
    MongoDB基本常用命令数据库操作选择和创建数据库选择和创建数据库的语法格式:use数据库名称如果数据库不存在则自动创建,例如,以下语句创建articledb数据库:usearticledb查看有权限查看的所有的数据库命令showdbs或showdatabases注意:在MongoDB中,集合只有在内......
  • AI 数据观 | TapData Cloud + MongoDB Atlas:大模型与 RAG 技术有机结合,落地实时工单处
    本篇为「AI数据观」系列文章第二弹,在这里,我们将进一步探讨AI行业的数据价值。以RAG的智能工单应用场景为例,共同探索如何使用TapdataCloud+MongoDBAtlas实现具备实时更新能力的向量数据库,为企业工单处理的智能化和自动化需求,提供准实时的新鲜数据。完整分布教程指引,详见......
  • Linux CentOS7 环境下安装 MongoDB
    一、环境准备操作系统:LinuxCentOS7.9安装包:mongodb-linux-x86_64-rhel70-4.4.29.tgz二、安装包下载官网下载地址:https://www.mongodb.com/try/download/community三、软件安装和启动3.1将下载好的安装包上传到Linux服务器某个目录下,使用以下命令解压压缩包tar-zxvf......
  • docker网络配置:bridge模式、host模式、container模式、none模式
    在docker平台里有四种网络模式,今天继续分享一下它们的常用知识,进一步加深对docker技术的理解。1、docker网络模式分类dockerrun创建Docker容器时,可以用--net选项指定容器的网络模式,Docker主要有以下4种网络模式。bridge模式:--net=bridge如果不指定的话默认设置。host模式......
  • docker-compose+nginx实现服务不中断更新
    思路是写一个脚本,docker-composescale扩容,然后重写nginx配置文件,刷新负载均衡nginx重写的配置文件,文件名service,里面只有upstream,例如:upstreame-chatbot-server-dev{server0.0.0.0:8080;server0.0.0.0:8081;}脚本使用方法:./rollupdate.sh--service=test-serve......