当前位置:首页 > 编程笔记 > 正文
已解决

Ubuntu Redis开机自启动服务

来自网友在路上 148848提问 提问时间:2023-09-27 11:40:15阅读次数: 48

最佳答案 问答题库488位专家为你答疑解惑

 1. 建立service文件

sudo vim /etc/systemd/system/redis-server.service
2. redis service文件
[Unit]
Description=Advanced key-value store
After=network.target
Documentation=http://redis.io/documentation, man:redis-server(1)[Service]
Type=notify
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --supervised systemd --daemonize no
PIDFile=/run/redis/redis-server.pid
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=2755UMask=007
PrivateTmp=yes
LimitNOFILE=65535
PrivateDevices=yes
ProtectHome=yes
ReadOnlyDirectories=/
ReadWritePaths=-/var/lib/redis
ReadWritePaths=-/var/log/redis
ReadWritePaths=-/var/run/redisNoNewPrivileges=true
CapabilityBoundingSet=CAP_SETGID CAP_SETUID CAP_SYS_RESOURCE
MemoryDenyWriteExecute=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectControlGroups=true
RestrictRealtime=true
RestrictNamespaces=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX# redis-server can write to its own config file when in cluster mode so we
# permit writing there by default. If you are not using this feature, it is
# recommended that you replace the following lines with "ProtectSystem=full".
ProtectSystem=true
ReadWriteDirectories=-/etc/redis[Install]
WantedBy=multi-user.target
Alias=redis.service
3. 启动服务并检查状态
$ systemctl daemon-reload
$ systemctl start redis
$ systemctl status redis
$ systemctl restart redis

4. 开机自启动 

$ systemctl enable redis

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"Ubuntu Redis开机自启动服务":http://eshow365.cn/6-14641-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!