目录
- [1. Mysql](#1. Mysql)
- [2. Redis](#2. Redis)
- [3. Nginx](#3. Nginx)
- [4. Elasticsearch](#4. Elasticsearch)
docker pull 容器名:版本号 拉取容器, 不指定版本号默认最新的
run 运行
-d 后台运行
-p 3306:3306 -p是port 对外端口:对内端口
--name xyy_mysql 容器名称
-e MYSQL_ROOT_PASSWORD=123456 环境变量
-v 系统地址:docker地址 docker 地址映射系统地址
docker exec -it 容器名称 bash 可以进入该容器,进行操作
最后指定启动那个镜像:版本
1. Mysql
shell
# 拉去mysql
docker pull mysql:version
# 启动mysql
docker run -p 3306:3306 --name xyy_mysql -e MYSQL_ROOT_PASSWORD=123456 -v D:/docker/mysql/data:/var/lib/mysql -d mysql:版本 --character-set-server=utf8mb4
后续不需要重复这么启动, 只需要以下方式即可启动, 其他同理
shell
docker start xyy_mysql
2. Redis
shell
docker pull redis:version
-
创建网络 里面有个
IPAM.Config.Gateway
的值记下来, 是网络ipshell# 删除网络信息 docker network rm redis_network # 重新创建子网指定subnet, 172.21这个很重要 docker network create --subnet 172.21.0.0/16 redis_network # 查看网络信息 `IPAM.Config.Subnet`的值 docker network inspect redis_network
-
创建本地磁盘和容器映射
shellvim conf\node-1\redis.conf vim conf\node-2\redis.conf vim conf\node-3\redis.conf `vim redis.conf` # 分别写入以下配置 port 6379 #端口 bind 0.0.0.0 #开其他设备访问权限 cluster-enabled yes #集群支持 cluster-config-file nodes.conf # 节点配置文件 cluster-node-timeout 5000 # 节点超时 cluster-announce-ip 172.21.0.11 ##node2 node3 分别+1 cluster-announce-port 6379 cluster-announce-bus-port 16379 appendonly yes #持久化 requirepass 123456 # 密码
-
启动redis
shelldocker run -p 6371:6379 -p 16371:16379 --name redis-1 -v D:\docker\redis\data\node-1:/data -v D:\docker\redis\conf\node-1\redis.conf:/etc/redis/redis.conf --net redis_network --ip 172.21.0.11 -d redis redis-server /etc/redis/redis.conf docker run -p 6372:6379 -p 16372:16379 --name redis-2 -v D:\docker\redis\data\node-2:/data -v D:\docker\redis\conf\node-2\redis.conf:/etc/redis/redis.conf --net redis_network --ip 172.21.0.12 -d redis redis-server /etc/redis/redis.conf docker run -p 6373:6379 -p 16373:16379 --name redis-3 -v D:\docker\redis\data\node-3:/data -v D:\docker\redis\conf\node-3\redis.conf:/etc/redis/redis.conf --net redis_network --ip 172.21.0.13 -d redis redis-server /etc/redis/redis.conf
-
集群配置
--cluster-replicas 1
表示每台主节点至少需要一个从节点shell# 进入redis-1 控制台 docker exec -it redis-1 bash # 集群配置 redis-cli --cluster [-replicas 1] create 172.21.0.11:6379 172.21.0.12:6379 172.21.0.13:6379
-
检查集群信息
shell# 登录 redis-cli -c # 认证密码 auth "123456" # 集群信息 cluster info # 节点信息 cluster nodes
3. Nginx
-
拉取nginx
shelldocker pull nginx:version
-
启动 nginx 并查看容器id
shelldocker run -p 9998:80 --name nginx -d nginx:版本 docker ps # 查看容器id
-
将nginx中的conf文件复制出来
docker下nginx的目录就是这里
shelldocker cp 容器ID:/etc/nginx/nginx.conf /server/nginx/conf
-
创建几个文件夹
shellmkdir -p /server/nginx/logs #日志 mkdir -p /server/nginx/conf #配置
-
停止之前的镜像并删除
shelldocker stop nginx docker rm nginx
-
重新启动nginx镜像配置
shelldocker run -d -p 9999:80 --name nginx -v /server/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /server/nginx/logs:/var/log/nginx --privileged=true nginx:1.17.8
4. Elasticsearch
-
拉取es
shelldocker pull docker.elastic.co/elasticsearch/elasticsearch:8.13.3
-
创建网络
shelldocker network create es_network
-
创建映射文件夹
shellmkdir -p D:/docker/es/conf mkdir -p D:/docker/es/data mkdir -p D:/docker/es/plugins echo "http.host : 0.0.0.0" >> D:/docker/es/conf/elasticsearch.yml
-
启动
discovery.type=single-node
单节点启动shelldocker run --name es -p 9200:9200 -p 9300:9300 \ -e "discovery.type=single-node"\ -e ES_JAVA_OPTS="-Xms64m -Xmx128m" -v D:/docker/es/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml\ -v D:/docker/es/data:/usr/share/elasticsearch/data\ -v D:/docker/es/plugins:/usr/share/elasticsearch/plugins\ -d elasticsearch:8.13.3
shelldocker run --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx128m" -v D:/docker/es/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v D:/docker/es/data:/usr/share/elasticsearch/data -v D:/docker/es/plugins:/usr/share/elasticsearch/plugins -d elasticsearch:8.13.3
-
下载ik分词器
下载地址: https://github.com/infinilabs/analysis-ik/releases/tag/v8.13.3
将对应下载好的zip安装包解压到
D:/docker/es/plugins
因为之前做了映射. (ps: 不要将压缩包放到目录下, 这个目录只放插件) -
将ik分词器作为默认分词器
ES的默认分词是standard, 会在分割中文时将每个汉字都拆分开,
IK分词器有两种设置, 一种是
ik_smart 最少分片
, 会将 "清华大学" 分为 "清华大学" , 另一种是ik_max_word 最细分片
会将"清华大学" 分为 "清华","大学"jsonPUT /school_index { "setting":{ "index":{ "analysis.analyzer.default.type":"ik_max_word" } } }
官网指导
官方指导链接: https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
集群模式下其中两个文件进行了修改:
-
c
# es 密码, 6位数起 ELASTIC_PASSWORD=123456 # kabana 密码, 6位数起 KIBANA_PASSWORD=123456 # es安装版本 STACK_VERSION=8.13.3 # 集群名称 CLUSTER_NAME=docker-es-cluster # 简单模式或者试用模式(30天) LICENSE=basic #LICENSE=trial # 映射ip, 如果指定端口则只有指定机器可以访问 ES_PORT=9200 #ES_PORT=127.0.0.1:9200 # kabana端口 KIBANA_PORT=5601 #KIBANA_PORT=80 # 内存大小(in bytes) MEM_LIMIT=1073741824 # 名称前缀 #COMPOSE_PROJECT_NAME=es
-
yml
version: "2.2" services: setup: image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION} volumes: - D:/docker/es/config/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: - D:/docker/es/config/certs:/usr/share/elasticsearch/config/certs - D:/docker/es/data/note01:/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: - D:/docker/es/config/certs:/usr/share/elasticsearch/config/certs - D:/docker/es/data/note02:/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: - D:/docker/es/config/certs:/usr/share/elasticsearch/config/certs - D:/docker/es/data/note03:/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: - D:/docker/es/config/certs:/usr/share/kibana/config/certs - D:/docker/es/data/kabana:/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 volumes: certs: driver: local esdata01: driver: local esdata02: driver: local esdata03: driver: local kibanadata: driver: local