先安装一些组件:
yum -y install gcc gcc-c++ libstdc++-devel
下载并安装:
# wget http://download.redis.io/releases/redis-2.8.19.tar.gz
# tar xzf redis-2.8..tar.gz
# cd redis-2.8.
# make && make install
如果有报错信息:
错误1:
[root@localhost redis-2.8.]# make && make install
cd src && make all
make[]: Entering directory `/data/software/redis-2.8./src'
CC adlist.o
In file included from adlist.c::
zmalloc.h::: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h::: error: #error "Newer version of jemalloc required"
make[]: *** [adlist.o] Error
make[]: Leaving directory `/data/software/redis-2.8./src'
make: *** [all] Error
解决方法:
# make MALLOC=libc
# make && make install
错误2:
[] Jan ::46.366 # Server started, Redis version 2.8.19
[] Jan ::46.366 # WARNING overcommit_memory is set to ! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
根据提示可以编辑 /etc/sysctl.conf 文件,在文件底部添加如下内容:
vm.overcommit_memory = 1
然后执行 /sbin/sysctl vm.overcommit_memory=1,使之生效。
可以通过 /sbin/sysctl -p 来查看是否添加成功!
错误3:
[] Jan ::14.324 # Server started, Redis version 2.8.
[] Jan ::14.324 # WARNING: The TCP backlog setting of cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of .
[] Jan ::14.324 * DB loaded from disk: 0.000 seconds
[] Jan ::14.324 * The server is now ready to accept connections on port
限制了接收新 TCP 连接侦听队列的大小。对于一个经常处理新连接的高负载 web服务环境来说,默认的 128 太小了。大多数环境这个值建议增加到 1024 或者更多。
服务进程会自己限制侦听队列的大小(例如 sendmail(8) 或者 Apache),常常在它们的配置文件中有设置队列大小的选项。大的侦听队列对防止拒绝服务 DoS 攻击也会有所帮助。
我们可以通过来修改这个参数。
解决方法:
# echo > /proc/sys/net/core/somaxconn
错误4:
[] May ::22.059 # Server started, Redis version 2.8.
[] May ::22.059 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
[] May ::22.059 * DB loaded from disk: 0.000 seconds
[] May ::22.059 * The server is now ready to accept connections on port
解决方法:
# echo never > /sys/kernel/mm/transparent_hugepage/enabled
启动redis:
# redis-server /data/redis/redis.conf
测试设置:
# redis-cli
127.0.0.1:> set name redisdev
OK
127.0.0.1:> get name
"redisdev"
关闭redis:
# redis-cli shutdown
加入服务,并开机自启动:
# vim /etc/init.d/redis
添加以下脚本:
# chkconfig:
# description: service of redis for start and stop add by tomener PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli PIDFILE=/var/run/redis.pid
CONF="/data/redis/redis.conf"
AUTH="" 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 [ "$?"="" ]
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
sleep
while [ -x $PIDFILE ]
do
echo "Waiting for Redis to shutdown..."
sleep
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${} stop
${} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&
exit
esac
# chmod /etc/init.d/redis
# /etc/init.d/redis start
# chkconfig --add redis
# chkconfig --level redis on #使用该命令能愉快的玩耍了
# service redis start|stop|restart
到此安装完成。那么您肯定会用到命令,附详细的命令大全。我也拿来参考用,防长时间忘记。