Linux上Redis的安装

来源:互联网 发布:ssh端口号 编辑:程序博客网 时间:2024/05/16 01:15
1.下载指定安装包
默认路径为root文件夹:
[root@iZ23wq3vv2xZ ~]# wget http://download.redis.io/releases/redis-4.0.2.tar.gz

2.解压

[root@iZ23wq3vv2xZ ~]# cd /root[root@iZ23wq3vv2xZ ~]# lsmysql-community-release-el7-5.noarch.rpm  redis-4.0.2.tar.gz[root@iZ23wq3vv2xZ ~]# tar zxvf redis-4.0.2.tar.gzredis-4.0.2/redis-4.0.2/.gitignoreredis-4.0.2/00-RELEASENOTESredis-4.0.2/BUGSredis-4.0.2/CONTRIBUTINGredis-4.0.2/COPYINGredis-4.0.2/INSTALLredis-4.0.2/MANIFESTOredis-4.0.2/Makefileredis-4.0.2/README.md......略

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

[root@iZ23wq3vv2xZ ~]# cd redis-4.0.2/[root@iZ23wq3vv2xZ redis-4.0.2]# makecd src && make allmake[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-aofHint: 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.depHint: 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]# lsbin[root@iZ23wq3vv2xZ redis]# cd bin[root@iZ23wq3vv2xZ bin]# lsredis-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]# lsbin  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.conf28708:C 13 Nov 17:34:28.632 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo28708:C 13 Nov 17:34:28.632 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=28708, just started28708:C 13 Nov 17:34:28.632 # Configuration loaded[root@iZ23wq3vv2xZ redis]# netstat -nltActive 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]# lsbin  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/[root@iZ23wq3vv2xZ redis]# redis-cli127.0.0.1:6379> set name testOK127.0.0.1:6379> exists name(integer) 1127.0.0.1:6379> get name"test"127.0.0.1:6379> del name(integer) 1127.0.0.1:6379> exists name(integer) 0127.0.0.1:6379> quit

7.关闭服务

[root@iZ23wq3vv2xZ ~]# pkill redis-server