1.将下载好的压缩包放到/usr/local目录下
# tar xzf redis-3.0.2.tar.gz # cd redis-3.0.2 # make
提示错误 make: cc: Command not found make: *** [adlist.o] Error 127
没有安装gcc环境,需要安装gcc
# yum install gcc
安装后检查是否安装成功
# rpm -qa |grep gcc
之后重新make
2.编译完成后,在Src目录下,有四个可执行文件redis-server、redis-benchmark、redis-cli和redis.conf将其拷贝到一个目录下。
# mkdir /usr/redis # cp redis-server /usr/redis # cp redis-benchmark /usr/redis # cp redis-cli /usr/redis # cp redis.conf /usr/redis # cd /usr/redis
3.启动服务
# redis-server redis.conf
提示错误 -bash :redis-server:command not found
建立软连接
# ln -s /usr/redis/redis-server /usr/bin/redis-server # ln -s /usr/redis/redis-cli /usr/bin/redis-cli
重新启动
# redis-server /usr/redis/redis.conf
启动成功
4.设置开机自启动
(1)先将redis.conf中daemonize设置为yes,确保守护进程开启。
(2)编写开机自启动脚本
# vi /etc/init.d/redis
PATH=/usr/local/bin:/sbin:/usr/bin:/bin REDISPORT=6379 EXEC=/usr/redis/redis-server REDIS_CLI=/usr/redis/redis-cli PIDFILE=/var/run/redis.pid CONF="/usr/redis/redis.conf" AUTH="1234" 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 sleep 2 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 注: redis设置AUTH命令 redis 127.0.0.1:6379> AUTH PASSWORD (error) ERR Client sent AUTH, but no password is set redis 127.0.0.1:6379> CONFIG SET requirepass "1234" OK redis 127.0.0.1:6379> AUTH 1234 Ok
(3)设置权限
# chmod 755 redis
(4)启动
# /etc/init.d/redis start
提示错误 /etc/init.d/redis:permission denied
# chmod a+x /etc/init.d/redis
a+x 是给所有人加上可执行权限,包括所有者,所属组,和其他人
o+x 只是给其他人加上可执行权限
重新启动后显示
Starting Redis server…
Redis is running …
(5)设置开机自启动
# chkconfig redis on
提示错误 service redis does not support chkconfig
把下面两行注释放在/etc/init.d/redis文件靠前的注释中:
# chkconfig: 2345 90 10 # description: Redis is a persistent key-value database
(6)关机重启测试