当前位置:网站首页>Deploy redis sentinel mode using bitnamiredis Sentinel
Deploy redis sentinel mode using bitnamiredis Sentinel
2022-06-27 12:57:00 【Qiyan】
Use bitnami/redis-sentinel Deploy Redis Sentinel mode
Why use Bitnami Mirror image ?
- Bitnami Closely track upstream source code changes , And use our automation system to release the new version of this image in time .
- With the help of Bitnami Mirror image , The latest bug fixes and functions can be provided as soon as possible .
- Bitnami Containers 、 Virtual machines and cloud images use the same components and configuration methods - You can easily switch formats according to your project needs .
- All our images are based on minideb, This is a base Debian Minimalist container image of , It provides you with a small base container for mirroring and leading Linux Familiarity with the distribution .
- Docker Hub All available in Bitnami All images use Docker Content Trust (DCT) To sign . You can use it
DOCKER_CONTENT_TRUST=1To verify the integrity of the image . - Bitnami Container images are published regularly , And provide the latest distribution package .
Get this image
obtain Bitnami Redis Sentinel Docker The recommended method of mirroring is from Docker Hub Registry Extract the pre built image .
docker pull bitnami/redis-sentinel:latest
To use a specific version , You can pull the versioning tab . You can Docker Hub Registry View in List of available versions .
docker pull bitnami/redis-sentinel:[TAG]
If you will , You can also build your own image .
docker build -t bitnami/redis-sentinel:latest 'https://github.com/bitnami/bitnami-docker-redis-sentinel.git#master:7.0/debian-11'
Connect to other containers
Use Docker Container network , Your application container can easily access the Redis The server .
Containers connected to the same network can communicate with each other using the container name as the host name .
Using the command line
In this example , We Will create a Redis Sentinel example , The instance will be monitored on the same docker Running on the network Redis example .
The first 1 Step : Creating networks
docker network create redis-sharednet --driver bridge
# swarm Cross node
docker network create -d overlay --attachable redis-sharednet
The first 2 Step : start-up Redis example
Using the command --network app-tier Parameters , take Redis The container is attached to app-tier The Internet .
# From the node docker run -d --name redis-server \
-e ALLOW_EMPTY_PASSWORD=yes \
--network app-tier \
bitnami/redis:4.0.14
# swarm Cross node
# Master node
docker run -d --name redis-server -p 6388:6379\
-e REDIS_REPLICATION_MODE=master \
-e REDIS_PASSWORD=root123 \
--network redis-sharednet \
bitnami/redis:4.0.14
The first 3 Step : Start your Redis Sentinel example
Last , Let's create a new container instance to start Redis Client and connect to the server created in the previous step :
docker run -it --rm \
-e REDIS_MASTER_HOST=redis-server \
--network app-tier \
bitnami/redis-sentinel:4.0.14
# swarm Cross node
# From the node
docker run -d --name redis-slave -p 6399:6379\
-e REDIS_REPLICATION_MODE=slave \
-e REDIS_MASTER_HOST=redis-server \
-e REDIS_MASTER_PASSWORD=root123 \
-e REDIS_PASSWORD=root123 \
--network redis-sharednet \
bitnami/redis:4.0.14
# The sentinel node
docker run -d --name redis-sentinel \
-e REDIS_MASTER_HOST=redis-server \
-e REDIS_MASTER_PASSWORD=root123 \
--network redis-sharednet \
bitnami/redis-sentinel:4.0.14
docker run -d --name redis-sentinel-02 \
-e REDIS_MASTER_HOST=redis-server \
-e REDIS_MASTER_PASSWORD=root123 \
--network redis-sharednet \
bitnami/redis-sentinel:4.0.14
docker run -d --name redis-sentinel-03 \
-e REDIS_MASTER_HOST=redis-server \
-e REDIS_MASTER_PASSWORD=root123 \
--network redis-sharednet \
bitnami/redis-sentinel:4.0.14
Use Docker writing
If not specified ,Docker Compose A new network is automatically set up and all deployed services are attached to the network . however , We will clearly define a bridge be known as The new network app-tier. In this example , Let's assume that you want to connect to... From your own custom application image Redis The server , The image is identified by the service name in the following code snippet myapp.
version: '2'
networks:
app-tier:
driver: bridge
services:
redis:
image: 'bitnami/redis:latest'
environment:
- ALLOW_EMPTY_PASSWORD=yes
networks:
- app-tier
redis-sentinel:
image: 'bitnami/redis-sentinel:latest'
environment:
- REDIS_MASTER_HOST=redis
ports:
- '26379:26379'
networks:
- app-tier
Start the container with the following command :
docker-compose up -d
Use master-slave settings
stay Master-Slave Use in settings Sentinel when , If you want to set Master and Slave The password of the node , Consider setting for them identical REDIS_PASSWORD Password REDIS_MASTER_PASSWORD(#23).
version: '2'
networks:
app-tier:
driver: bridge
services:
redis:
image: 'bitnami/redis:latest'
environment:
- REDIS_REPLICATION_MODE=master
- REDIS_PASSWORD=str0ng_passw0rd
networks:
- app-tier
ports:
- '6379'
redis-slave:
image: 'bitnami/redis:latest'
environment:
- REDIS_REPLICATION_MODE=slave
- REDIS_MASTER_HOST=redis
- REDIS_MASTER_PASSWORD=str0ng_passw0rd
- REDIS_PASSWORD=str0ng_passw0rd
ports:
- '6379'
depends_on:
- redis
networks:
- app-tier
redis-sentinel:
image: 'bitnami/redis-sentinel:latest'
environment:
- REDIS_MASTER_PASSWORD=str0ng_passw0rd
depends_on:
- redis
- redis-slave
ports:
- '26379-26381:26379'
networks:
- app-tier
Start the container with the following command :
docker-compose up --scale redis-sentinel=3 -d
To configure
environment variable
Redis Sentinel Instances can be customized by specifying environment variables at the first run . Provide the following environment values to customize Redis Sentinel:
REDIS_MASTER_HOST: To monitor Redis Main control host . The default value is :redis.REDIS_MASTER_PORT_NUMBER: To monitor Redis master The port of . The default value is :6379.REDIS_MASTER_SET: To monitor Redis Name of the instance set . The default value is :mymaster.REDIS_MASTER_PASSWORD: Password to authenticate with the primary server . No default . As an alternative , You can use the password to mount the file and setREDIS_MASTER_PASSWORD_FILEVariable .REDIS_MASTER_USER: by master Enable ACL User name for authentication when . No default . This only applies to Redis 6 Or later . If not specified ,Redis Sentinel Will attempt to authenticate with password only ( Usesentinel auth-pass <master-name> <password>).REDIS_SENTINEL_PORT_NUMBER:Redis Sentinel port . The default value is :26379.REDIS_SENTINEL_QUORUM: If you need it master The fact that it is inaccessible Sentinel Number . The default value is :2.REDIS_SENTINEL_PASSWORD: A password that uses this sentinel to authenticate and authenticate with other sentinels . No default . All sentinels need to be the same . As an alternative , You can use the password to mount the file and setREDIS_SENTINEL_PASSWORD_FILEVariable .REDIS_SENTINEL_DOWN_AFTER_MILLISECONDS: announce master Number of milliseconds before shutdown . The default value is :60000.REDIS_SENTINEL_FAILOVER_TIMEOUT: Specify failover timeout in milliseconds . The default value is :180000.REDIS_SENTINEL_RESOLVE_HOSTNAMES: Enable sentinel hostname support . This only applies to Redis 6.2 Or later . The default value is : no .REDIS_SENTINEL_TLS_ENABLED: Whether to enable... For traffic TLS. The default value is : no .REDIS_SENTINEL_TLS_PORT_NUMBER: be used for TLS Port for secure traffic . The default value is :26379.REDIS_SENTINEL_TLS_CERT_FILE: contain TLS Traffic certificate file . No default .REDIS_SENTINEL_TLS_KEY_FILE: File containing certificate key . No default .REDIS_SENTINEL_TLS_CA_FILE: Include certificate CA The file of . No default .REDIS_SENTINEL_TLS_DH_PARAMS_FILE: contain DH Parameter file ( In order to support DH Password ). No default .REDIS_SENTINEL_TLS_AUTH_CLIENTS: Whether the client is required to authenticate . The default value is : yes .REDIS_SENTINEL_ANNOUNCE_IP: stay HELLO The specified... Is used in the message IP Address to gossip about its existence . The default value is : Automatically detected local address .REDIS_SENTINEL_ANNOUNCE_PORT: Use HELLO Specify the port in the message to gossip about its existence . The default value is : stay The port specified inREDIS_SENTINEL_PORT_NUMBER.
Protect Redis Sentinel Traffic
From version 6 Start ,Redis Added right SSL/TLS Connection support . If you want to enable this optional feature , You can use the above REDIS_SENTINEL_TLS_* Environment variables to configure the application .
Enable TLS when , General standard traffic is disabled by default . However , This new feature is not mutually exclusive , This means you can listen at the same time TLS He Fei TLS Connect . To enable non TLS Traffic , Please set up REDIS_SENTINEL_PORT_NUMBER Different from 0.
Use
docker rundocker run --name redis-sentinel \ -v /path/to/certs:/opt/bitnami/redis/certs \ -v /path/to/redis-sentinel/persistence:/bitnami \ -e REDIS_MASTER_HOST=redis \ -e REDIS_SENTINEL_TLS_ENABLED=yes \ -e REDIS_SENTINEL_TLS_CERT_FILE=/opt/bitnami/redis/certs/redis.crt \ -e REDIS_SENTINEL_TLS_KEY_FILE=/opt/bitnami/redis/certs/redis.key \ -e REDIS_SENTINEL_TLS_CA_FILE=/opt/bitnami/redis/certs/redisCA.crt \ bitnami/redis-cluster:latest bitnami/redis-sentinel:latestmodify
docker-compose.ymlFiles that exist in this repository :redis-sentinel: ... environment: ... - REDIS_SENTINEL_TLS_ENABLED=yes - REDIS_SENTINEL_TLS_CERT_FILE=/opt/bitnami/redis/certs/redis.crt - REDIS_SENTINEL_TLS_KEY_FILE=/opt/bitnami/redis/certs/redis.key - REDIS_SENTINEL_TLS_CA_FILE=/opt/bitnami/redis/certs/redisCA.crt ... volumes: - /path/to/certs:/opt/bitnami/redis/certs ... ...
perhaps , You can also be in Customize This configuration is provided in the configuration file .
The configuration file
The image is in /bitnami/redis-sentinel/conf/. You can /bitnami stay /path/to/redis-persistence/redis-sentinel/conf/. conf/ If the directory is empty , The default configuration will be populated into the directory .
The first 1 Step : function Redis Sentinel Mirror image
function Redis Sentinel Mirror image , Mount a directory from your host .
docker run --name redis-sentinel \
-e REDIS_MASTER_HOST=redis \
-v /path/to/redis-sentinel/persistence:/bitnami \
bitnami/redis-sentinel:latest
You can also modify docker-compose.yml Files that exist in this repository :
services:
redis-sentinel:
...
volumes:
- /path/to/redis-persistence:/bitnami
...
The first 2 Step : Edit the configuration
Use your favorite editor to edit the configuration on the host .
vi /path/to/redis-persistence/redis-sentinel/conf/redis.conf
The first 3 Step : Restart Redis
After changing the configuration , Restart Redis Container for changes to take effect .
docker restart redis
Or use Docker writing :
docker-compose restart redis
Complete list of configuration options , see also Redis To configure manual .
logging
Bitnami Redis Sentinel Docker Image Send container logs to stdout. Check the log :
docker logs redis
Or use Docker writing :
docker-compose logs redis
If you want to use container logging differently , You can use this option to configure the container Logging driver .--log-driver In the default configuration ,docker Use json-file The driver .
maintain
Promote this image
Bitnami The latest version will be available soon after upstream production Redis Sentinel, Including security patches . We recommend that you follow these steps to upgrade your container .
The first 1 Step : Get the updated image
docker pull bitnami/redis-sentinel:latest
perhaps , If you're using Docker Compose, Please put image The value of the property is updated to bitnami/redis-sentinel:latest.
The first 2 Step : Stop and back up the currently running container
Use the command to stop the currently running container
docker stop redis
Or use Docker writing :
docker-compose stop redis
Next , Use the following command to take a snapshot of the persistent volume /path/to/redis-persistence:
rsync -a /path/to/redis-persistence /path/to/redis-persistence.bkp.$(date +%Y%m%d-%H.%M.%S)
The third step : Remove the currently running container
docker rm -v redis
Or use Docker writing :
docker-compose rm -v redis
Step four : Run the new image
Recreate your container from a new image .
docker run --name redis bitnami/redis-sentinel:latest
Or use Docker writing :
docker-compose up redis
边栏推荐
- Picocli getting started
- Custom multithreading base class threading Event
- AI for Science: scientific research paradigm, open source platform and industrial form
- VS调试技巧
- Quanzhi A13 tossing memo
- Configuration of thymeleaf
- Nifi from introduction to practice (nanny level tutorial) - identity authentication
- printf不定长参数原理
- What is the next step in the recommendation system? Alispacetime aggregates GNN, and the effect is to sling lightgcn!
- Nmcli team bridge basic configuration
猜你喜欢

What is the next step in the recommendation system? Alispacetime aggregates GNN, and the effect is to sling lightgcn!

Microservice splitting

JMeter connection DM8

Neo4j: basic introduction (I) installation and use

今天运气不错

Uniapp drop-down layer selection box effect demo (sorting)

OpenFeign服务接口调用

Browser cookie to selenium cookie login

Principle of printf indefinite length parameter

Ali an interview question: use two threads to output letters and numbers alternately
随机推荐
gcc编译动态库和静态库
What is the next step in the recommendation system? Alispacetime aggregates GNN, and the effect is to sling lightgcn!
ZABBIX supports nail alarm
build. Gradle configuration
Review summary of database
手把手教你搭一个永久运行的个人服务器!
Uniapp drop-down layer selection box effect demo (sorting)
MySQL learning 1: installing MySQL
Ali an interview question: use two threads to output letters and numbers alternately
Win10彻底永久关闭自动更新的步骤
Picocli getting started
浏览器cookie转selenium cookie登录
Airbnb复盘微服务
Principle of printf indefinite length parameter
如何下载带有超链接的图片
LeetCode_ Fast power_ Recursion_ Medium_ 50.Pow(x, n)
log4j.properties的配置详解
数据库的复习总结
Microservice splitting
First encounter with dynamic programming