linux 下centos 安装redis

linux 下centos 安装 redis

centos 版本:

linux 下centos 安装redis

redis 版本:redis-4.0.11.tar.gz

linux 下centos 安装redis

 在线安装:wget 命令。

centos 如缺少命令。使用 yum install wget

安装目录:/usr/local/redis 下

cd /usr/local/

获取redis包

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

解压  至redis 目录  

tar xzf redis-4.0.11.tar.gz   redis-4.0.11

进入redis 目录  

cd redis-4.0.11

安装make  

yum install make

安装gcc

yum install gcc

编译redis

make

错误问题:

1、linux 下centos 安装redis

make MALLOC=libcmake PREFIX=/usr/local/redis install

 创建redis目录至、usr/local 目录下

mkdir /usr/local/redis

将redis.conf 复制至  /usr/local/redis 目录下

cp redis.conf /usr/local/redis/redis.conf

更改后的redis目录

linux 下centos 安装redis

修改redis.conf的配置

vim redis.conf

1.后台启动,daemonize yes

2.绑定端口,port 6379 默认是6379 需要安全组开放端口

3.绑定IP,bind 192.168.2.128

4.指定数据存放路径,/usr/local/redis/log rdb存放的路径

5.指定持久化方式,appendonly yes

6.requirepass 123456 设置密码

配置说明:bind_ip 可绑多个,也可直接#注释。 

配置完成后,将redis.conf复制到/etc/redis/6379.conf       6379为端口号

cp redis.conf /etc/redis/6379.conf

在/etc/init.d/目录下 增加redis文件

vi /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.

### BEGIN INIT INFO
# Provides:     redis_6379
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Redis data structure server
# Description:          Redis data structure server. See https://redis.io
### END INIT INFO

REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

PASSWORD=$(cat $CONF|grep ‘^\s*requirepass‘|awk ‘{print $2}‘|sed ‘s/"//g‘)

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 ..."
                        if [ -z $PASSWORD ]
                        then
                                $CLIEXEC -p $REDISPORT shutdown
                        else
                                $CLIEXEC -a $PASSWORD -p $REDISPORT shutdown
                        fi
                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

配置截图:

linux 下centos 安装redis

保存退出,设置权限

chmod 777 /etc/init.d/redis

设为开机启动

chkconfig redis on

启动redis

service redis start