> 数据库 > Redis >

redis: 启动和关闭

redis 的启动和关闭非常简单,目前发现两种 redis 启动方式,如下:

方式一 直接启动
    编译安装完 redis 后会在 src 目录下产生 redis-server 等可执行文件, 配置好  redis_6379.conf 文件后直接启动即可。

--配置文件 redis_6379.conf

daemonize yes pidfile /usr/local/redis/redis_6379.pid port 6379 logfile "/usr/local/redis/redis.log" dbfilename dump.rdb dir /usr/local/redis

备注: 仅修改以上配置参数。      --启动 redis

[redis@db1 redis]$ redis-server redis_6379.conf

--关闭 redis

[redis@db1 redis]$ redis-cli shutdown  

方式二:  通过服务方式启动      redis 启动脚本位于 redis-2.8.17/utils/ 目录下, 名为 redis_init_script ,通过以下步骤配置 -- copy 文件

# cp redis_init_script /etc/init.d/redisd  

--修改  redisd 文件

#!/bin/sh # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. REDISPORT=6379 EXEC=/usr/local/redis/bin/redis-server CLIEXEC=/usr/local/redis/bin/redis-cli PIDFILE=/usr/local/redis/redis_${REDISPORT}.pid CONF="/usr/local/redis/redis_${REDISPORT}.conf"

备注:主要根据实际情况修改 redisd 文件头部配置项。 --启动 redis

[root@db1 init.d]# /etc/init.d/redisd start Starting Redis server...

--关闭 redis

[root@db1 init.d]# /etc/init.d/redisd stop Stopping ... Redis stopped

--加入自启动

[root@db1 init.d]# chkconfig redisd on service redisd does not support chkconfig

备注: 加入 redis 服务自启动报错,需要修改 /etc/init.d/redisd  文件,增加以下两行

# chkconfig:   2345 90 10   # description:  Redis is a persistent key-value database  

--再次执行 chkconfig

[root@db1 init.d]# chkconfig redisd on

--附: 我这里配置的 redisd 文件

[root@db1 init.d]# cat /etc/init.d/redisd       #!/bin/sh # chkconfig:   2345 90 10   # description:  Redis is a persistent key-value database   # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. REDISPORT=6379 EXEC=/usr/local/redis/bin/redis-server CLIEXEC=/usr/local/redis/bin/redis-cli PIDFILE=/usr/local/redis/redis_${REDISPORT}.pid CONF="/usr/local/redis/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

参考 (责任编辑:IT)