Centos7中源码安装Redis4.0版本并进行相关的配置

背景:

系统:Centos7.4 64位
服务:Redis4.0.14

1. 首先安装依赖

主要是安装系统常用的一些底层依赖库

yum -y install vim automake libtool flex bison pkgconfig gcc-c++ \
boost-devel boost-devel-static libevent-devel zlib-devel python-devel \
ruby-devel openssl-devel fontconfig net-tools.x86_64 lrzsz libffi-devel \
bzip2-devel libgif-devel libjpeg-devel libpng-devel readline-devel sqlite-devel ctags

安装完成后,如下所示:

Installed:
  automake.noarch 0:1.13.4-3.el7                      bison.x86_64 0:3.0.4-2.el7                      boost-devel.x86_64 0:1.53.0-27.el7
  boost-static.x86_64 0:1.53.0-27.el7                 bzip2-devel.x86_64 0:1.0.6-13.el7               ctags.x86_64 0:5.8-13.el7
  flex.x86_64 0:2.5.37-6.el7                          fontconfig.x86_64 0:2.13.0-4.3.el7              gcc-c++.x86_64 0:4.8.5-36.el7_6.2
  libevent-devel.x86_64 0:2.0.21-4.el7                libffi-devel.x86_64 0:3.0.13-18.el7             libjpeg-turbo-devel.x86_64 0:1.2.90-6.el7
  libpng-devel.x86_64 2:1.5.13-7.el7_2                libtool.x86_64 0:2.4.2-22.el7_3                 lrzsz.x86_64 0:0.12.20-36.el7
  openssl-devel.x86_64 1:1.0.2k-16.el7_6.1            python-devel.x86_64 0:2.7.5-77.el7_6            readline-devel.x86_64 0:6.2-10.el7
  ruby-devel.x86_64 0:2.0.0.648-34.el7_6              sqlite-devel.x86_64 0:3.7.17-8.el7              zlib-devel.x86_64 0:1.2.7-18.el7

Dependency Installed:
  autoconf.noarch 0:2.69-11.el7                      boost.x86_64 0:1.53.0-27.el7                      boost-atomic.x86_64 0:1.53.0-27.el7
  boost-chrono.x86_64 0:1.53.0-27.el7                boost-context.x86_64 0:1.53.0-27.el7              boost-date-time.x86_64 0:1.53.0-27.el7
  boost-filesystem.x86_64 0:1.53.0-27.el7            boost-graph.x86_64 0:1.53.0-27.el7                boost-iostreams.x86_64 0:1.53.0-27.el7
  boost-locale.x86_64 0:1.53.0-27.el7                boost-math.x86_64 0:1.53.0-27.el7                 boost-program-options.x86_64 0:1.53.0-27.el7
  boost-python.x86_64 0:1.53.0-27.el7                boost-random.x86_64 0:1.53.0-27.el7               boost-regex.x86_64 0:1.53.0-27.el7
  boost-serialization.x86_64 0:1.53.0-27.el7         boost-signals.x86_64 0:1.53.0-27.el7              boost-system.x86_64 0:1.53.0-27.el7
  boost-test.x86_64 0:1.53.0-27.el7                  boost-thread.x86_64 0:1.53.0-27.el7               boost-timer.x86_64 0:1.53.0-27.el7
  boost-wave.x86_64 0:1.53.0-27.el7                  dejavu-fonts-common.noarch 0:2.33-6.el7           dejavu-sans-fonts.noarch 0:2.33-6.el7
  fontpackages-filesystem.noarch 0:1.44-8.el7        keyutils-libs-devel.x86_64 0:1.5.8-3.el7          krb5-devel.x86_64 0:1.15.1-37.el7_6
  libcom_err-devel.x86_64 0:1.42.9-13.el7            libevent.x86_64 0:2.0.21-4.el7                    libicu.x86_64 0:50.1.2-17.el7
  libjpeg-turbo.x86_64 0:1.2.90-6.el7                libkadm5.x86_64 0:1.15.1-37.el7_6                 libpng.x86_64 2:1.5.13-7.el7_2
  libselinux-devel.x86_64 0:2.5-14.1.el7             libsepol-devel.x86_64 0:2.5-10.el7                libstdc++-devel.x86_64 0:4.8.5-36.el7_6.2
  libverto-devel.x86_64 0:0.2.5-4.el7                libyaml.x86_64 0:0.1.4-11.el7_0                   ncurses-devel.x86_64 0:5.9-14.20130511.el7_4
  pcre-devel.x86_64 0:8.32-17.el7                    perl-Data-Dumper.x86_64 0:2.145-3.el7             perl-Test-Harness.noarch 0:3.28-3.el7
  perl-Thread-Queue.noarch 0:3.02-2.el7              ruby.x86_64 0:2.0.0.648-34.el7_6                  ruby-irb.noarch 0:2.0.0.648-34.el7_6
  ruby-libs.x86_64 0:2.0.0.648-34.el7_6              rubygem-bigdecimal.x86_64 0:1.2.0-34.el7_6        rubygem-io-console.x86_64 0:0.4.2-34.el7_6
  rubygem-json.x86_64 0:1.7.7-34.el7_6               rubygem-psych.x86_64 0:2.0.0-34.el7_6             rubygem-rdoc.noarch 0:4.0.0-34.el7_6
  rubygems.noarch 0:2.0.14.1-34.el7_6

