--直接到官网下载 http://download.redis.io/releases/redis-3.0.2.tar.gz (1)基础安装 --下载后解压 /home/www/redis-3.0.2 --安装 make 报错: error: jemalloc/jemalloc.h: No such file or directory --解决 make MALLOC=libc 原因:jemalloc是默认的分配器,系统没有jemalloc仅仅有libc 再次运行make就可以安装完毕! (2)多port多实例安装(可參考http://blog.csdn.net/xu470438000/article/details/42971091文章,涉及到集群) 在/home/www/redis-3.0.2建立文件夹cluster mkdir -p /home/www/redis-3.0.2/cluster --在该文件夹下建立三个文件夹 mkdir 6379 mkdir 6380 mkdir 6381 --把redis.conf文件复制到6379下: cp /home/www/redis-3.0.2/redis.conf /home/www/redis-3.0.2/cluster/6379 --改动配置(眼下仅仅改动前两项也能够) pidfile /var/run/redis-6379.pid #当执行多个redis要指定不同PID port 6379 #端口号 daemonize yes #是否以守护进程启动 cluster-enabled yes #开启集群模式 cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes logfile /var/log/redis/redis-6379.log #配置日志文件位置 --同理把redis.conf拷贝到6380、6381下改动port cp /home/www/redis-3.0.2/cluster/6379/redis.conf /home/www/redis-3.0.2/cluster/6380/ cp /home/www/redis-3.0.2/cluster/6379/redis.conf /home/www/redis-3.0.2/cluster/6381/ --启动服务 /home/www/redis-3.0.2/src/redis-server /home/www/redis-3.0.2/cluster/6379/redis.conf /home/www/redis-3.0.2/src/redis-server /home/www/redis-3.0.2/cluster/6380/redis.conf /home/www/redis-3.0.2/src/redis-server /home/www/redis-3.0.2/cluster/6381/redis.conf --查看port ps -ef|grep redis --连接6380库(命令行) /home/www/redis-3.0.2/src/redis-cli -h 192.168.5.128 -p 6380 启动后依据conf配置会创建/var/run/redis-6379.pid进程(在redis.conf中配置) --关闭某个port /home/www/redis-3.0.2/src/redis-cli -p 6379 shutdown --批量模糊删除键 redis-cli -p 6381 KEYS "t_hash:*" | xargs redis-cli -p 6381 del 至此多port已安装完毕! (3)启动脚本 #!/bin/sh PATH=/usr/local/bin:/sbin:/usr/bin:/bin REDISPORT=6379 #实际环境而定 EXEC=/home/www/redis-3.0.2/src/redis-server #实际环境而定 REDIS_CLI=/home/www/redis-3.0.2/src/redis-cli #实际环境而定 PIDFILE=/var/run/redis-6379.pid #实际环境而定 CONF="/home/www/redis-3.0.2/cluster/6379/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 exists, process is not running." else PID=$(cat $PIDFILE) echo "Stopping..." $REDIS_CLI -p $REDISPORT SHUTDOWN while [ -x $PIDFILE ] do echo "Waiting for Redis to shutdown..." sleep 1 done echo "Redis stopped" fi ;; restart|force-reload) ${0} stop ${0} start ;; *) echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2 exit 1 esac --创建脚本 mkdir /etc/init.d/redis-6379 chmod +x /etc/init.d/redis-6379 --启动、停止 service redis-6379 start|stop (5)开机增加自启动 chkconfig redis-6379 on chkconfig redis-6380 on chkconfig redis-6381 on 报错:service redis does not support chkconfig 解决方法:(必须把以下两行凝视放在/etc/init.d/redis文件靠前的凝视中) # chkconfig: 2345 90 10 # description: Redis is a persistent key-value database 上面的凝视的意思是。redis服务必须在执行级2,3,4,5下被启动或关闭,启动的优先级是90。关闭的优先级是10。 (6)使用client 下载Redis DeskTop Managerclient Add New Connection name:192.168.5.128--6380 host:192.168.5.128 port:6380 auth:(此处默认没有值。为安全起见会设置password)