关闭

Redis安装

标签: ubunturedis
66人阅读 评论(0) 收藏 举报
分类:

Ubuntu安装Redis


1.redis配置文件

redis.cof

protected-mode no
port 6379
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
 requirepass qwer1234
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

2.redis启动脚本

redis启动脚本redis_init_script在redis/utils路径下,修改redis_init_script,拷贝到/etc/init.d/下,重命名为redisd,d表示后台服务。

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

#redis服务器监听的端口
REDISPORT=6379
#redis密码
PASSWORD=qwer1234
#服务端所处位置,在make install后默认存放与`/usr/local/bin/redis-server`,如果未make install则需要修改该路径,下同。
EXEC=/home/hurry/mySoftware/redis-3.2.1/src/redis-server
#客户端路径
CLIEXEC=/home/hurry/mySoftware/redis-3.2.1/src/redis-cli

#redis的PID文件路径
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 -a $PASSWORD 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.新建文件路径

配置文件要求存在这些路径,必须手动创建,否则报错。

#创建pid文件路径
$ sudo mkdir -p /var/run/redis
$ sudo chown -R hurry:hurry /var/run/redis

#创建配置文件路径
$ sudo mkdir /etc/redis
$ sudo chown -R hurry:hurry /etc/redis
$ cp -a redis.conf /etc/redis/6379.conf

4.启动/关闭redis

$ /etc/init.d/redisd start 
$ /etc/init.d/redisd stop

#查看是否启动成功
$ ps -ef|grep redis
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:331次
    • 积分:32
    • 等级:
    • 排名:千里之外
    • 原创:3篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档