Redis数据库配置和开机自启

2016/05/20 Redis 阅读次数:

摘要: redis数据库redis.conf配置文件的内容介绍,以及修改方法

redis数据库配置

  • 配置
    Redis的配置信息在/etc/redis/redis.conf下。
  • 查看
    sudo vi /etc/redis/redis.conf

  • 核心配置选项
    • 绑定ip:如果需要远程访问,可将此⾏注释,或绑定⼀个真实ip
      bind 127.0.0.1

    • 端⼝,默认为6379
      port 6379

    是否以守护进程运⾏

    如果以守护进程运⾏,则不会在命令⾏阻塞,类似于服务
    如果以⾮守护进程运⾏,则当前终端被阻塞
    设置为yes表示守护进程,设置为no表示⾮守护进程
    推荐设置为yes
    daemonize yes

    数据⽂件
    dbfilename dump.rdb

    数据⽂件存储路径
    dir /var/lib/redis

    ⽇志⽂件
    logfile /var/log/redis/redis-server.log

    数据库,默认有16个
    database 16

    主从复制,类似于双机备份。
    slaveof

参考资料
redis配置信息http://blog.csdn.net/ljphilp/article/details/52934933

redis开机自启

readhat、contos 如下配置

将utils目录下的redis_init_script 复制到etc/init.d目录下
derek@deepin:/usr/local/redis/utils$ sudo cp redis_init_script /etc/init.d/redis
derek@deepin:/etc/init.d$ sudo vi redis 

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
# 下面这两行注释必须有
# chkconfig: 2345 10 90  
# description: Start and Stop redis   

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

centos 加入开机自启命令

// 加入开机自启,ok
chkconfig redis on

deban、deepin、ubuntu如下配置

#!/bin/sh
### BEGIN INIT INFO
# Provides: OSSEC HIDS
# Required-Start: $network $remote_fs $syslog $time
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OSSEC HIDS
### END INIT INFO


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

修改为可执行文件

derek@deepin:/etc/init.d$ sudo chmod +x /etc/init.d/redis

ubuntu 注册开机自启

sudo update-rc.d redis defaults

若是报错,就是redisd缺少如下代码:

#!/bin/sh
### BEGIN INIT INFO
# Provides: OSSEC HIDS
# Required-Start: $network $remote_fs $syslog $time
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OSSEC HIDS
### END INIT INFO

redis

Search

    Table of Contents