单机redis基本安装

325人阅读 评论(0) 收藏 举报
分类:
单机redis基本安装

CentsOS 6.7 (Santiago)
Redis  3.2.11 64bit

-检测redis依赖包,参数
# rpm -qa | grep tcl
tcl-8.5.7-6.el6.x86_64
tcl-devel-8.5.7-6.el6.x86_64

vi /etc/security/limits.conf 最后增加

redis              soft    nofile  65536
redis              hard    nofile  65536 

vi /etc/pam.d/login文件最后增加
 
session    required     pam_limits.so

1.配置yum仓库,可以配本地或者阿里云的yum,不再详述

参考链接:http://blog.csdn.net/evils798/article/details/78401784

2.yum 安装gcc等依赖库

# yum install  -y gcc gcc-c++    

Installed:
  gcc.x86_64 0:4.4.7-18.el6                  
  gcc-c++.x86_64 0:4.4.7-18.el6                                                       

Dependency Installed:
  cloog-ppl.x86_64 0:0.15.7-1.2.el6          
   cpp.x86_64 0:4.4.7-18.el6           
   libstdc++-devel.x86_64 0:4.4.7-18.el6           
   ppl.x86_64 0:0.10.2-11.el6          

Dependency Updated:
  libgcc.i686 0:4.4.7-18.el6             
  libgcc.x86_64 0:4.4.7-18.el6             
  libgomp.x86_64 0:4.4.7-18.el6             
  libstdc++.x86_64 0:4.4.7-18.el6            

Complete!

3.下载 3.2.11版本的redis  

# cd /usr/local/src/
# wget http://download.redis.io/releases/redis-3.2.11.tar.gz
--2017-11-08 18:30:18--  http://download.redis.io/releases/redis-3.2.11.tar.gz
Resolving download.redis.io... 109.74.203.151
Connecting to download.redis.io|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://111.1.62.113/cloud/111.1.50.15/files/516100000648EA55//download.redis.io/releases/redis-3.2.11.tar.gz [following]
--2017-11-08 18:30:18--  http://111.1.62.113/cloud/111.1.50.15/files/516100000648EA55//download.redis.io/releases/redis-3.2.11.tar.gz
Connecting to 111.1.62.113:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1550452 (1.5M) [application/octet-stream]
Saving to: “redis-3.2.11.tar.gz”

100%[=======================================================================>] 1,550,452   --.-K/s   in 0.1s    

2017-11-08 18:30:18 (10.5 MB/s) - “redis-3.2.11.tar.gz” saved [1550452/1550452]


3.下载完成后解压、编译、安装
# tar zxf redis-3.2.11.tar.gz  
# ls
redis-3.2.11  redis-3.2.11.tar.gz

# cd redis-3.2.11
# ls
00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README.md   runtest          runtest-sentinel  src    utils
BUGS             COPYING       INSTALL  MANIFESTO  redis.conf  runtest-cluster  sentinel.conf     tests


4.编译安装redis,make之前用make test 检查是否存在错误

#make test
make[1]: Entering directory `/usr/local/src/redis-3.2.11/src'
39 seconds - unit/geo
  98 seconds - unit/type/list-3
  111 seconds - integration/replication-psync

\o/ All tests passed without errors!  --test测试成功,没有错误

Cleanup: may take some time... OK
make[1]: Leaving directory `/usr/local/src/redis-3.2.11/src'

5.编译安装
# make && make install
cd src && make all
make[1]: Entering directory `/usr/local/src/redis-3.2.11/src'
    INSTALL redis-sentinel
    CC redis-cli.o
    LINK redis-cli
    CC redis-benchmark.o
    LINK redis-benchmark
    INSTALL redis-check-rdb

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

make[1]: Leaving directory `/usr/local/src/redis-3.2.11/src'
cd src && make install
make[1]: Entering directory `/usr/local/src/redis-3.2.11/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 `/usr/local/src/redis-3.2.11/src'

6.查看redis进程,系统中无redis进程

