Linux系统设置redis集群开机自启动
Redis集群开机自启:
例如本文示例中,3 台 Linux 服务器,每台服务器上部署 2 个节点,3 台服务器运行 6 个 Redis 实例,组成一个经典的「三主三从」的 Redis 集群。
| 服务器 | 服务器IP地址(示例) | 端口 |
|---|---|---|
| 服务器1 | 192.168.239.130 | 7001、7002 |
| 服务器2 | 192.168.239.131 | 7003、7004 |
| 服务器3 | 192.168.239.132 |
7005、7006 |
下面以配置服务器1为列,其他服务器配置同理。
第一步:分别给各节点创建或编辑每个Redis节点的systemd服务文件,这里以端口标注区分
命令:vim /lib/systemd/system/redis_7001.service
添加:
#!/bin/bash [Unit] Description=Redis persistent key-value database After=network.target [Service] Type=forking ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis-cluster/7001/redis.conf ExecReload=/usr/local/bin/redis-server -s reload ExecStop=/usr/local/bin/redis-server -s stop PrivateTmp=true User=redisUser Group=redisUser [Install] WantedBy=multi-user.target
其中 ExecStart、ExecReload、ExecStop 启动文件路径需修改为自己的实际路径,
使用User、Group指定 redisUser 用户启动 redis,不指定则默认root用户启动。
命令:vim /lib/systemd/system/redis_7002.service
添加:
#!/bin/bash [Unit] Description=Redis persistent key-value database After=network.target [Service] Type=forking ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis-cluster/7002/redis.conf ExecReload=/usr/local/bin/redis-server -s reload ExecStop=/usr/local/bin/redis-server -s stop PrivateTmp=true User=redisUser Group=redisUser [Install] WantedBy=multi-user.target
第二步:设置开机自启
systemctl daemon-reload #重新加载服务配置 systemctl enable redis_7001.service #设置为开机自启动 systemctl start redis_7001.service #启动redis服务 systemctl status redis_7001.service #查看redis服务状态 journalctl -u redis_7001.service #查看启动日志是否正常

浙公网安备 33010602011771号