Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Redis setup Application Boot self-start

Shulou Source: shulou.com Published: 2022-06-02 07:34:48 11月02日 Update

This article mainly explains the "redis setup application boot self-start", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "redis setup application boot self-start" bar!

This paper describes how to manage our application through systemctl, and takes redis as an example to explain how to set redis as the system program to manage its self-startup process after installing redis through binary compilation.

Redis start, stop, boot

1. Create a service

When you use service to manage a service, you create a script file in the / etc/init.d/ directory to manage the start and stop of the service. Similarly, in systemctl, the file directory is different. Create a script file redis.service in the / lib/systemd/system directory, which contains the following contents:

[Unit]

Description=Redis

After=network.target

[Service]

ExecStart=/usr/local/bin/redis-server / usr/local/redis/redis.conf-- daemonize no

ExecStop=/usr/local/bin/redis-cli-h 127.0.0.1-p 6379 shutdown

[Install]

WantedBy=multi-user.target

[Unit] indicates that this is basic information.

Description is the description

After starts after that service, usually after the network service starts.

[Service] indicates that this is the service information

ExecStart is the command to start the service

ExecStop is the order to stop the service

[Install] indicates that this is installation related information.

How does WantedBy start: multi-user.target indicates that this service needs to be run automatically when the system is started in multi-user mode (the default runlevel).

two。 Create a soft link

A copy can be generated through sysntemctl enable redis sysntemctl disable redis.

$ll / etc/systemd/system/multi-user.target.wants/

Total 8

Drwxr-xr-x 2 root root 4096 Mar 30 15:46. /

Drwxr-xr-x 13 root root 4096 Mar 13 14:18.. /

Lrwxrwxrwx 1 root root 31 Nov 23 14:43 redis.service-> / lib/systemd/system/redis.service

... A little.

3. Refresh configuration

The service just configured needs to be recognized by systemctl, so the configuration must be refreshed.

$systemctl daemon-reload

You can use sudo if you don't have permission.

$sudo systemctl daemon-reload

4. Start, restart, stop

Start redis

$systemctl start redis

Restart redis

$systemctl restart redis

Stop redis

$systemctl stop redis

5. Boot self-start

Redis service joins boot startup

$systemctl enable redis

Do not start up.

$systemctl disable redis

6. View statu

View statu

$systemctl status redis

Thank you for your reading, the above is the content of "redis setup application boot self-startup". After the study of this article, I believe you have a deeper understanding of the problem of redis setting application boot self-startup, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Service program application application management information content file directory learning configuration way is in status management service system script this is problem run Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft NVidia OPPO Reno Linux