Redis 安装及配置

  • 安装 gcc
# yum -y install gcc
  • 解压 tcl8.6.1-src.tar.gz
[root@grape0 download]# tar -zxvf tcl8.6.1-src.tar.gz -C /usr/local/

进入目录

[root@grape0 download]# cd /usr/local/tcl8.6.1/unix/

./configure 生成 Makefile 文件,为下一步编译做准备

[root@grape0 unix]# ./configure

编译及安装,make 以及 make install

[root@grape0 unix]# make
[root@grape0 unix]# make install

报错:

make[1]: Leaving directory `/usr/local/tcl8.6.1/unix/pkgs/thread2.7.0'
  • 解压redis-2.8.13.tar.gz
[root@grape0 download]# tar -zxvf redis-2.8.13.tar.gz  -C /usr/local/
[root@grape0 download]#cd /usr/local/redis-2.8.13/
[root@grape0 redis-2.8.13]# make
Hint: To run 'make test' is a good idea ;)
make[1]: Leaving directory `/usr/export/software/redis-2.8.13/src'
  • 执行安装命令
make PREFIX=/usr/local/redis install
#PREFIX=/usr/local/redis可以省略,省略情况下redis会默认安装到/usr/local/bin目录下
cd src && make install
make[1]: Entering directory `/usr/export/software/redis-2.8.13/src'

Hint: To run 'make test' is a good idea ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/usr/export/software/redis-2.8.13/src'
  • 根据提示,执行:cd src && make install
[root@grape0 redis-2.8.13]# cd src && make install

Hint: To run 'make test' is a good idea ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install

[root@grape0 src]#
  • 安装tcl8.5(如不进行redis test测试可以不安装)
[root@grape0 src]# yum install tcl
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os error was
12: Timeout on http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os: (28, 'Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds')
 * base: mirrors.btte.net
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
base                                                   | 3.7 kB     00:00
extras                                                 | 3.4 kB     00:00
updates                                                | 3.4 kB     00:00
updates/primary_db                                     | 4.7 MB     00:05
Setting up Install Process
Package 1:tcl-8.5.7-6.el6.x86_64 already installed and latest version
Nothing to do
[root@grape0 src]#
  • 测试Redis
[root@grape0 src]# make test
Cleanup: may take some time... OK
Starting test server at port 11111
Executing test client: couldn't open socket: connection refused.
couldn't open socket: connection refused
    while executing
"socket localhost $server_port"
    (procedure "test_client_main" line 2)
    invoked from within
"test_client_main $::test_server_port "
Executing test client: couldn't open socket: connection refused.
couldn't open socket: connection refused
    while executing
    ......
[root@grape0 redis-2.8.13]# make test
cd src && make test
make[1]: Entering directory `/usr/export/software/redis-2.8.13/src'
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] Error 1
make[1]: Leaving directory `/usr/export/software/redis-2.8.13/src'
make: *** [test] Error 2

没有出错继续

[root@grape0 redis-2.8.13]# make install
  • 复制并修改配置文档
    — 创建redis日志目录,和数据文件目录
[root@grape1 src]#cd /usr/local/redis-2.8.13
[root@grape1 redis-2.8.13]# cp redis.conf  /usr/local/redis/
[root@grape1 redis-2.8.13]# mkdir -p /usr/local/redis/log
[root@grape1 redis-2.8.13]# mkdir -p /usr/local/redis/db
  • 修改redis.conf下面的配置项
[root@grape1 redis-2.8.13]# cd /usr/local/redis/
[root@grape1 redis]# vi redis.conf
daemonize yes  #确保守护进程开启 
pidfile /usr/local/redis/redis.pid
logfile /usr/local/redis/log
dir /usr/local/redis/db
  • 启动redis
[root@grape1 redis]#cd /usr/local/redis/bin/
[root@grape1 bin]# ./redis-server
//以daem方式启动redis服务
# redis-server

《Redis 安装及配置》

  • 启动客户端(另起一个命令框)
[root@grape0 src]#  /usr/local/redis/bin/redis-cli
或
[root@grape0 src]#  /usr/local/bin/redis-cli
127.0.0.1:6379>
  • 测试
127.0.0.1:6379> set welcome 'hello redis'
OK
127.0.0.1:6379> get welcome
"hello redis"
127.0.0.1:6379>
  • 关闭服务
127.0.0.1:6379> shutdown
  或者
[root@grape0 src]# redis-cli shutdown
[25723] 07 Oct 19:32:39.046 # User requested shutdown...
[25723] 07 Oct 19:32:39.046 * Saving the final RDB snapshot before exiting.
[25723] 07 Oct 19:32:39.079 * DB saved on disk
[25723] 07 Oct 19:32:39.079 # Redis is now ready to exit, bye bye...
[root@grape0 redis-2.8.13]#
  • 设置开机启动 redis
vi /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.

PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/home/cloud/Desktop/redis-4.0.1/redis.conf"
AUTH="1234"

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
        ;;
     restart | force-reloaded)
                ${0} stop
                ${0} start
                ;;
    *)
        echo "Usage: /etc/init.d/redis {start|stop|restart|force-reloaded}" >&2
        exit 1
esac

添加权限

chmod 755 /etc/init.d/redis

启动或关闭服务 进行测试

service redis start  
service redis stop

设置开机启动

chkconfig redis on

参考:
CentOS 6.5下Redis安装记录Redis之——CentOS 6.5安装配置rediscentos7下redis的安装

    原文作者:舰长同学
    原文地址: https://www.jianshu.com/p/970c3a75edd0
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