1、下载Redis3.2.5安装包
wget
2、解压、编译、安装redis-3.2.5:
tar -zxvf redis-3.2.5.tar.gz -C /usr/src/cd /usr/src/redis-3.2.5/make && make install
3、创建redis相关目录:
mkdir -p /home/redis/binmkdir -p /home/redis/logmkdir -p /home/redis/pidmkdir -p /home/redis/db
4、将可执行文件复制到自己的安装目录:/home/redis/
ln -s /usr/local/bin/redis-* /home/redis/bin/
5、复制配置文件到自己的安装目录:/home/redis/
cp redis.conf /home/redis/
6、进入自己的安装目录,编辑redis.conf配置文件:
cd /home/redis/
vim /home/redis/redis.conf根据实际需要修改配置文件,以下仅供参考
daemonize yespidfile /home/redis/pid/redis.pidlogfile /home/redis/log/redis.logdir /home/redis/dbport 6379tcp-backlog 511timeout 600tcp-keepalive 0loglevel noticedatabases 16save 900 1save 300 10save 60 10000rdbcompression yesdbfilename dump.rdbslave-serve-stale-data yesappendonly yesappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbslowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-entries 512list-max-ziplist-value 64set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes
# vm-enabled no# maxmemory 4G
7、创建redis服务脚本,并赋予权限:
vim /etc/init.d/redis#!/bin/sh## Simple Redis init.d script conceived to work on Linux systems# as it does use of the /proc filesystem.PATH=/home/redis/bin:/sbin:/usr/bin:/binREDISPORT=6379EXEC=/home/redis/bin/redis-serverCLIEXEC=/home/redis/bin/redis-cliPIDFILE=/home/redis/pid/redis.pidCONF="/home/redis/redis.conf"case "$1" instart)if [ -f $PIDFILE ]thenecho "$PIDFILE exists, process is already running or crashed"elseecho "Starting Redis server..."$EXEC $CONFfi;;stop)if [ ! -f $PIDFILE ]thenecho "$PIDFILE does not exist, process is not running"elsePID=$(cat $PIDFILE)echo "Stopping ..."$CLIEXEC -p $REDISPORT shutdownwhile [ -x /proc/${PID} ]doecho "Waiting for Redis to shutdown ..."sleep 1doneecho "Redis stopped"fi;;*)echo "Please use start or stop as first argument";;esac
8、添加redis服务开机启动:
chmod a+x /etc/init.d/redis
9、启动redis服务:
service redis startps -ef | grep redisnetstat -anptu | grep 6379
10、测试OK
redis-cli
set key1 hello
get key1
quit
(防火墙启用6379端口: iptables -A INPUT -p tcp --dport 6379 -j ACCEPT)