wget http://download.redis.io/releases/redis-3.2.6.tar.gz
tar -zxvf redis-3.2.6.tar.gzcd redis-3.2.6 make//编译,生成src、redis.conf文件cd src cp redis-cli redis-server /usr/local/redis/cd redis-3.2.6cp redis.conf /usr/local/redis///redis下开启前台服务./redis-server//redis下开启后台服务,修改redis.conf 文件,将daemonize no 改为daemonize yesvi redis.conf//杀掉rdis进程,然后再次打开redis服务,没有killall命令就yum安装,yum install psmisc -y(centos7下)killall redis-server//开启服务./redis-server redis.conf//查看开启的服务pstree//后台运行成功以后,用redis-cli本地客户端连接redis。如果是连接网络机器 :./redis-cli IP 端口号,IP地址和端口号可以不写,不写的话,默认连接本机redis./redis-cli//配置开机自启mkdir /etc/init.d/redisvi /etc/init.d/redis
#!/bin/bash#chkconfig: 2345 10 90# description: Start and Stop redis PATH=/usr/local/bin:/sbin:/usr/bin:/bin REDISPORT=6379 EXEC=/usr/local/redis/redis-server REDIS_CLI=/usr/local/redis/redis-cli PIDFILE=/var/run/redis.pid CONF="/usr/local/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
///etc/init.d/redis下设置权限
chmod 755 redis//启动测试/etc/init.d/redis start//返回,Starting Redis server... Redis is running...//执行脚本,开机自启,chkconfig redis on