redis的多实例
Posted y_zilong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis的多实例相关的知识,希望对你有一定的参考价值。
[root@cen7_17 ~]# ls /apps/redis/
bin data etc log run
[root@cen7_17 ~]# tree /apps/redis/
/apps/redis/
├── bin
│ ├── redis-benchmark
│ ├── redis-check-aof -> redis-server
│ ├── redis-check-rdb -> redis-server
│ ├── redis-cli
│ ├── redis-sentinel -> redis-server
│ └── redis-server
├── data
│ └── dump.rdb
├── etc
│ └── redis.conf
├── log
│ └── redis-6379.log
└── run
└── redis_6379.pid
5 directories, 10 files
[root@cen7_17 ~]#
[root@cen7_17 ~]# systemctl stop redis
[root@cen7_17 ~]# systemctl status redis
● redis.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
Active: failed (Result: signal) since Tue 2021-06-29 08:58:14 EDT; 3s ago
Process: 28597 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
Process: 28484 ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis.conf --supervised systemd (code=killed, signal=QUIT)
Main PID: 28484 (code=killed, signal=QUIT)
Status: "Ready to accept connections"
Jun 29 08:28:30 cen7_17.yzl systemd[1]: Starting Redis persistent key-value database...
Jun 29 08:28:30 cen7_17.yzl systemd[1]: Started Redis persistent key-value database.
Jun 29 08:58:14 cen7_17.yzl systemd[1]: Stopping Redis persistent key-value database...
Jun 29 08:58:14 cen7_17.yzl systemd[1]: redis.service: main process exited, code=killed, status=3/QUIT
Jun 29 08:58:14 cen7_17.yzl systemd[1]: Stopped Redis persistent key-value database.
Jun 29 08:58:14 cen7_17.yzl systemd[1]: Unit redis.service entered failed state.
Jun 29 08:58:14 cen7_17.yzl systemd[1]: redis.service failed.
#redis.conf文件
[root@cen7_17 ~]# cd /apps/redis/etc/
[root@cen7_17 etc]# ls
redis.conf
[root@cen7_17 etc]# cp redis.conf redis_6379.conf
[root@cen7_17 etc]# grep dump.rdb redis_6379.conf
dbfilename dump.rdb
[root@cen7_17 etc]# sed -i 's/dbfilename dump.rdb/dbfilename dump_6379.rdb/' redis_6379.conf
[root@cen7_17 etc]# grep dump_6379.rdb redis_6379.conf
dbfilename dump_6379.rdb
[root@cen7_17 etc]# ls
redis_6379.conf redis.conf
[root@cen7_17 etc]# cp redis_6379.conf redis_6380.conf
[root@cen7_17 etc]# cp redis_6379.conf redis_6381.conf
[root@cen7_17 etc]# sed -i 's/dbfilename dump_6379.rdb/dbfilename dump_6380.rdb/' redis_6380.conf
[root@cen7_17 etc]# sed -i 's/dbfilename dump_6379.rdb/dbfilename dump_6381.rdb/' redis_6381.conf
[root@cen7_17 etc]# grep "^dbfilename" redis_6379.conf
dbfilename dump_6379.rdb
[root@cen7_17 etc]# grep "^dbfilename" redis_6380.conf
dbfilename dump_6380.rdb
[root@cen7_17 etc]# grep "^dbfilename" redis_6381.conf
dbfilename dump_6381.rdb
[root@cen7_17 etc]# cd ..
[root@cen7_17 redis]# tree
.
├── bin
│ ├── redis-benchmark
│ ├── redis-check-aof -> redis-server
│ ├── redis-check-rdb -> redis-server
│ ├── redis-cli
│ ├── redis-sentinel -> redis-server
│ └── redis-server
├── data
│ └── dump.rdb
├── etc
│ ├── redis_6379.conf
│ ├── redis_6380.conf
│ ├── redis_6381.conf
│ └── redis.conf
├── log
│ └── redis-6379.log
└── run
└── redis_6379.pid
5 directories, 13 files
[root@cen7_17 redis]# grep redis-6379.log etc/redis_6380.conf
logfile /apps/redis/log/redis-6379.log
[root@cen7_17 redis]# sed -i 's/redis-6379.log/redis-6380.log/' etc/redis_6380.conf
[root@cen7_17 redis]# sed -i 's/redis-6379.log/redis-6381.log/' etc/redis_6381.conf
[root@cen7_17 redis]# grep redis_6379.pid etc/redis_6380.conf
pidfile /apps/redis/run/redis_6379.pid
[root@cen7_17 redis]# sed -i 's/redis_6379.pid/redis_6380.pid/' etc/redis_6380.conf
[root@cen7_17 redis]# sed -i 's/redis_6379.pid/redis_6381.pid/' etc/redis_6381.conf
[root@cen7_17 redis]# grep redis_6380.pid etc/redis_6380.conf
pidfile /apps/redis/run/redis_6380.pid
[root@cen7_17 redis]# grep redis_6381.pid etc/redis_6381.conf
pidfile /apps/redis/run/redis_6381.pid
#端口
[root@cen7_17 ~]# cd /apps/redis/etc/
[root@cen7_17 etc]# ls
redis_6379.conf redis_6380.conf redis_6381.conf redis.conf
[root@cen7_17 etc]# vim redis_6380.conf
[root@cen7_17 etc]# grep 6379 redis_6380.conf
# Accept connections on the specified port, default is 6379 (IANA #815344).
port 6379
# tls-port 6379
# cluster-config-file nodes-6379.conf
# cluster-announce-tls-port 6379
[root@cen7_17 etc]# sed -i 's/6379/6380/' redis_6380.conf
[root@cen7_17 etc]# grep 6380 redis_6380.conf
# Accept connections on the specified port, default is 6380 (IANA #815344).
port 6380
# tls-port 6380
pidfile /apps/redis/run/redis_6380.pid
logfile /apps/redis/log/redis-6380.log
dbfilename dump_6380.rdb
# cluster-config-file nodes-6380.conf
# cluster-announce-tls-port 6380
# cluster-announce-bus-port 6380
[root@cen7_17 etc]# sed -i 's/6379/6381/' redis_6381.conf
[root@cen7_17 etc]# grep 6381 redis_6381.conf
# Accept connections on the specified port, default is 6381 (IANA #815344).
port 6381
# tls-port 6381
pidfile /apps/redis/run/redis_6381.pid
logfile /apps/redis/log/redis-6381.log
dbfilename dump_6381.rdb
# cluster-config-file nodes-6381.conf
# cluster-announce-tls-port 6381
[root@cen7_17 etc]#
#redis.service文件
[root@cen7_17 ~]# cat /lib/systemd/system/redis_6379.service
[Unit]
Description=Redis persistent key-value database
After=network.target
[Service]
ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis.conf --supervised systemd
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
[root@cen7_17 ~]# grep redis.conf /lib/systemd/system/redis_6379.service
ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis.conf --supervised systemd
[root@cen7_17 ~]# sed -i 's/redis.conf/redis_6379.conf/' /lib/systemd/system/redis_6379.service
[root@cen7_17 ~]# grep redis_6379.conf /lib/systemd/system/redis_6379.service
ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis_6379.conf --supervised systemd
[root@cen7_17 ~]# sed -i 's/redis.conf/redis_6380.conf/' /lib/systemd/system/redis_6380.service
[root@cen7_17 ~]# sed -i 's/redis.conf/redis_6381.conf/' /lib/systemd/system/redis_6381.service
[root@cen7_17 ~]# grep redis_6380.conf /lib/systemd/system/redis_6380.service
ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis_6380.conf --supervised systemd
[root@cen7_17 ~]# grep redis_6381.conf /lib/systemd/system/redis_6381.service
ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis_6381.conf --supervised systemd
#启动
[root@cen7_17 ~]# systemctl start redis_6379.service redis_6380.service redis_6381.service
[root@cen7_17 ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 511 *:6379 *:*
LISTEN 0 511 *:6380 *:*
LISTEN 0 511 *:6381 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
[root@cen7_17 ~]# systemctl status redis_6379.service
● redis_6379.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis_6379.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2021-06-29 09:32:00 EDT; 10min ago
Main PID: 29168 (redis-server)
Status: "Ready to accept connections"
CGroup: /system.slice/redis_6379.service
└─29168 /apps/redis/bin/redis-server 0.0.0.0:6379
Jun 29 09:32:00 cen7_17.yzl systemd[1]: Starting Redis persistent key-value database...
Jun 29 09:32:00 cen7_17.yzl systemd[1]: Started Redis persistent key-value database.
[root@cen7_17 ~]# systemctl status redis_6380.service
● redis_6380.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis_6380.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2021-06-29 09:39:32 EDT; 2min 42s ago
Main PID: 29277 (redis-server)
Status: "Ready to accept connections"
CGroup: /system.slice/redis_6380.service
└─29277 /apps/redis/bin/redis-server 0.0.0.0:6380
Jun 29 09:39:32 cen7_17.yzl systemd[1]: Starting Redis persistent key-value database...
Jun 29 09:39:32 cen7_17.yzl systemd[1]: Started Redis persistent key-value database.
[root@cen7_17 ~]# systemctl status redis_6381.service
● redis_6381.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis_6381.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2021-06-29 09:39:32 EDT; 2min 46s ago
Main PID: 29278 (redis-server)
Status: "Ready to accept connections"
CGroup: /system.slice/redis_6381.service
└─29278 /apps/redis/bin/redis-server 0.0.0.0:6381
Jun 29 09:39:32 cen7_17.yzl systemd[1]: Starting Redis persistent key-value database...
Jun 29 09:39:32 cen7_17.yzl systemd[1]: Started Redis persistent key-value database.
[root@cen7_17 ~]# redis-cli -h 10.0.0.17 -p 6380 -a 123456 info
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Server
redis_version:6.2.2
[root@cen7_17 ~]# redis-cli -h 10.0.0.17 -p 6381 -a 123456 info
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Server
redis_version:6.2.2
[root@cen7_17 ~]#
以上是关于redis的多实例的主要内容,如果未能解决你的问题,请参考以下文章