mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-06-26 14:19:38 +08:00
supoort redisMode.
This commit is contained in:
parent
f309e0ad3b
commit
e09c62226e
@ -1,11 +1,14 @@
|
|||||||
address: [localhost:16379]
|
address: [localhost:16379]
|
||||||
username:
|
username:
|
||||||
password: openIM123
|
password: openIM123
|
||||||
clusterMode: false
|
# redis Mode, including "standalone","cluster","sentinel"
|
||||||
|
redisMode: "sentinel"
|
||||||
db: 0
|
db: 0
|
||||||
maxRetry: 10
|
maxRetry: 10
|
||||||
poolSize: 100
|
poolSize: 100
|
||||||
|
# Sentinel configuration (only used when redisMode is "sentinel")
|
||||||
sentinelMode:
|
sentinelMode:
|
||||||
enable: false
|
|
||||||
masterName: "redis-master"
|
masterName: "redis-master"
|
||||||
sentinelsAddrs: ["127.0.0.1:26379", "127.0.0.1:26380", "127.0.0.1:26381"]
|
sentinelsAddrs: ["127.0.0.1:26379", "127.0.0.1:26380", "127.0.0.1:26381"]
|
||||||
|
routeByLatency: true
|
||||||
|
routeRandomly: true
|
||||||
|
@ -1,208 +0,0 @@
|
|||||||
networks:
|
|
||||||
openim:
|
|
||||||
driver: bridge
|
|
||||||
|
|
||||||
services:
|
|
||||||
redis:
|
|
||||||
image: "${REDIS_IMAGE}"
|
|
||||||
container_name: redis
|
|
||||||
ports:
|
|
||||||
- "16379:6379"
|
|
||||||
volumes:
|
|
||||||
- "${DATA_DIR}/components/redis/data:/data"
|
|
||||||
- "${DATA_DIR}/components/redis/config/redis.conf:/usr/local/redis/config/redis.conf"
|
|
||||||
environment:
|
|
||||||
TZ: Asia/Shanghai
|
|
||||||
restart: always
|
|
||||||
sysctls:
|
|
||||||
net.core.somaxconn: 1024
|
|
||||||
command: redis-server /usr/local/redis/config/redis.conf --requirepass openIM123 --appendonly yes
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "redis-cli", "-a", "openIM123", "ping"]
|
|
||||||
interval: 10s
|
|
||||||
timeout: 3s
|
|
||||||
retries: 3
|
|
||||||
start_period: 30s
|
|
||||||
networks:
|
|
||||||
- openim
|
|
||||||
|
|
||||||
redis-slave-1:
|
|
||||||
image: "${REDIS_IMAGE}"
|
|
||||||
container_name: redis-slave-1
|
|
||||||
ports:
|
|
||||||
- "16380:6379"
|
|
||||||
volumes:
|
|
||||||
- "${DATA_DIR}/components/redis/slave1:/data"
|
|
||||||
environment:
|
|
||||||
TZ: Asia/Shanghai
|
|
||||||
REDIS_MASTER_HOST: redis
|
|
||||||
REDIS_MASTER_PORT: 6379
|
|
||||||
REDIS_MASTER_PASSWORD: openIM123
|
|
||||||
REDIS_SLAVE_PASSWORD: openIM123
|
|
||||||
restart: always
|
|
||||||
command: >
|
|
||||||
bash -c '
|
|
||||||
echo "port 6379" > /data/redis-slave.conf &&
|
|
||||||
echo "replicaof $${REDIS_MASTER_HOST} $${REDIS_MASTER_PORT}" >> /data/redis-slave.conf &&
|
|
||||||
echo "masterauth $${REDIS_MASTER_PASSWORD}" >> /data/redis-slave.conf &&
|
|
||||||
echo "requirepass $${REDIS_SLAVE_PASSWORD}" >> /data/redis-slave.conf &&
|
|
||||||
echo "appendonly yes" >> /data/redis-slave.conf &&
|
|
||||||
echo "replica-read-only yes" >> /data/redis-slave.conf &&
|
|
||||||
redis-server /data/redis-slave.conf
|
|
||||||
'
|
|
||||||
depends_on:
|
|
||||||
- redis
|
|
||||||
networks:
|
|
||||||
- openim
|
|
||||||
|
|
||||||
redis-slave-2:
|
|
||||||
image: "${REDIS_IMAGE}"
|
|
||||||
container_name: redis-slave-2
|
|
||||||
ports:
|
|
||||||
- "16381:6379"
|
|
||||||
volumes:
|
|
||||||
- "${DATA_DIR}/components/redis/slave2:/data"
|
|
||||||
environment:
|
|
||||||
TZ: Asia/Shanghai
|
|
||||||
REDIS_MASTER_HOST: redis
|
|
||||||
REDIS_MASTER_PORT: 6379
|
|
||||||
REDIS_MASTER_PASSWORD: openIM123
|
|
||||||
REDIS_SLAVE_PASSWORD: openIM123
|
|
||||||
restart: always
|
|
||||||
command: >
|
|
||||||
bash -c '
|
|
||||||
echo "port 6379" > /data/redis-slave.conf &&
|
|
||||||
echo "replicaof $${REDIS_MASTER_HOST} $${REDIS_MASTER_PORT}" >> /data/redis-slave.conf &&
|
|
||||||
echo "masterauth $${REDIS_MASTER_PASSWORD}" >> /data/redis-slave.conf &&
|
|
||||||
echo "requirepass $${REDIS_SLAVE_PASSWORD}" >> /data/redis-slave.conf &&
|
|
||||||
echo "appendonly yes" >> /data/redis-slave.conf &&
|
|
||||||
echo "replica-read-only yes" >> /data/redis-slave.conf &&
|
|
||||||
redis-server /data/redis-slave.conf
|
|
||||||
'
|
|
||||||
depends_on:
|
|
||||||
- redis
|
|
||||||
networks:
|
|
||||||
- openim
|
|
||||||
|
|
||||||
redis-sentinel-1:
|
|
||||||
image: "${REDIS_IMAGE}"
|
|
||||||
container_name: redis-sentinel-1
|
|
||||||
ports:
|
|
||||||
- "26379:26379"
|
|
||||||
volumes:
|
|
||||||
- "${DATA_DIR}/components/redis/sentinel1:/data"
|
|
||||||
environment:
|
|
||||||
TZ: Asia/Shanghai
|
|
||||||
SENTINEL_PORT: 26379
|
|
||||||
REDIS_MASTER_NAME: redis-master
|
|
||||||
REDIS_MASTER_HOST: 127.0.0.1
|
|
||||||
REDIS_MASTER_PORT: 16379
|
|
||||||
REDIS_MASTER_PASSWORD: openIM123
|
|
||||||
SENTINEL_QUORUM: 2
|
|
||||||
SENTINEL_DOWN_AFTER: 30000
|
|
||||||
SENTINEL_PARALLEL_SYNCS: 1
|
|
||||||
SENTINEL_FAILOVER_TIMEOUT: 180000
|
|
||||||
restart: always
|
|
||||||
command: >
|
|
||||||
bash -c '
|
|
||||||
echo "port $${SENTINEL_PORT}" > /data/sentinel.conf &&
|
|
||||||
echo "sentinel monitor $${REDIS_MASTER_NAME} $${REDIS_MASTER_HOST} $${REDIS_MASTER_PORT} $${SENTINEL_QUORUM}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel auth-pass $${REDIS_MASTER_NAME} $${REDIS_MASTER_PASSWORD}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel down-after-milliseconds $${REDIS_MASTER_NAME} $${SENTINEL_DOWN_AFTER}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel parallel-syncs $${REDIS_MASTER_NAME} $${SENTINEL_PARALLEL_SYNCS}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel failover-timeout $${REDIS_MASTER_NAME} $${SENTINEL_FAILOVER_TIMEOUT}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel resolve-hostnames yes" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel announce-hostnames yes" >> /data/sentinel.conf &&
|
|
||||||
redis-sentinel /data/sentinel.conf
|
|
||||||
'
|
|
||||||
depends_on:
|
|
||||||
redis:
|
|
||||||
condition: service_healthy
|
|
||||||
redis-slave-1:
|
|
||||||
condition: service_started
|
|
||||||
redis-slave-2:
|
|
||||||
condition: service_started
|
|
||||||
networks:
|
|
||||||
- openim
|
|
||||||
|
|
||||||
redis-sentinel-2:
|
|
||||||
image: "${REDIS_IMAGE}"
|
|
||||||
container_name: redis-sentinel-2
|
|
||||||
ports:
|
|
||||||
- "26380:26379"
|
|
||||||
volumes:
|
|
||||||
- "${DATA_DIR}/components/redis/sentinel2:/data"
|
|
||||||
environment:
|
|
||||||
TZ: Asia/Shanghai
|
|
||||||
SENTINEL_PORT: 26379
|
|
||||||
REDIS_MASTER_NAME: redis-master
|
|
||||||
REDIS_MASTER_HOST: 127.0.0.1
|
|
||||||
REDIS_MASTER_PORT: 16379
|
|
||||||
REDIS_MASTER_PASSWORD: openIM123
|
|
||||||
SENTINEL_QUORUM: 2
|
|
||||||
SENTINEL_DOWN_AFTER: 30000
|
|
||||||
SENTINEL_PARALLEL_SYNCS: 1
|
|
||||||
SENTINEL_FAILOVER_TIMEOUT: 180000
|
|
||||||
restart: always
|
|
||||||
command: >
|
|
||||||
bash -c '
|
|
||||||
echo "port $${SENTINEL_PORT}" > /data/sentinel.conf &&
|
|
||||||
echo "sentinel monitor $${REDIS_MASTER_NAME} $${REDIS_MASTER_HOST} $${REDIS_MASTER_PORT} $${SENTINEL_QUORUM}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel auth-pass $${REDIS_MASTER_NAME} $${REDIS_MASTER_PASSWORD}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel down-after-milliseconds $${REDIS_MASTER_NAME} $${SENTINEL_DOWN_AFTER}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel parallel-syncs $${REDIS_MASTER_NAME} $${SENTINEL_PARALLEL_SYNCS}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel failover-timeout $${REDIS_MASTER_NAME} $${SENTINEL_FAILOVER_TIMEOUT}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel resolve-hostnames yes" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel announce-hostnames yes" >> /data/sentinel.conf &&
|
|
||||||
redis-sentinel /data/sentinel.conf
|
|
||||||
'
|
|
||||||
depends_on:
|
|
||||||
redis:
|
|
||||||
condition: service_healthy
|
|
||||||
redis-slave-1:
|
|
||||||
condition: service_started
|
|
||||||
redis-slave-2:
|
|
||||||
condition: service_started
|
|
||||||
networks:
|
|
||||||
- openim
|
|
||||||
|
|
||||||
redis-sentinel-3:
|
|
||||||
image: "${REDIS_IMAGE}"
|
|
||||||
container_name: redis-sentinel-3
|
|
||||||
ports:
|
|
||||||
- "26381:26379"
|
|
||||||
volumes:
|
|
||||||
- "${DATA_DIR}/components/redis/sentinel3:/data"
|
|
||||||
environment:
|
|
||||||
TZ: Asia/Shanghai
|
|
||||||
SENTINEL_PORT: 26379
|
|
||||||
REDIS_MASTER_NAME: redis-master
|
|
||||||
REDIS_MASTER_HOST: 127.0.0.1
|
|
||||||
REDIS_MASTER_PORT: 16379
|
|
||||||
REDIS_MASTER_PASSWORD: openIM123
|
|
||||||
SENTINEL_QUORUM: 2
|
|
||||||
SENTINEL_DOWN_AFTER: 30000
|
|
||||||
SENTINEL_PARALLEL_SYNCS: 1
|
|
||||||
SENTINEL_FAILOVER_TIMEOUT: 180000
|
|
||||||
restart: always
|
|
||||||
command: >
|
|
||||||
bash -c '
|
|
||||||
echo "port $${SENTINEL_PORT}" > /data/sentinel.conf &&
|
|
||||||
echo "sentinel monitor $${REDIS_MASTER_NAME} $${REDIS_MASTER_HOST} $${REDIS_MASTER_PORT} $${SENTINEL_QUORUM}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel auth-pass $${REDIS_MASTER_NAME} $${REDIS_MASTER_PASSWORD}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel down-after-milliseconds $${REDIS_MASTER_NAME} $${SENTINEL_DOWN_AFTER}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel parallel-syncs $${REDIS_MASTER_NAME} $${SENTINEL_PARALLEL_SYNCS}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel failover-timeout $${REDIS_MASTER_NAME} $${SENTINEL_FAILOVER_TIMEOUT}" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel resolve-hostnames yes" >> /data/sentinel.conf &&
|
|
||||||
echo "sentinel announce-hostnames yes" >> /data/sentinel.conf &&
|
|
||||||
redis-sentinel /data/sentinel.conf
|
|
||||||
'
|
|
||||||
depends_on:
|
|
||||||
redis:
|
|
||||||
condition: service_healthy
|
|
||||||
redis-slave-1:
|
|
||||||
condition: service_started
|
|
||||||
redis-slave-2:
|
|
||||||
condition: service_started
|
|
||||||
networks:
|
|
||||||
- openim
|
|
2
go.mod
2
go.mod
@ -13,7 +13,7 @@ require (
|
|||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
||||||
github.com/mitchellh/mapstructure v1.5.0
|
github.com/mitchellh/mapstructure v1.5.0
|
||||||
github.com/openimsdk/protocol v0.0.73-alpha.12
|
github.com/openimsdk/protocol v0.0.73-alpha.12
|
||||||
github.com/openimsdk/tools v0.0.50-alpha.87
|
github.com/openimsdk/tools v0.0.50-alpha.91
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/prometheus/client_golang v1.18.0
|
github.com/prometheus/client_golang v1.18.0
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.9.0
|
||||||
|
4
go.sum
4
go.sum
@ -349,8 +349,8 @@ github.com/openimsdk/gomake v0.0.15-alpha.5 h1:eEZCEHm+NsmcO3onXZPIUbGFCYPYbsX5b
|
|||||||
github.com/openimsdk/gomake v0.0.15-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
|
github.com/openimsdk/gomake v0.0.15-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
|
||||||
github.com/openimsdk/protocol v0.0.73-alpha.12 h1:2NYawXeHChYUeSme6QJ9pOLh+Empce2WmwEtbP4JvKk=
|
github.com/openimsdk/protocol v0.0.73-alpha.12 h1:2NYawXeHChYUeSme6QJ9pOLh+Empce2WmwEtbP4JvKk=
|
||||||
github.com/openimsdk/protocol v0.0.73-alpha.12/go.mod h1:WF7EuE55vQvpyUAzDXcqg+B+446xQyEba0X35lTINmw=
|
github.com/openimsdk/protocol v0.0.73-alpha.12/go.mod h1:WF7EuE55vQvpyUAzDXcqg+B+446xQyEba0X35lTINmw=
|
||||||
github.com/openimsdk/tools v0.0.50-alpha.87 h1:42jaKZZ5874o+1qup9KKHYmCQJWO7ibOKppxr8rhIS0=
|
github.com/openimsdk/tools v0.0.50-alpha.91 h1:4zXtTwwCIUawet1VDvnD3C/1E4N4ostDfh+RfL5nz90=
|
||||||
github.com/openimsdk/tools v0.0.50-alpha.87/go.mod h1:n2poR3asX1e1XZce4O+MOWAp+X02QJRFvhcLCXZdzRo=
|
github.com/openimsdk/tools v0.0.50-alpha.91/go.mod h1:n2poR3asX1e1XZce4O+MOWAp+X02QJRFvhcLCXZdzRo=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||||
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
|
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
|
||||||
|
@ -327,7 +327,7 @@ type Redis struct {
|
|||||||
Address []string `yaml:"address"`
|
Address []string `yaml:"address"`
|
||||||
Username string `yaml:"username"`
|
Username string `yaml:"username"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
ClusterMode bool `yaml:"clusterMode"`
|
RedisMode string `yaml:"redisMode"`
|
||||||
DB int `yaml:"db"`
|
DB int `yaml:"db"`
|
||||||
MaxRetry int `yaml:"maxRetry"`
|
MaxRetry int `yaml:"maxRetry"`
|
||||||
PoolSize int `yaml:"poolSize"`
|
PoolSize int `yaml:"poolSize"`
|
||||||
@ -335,9 +335,10 @@ type Redis struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Sentinel struct {
|
type Sentinel struct {
|
||||||
Enable bool `yaml:"enable"`
|
MasterName string `yaml:"masterName"`
|
||||||
MasterName string `yaml:"masterName"`
|
SentinelAddrs []string `yaml:"sentinelsAddrs"`
|
||||||
SentinelAddrs []string `yaml:"sentinelsAddrs"`
|
RouteByLatency bool `yaml:"routeByLatency"`
|
||||||
|
RouteRandomly bool `yaml:"routeRandomly"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BeforeConfig struct {
|
type BeforeConfig struct {
|
||||||
@ -494,17 +495,18 @@ func (m *Mongo) Build() *mongoutil.Config {
|
|||||||
|
|
||||||
func (r *Redis) Build() *redisutil.Config {
|
func (r *Redis) Build() *redisutil.Config {
|
||||||
return &redisutil.Config{
|
return &redisutil.Config{
|
||||||
ClusterMode: r.ClusterMode,
|
RedisMode: r.RedisMode,
|
||||||
Address: r.Address,
|
Address: r.Address,
|
||||||
Username: r.Username,
|
Username: r.Username,
|
||||||
Password: r.Password,
|
Password: r.Password,
|
||||||
DB: r.DB,
|
DB: r.DB,
|
||||||
MaxRetry: r.MaxRetry,
|
MaxRetry: r.MaxRetry,
|
||||||
PoolSize: r.PoolSize,
|
PoolSize: r.PoolSize,
|
||||||
Sentinel: &redisutil.Sentinel{
|
Sentinel: &redisutil.Sentinel{
|
||||||
Enable: r.SentinelMode.Enable,
|
MasterName: r.SentinelMode.MasterName,
|
||||||
MasterName: r.SentinelMode.MasterName,
|
SentinelAddrs: r.SentinelMode.SentinelAddrs,
|
||||||
SentinelAddrs: r.SentinelMode.SentinelAddrs,
|
RouteByLatency: r.SentinelMode.RouteByLatency,
|
||||||
|
RouteRandomly: r.SentinelMode.RouteRandomly,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func NewDiscoveryRegister(discovery *config.Discovery, watchNames []string) (dis
|
|||||||
return standalone.GetSvcDiscoveryRegistry(), nil
|
return standalone.GetSvcDiscoveryRegistry(), nil
|
||||||
}
|
}
|
||||||
if runtimeenv.RuntimeEnvironment() == config.KUBERNETES {
|
if runtimeenv.RuntimeEnvironment() == config.KUBERNETES {
|
||||||
return kubernetes.NewKubernetesConnManager(discovery.Kubernetes.Namespace,
|
return kubernetes.NewConnManager(discovery.Kubernetes.Namespace, nil,
|
||||||
grpc.WithDefaultCallOptions(
|
grpc.WithDefaultCallOptions(
|
||||||
grpc.MaxCallSendMsgSize(1024*1024*20),
|
grpc.MaxCallSendMsgSize(1024*1024*20),
|
||||||
),
|
),
|
||||||
|
@ -26,7 +26,7 @@ func TestName111111(t *testing.T) {
|
|||||||
"172.16.8.124:7005",
|
"172.16.8.124:7005",
|
||||||
"172.16.8.124:7006",
|
"172.16.8.124:7006",
|
||||||
},
|
},
|
||||||
ClusterMode: true,
|
RedisMode: "cluster",
|
||||||
Password: "passwd123",
|
Password: "passwd123",
|
||||||
//Address: []string{"localhost:16379"},
|
//Address: []string{"localhost:16379"},
|
||||||
//Password: "openIM123",
|
//Password: "openIM123",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user