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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值