04.Redis 的多实例
Redis 的多实例
使用多实例,需要指定不同实例的相应的端口,配置文件,日志文件等相关配置
# 在前面的编译安装的基础上,需要再指定不同实例的service文件、相应的端口,配置文件,日志文件等相关配置
[root@ubuntu2204 ~]#sed 's/6379/6380/' /apps/redis/etc/redis.conf > /apps/redis/etc/redis_6380.conf[root@ubuntu2204 ~]#grep 6380 /apps/redis/etc/redis_6380.confport 6380
# tls-port 6380
pidfile /apps/redis/run/redis_6380.pid
logfile "/apps/redis/log/redis_6380.log"
dbfilename dump_6380.rdb
appendfilename "appendonly_6380.aof"
# cluster-config-file nodes-6380.conf
# cluster-announce-tls-port 6380
# cluster-announce-bus-port 6380[root@ubuntu2204 ~]#cd /lib/systemd/system
[root@ubuntu2204 system]#cp redis.service redis_6380.service# 修改配置文件 /apps/redis/etc/redis_6380.conf 来启动这个实例
[root@ubuntu2204 system]#cat redis_6380.service
[Unit]
Description=Redis persistent key-value database
After=network.target[Service]
ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis_6380.conf --supervised systemd
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
LimitNOFILE=1000000[Install]
WantedBy=multi-user.target[root@ubuntu2204 system]#systemctl daemon-reload
[root@ubuntu2204 system]#systemctl enable --now redis_6380.service
[root@ubuntu2204 system]#systemctl restart redis_6380.service
[root@ubuntu2204 system]#ss -nlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 511 0.0.0.0:6379 0.0.0.0:*
LISTEN 0 511 0.0.0.0:6380 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:* # 客户端连接
[root@ubuntu2204 ~]#redis-cli -p 6380 -a 123456 --no-auth-warning
127.0.0.1:6380>
前台运行redis多实例
[root@ubuntu2204 system]#redis-server --port 6381[root@ubuntu2204 ~]#ss -nlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 511 0.0.0.0:6379 0.0.0.0:*
LISTEN 0 511 0.0.0.0:6381 0.0.0.0:*
LISTEN 0 511 0.0.0.0:6380 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 511 [::]:6381 [::]:*
LISTEN 0 128 [::]:22 [::]:*