- 进入到redis安装目录,具体位置看你安装时的路径了。
# cd /root/tools/redis-5.0.4/
- 编辑配置文件
# vim redis.conf
- 将如下配置项注释掉
#bind 127.0.0.1
- 如下项修改为yes,默认是no
daemonize yes
- 修改pid文件路径,此处可选,使用默认路径也可以。
# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
#
# When the server runs non daemonized, no pid file is created if none is
# specified in the configuration. When the server is daemonized, the pid file
# is used even if not specified, defaulting to "/var/run/redis.pid".
#
# Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally.
pidfile /var/run/redis_6379.pid
- 取消保护模式,此处可选。取消了便不要求使用密码验证了。
protected-mode no
-
保存文件。
-
新建 service 文件
sudo vim /usr/lib/systemd/system/redis.service
- 新建 pid 文件
# cd /var/run/
# touch redis_6379.pid
- 写入如下内容,具体文件路径,各异。
[Unit]
Description=Redis
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/root/tools/redis-5.0.4/src/redis-server /root/tools/redis-5.0.4/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
- 重载系统服务
sudo systemctl daemon-reload
- 启动redis
sudo systemctl start redis