码迷,mamicode.com
首页 > 系统相关 > 详细

Linux下Redis开机自启(Centos6)

时间:2019-01-05 13:40:18      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:配置   roc   sage   ror   rest   ESS   图片   root   ase   

1、设置redis.conf中daemonize为yes,确保守护进程开启。

  查找redis配置文件redis.conf

[root@localhost /]# find / -name redis.conf
/usr/local/redis/redis.conf

  编辑redis配置文件

[root@localhost ~]# vim /usr/local/redis/redis.conf

命令行模式下输入 /daemonize 查找

技术分享图片

将配置文件中daemonize为yes

2、编写开机自启动脚本

vi /etc/init.d/redis
# chkconfig: 2345 10 90  
# description: Start and Stop redis   
  
PATH=/usr/local/bin:/sbin:/usr/bin:/bin   
REDISPORT=6379  

  EXEC=/usr/local/redis/redis-server
  REDIS_CLI=/usr/local/redis/redis-cli

 PIDFILE=/var/run/redis.pid
  CONF="/usr/local/redis/redis.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   
                if [ "$?"="0" ]   
                then   
                        echo "Redis is running..."  
                fi   
                ;;   
        stop)   
                if [ ! -f $PIDFILE ]   
                then   
                        echo "$PIDFILE exists, process is not running."  
                else  
                        PID=$(cat $PIDFILE)   
                        echo "Stopping..."  
                       $REDIS_CLI -p $REDISPORT  SHUTDOWN    
                        sleep 2  
                       while [ -x $PIDFILE ]   
                       do  
                                echo "Waiting for Redis to shutdown..."  
                               sleep 1  
                        done   
                        echo "Redis stopped"  
                fi   
                ;;   
        restart|force-reload)   
                ${0} stop   
                ${0} start   
                ;;   
        *)   
               echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2  
                exit 1  
esac

3、写完后保存退出VI

4、设置权限

[root@localhost init.d]# chmod 777 /etc/init.d/redis

5、启动测试

/etc/init.d/redis start

启动成功会提示如下信息:

[root@localhost init.d]# /etc/init.d/redis start
/etc/init.d/redis: line 1: kconfig:: command not found
Starting Redis server...
4046:C 05 Jan 2019 12:00:02.611 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
4046:C 05 Jan 2019 12:00:02.611 # Redis version=5.0.0, bits=32, commit=00000000, modified=0, pid=4046, just started
4046:C 05 Jan 2019 12:00:02.611 # Configuration loaded
Redis is running...

使用redis-cli测试:(可能会出现auth认证问题,应该是设置了认证密码,输入密码既可以啦

[root@localhost init.d]# redis-cli
127.0.0.1:6379> set fgf 123456
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> set fgf 123
OK
127.0.0.1:6379> get fgf
"123"
127.0.0.1:6379> 

6、设置开机自启动

[root@localhost init.d]# chkconfig redis on

7、关机重启测试

reboot

然后在用redis-cli测试即可











Linux下Redis开机自启(Centos6)

标签:配置   roc   sage   ror   rest   ESS   图片   root   ase   

原文地址:https://www.cnblogs.com/clubs/p/10223775.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!