前端之家收集整理的这篇文章主要介绍了
Centos下配置Redis开机启动,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1、设置redis.conf中daemonize为yes,确保守护进程开启。
2、编写开机自启动脚本
脚本内容如下:
-
- #!/bin/bash
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
# description: Start and Stop redis
- PATH=/usr/local/bin:/sbin:/usr/bin:/bin
- #redis端口号
- REDISPORT=6379
- #redis-server所在目录的绝对路径
- EXEC=/usr/apk/redis-2.8.17/redis-server
- #redis-cli所在目录的绝对路径
- REDIS_CLI=/usr/apk/redis-2.8.17/redis-cli
-
- PIDFILE=/var/run/redis.pid
- #redis.conf所在目录的绝对路径
- CONF="/usr/apk/redis-2.8.17/redis.conf"
- AUTH="Nginx"
-
- case"$1"in
- start)
- if[-f$PIDFILE]
- then
- echo"$PIDFILEexists,processisalreadyrunningorcrashed."
- else
- echo"StartingRedisserver..."
- $EXEC$CONF
- fi
- if["$?"="0"]
- then
- echo"Redisisrunning..."
- ;;
- stop)
- if[!-f$PIDFILE]
- echo"$PIDFILEexists,processisnotrunning."
- else
- PID=$(cat$PIDFILE)
- echo"Stopping..."
- $REDIS_CLI-p$REDISPORTSHUTDOWN
- sleep2
- while[-x$PIDFILE]
- do
- echo"WaitingforRedistoshutdown..."
- sleep1
- done
- echo"Redisstopped"
- fi
- ;;
- restart|force-reload)
- ${0}stop
- ${0}start
- *)
- echo"Usage:/etc/init.d/redis{start|stop|restart|force-reload}">&2
- exit1
- esac
写完后保存退出VI
3、设置权限
chmod 755 /etc/init.d/redis
4,设定开机启动服务
5,启动,停止redis
启动成功会提示如下信息:
@H_296_
403@Starting Redis server...
Redis
is running...
使用redis-cli测试:
[root@rk ~]# /usr/redisbin/redis-@H_296_
403@cli
127.0.
0.1:
6379>
set@H_296_
403@ foo bar
OK
get@H_296_
403@ foo
"bar"
6379> exit
6、关机重启测试
reboot
然后在用redis-cli测试即可。