搭建 Nacos v2.2.2
mkdir -p /root/docker/nacos/logs
mkdir -p /root/docker/nacos/application.properties
mkdir -p /root/docker/nacos/data
docker run --name nacos-standalone-mysql -e MODE=standalone \ -e SPRING_DATASOURCE_PLATFORM=mysql \ -e MYSQL_SERVICE_HOST=xxxxx \ -e MYSQL_SERVICE_PORT=666 \ -e MYSQL_SERVICE_DB_NAME=nacos_config \ -e MYSQL_SERVICE_USER=root \ -e MYSQL_SERVICE_PASSWORD=xxxxxxx \ -v /root/docker/nacos/logs:/home/nacos/logs \ -v /root/docker/nacos/application.properties:/home/nacos/conf/application.properties \ -v /root/docker/nacos/data:/home/nacos/data \ -p 8949:8848 -d nacos/nacos-server:v2.2.2
CockerCompose
version: '3' services: nacos: image: nacos/nacos-server:v2.0.4 container_name: nacos ports: - 8848:8848 - 9848:9848 - 9849:9849 environment: TZ: Asia/Shanghai MODE: standalone SPRING_DATASOURCE_PLATFORM: mysql MYSQL_SERVICE_HOST: 数据库ip MYSQL_SERVICE_PORT: 3306 MYSQL_SERVICE_USER: 数据库用户 MYSQL_SERVICE_PASSWORD: 数据库密码 MYSQL_SERVICE_DB_NAME: 数据库名 MYSQL_SERVICE_DB_PARAM: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC volumes: - /root/docker/nacos/logs/:/home/nacos/logs
搭建Minio 分布式文件管理
Docker部署
docker run -d -p 9000:9000 -p 9001:9001 --name minio \ -e "MINIO_ROOT_USER=admin" \ -e "MINIO_ROOT_PASSWORD=admin123" \ -v /root/minio/data:/data \ -v /root/minio/config:/root/.minio \ minio/minio server --console-address ":9001" /data DockerCompose部署
单机编排
version: '3' services: minio: image: minio/minio hostname: "minio2" ports: - 9010:9010 # api 端口 - 9011:9011 # 控制台端口 environment: MINIO_ACCESS_KEY: admin #管理后台用户名 MINIO_SECRET_KEY: admin123 #管理后台密码,最小8个字符 volumes: - /root/minio/data:/data #映射当前目录下的data目录至容器内/data目录 - /root/minio/config:/root/.minio/ #映射配置目录 command: server --console-address ':9011' /data #指定容器中的目录 /data privileged: true restart: always
集群编排
version: '3' # starts 4 docker containers running minio server instances. # using nginx reverse proxy, load balancing, you can access # it through port 9000. services: minio1: image: minio/minio hostname: minio1 volumes: - data1-1:/data1 - data1-2:/data2 expose: - "9000" - "9001" environment: MINIO_ROOT_USER: minio MINIO_ROOT_PASSWORD: minio123 command: server --console-address ":9001" http://minio{1...4}/data{1...2} healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] interval: 30s timeout: 20s retries: 3 minio2: image: minio/minio hostname: minio2 volumes: - data2-1:/data1 - data2-2:/data2 expose: - "9000" - "9001" environment: MINIO_ROOT_USER: minio MINIO_ROOT_PASSWORD: minio123 command: server --console-address ":9001" http://minio{1...4}/data{1...2} healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] interval: 30s timeout: 20s retries: 3 minio3: image: minio/minio hostname: minio3 volumes: - data3-1:/data1 - data3-2:/data2 expose: - "9000" - "9001" environment: MINIO_ROOT_USER: minio MINIO_ROOT_PASSWORD: minio123 command: server --console-address ":9001" http://minio{1...4}/data{1...2} healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] interval: 30s timeout: 20s retries: 3 minio4: image: minio/minio hostname: minio4 volumes: - data4-1:/data1 - data4-2:/data2 expose: - "9000" - "9001" environment: MINIO_ROOT_USER: minio MINIO_ROOT_PASSWORD: minio123 command: server --console-address ":9001" http://minio{1...4}/data{1...2} healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] interval: 30s timeout: 20s retries: 3 nginx: image: nginx:1.19.2-alpine hostname: nginx volumes: - ./nginx.conf:/etc/nginx/nginx.conf:ro ports: - "9000:9000" - "9001:9001" depends_on: - minio1 - minio2 - minio3 - minio4 ## By default this config uses default local driver, ## For custom volumes replace with volume driver configuration. volumes: data1-1: data1-2: data2-1: data2-2: data3-1: data3-2: data4-1: data4-2:
搭建Redis7.x 分布式缓存
设置挂载redis配置文件地址
mkdir -p docker/redis mkdir docker/data
- data用来存储持久化文件
- conf放置配置文件
把redis.conf放在/docker/redis目录下
redis.conf 配置
# 修改连接为所有ip bind 0.0.0.0 # 允许外网访问 protected-mode no port 6379 timeout 0 # RDB存储配置 save 900 1 save 300 10 save 60 10000 rdbcompression yes dbfilename dump.rdb # 数据存放位置 dir /data # 开启aof配置 appendonly yes appendfsync everysec appendfilename "appendonly.aof" # 设置密码 requirepass "123456"
Docker部署
sudo docker run \ -p 6379:6379 \ --name redis \ -v /docker/redis/redis.conf:/etc/redis/redis.conf \ -v /docker/redis/data:/data \ --restart=always \ -d redis:7.0.4 redis-server /etc/redis/redis.conf docker run \ -p 6379:6379 \ docker与宿主机的端口映射 --name redis \ redis容器的名字 -v /docker/redis/redis.conf:/etc/redis/redis.conf \ 挂载redis.conf文件 -v /docker/redis/data:/data \ 挂在redis的持久化数据 --restart=always \ 设置redis容器随docker启动而自启动 -d redis:7.0.4 redis-server /etc/redis/redis.conf \ 指定redis在docker中的配置文件路径,后台启动redis
redis latest
mkdir -p /root/docker/redis/redis.conf mkdir -p /root/docker/redis/data
docker run -p 6392:6392 --name redis-6392 \ -v /root/docker/redis/redis.conf:/etc/redis/redis.conf \ -v /root/docker/redis/data:/data \ -d redis:latest redis-server /etc/redis/redis.conf --appendonly yes
DockerCompose
version: '3' services: redis: # 镜像名 image: redis:6.2.0 # 容器名 container_name: redis # 重启策略 restart: always # 端口映射 ports: - 6379:6379 environment: # 设置环境变量 时区上海 编码UTF-8 TZ: Asia/Shanghai LANG: en_US.UTF-8 volumes: # 配置文件 - /root/redis/conf/redis.conf:/redis.conf:rw # 数据文件 - /root/redis/data:/data:rw