centos 6.5(64bit)安装配置redis

2018-10-12  本文已影响1人  星门小嗝嗝

centos 6.5(64bit)安装配置redis

1、先建几个后面要用到的文件夹

mkdir /etc/redis

mkdir /var/redis

cd /var/redis

mkdir data log run

2、下载并安装redis(下载最新的redis包)

cd /usr/local/src

wget http://download.redis.io/releases/redis-4.0.10.tar.gz

tar xzf redis-4.0.10.tar.gz

cd redis-4.0.10

make

make install

3、安装完成,可以查看redis版本

redis-server -v

4、配置redis

cp redis.conf /etc/redis

vi /etc/redis/redis.conf

如果需要本机意外的ip访问,默认是“bind 127.0.0.1 ::1”,改为“bind 0.0.0.0”;

修改启动模式为后台启动 daemonize yes

修改数据文件存储位置 dir /var/redis/data

修改pid目录 pidfile /var/redis/run/redis.pid

修改log存储目录 logfile /var/redis/log/redis.log

如果需要持久化存储 修改 appendonly

5、配置服务及开机自启动

vi /etc/init.d/redis

写入下面内容

# chkconfig:   2345 90 10  

# description:  Redis is a persistent key-value database  

###########################  

PATH=/usr/local/bin:/sbin:/usr/bin:/bin  

REDISPORT=6379  

EXEC=/usr/local/bin/redis-server  

REDIS_CLI=/usr/local/bin/redis-cli  

PIDFILE=/var/redis/run/redis.pid  

CONF="/etc/redis/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 does not exist, 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  

############################## 

完毕,给予权限

chmod +x /etc/init.d/redis

chkconfig redis on

service redis start/stop/restart

可以测试一下redis

# redis-cli

127.0.0.1:6379> set key 123

OK

127.0.0.1:6379> get key

"123"

127.0.0.1:6379> exit

上一篇下一篇

猜你喜欢

热点阅读