Redis之二--单节点搭建

本文仅用于个人学习,可随意转载,但是初学难免会有所纰漏,谨慎操作

2019-06-05 00:37:42

一、环境准备

安装gcc

[root@redis ~]# yum install -y gcc

上传压缩包到指定路径,解压到指定路径,更改目录名称

[root@redis ~]# cd /data/software/
[root@redis software]# ls
redis-3.0.0-rc2.tar.gz
[root@redis software]# tar zxvf redis-3.0.0-rc2.tar.gz -C /data
[root@redis software]# mv /data/redis-3.0.0-rc2 /data/redis-3.0.0

二、编译安装并修改配置文件

编译

[root@redis data]# cd redis-3.0.0/
[root@redis redis-3.0.0]# ls
00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README      runtest          runtest-sentinel  src    utils
BUGS             COPYING       INSTALL  MANIFESTO  redis.conf  runtest-cluster  sentinel.conf     tests
[root@redis redis-3.0.0]# make

输出下图为编译成功

安装

[root@redis redis-3.0.0]# ls
00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README      runtest          runtest-sentinel  src    utils
BUGS             COPYING       INSTALL  MANIFESTO  redis.conf  runtest-cluster  sentinel.conf     tests
[root@redis redis-3.0.0]# cd src
[root@redis src]# make install

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

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
[root@redis src]# 

配置文件说明

redis-server:服务启动脚本

redis-cli:客户端启动脚本

redis-3.0.0/redis.conf配置文件详解:

#启动方式,默认为no表示前台启动,改为yes,后台启动
daemonize yes 
#监听端口,默认是6379
port 6379
#启动日志文件名称,默认为空,看心情设置
logfile "log-start"
#将redis分割为多少个数据库,默认为16,从0开始
databases 16
#数据文件名称,redis默认持久化方式为rdb模式
dbfilename dump.rdb
#数据文件及日志文件存放路径,默认是./ 即与redis.conf在同级目录下,可新建logs文件存放
dir ./logs
#是否开启aof持久化方式,默认关闭
appendonly no
#aof数据文件名称,默认appendonly.aof
appendfilename "appendonly.aof"

新建日志文件路径并启动

[root@redis redis-3.0.0]# pwd
/data/redis-3.0.0
[root@redis redis-3.0.0]# mkdir logs
[root@redis redis-3.0.0]# ./src/redis-server ./redis.conf

停止命令(使用kill时,不会进行持久化生成dump数据文件?)

./src/redis-cli shutdown

查看启动日志

 启动时,会在与 redis.conf 同级目录(./)下创建一个空的启动日志文件,同时在指定路径(./logs)下创建启动日志文件,如下表示启动成功

[root@redis redis-3.0.0]# ls
00-RELEASENOTES  CONTRIBUTING  deps     logs       Makefile   README      runtest          runtest-sentinel  src    utils
BUGS             COPYING       INSTALL  log-start  MANIFESTO  redis.conf  runtest-cluster  sentinel.conf     tests
[root@redis redis-3.0.0]# cat log-start 
[root@redis redis-3.0.0]# cd logs
[root@redis logs]# ls
log-start
[root@redis logs]# cat log-start 
4045:M 05 Jun 01:31:01.075 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 2.9.102 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 4045
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

4045:M 05 Jun 01:31:01.076 # Server started, Redis version 2.9.102
4045:M 05 Jun 01:31:01.076 # 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.
4045:M 05 Jun 01:31:01.076 # 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.
4045:M 05 Jun 01:31:01.076 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
4045:M 05 Jun 01:31:01.076 * The server is now ready to accept connections on port 6379
[root@redis logs]# 

登录客户端

[root@redis redis-3.0.0]# pwd
/data/redis-3.0.0
[root@redis redis-3.0.0]# ./src/redis-cli 
127.0.0.1:6379> 

基本命令

127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set name Sara
OK
127.0.0.1:6379> get name
"Sara"
127.0.0.1:6379> set age 17
OK
127.0.0.1:6379> get age
"17"
127.0.0.1:6379> keys *
1) "age"
2) "name"
127.0.0.1:6379> del age
(integer) 1
127.0.0.1:6379> keys *
1) "name"
127.0.0.1:6379> quit
[root@redis redis-3.0.0]#

 

posted @ 2019-06-05 01:54  人间丶迷走  阅读(298)  评论(0编辑  收藏  举报