Centos6.5下Redis安装、主从配置、卸载详解

一、安装

1.通过工具将redis-2.8.13.tar.gz上传到服务器

Centos6.5下Redis安装、主从配置、卸载详解

2. 解压安装包

Centos6.5下Redis安装、主从配置、卸载详解

3.打开redis-2.8.13,并创建db log pid文件夹

Centos6.5下Redis安装、主从配置、卸载详解

4.复制redis.cnf文件到etc

Centos6.5下Redis安装、主从配置、卸载详解

5.编辑文件redis.cnf

Centos6.5下Redis安装、主从配置、卸载详解

daemonize yes

pidfile /home/redis/pid/redis.pid

port 6379

tcp-backlog 511

timeout 600

tcp-keepalive 0

loglevel notice

logfile /home/redis/log/redis.log

databases 16

save 900 1

save 300 10

save 60 10000

rdbcompression yes

dbfilename dump.rdb

dir /home/redis/db

slave-serve-stale-data yes

appendonly yes

appendfilename "appendonly.aof"

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

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-entries 512

list-max-ziplist-value 64

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

6.创建文件init.d

Centos6.5下Redis安装、主从配置、卸载详解

#!/bin/sh

# chkconfig: 2345 60 40

# Description: Start and Stop redis

# Provides: redis

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

PATH=/usr/local/bin:/sbin:/usr/bin:/bin

REDISPORT=6379

EXEC=/usr/local/bin/redis-server

REDIS_CLI=/usr/local/bin/redis-cli

PIDFILE=/home/redis/pid/redis.pid

CONF="/etc/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 does not exist, process is not running"

else

PID=$(cat $PIDFILE)

echo "Stopping Redis server..."

$REDIS_CLI -p $REDISPORT SHUTDOWN

while [ -x ${PIDFILE} ]

do

echo "Waiting for Redis to shutdown ..."

sleep 1

done

echo "Redis is stopped"

fi

;;

restart|force-reload)

${0} stop

${0} start

;;

*)

echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}">&2

exit 1

esac

二、主从配置

1.在从服务器中修改Redis的文件 redis.conf

slaveof 主服务器IP 端口例如:slaveof 127.0.0.1 6379

Centos6.5下Redis安装、主从配置、卸载详解

2.启动主/从服务器

主:

Centos6.5下Redis安装、主从配置、卸载详解

从:

Centos6.5下Redis安装、主从配置、卸载详解

3.登录主/从服务器,测试同步

主:

Centos6.5下Redis安装、主从配置、卸载详解

从:

Centos6.5下Redis安装、主从配置、卸载详解

三、卸载

1.CD 命令进入编译后的安装目录, 执行反安装命令:make uninstall

2.查找残留Redis相关文件

Centos6.5下Redis安装、主从配置、卸载详解

相关推荐