Home >Database >Redis >redis custom systemctl management service

redis custom systemctl management service

尚
forward
2020-04-11 09:07:562494browse

redis custom systemctl management service

1. Preparation

Compile and install redis (my installation directory/usr/loacl/tool)

Connect redis-server and redis- cli move to the environment variable directory (/usr/loacl/bin); give execution permission

cp redis.conf to the configuration directory (/etc/redis/redis.conf) or make a soft connection; (I choose the former )

Note: For the corresponding directory and permissions, please refer to other requirements

2. Create systemctl service

When using service to manage services, it is in /etc/init. Create a script file in the d/ directory to manage the start and stop of the service. In systemctl, it is similar, but the file directory is different. Create a script file redis.service in the /lib/systemd/system directory with the contents inside. As follows:

[Unit]
Description=Redis
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecReload=/usr/local/bin/redis-server -s reload
ExecStop=/usr/local/bin/redis-server -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

[Unit] indicates that this is basic information

Description is a description

After is started after that service, usually after the network service is started

[Service] means here is the service information

ExecStart is the command to start the service

ExecReload is the command to restart the service

ExecStop is the command to stop the service

[Install] Indicates that this is installation related information

WantedBy In which way it is started: multi-user.target indicates that when the system is started in multi-user mode (default run level), this service Needs to be run automatically.

3. Refresh the configuration

The systemctl just configured needs to refresh the configuration to take effect

$ systemctl daemon-reload

4. Set the boot usage

Set the redis service to be enabled at boot

$ systemctl enable redis.service

For more redis knowledge, please pay attention to the redis introductory tutorial column.

The above is the detailed content of redis custom systemctl management service. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete