启动redis

[root ~]#redis-server
8988:C 25 Jun 11:24:31.317 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
8988:M 25 Jun 11:24:31.319 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 3.2.12 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 8988
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

8988:M 25 Jun 11:24:31.320 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
8988:M 25 Jun 11:24:31.321 # Server started, Redis version 3.2.12
8988:M 25 Jun 11:24:31.321 # 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.

指定配置启动

redis-server /etc/redis.conf 

redis-server ./redis.conf

后台运行

[root ~]#redis-server /etc/redis.conf --daemonize yes
[root ~]#
[root ~]#ps -ef | grep redis
root     20568     1  0 11:29 ?        00:00:00 redis-server *:6379
root     23088  8695  0 11:29 pts/0    00:00:00 grep --color=auto redis
[root ~]#

关闭redis

redis-cli shutdown

redis客户端

启动redis命令行
[root ~]#redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> ping
PONG

这里如果不指定-h 和-p的默认-h是127.0.0.1 -p是6379
我们除了在本机登陆也可以在其它机器远程访问:

远程登录redis

需要修改配置文件/etc/redis.conf,注释如下一行

bind 127.0.0.1

类似于mongo,默认监听的是本机,可以在nestat -anlp | grep redis中看到.

[root ~]#netstat -anlp | grep redis
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      26444/redis-server
tcp6       0      0 :::6379                 :::*                    LISTEN      26444/redis-server
[root ~]#

修改配置:

protected-mode no

这个特性禁止外部访问redis ,加强redis的安全性。
放通端口:

[root ~]#firewall-cmd --zone=public --add-port=6379/tcp --permanent
success
[root ~]#
[root ~]#firewall-cmd --reload
success

在外部机器访问:

coder52@52coder ~ % redis-cli -h 192.168.31.103 -p 6379
192.168.31.103:6379> ping
PONG
192.168.31.103:6379>