debian下編譯安裝redis並加入到systemd啟動管理


原文地址: http://blog.duhbb.com/2022/02/09/compile-and-install-redis-debian-and-add-to-systemd/
歡迎訪問我的個人博客: http://blog.duhbb.com/

引言

安裝遇到的問題:

systemd supervision requested or auto-detected, but Redis is compiled without libsystemd support!

systemd[1]: redis.service: Failed with result 'protocol'.

下載

wget https://download.redis.io/releases/redis-6.2.6.tar.gz

編譯並安裝

安裝libsystemd-dev

apt-get install libsystemd-dev

編譯並安裝redis

make USE_SYSTEMD=yes install

如果交給systemd管理的話, 需要在編譯的時候指定USE_SYSTEMD=yes.

如果報systemd的頭文件沒有找到的話, 需要先安裝``.

報錯如下:

fatal error: systemd/sd-daemon.h: No such file or directory

systemd的service文件

文件位置:

root@mydebian:~# cat /lib/systemd/system/redis.service

文件內容如下:

# example systemd service unit file for redis-server
#
# In order to use this as a template for providing a redis service in your
# environment, _at the very least_ make sure to adapt the redis configuration
# file you intend to use as needed (make sure to set "supervised systemd"), and
# to set sane TimeoutStartSec and TimeoutStopSec property values in the unit's
# "[Service]" section to fit your needs.
#
# Some properties, such as User= and Group=, are highly desirable for virtually
# all deployments of redis, but cannot be provided in a manner that fits all
# expectable environments. Some of these properties have been commented out in
# this example service unit file, but you are highly encouraged to set them to
# fit your needs.
#
# Please refer to systemd.unit(5), systemd.service(5), and systemd.exec(5) for
# more information.

[Unit]
Description=Redis data structure server
Documentation=https://redis.io/documentation
#Before=your_application.service another_example_application.service
#AssertPathExists=/var/lib/redis
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis/6379.conf --supervised systemd
ExecStop=/usr/local/bin/redis-cli -p 6379 shutdown
## Alternatively, have redis-server load a configuration file:
#ExecStart=/usr/local/bin/redis-server /path/to/your/redis.conf
LimitNOFILE=10032
NoNewPrivileges=yes
#OOMScoreAdjust=-900
#PrivateTmp=yes
Type=notify
TimeoutStartSec=infinity
TimeoutStopSec=infinity
UMask=0077
#User=redis
#Group=redis
#WorkingDirectory=/var/lib/redis

[Install]
WantedBy=multi-user.target
root@mydebian:~#

在redis.conf的配置文件中一定要設置:

daemonize no
supervised systemd

這是因為redis要和systemd交互.

下面是一份可供參考的redis配置文件:

bind * -::*
protected-mode no
port 8000
daemonize no
pidfile "/usr/local/redis/run/redis_8000.pid"
loglevel notice
logfile "/usr/local/redis/log/redis8000.log"
save 3600 1
save 300 100
save 60 10000
stop-writes-on-bgsave-error no
dbfilename "dump8000.rdb"
dir "/usr/local/redis-6.2.3/data"
requirepass "monkey"
maxclients 1000
maxmemory 24gb
appendonly yes
appendfilename "appendonly8000.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 1gb
aof-load-truncated yes
aof-use-rdb-preamble yes
supervised systemd

systemctl相關命令

systemctl daemon-reload         # 重新加載service文件
systemctl status redis.service  # 查看redis服務的狀態
systemctl enable redis.service  # 加入到開機自啟中

參考資料

原文地址: http://blog.duhbb.com/2022/02/09/compile-and-install-redis-debian-and-add-to-systemd/
歡迎訪問我的個人博客: http://blog.duhbb.com/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM