安装与配置

  1. # 在/usr目录下创建redis目录
  2. [root@jianbao ~]# cd /usr
  3. [root@jianbao usr]# mkdir redis
  4. [root@jianbao usr]# cd redis
  5. # 将redis-linux包拖到redis目录下
  6. [root@jianbao redis]# ls
  7. redis-5.0.7.tar.gz
  8. # 解压redis-linux包
  9. [root@jianbao redis]# tar -zxvf redis-5.0.7.tar.gz
  10. [root@jianbao redis]# ls
  11. redis-5.0.7 redis-5.0.7.tar.gz
  12. # 进入redis-linux包目录,执行make命令
  13. [root@jianbao redis]# cd redis-5.0.7
  14. [root@jianbao redis-5.0.7]# make
  15. [root@jianbao redis-5.0.7]# make install
  16. # 在redis目录下新建config目录,将redis-5.0.7包中的配置文件redis.conf复制到config目录下。这样方便使用且可以保证安装包的完整性
  17. [root@jianbao redis-5.0.7]# cd ..
  18. [root@jianbao redis]# ls
  19. redis-5.0.7 redis-5.0.7.tar.gz
  20. [root@jianbao redis]# mkdir config
  21. [root@jianbao redis]# cd config
  22. [root@jianbao config]# cp /usr/redis/redis-5.0.7/redis.conf /usr/redis/config
  23. [root@jianbao config]# ls
  24. redis.conf

启动与关闭

通过配置文件首先启动 redis 服务端。

  1. [root@jianbao redis]# redis-server config/redis.conf

随后启动 redis 客户端并用 ping 命令测试是否启动成功,如果返回 PONG 则说明启动成功。

  1. [root@jianbao redis]# redis-cli -p 6379
  2. 127.0.0.1:6379> ping
  3. PONG

通过查看进程查看 redis 进程是否存在。

  1. [root@jianbao redis]# ps -ef|grep redis
  2. root 5369 1565 0 18:13 pts/0 00:00:00 redis-server 127.0.0.1:6379
  3. root 11846 5467 0 18:15 pts/2 00:00:00 redis-cli -p 6379
  4. root 18420 16176 0 18:17 pts/4 00:00:00 grep --color=auto redis

通过 shutdown 和 exit 命令关闭 redis。

  1. 127.0.0.1:6379> shutdown
  2. not connected> exit
  3. [root@jianbao redis]# ps -ef|grep redis
  4. root 22840 16176 0 18:18 pts/4 00:00:00 grep --color=auto redis