debian下编译安装redis并加入到systemd启动管理
2022/2/9 19:13:16
本文主要是介绍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://www.manongjc.com/detail/23-xvtvqgqadcuaveg.html
- https://www.cnblogs.com/monkey6/p/14781775.html[原文已经被删除了]
原文地址: http://blog.duhbb.com/2022/02/09/compile-and-install-redis-debian-and-add-to-systemd/ 欢迎访问我的个人博客: http://blog.duhbb.com/
这篇关于debian下编译安装redis并加入到systemd启动管理的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-18Redis安装入门:新手必读指南
- 2024-11-08阿里云Redis项目实战入门教程
- 2024-11-08阿里云Redis资料:新手入门与初级使用指南
- 2024-11-08阿里云Redis教程:新手入门及实用指南
- 2024-11-07阿里云Redis学习入门:新手必读指南
- 2024-11-07阿里云Redis学习入门:从零开始的操作指南
- 2024-11-07阿里云Redis学习:初学者指南
- 2024-11-06阿里云Redis入门教程:轻松搭建与使用指南
- 2024-11-02Redis项目实战:新手入门教程
- 2024-10-22Redis入门教程:轻松掌握数据存储与操作