ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

debian下编译安装redis并加入到systemd启动管理

2022-02-09 17:04:44  阅读:243  来源: 互联网

标签:systemd service redis usr yes local debian


原文地址: 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/

标签:systemd,service,redis,usr,yes,local,debian
来源: https://www.cnblogs.com/tuhooo/p/15875754.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有