# ps -ef | grep redis
root      9688  4443  0 18:35 pts/1    00:00:00 grep redis

7.创建相关文件夹

# mkdir -p /usr/local/redis
# mkdir -p /redis/data
# mkdir -p /usr/local/redis/bin

进入utils目录,使用install_server.sh脚本配置安装redis 
# cd utils/
# pwd
/usr/local/src/redis-3.2.11/utils
# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 7000                                          --指定端口 
Please select the redis config file name [/etc/redis/7000.conf] /usr/local/redis/redis_7000.conf        --指定conf配置文件目录
Please select the redis log file name [/var/log/redis_7000.log] /usr/local/redis/redis_7000.log           --指定log位置
Please select the data directory for this instance [/var/lib/redis/7000] /redis/data/                       --指定数据文件位置
Please select the redis executable path [/usr/local/bin/redis-server]   
Selected config:
Port           : 7000                                        
Config file    : /usr/local/redis/redis_7000.conf
Log file       : /usr/local/redis/redis_7000.log
Data dir       : /redis/data/
Executable     : /usr/local/bin/redis-server                      
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/7000.conf => /etc/init.d/redis_7000                     --生成的redis启动脚本redis_7000
Installing service...
Successfully added to chkconfig! 
Successfully added to runlevels 345!             
Starting Redis server...
Installation successful!

8.安装完成后查看redis进程
# netstat  -tpnl | grep 7000
tcp        0      0 127.0.0.1:7000              0.0.0.0:*                   LISTEN      9725/redis-server 1 

# /etc/init.d/redis_7000  status
Redis is running (9725)

9.增加redis用户来启动维护redis,  (-s 指定shell  -M 不创建HOME目录)

# useradd   redis -s  /sbin/nologin  -M

查看redis id

# id redis
uid=501(redis) gid=501(redis) groups=501(redis)

10.修改相关目录权限

# chown  -R redis.redis /usr/local/redis/
# ls -al /redis/

drwxr-xr-x.  2 root root 4096 Nov  8 18:36 data

# chown  -R redis.redis /redis/data/

# /etc/init.d/redis_7000 stop
Stopping ...
Redis stopped

11.修改启动脚本,增加切换用户redis 执行
# vi /etc/init.d/redis_7000 

注意以下几行变量的路径都要有redis用户的读写权限,否则在使用/etc/init.d/redis_7000脚本关闭redis服务的时候会报redis_7000.pid does not exist, process is not running错误,导致无法正常关闭redis

#!/bin/sh
EXEC=/usr/local/bin/redis-server             
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/usr/local/redis/redis_7000.pid     --指定pid文件路径,在/usr/local/redis/redis_7000.conf配置文件中的也要将pid文件的路径修改为/usr/local/redis/redis_7000.pid
CONF="/usr/local/redis/redis_7000.conf"    
REDISPORT="7000"

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
        ;;
    status)
        PID=$(cat $PIDFILE)
        if [ ! -x /proc/${PID} ]
        then
            echo 'Redis is not running'
        else
            echo "Redis is running ($PID)"
        fi
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Please use start, stop, restart or status as first argument"
        ;;
esac

12.增加redis用户

在redis_7000脚本中的echo "Starting Redis server..."下面增加一段执行语句
                 sudo -u redis $EXEC $CONF --pidfile $PIDFILE
添加后如下:
case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
            echo "$PIDFILE exists, process is already running or crashed"
        else
            echo "Starting Redis server..."
            sudo -u redis $EXEC $CONF --pidfile $PIDFILE
            
13.启动,关闭redis 测试相关功能          
# /etc/init.d/redis_7000 start
Starting Redis server...

# ps -aux | grep redis
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
redis     9781  0.0  0.1 133524  7564 ?        Ssl  18:48   0:00 /usr/local/bin/redis-server 127.0.0.1:7000                                                    
root      9789  0.0  0.0 103304   900 pts/1    S+   18:49   0:00 grep redis

14.使用客户端工具登录测试redis(无密码验证模式)

