顿搜
飞过闲红千叶,夕岸在哪
类目归类
yum install gcc-g++wget http://download.redis.io/releases/redis-3.2.3.tar.gz
tar xzf redis-3.2.3.tar.gzcd redis-3.2.3
make MALLOC=libc #如果不加参数,linux下会报错mkdir /home/redis/log
mkdir /home/redis/pid
mkdir /home/redis/db
mkdir /home/redis/bin
mkdir /home/redis/conf
mkdir /home/redis/script将编译好的src下的文件拷贝到/home/redis/bin目录下,需要拷贝的文件包括
①、mkreleasehdr.sh
②、redis-benchmark
③、redis-check-aof
④、redis-check-rdb
⑤、redis-cli
⑥、redis-sentinel
⑦、redis-server
⑧、redis-trib.rb
将编译好的redis.conf复制到/home/redis/conf下,编辑
daemonize yes #是否把redis-server启动在后台,默认是“否”。若改成yes,会生成一个pid文件。
pidfile /home/redis/pid/redis.pid #redis-server的pid文件
port 6379 #redis-server的端口号
tcp-backlog 511
timeout 600
tcp-keepalive 0
loglevel notice #日志级别,有四种,debug,verbose,notice,warning。
logfile /home/redis/log/redis.log #日志的输出文件,默认是标准输出。例如:logfile /tmp/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在/home/redis/script目录下创建redis-server.sh,并写入以下脚本
#!/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=/home/redis/bin
REDISPORT=6379
EXEC=/home/redis/bin/redis-server
REDIS_CLI=/home/redis/bin/redis-cli
PIDFILE=/home/redis/pid/redis.pid
CONF="/home/redis/conf/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在/home/redis/script目录下创建client.sh,并写入以下脚本
cd /home/redis/script
./bin/redis-cli -h ip -p port #ip换成自己的ip,port换成6379cd /home/redis/script
sh redis-server startps -ef | grep redis找到进程号后kill掉
cd /home/redis/script
sh redis-server stopcd /home/redis/script
./client.sh
set ds dunso
get ds如果能得到dunso,说明写入成功
以安装在/home/redis-slave/目录下为例
在redis.conf中增加
slaveof ip port #ip填写master的ip,端口填写master的端口
slave-read-only yes #表示slave只读不写,也是推荐设置首先启动slave,然后
cd /home/redis-slave/script
./client.sh
get ds如果能够得到dunso,说明已经同步成功。