发布于 2年前

CentOS 7配置安装多个redis实例

1、给新redis实例创建redis配置(复制redis.conf)

$ cp /etc/redis.conf /etc/redis-xxx.conf

2、修改复制的redis-xxx.conf

...
#修改pidfile
#pidfile /var/run/redis/redis.pid
pidfile /var/run/redis/redis-xxx.pid
...
#dir /var/lib/redis/
dir /var/lib/redis-xxx/
...
#修改端口 port
#port 6379
port 6380
...
#修改日志文件路径 logfile
#logfile /var/log/redis/redis.log
logfile /var/log/redis/redis-xxx.log
...
#修改 vm-swap-file
#vm-swap-file /tmp/redis.swap
vm-swap-file /tmp/redis-xxx.swap
...

3、创建目录 /var/lib/redis-xxx

$ mkdir -p /var/lib/redis-xx

4、复制原来redis的service脚本

$ cp /usr/lib/systemd/system/redis.service /usr/lib/systemd/system/redis-xxx.service

5、修改新的redis-xxx.service脚本

...
#[Unit]
Description=Redis persistent key-value database
After=network.target
#[Service]
ExecStart=/usr/bin/redis-server /etc/redis-xxx.conf --daemonize no
ExecStop=/usr/bin/redis-shutdown
User=redis
Group=redis
#[Install]
WantedBy=multi-user.target
...

注意:这里只修改redis-xxx.conf路径,其他项目不需要修改。

6、启动:

$ service redis-xxx start

7、检查status:

$ service redis-xxx status

8、关闭:

$ service redis-xxx stop

9、重启:

$ service redis-xxx restart

10、问题

如果service找不到,可以先执行以下命令:

$ systemctl unmask packagekit.service
$ systemctl mask packagekit.service

然后重新运行service命令

©2020 edoou.com   京ICP备16001874号-3