redis启动多个实例,配置多个端口,加入systemctl自动启动
redis启动多个实例,配置多个端口,加入systemctl自动启动
·
参考redis启动多个实例,配置多个端口 - Linux - 我是前端亲测后加入一步:修改dbfilename
如果使用 systemctl
系统命令,启动两个redis实例
1、复制一个redis的配置文件为/etc/redis/redis.6380.conf
// 修改port 为6380
// 修改pidfile 为 /var/run/redis/redis6380-server.pid
// 修改logfile 为 /var/log/redis/redis6380-server.log
//修改 dbfilename 为 dump6380.rdb,否则会在原来的数据库文件上修改,相当于只开了一个新端口,不是新数据库
2、复制一个redis的.service
文件,相关路径参考如下
cp /usr/lib/systemd/system/redis.service /usr/lib/systemd/system/redis6380.service
3、编辑redis6380.service
只需要改动ExecStart
的redis配置文件指向新的即可
Description=Redis
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/bin/redis-server /etc/redis.6380.conf --daemonize no --supervised systemd
ExecStop=/usr/libexec/redis-shutdown
Type=nofify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
4、执行systemctl daemon-reload
5、检查redis的6380日志文件是否存在,它的用户是否为redis
如果redis.6380.log
的用户跟上面redis.6380.service
中的User
不致,请删除该日志文件。避免启动的时候启动失败
[root redis]# ll
total 28
-rw-r--r-- 1 redis redis 3634 Nov 9 15:19 redis.6380.log
-rw-r--r-- 1 redis redis 18029 Nov 9 14:29 redis.log
6、启动6380
systemctl start redis6380
7、结果
[root redis]# systemctl start redis6380
[root redis]# systemctl start redis
[root redis]# ps -ef|grep redis
redis 14924 1 0 15:36 ? 00:00:00 /usr/bin/redis-server 127.0.0.1:6380
redis 14930 1 0 15:36 ? 00:00:00 /usr/bin/redis-server 127.0.0.1:6379
root 14935 13821 0 15:36 pts/3 00:00:00 grep --color=auto redis
更多推荐
所有评论(0)