centos7 redis5编译安装

Redis

准备

准备yum源

yum -y install wget
wget -O /etc/yum.repos.d/CentOSBase.repo http://mirrors.aliyun.com/repo/Centos-7.repo
rm -rf /etc/yum.repos.d/CentOS-*
yum -y install vim net-tools lrzsz epel-release bash-completion

安装编译环境

yum -y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake  pcre pcre-devel openssl openssl-devel   jemalloc-devel tlc libtool

下载redis

redis文件放在/root下

redis-5.0.5.tar.gz

官方下载地址

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

安装

解压redis

tar xvf redis-5.0.5.tar.gz

编译redis

cd redis-5.0.5/
make && make install PREFIX=/usr/local/redis

redis配置修改

cd  /usr/local/redis/
## 将/usr/local/redis/bin加入到PATH中
echo "export PATH=$PATH:/usr/local/redis/bin" > /etc/profile.d/redis_bin.sh

source /etc/profile.d/redis_bin.sh 


## 创建配置文件目录
mkdir /usr/local/redis/etc

## 拷贝配置文件
cp /root/redis-5.0.5/redis.conf   /usr/local/redis/etc/


## 默认情况下,Redis服务不会在后台静默执行,需要通过使用&显示指定后台执行或改redis配置文件
vim  /usr/local/redis/etc/redis.conf

## 将daemonize的值改为yes
daemonize yes

## 将bind 127.0.0.1改为bind 0.0.0.0
bind 0.0.0.0

## 将requirepass foobared 去掉#改成自己的密码
requirepass  123456root

redis启动

直接启动

/usr/local/redis/bin/redis-server   /usr/local/redis/etc/redis.conf 

直接关闭

[root@master ~]# ps -ef|grep redis
root      15659      1  0 14:20 ?        00:00:00 /usr/local/redis/bin/redis-server 0.0.0.0:6379
root      15665  10964  0 14:21 pts/1    00:00:00 grep --color=auto redis
[root@master ~]# kill -9 15659

系统启动

编辑启动脚本
vim /etc/init.d/redis

#!/bin/sh
# chkconfig: 2345 10 90  
# description: Start and Stop redis
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

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

PIDFILE=/run/redis_6379.pid
CONF=/usr/local/redis/etc/redis.conf
AUTH=123456root

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 -a $AUTH 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
启动
## 给脚本添加执行权限
chmod  +x /etc/init.d/redis

## redis启动
service redis start

## redis关闭
service redis stop

## redis添加到开机自动启动
chkconfig --add redis

你可能感兴趣的:(install)