文档 · 2019年3月1日 0

Redis单节点部署

redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set –有序集合)和hash(哈希类型)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。在此基础上,redis支持各种不同方式的排序。与memcached一样,为了保证效率,数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现了master-slave(主从)同步。

首先去Redis官网找到自己想要的版本,下载到服务器中;

[root@az2-ccs-uat-main-01 /]# wget http://download.redis.io/releases/redis-4.0.13.tar.gz

我下载的4.0.13版本,目前最新的是5.0.*

下载后解压,安装

[root@az2-ccs-uat-main-01 /]# tar -zxvf redis-4.0.13.tar.gz
[root@az2-ccs-uat-main-01 local]# cd redis-4.0.13/
[root@az2-ccs-uat-main-01 redis-4.0.13]# ls
00-RELEASENOTES  COPYING  INSTALL    README.md   runtest-cluster   src
BUGS             data     Makefile   redis.conf  runtest-sentinel  tests
CONTRIBUTING     deps     MANIFESTO  runtest     sentinel.conf     utils
[root@az2-ccs-uat-main-01 redis-4.0.13]#
[root@az2-ccs-uat-main-01 redis-4.0.13]# make
[root@az2-ccs-uat-main-01 redis-4.0.13]# cd src
[root@az2-ccs-uat-main-01 redis-4.0.13]# make install

搞定!!!

简单配置一下配置文件:

编辑 redis目录的redis.conf文件  配置文件详细参数介绍请看《Redis配置文件详解

[root@az2-ccs-uat-main-01 redis-4.0.13]# vim redis.conf

简单介绍几个参数:
bind 10.10.10.10   ###指定服务端的IP地址。默认是127.0.0.1,建议修改为网卡的内网IP地址;
port 6379          ###redis服务的端口号,默认6379,建议修改为其他的端口。
daemonize yes      ### 值为yes :允许后台运行
logfile "/var/log/redis.log"    ###配置日志路径,默认为空.不输出日志;
requirepass password            ###配置redis的登录密码。

启动Redis

[root@az2-ccs-uat-main-01 /]# redis-server
18732:C 01 Mar 15:38:48.250 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
18732:C 01 Mar 15:38:48.250 # Redis version=4.0.13, bits=64, commit=00000000, modified=0, pid=18732, just started
18732:C 01 Mar 15:38:48.250 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
18732:M 01 Mar 15:38:48.250 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.13 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 18732
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

18732:M 01 Mar 15:38:48.251 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
18732:M 01 Mar 15:38:48.251 # Server initialized
18732:M 01 Mar 15:38:48.251 # 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.
18732:M 01 Mar 15:38:48.251 # 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.
18732:M 01 Mar 15:38:48.251 * Ready to accept connections

指定配置文件启动

[root@az2-ccs-uat-main-01 /]# redis-server /usr/local/redis-4.0.13/redis.conf
[root@az2-ccs-uat-main-01 /]# ps -elf | grep redis
5 S root     18788     1  0  80   0 - 36327 ep_pol 15:47 ?        00:00:00 redis-server 10.10.10.10:6379

入果没有查到进程就到日志去看一下,基本都没有什么问题。

本地链接redis

[root@az2-ccs-uat-main-01 /]# redis-cli -h 10.10.10.10
10.10.10.10:6379> 
10.10.10.10:6379> auth password
OK
10.10.10.10:6379>
10.10.10.10:6379> quit
[root@az2-ccs-uat-main-01 /]#

搞定。

 

打赏