首页 > Redis > 正文

Redis安装【单实例】

佛若2018-09-170人围观

Redis安装【单实例】

下载

可以windows下载并上传至Centos或直接wget下载

  1. wget http://download.redis.io/releases/redis-4.0.8.tar.gz

解压

  1. tar -zxvf redis-4.0.8.tar.gz

安装环境依赖

  1. yum install gcc

编译安装

  1. # 进入目录
  2. cd redis-4.0.8
  3. # 编译安装
  4. make MALLOC=libc
  5. # 将src目录下的文件加到/usr/local/bin目录
  6. cd src && make install

测试安装结果

  1. # 进入安装目录下的src目录
  2. cd /usr/local/redis-4.0.8/src/
  3. # 启动redis服务
  4. ./redis-server

如果出现以下界面说明成功

  1. 11446:C 13 Sep 22:05:59.164 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
  2. 11446:C 13 Sep 22:05:59.164 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=11446, just started
  3. 11446:C 13 Sep 22:05:59.164 # Warning: no config file specified, using the default config. In order to specify a config file use ./src/redis-server /path/to/redis.conf
  4. 11446:M 13 Sep 22:05:59.165 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
  5. 11446:M 13 Sep 22:05:59.165 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
  6. 11446:M 13 Sep 22:05:59.165 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
  7. _._
  8. _.-``__ ''-._
  9. _.-`` `. `_. ''-._ Redis 4.0.8 (00000000/0) 64 bit
  10. .-`` .-```. ```\/ _.,_ ''-._
  11. ( ' , .-` | `, ) Running in standalone mode
  12. |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
  13. | `-._ `._ / _.-' | PID: 11446
  14. `-._ `-._ `-./ _.-' _.-'
  15. |`-._`-._ `-.__.-' _.-'_.-'|
  16. | `-._`-._ _.-'_.-' | http://redis.io
  17. `-._ `-._`-.__.-'_.-' _.-'
  18. |`-._`-._ `-.__.-' _.-'_.-'|
  19. | `-._`-._ _.-'_.-' |
  20. `-._ `-._`-.__.-'_.-' _.-'
  21. `-._ `-.__.-' _.-'
  22. `-._ _.-'
  23. `-.__.-'
  24. 11446:M 13 Sep 22:05:59.168 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
  25. 11446:M 13 Sep 22:05:59.168 # Server initialized
  26. 11446:M 13 Sep 22:05:59.168 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
  27. 11446:M 13 Sep 22:05:59.168 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
  28. 11446:M 13 Sep 22:05:59.195 * DB loaded from disk: 0.027 seconds
  29. 11446:M 13 Sep 22:05:59.195 * Ready to accept connections

其中默认端口6379,后台启动命令

  1. ./redis-server &

查看当前进程

  1. ps -ef | grep redis

输出

  1. gy 11446 11216 0 22:05 pts/0 00:00:00 ./src/redis-server *:6379
  2. gy 11490 11216 0 22:08 pts/0 00:00:00 grep --color=auto redis

可以看出,redis-server服务成功启动,并且端口号为6379;

客户端连接

下面我们使用redis自带的客户端连接工具

  1. # 进入src目录
  2. cd /usr/local/redis-4.0.8/src/
  3. # 使用redis-cli工具 (-h表示host,-p表示port)
  4. ./redis-cli -h 127.0.0.1 -p 6379

回车后界面会进入redis客户端控制台

  1. 127.0.0.1:6379>

尝试string数据存储与获取

  1. 127.0.0.1:6379> set name gaoyuan
  2. OK
  3. 127.0.0.1:6379> get name
  4. "gaoyuan"

综上

至此,单实例的redis已搭建完成,下一章节将会介绍哨兵架构高可用分布式集群架构

博客

开源中国博客地址

https://my.oschina.net/gmarshal

个人博客地址

http://blog.foruo.top

欢迎关注我的个人微信订阅号:(据说这个头像程序猿专用)

输入图片说明