[root@localhost redis]# redis-cli  -h  127.0.0.1 -p 7000

127.0.0.1:7000> ping
PONG

127.0.0.1:7000> echo hi
"hi"
127.0.0.1:7000> 
127.0.0.1:7000> 
127.0.0.1:7000> select 1
OK
127.0.0.1:7000[1]> INCR foo
(integer) 1
127.0.0.1:7000[1]> set bar 1
OK
127.0.0.1:7000[1]> get bar
"1"
关闭redis
# /etc/init.d/redis_7000 stop
Stopping ...
Redis stopped



查看评论

【精】Redis3.2.11在centos9安装

首先更新yum环境 yum -y update 1.安装gcc环境 yum -y install gcc 2.首先下载redis安装包 cd /home/apps wget http:...
  • fenglixiong123
  • fenglixiong123
  • 2018-01-18 16:23:17
  • 407

redis-3.2.11.tar.gz 以及redis-3.3.5.gem

  • 2017年12月07日 16:28
  • 1.56MB
  • 下载

Redis教程(十一) Redis集群安装

集群要实现的目的是要将不同的 key 分散放置到不同的 redis 节点,这里我们需要一个规则或者算法,通常的做法是获取 key 的哈希值,然后根据节点数来求模,但这种做法有其明显的弊端,当我们需要增...
  • yuan_xw
  • yuan_xw
  • 2016-12-20 16:03:18
  • 710

linux系统上面安装redis 3.2

首先从官网下载redis-3.2最新的稳定版本 安装前需要先检查操作系统是否安装gcc环境,rpm –qa | grep gcc 如果没有就使用yum –y install gcc,来安装。 ...
  • lwj_199011
  • lwj_199011
  • 2016-05-16 11:42:05
  • 2170

linux搭建redis(单机版)

1.redis的安装   1.1 redis 下载    官网地址 点击打开链接    下载地址  点击打开链接   1.2 redis 的安装    安装redis需要c...
  • qq_40794266
  • qq_40794266
  • 2018-01-27 21:54:39
  • 196

在linux服务器上安装单机版redis

一、环境准备 因为redis使用c语言开发的,如果要运行在linux上,需要gcc-c++的环境。 ​那么我们就要先看一下是否安装了gcc-c++如果没有的话, ​需要安装gcc-c++环境...
  • fireroll
  • fireroll
  • 2017-11-27 14:32:07
  • 179

CentOS6.5 中安装单机版redis

ContOS65 64位中安装redis 安装gcc环境 官网下载redis 326 解压并将文件拷贝到 userlocalreids中 拷贝文件到 usrlocalredis-326中 进入解...
  • liudongdong0909
  • liudongdong0909
  • 2016-12-24 21:36:53
  • 374

Redis安装(单机)

之前一段时间由于业务需要研究了下Redis相关信息,现特将Redex的从单机到集群的各种配置在个人博客上做更新,以便需要的道友! 1  概述 Redis是一个开源的、使用C语言编写的、支持网络...
  • vtopqx
  • vtopqx
  • 2015-07-10 17:04:38
  • 26439

Redis cluster 3.2.11 集群搭建

安装环境与版本redis 采用 redis-3.2.11 版本。两台虚拟机都是 CentOS ,一台 CentOS6.5 (IP:192.168.231.129)CentOS6.5(IP:192.16...
  • u010571316
  • u010571316
  • 2018-03-11 13:37:25
  • 84

redis3.0.2 编译安装(启动参数方式启动)

1.下载redis3.0.2[root@Moxiaokai ~]# wget http://download.redis.io/releases/redis-3.0.2.tar.gz  [root@M...
  • cy309173854
  • cy309173854
  • 2016-09-22 11:36:06
  • 1711
    个人资料
    持之以恒
    等级:
    访问量: 85万+
    积分: 9305
    排名: 2483
    简介
    此博客为笔者的DT工作记录,欢迎一起交流学习工作中的点滴,若博客文章观点存在原理的错误、纰漏,笔者非常欢迎各位不保留地指出
    最新评论