centos7安装redis

centos7安装redis的步骤说明

  1. 安装gcc环境:
yum install gcc
  1. 安装wget环境:
yum -y install wget
  1. 官方下载redis包:
wget http://download.redis.io/releases/redis-3.2.3.tar.gz $ tar xzf redis-3.2.3.tar.gz
  1. 进入redis目录 编译安装
cd redis-3.2.3
make
  1. 执行安装命令
make install

make install安装完成后,会在/usr/local/bin目录下生成下面几个可执行文件,它们的作用分别是:
redis-server:Redis服务器端启动程序
redis-cli:Redis客户端操作工具。也可以用telnet根据其纯文本协议来操作
redis-benchmark:Redis性能测试工具
redis-check-aof:数据修复工具
redis-check-dump:检查导出工具

  1. 配置redis
cp redis.conf /etc/ 6379.conf

修改配置文件6379.conf

vi /etc/6379.conf

(1)修改daemonize配置项为yes(大概在128行),使Redis进程在后台运行
daemonize yes
(2)注释 bind 127.0.0.1 (取消限制ip)
#bind 127.0.0.1
(3)设置密码
将”# requirepass foobared“ 取掉注释改成 requirepass 123
(4)关闭防火墙

service firewalld stop
  1. 启动redis
cd /usr/local/bin 
 ./redis-server /etc/6379.conf
  1. 检查启动情况
ps -ef | grep redis
  1. 添加开机启动项
    (1)编写脚本
vi /etc/init.d/redis
#!/bin/sh
# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database

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

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/${REDISPORT}.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 -a "123" -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

(2)保存退出,设置权限

chmod 777 /etc/init.d/redis
  1. 启动redis

打开redis命令:service redis start

关闭redis命令:service redis stop

设为开机启动:chkconfig redis on

设为开机关闭:chkconfig redis off

上一篇:redis安装与配置


下一篇:LINUX 下安装Nginx