redis设置开机自启动会不会用root用户启动
时间: 2023-05-17 19:06:13 浏览: 171
可以使用root用户启动redis开机自启动。您可以使用以下命令将redis添加到系统启动项中:
1. 编辑redis的启动脚本:sudo vi /etc/init.d/redis
2. 在脚本中添加以下内容:
```
#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
```
3. 保存并退出文件
4. 添加执行权限:sudo chmod +x /etc/init.d/redis
5. 将redis添加到系统启动项中:sudo update-rc.d redis defaults
6. 启动redis:sudo service redis start
这样,redis就会在系统启动时自动启动。
阅读全文