Updated:
  net-tools.x86_64 0:2.0-0.24.20131004git.el7                                      vim-enhanced.x86_64 2:7.4.160-5.el7

Dependency Updated:
  cpp.x86_64 0:4.8.5-36.el7_6.2           e2fsprogs.x86_64 0:1.42.9-13.el7   e2fsprogs-libs.x86_64 0:1.42.9-13.el7   freetype.x86_64 0:2.8-12.el7_6.1
  gcc.x86_64 0:4.8.5-36.el7_6.2           krb5-libs.x86_64 0:1.15.1-37.el7_6 libcom_err.x86_64 0:1.42.9-13.el7       libgcc.x86_64 0:4.8.5-36.el7_6.2
  libgomp.x86_64 0:4.8.5-36.el7_6.2       libselinux.x86_64 0:2.5-14.1.el7   libselinux-python.x86_64 0:2.5-14.1.el7 libselinux-utils.x86_64 0:2.5-14.1.el7
  libsepol.x86_64 0:2.5-10.el7            libss.x86_64 0:1.42.9-13.el7       libstdc++.x86_64 0:4.8.5-36.el7_6.2     openssl.x86_64 1:1.0.2k-16.el7_6.1
  openssl-libs.x86_64 1:1.0.2k-16.el7_6.1 python.x86_64 0:2.7.5-77.el7_6     python-libs.x86_64 0:2.7.5-77.el7_6     vim-common.x86_64 2:7.4.160-5.el7
  zlib.x86_64 0:1.2.7-18.el7

Complete!

2. 安装Redis4.0.14

2.1 下载并解压

下载Redis4.0.14的源码包,并解压

wget http://download.redis.io/releases/redis-4.0.14.tar.gz
tar -zxvf redis-4.0.14.tar.gz
2.2 安装并编译
# 进入文件夹
cd redis-4.0.14
# 编译文件
make
# 然后出现
    CC redis-cli.o
    LINK redis-cli
    CC redis-benchmark.o
    LINK redis-benchmark
    INSTALL redis-check-rdb
    INSTALL redis-check-aof

Hint: It's a good idea to run 'make test' ;)
这就表明 make成功啦

# 然后编译安装到指定的文件夹下面
make PREFIX=/usr/local/redis4.0 install


# 出现下面这样就表示已经源码安装编译到指定位置啦
make PREFIX=/usr/local/redis4.0 install
cd src && make install
make[1]: Entering directory `/root/redis-4.0.14/src'
    CC Makefile.dep
make[1]: Leaving directory `/root/redis-4.0.14/src'
make[1]: Entering directory `/root/redis-4.0.14/src'

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/root/redis-4.0.14/src'

3. 修改配置

3.1 生成配置文件

把默认配置文件复制到 /usr/local/redis4.0/bin目录下

cd ~/redis-4.0.14
cp redis.conf /usr/local/redis4.0/bin/
cd /usr/local/redis4.0/bin/
3.2 修改 bind
bind 127.0.0.1
这一行给注释掉 或者改为:
bind 0.0.0.0
3.3 配置日志文件夹路径
logfile ""
改为:
logfile "/data/logs/redis4.0/redis.log"
注意:redis-server启动前,要先创建好 /data/logs/redis4.0文件夹,不然会报错
3.4 允许后台启动运行
daemonize no
改为:
daemonize yes
3.5 关闭protect-mode 保护模式
protected-mode  yes
改为:
protected-mode no

4. 开启服务

编写redis4.0的开启shell脚本
vim redis_start.sh
"redis_start.sh"[New File]

!/usr/bin/env bash

nohup /usr/local/redis4.0/bin/redis-server /usr/local/redis4.0/bin/redis.conf 1>/data/logs/redis4.0/redis.log 2>&1 &
echo "redis-server is started..."

# 然后赋予可执行权限
chmod +x redis_start.sh
编写redis4.0的关闭shell脚本
vim redis_stop.sh
"redis_stop.sh" [New File]

#!/usr/bin/env bash

/usr/local/redis4.0/bin/redis-cli shutdown
echo 'redis-server is shutdown successful'

将 redis4.0配置到系统环境中
vim /etc/profile

export REDIS_HOME="/usr/local/redis4.0"
export PATH="$PATH:$REDIS_HOME/bin"

source /etc/profile

开启 redis-server服务
redis_start.sh
 查看redis服务是否开启:
 ps -ef | grep redis 如下:
 
root     17396     1  0 23:11 ?        00:00:00 /usr/local/redis4.0/bin/redis-server 0.0.0.0:6379
root     17402 17152  0 23:13 pts/0    00:00:00 grep --color=auto redis
说明redis-server服务已经开启了

你可能感兴趣的:(数据库)