Centos6.5安装redis服务

来源:互联网 发布:冰川网络不败传说 编辑:程序博客网 时间:2024/05/12 01:15

下载redis安装包

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

解压、编译、安装

tar -xvzf redis-3.2.6.tar.gz -C /usr/srccd /usr/src/redis-3.2.6/make && make install

创建redis相关目录

mkdir -p /home/redis/binmkdir -p /home/redis/logmkdir -p /home/redis/pidmkdir -p /home/redis/db

将可执行文件复制到自己的安装目录:/home/redis/

ln -s /usr/local/bin/redis-* /home/redis/bin/

复制配置文件到安装目录:/home/redis

cp redis.conf /home/redis/

编辑redis配置文件

cd /home/redis/vim /home/redis/redis.conf

根据实际需要修改配置文件,以下仅供参考

daemonize yespidfile /home/redis/pid/redis.pidlogfile /home/redis/log/redis.logdir /home/redis/dbport 6379tcp-backlog 511timeout 600tcp-keepalive 0loglevel noticedatabases 16save 900 1save 300 10save 60 10000rdbcompression yesdbfilename dump.rdbslave-serve-stale-data yesappendonly yesappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbslowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-entries 512list-max-ziplist-value 64set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes# vm-enabled no# maxmemory 4G

创建redis服务脚本

vim /etc/init.d/redis
#!/bin/sh## Simple Redis init.d script conceived to work on Linux systems# as it does use of the /proc filesystem.PATH=/home/redis/bin:/sbin:/usr/bin:/binREDISPORT=6379EXEC=/home/redis/bin/redis-serverCLIEXEC=/home/redis/bin/redis-cliPIDFILE=/home/redis/pid/redis.pidCONF="/home/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        ;;    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

添加redis服务开机启动

chmod a+x /etc/init.d/redis

启动redis服务

service redis startps -ef | grep redisnetstat -anptu | grep 6379

测试OK

 redis-cli     set key1 hello     get key1     quit

(防火墙启用6379端口:iptables -A INPUT -p tcp --dport 6379 -j ACCEPT)
1 0
原创粉丝点击