Linux上Redis的安装

1.下载指定安装包
默认路径为root文件夹:
[root@iZ23wq3vv2xZ ~]# wget http://download.redis.io/releases/redis-4.0.2.tar.gz

2.解压

[root@iZ23wq3vv2xZ ~]# cd /root
[root@iZ23wq3vv2xZ ~]# ls
mysql-community-release-el7-5.noarch.rpm  redis-4.0.2.tar.gz
[root@iZ23wq3vv2xZ ~]# tar zxvf redis-4.0.2.tar.gz
redis-4.0.2/
redis-4.0.2/.gitignore
redis-4.0.2/00-RELEASENOTES
redis-4.0.2/BUGS
redis-4.0.2/CONTRIBUTING
redis-4.0.2/COPYING
redis-4.0.2/INSTALL
redis-4.0.2/MANIFESTO
redis-4.0.2/Makefile
redis-4.0.2/README.md
......略

3.安装(必须先安装gcc服务,教程另觅)

[root@iZ23wq3vv2xZ ~]# cd redis-4.0.2/
[root@iZ23wq3vv2xZ redis-4.0.2]# make
cd src && make all
make[1]: Entering directory `/root/redis-4.0.2/src'
    CC Makefile.dep
......    略
    INSTALL redis-sentinel
    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[1]: Leaving directory `/root/redis-4.0.2/src' 

安装到指定目录/usr/local/redis

[root@iZ23wq3vv2xZ redis-4.0.2]# cd src
[root@iZ23wq3vv2xZ src]# make PREFIX=/usr/local/redis install
    CC Makefile.dep

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

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install

工具命令列表:

[root@iZ23wq3vv2xZ src]# cd /usr/local/redis/
[root@iZ23wq3vv2xZ redis]# ls
bin
[root@iZ23wq3vv2xZ redis]# cd bin
[root@iZ23wq3vv2xZ bin]# ls
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server

拷贝redis的配置文件redis.conf到安装目录:

[root@iZ23wq3vv2xZ ~]# cd redis-4.0.2/
[root@iZ23wq3vv2xZ redis-4.0.2]# cp redis.conf /usr/local/redis
[root@iZ23wq3vv2xZ redis-4.0.2]# cd /usr/local/redis
[root@iZ23wq3vv2xZ redis]# ls
bin  redis.conf

4.启动服务
修改配置文件,将daemonize修改为yes并保存:

[root@iZ23wq3vv2xZ redis]# vim redis.conf 
......

################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
......

输入启动指令,默认端口号为6379:

[root@iZ23wq3vv2xZ redis]# ./bin/redis-server ./redis.conf
28708:C 13 Nov 17:34:28.632 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
28708:C 13 Nov 17:34:28.632 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=28708, just started
28708:C 13 Nov 17:34:28.632 # Configuration loaded
[root@iZ23wq3vv2xZ redis]# netstat -nlt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp6       0      0 :::3306                 :::*                    LISTEN  

5.开启远程服务
注释绑定的端口号127.0.0.1并将protected-mode设置为no:

[root@iZ23wq3vv2xZ ~]# cd /usr/local/redis/
[root@iZ23wq3vv2xZ redis]# ls
bin  dump.rdb  redis.conf
[root@iZ23wq3vv2xZ redis]# vim redis.conf 
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#bind 127.0.0.1
......
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no

6.简单使用测试
以键值对形式保存:

[root@iZ23wq3vv2xZ ~]# cd /usr/local/redis/bin
[root@iZ23wq3vv2xZ redis]# ./redis-cli
127.0.0.1:6379> set name test
OK
127.0.0.1:6379> exists name
(integer) 1
127.0.0.1:6379> get name
"test"
127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> exists name
(integer) 0
127.0.0.1:6379> quit

7.关闭服务

[root@iZ23wq3vv2xZ ~]# pkill redis-server

你可能感兴趣的:(redis)