安装:
1.获取redis资源
wget http://download.redis.io/releases/redis-4.0.8.tar.gz
2.解压
tar xzvf redis-4.0.8.tar.gz
3.安装
cd redis-4.0.8
make
cd src
make install PREFIX=/usr/local/redis
4.移动配置文件到安装目录下
cd ../
mkdir /usr/local/redis/etc
mv redis.conf /usr/local/redis/etc
5.配置redis.conf文件
注掉本地IP,允许远程访问:#bind 127.0.0.1
修改保护模式,允许远程访问:protected-mode no
redis执行后台运行:daemonize yes
6.将redis服务脚本(redis-4.0.8/utils/redis_init_script)移动到 /etc/init.d目录下
mv /usr/local/redis-4.0.8/utils/redis_init_script /etc/init.d
cd /etc/init.d
mv redis_init_script redis
7.修改配置信息
vim redis
#!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. # chkconfig:2345 90 10 # description:Redis is a persistent key-value database REDISPORT=6379 EXEC=/usr/local/redis/bin/redis-server CLIEXEC=/usr/local/redis/bin/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid CONF="/usr/local/redis/etc/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 ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $CLIEXEC -p $REDISPORT shutdown while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; *) echo "Please use start or stop as first argument" ;; esac
8.增加文件执行权限,并加入服务
chmod +x /etc/init.d/redis
chkconfig --add redis
9.查看开机启动项
chkconfig --list
常用命令
启动:service redis start
停止:service redis stop
pkill redis //停止redis
卸载redis:
rm -rf /usr/local/redis //删除安装目录
rm -rf /usr/bin/redis-* //删除所有redis相关命令脚本
rm -rf /root/download/redis-4.0.8 //删除redis解压文件夹