linux systemd 管理 redis1 、 redis2 两个服务同时还有一个redis服务同时管理redis1、redis2两个服务包括systemctl status redis 显示 redis1redis2的状态restart 就重启2个服务
要同时管理 redis1 和 redis2 两个服务,并且在 systemctl status redis 命令中显示 redis1 和 redis2 的状态,以及在重启时重启这两个服务,你可以按照以下步骤进行操作:
-
首先,创建 redis1 和 redis2 的 systemd service 配置文件。在终端中执行以下命令:
sudo nano /etc/systemd/system/redis1.service在打开的文件中,添加以下内容:
[Unit] Description=Redis1 Server After=network.target [Service] ExecStart=/path/to/redis1/executable [Install] WantedBy=multi-user.target替换
/path/to/redis1/executable为 redis1 可执行文件的实际路径。然后保存并关闭文件。
-
类似地,创建 redis2 的 systemd service 配置文件。在终端中执行以下命令:
sudo nano /etc/systemd/system/redis2.service在打开的文件中,添加以下内容:
[Unit] Description=Redis2 Server After=network.target [Service] ExecStart=/path/to/redis2/executable [Install] WantedBy=multi-user.target替换
/path/to/redis2/executable为 redis2 可执行文件的实际路径。然后保存并关闭文件。
-
接下来,创建一个新的 systemd service 配置文件来管理 redis1 和 redis2 两个服务。在终端中执行以下命令:
sudo nano /etc/systemd/system/redis.service在打开的文件中,添加以下内容:
[Unit] Description=Redis Server After=network.target [Service] ExecStart=/bin/true ExecReload=/bin/true ExecStop=/bin/true RemainAfterExit=yes [Install] WantedBy=multi-user.target [Service] Type=oneshot ExecStart=/bin/systemctl start redis1.service redis2.service ExecReload=/bin/systemctl reload redis1.service redis2.service ExecStop=/bin/systemctl stop redis1.service redis2.service然后保存并关闭文件。
-
更新 systemd 配置并启动服务。在终端中执行以下命令:
sudo systemctl daemon-reload sudo systemctl start redis1.service sudo systemctl start redis2.service sudo systemctl start redis.service这将启动 redis1、redis2 和 redis 服务,并将 redis1 和 redis2 作为 redis 服务的依赖项。
-
最后,你可以使用 systemctl status redis 命令来检查 redis1 和 redis2 的状态,以及使用 systemctl restart redis 命令来重启这两个服务。
sudo systemctl status redis sudo systemctl restart redissystemctl status redis 命令将显示 redis1 和 redis2 的状态,而 systemctl restart redis 命令将重启这两个服务。
注意:在以上步骤中,你需要将 /path/to/redis1/executable 和 /path/to/redis2/executable 替换为 redis1 和 redis2 可执行文件的实际路径。另外,确保你有足够的权限来创建和修改 systemd service 配置文件
原文地址: https://www.cveoy.top/t/topic/icxA 著作权归作者所有。请勿转载和采集!