部署redis5.0.3

一、准备环境

1、下载

# wget http://download.redis.io/releases/redis-5.0.3.tar.gz

[root@localhost ~]# wget http://download.redis.io/releases/redis-5.0.3.tar.gz
--2019-03-25 09:04:37--  http://download.redis.io/releases/redis-5.0.3.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1959445 (1.9M) [application/x-gzip]
Saving to: 'redis-5.0.3.tar.gz'

100%[============================================================================================================================>] 1,959,445    751KB/s   in 2.5s

2019-03-25 09:04:40 (751 KB/s) - 'redis-5.0.3.tar.gz' saved [1959445/1959445]

[root@localhost ~]# ls
redis-5.0.3.tar.gz 

2、解压

[root@localhost ~]# tar xzf redis-5.0.3.tar.gz
[root@localhost ~]#
[root@localhost ~]# ls
anaconda-ks.cfg  redis-5.0.3  redis-5.0.3.tar.gz
[root@localhost ~]#
[root@localhost ~]# cd redis-5.0.3
[root@localhost redis-5.0.3]#
[root@localhost redis-5.0.3]# ls
00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README.md   runtest          runtest-sentinel  src    utils
BUGS             COPYING       INSTALL  MANIFESTO  redis.conf  runtest-cluster  sentinel.conf     tests

3、编译

# make

[root@localhost redis-5.0.3]# make
……………………
……………………
Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/root/redis-5.0.3/src'

4、简单启动

进入到解压后的 src 目录,通过如下命令启动Redis:

# ./redis-server

[root@localhost redis-5.0.3]# ls
00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README.md   runtest          runtest-sentinel  src    utils
BUGS             COPYING       INSTALL  MANIFESTO  redis.conf  runtest-cluster  sentinel.conf     tests
[root@localhost redis-5.0.3]#
[root@localhost redis-5.0.3]# cd src/
[root@localhost src]#
[root@localhost src]# ./redis-server
6788:C 25 Mar 2019 18:12:12.145 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
6788:C 25 Mar 2019 18:12:12.145 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=6788, just started
6788:C 25 Mar 2019 18:12:12.145 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
6788:M 25 Mar 2019 18:12:12.147 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 5.0.3 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 6788
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

6788:M 25 Mar 2019 18:12:12.151 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
6788:M 25 Mar 2019 18:12:12.151 # Server initialized
6788:M 25 Mar 2019 18:12:12.151 # 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.
6788:M 25 Mar 2019 18:12:12.151 # 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.
6788:M 25 Mar 2019 18:12:12.152 * Ready to accept connections

新打开一个窗口页进行简单的交互

可以使用内置的客户端与Redis进行交互:

# ./redis-cli

[root@localhost src]# ./redis-cli
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379>

二、正常安装

以下两个选项任选其一进行 (推荐选择默认安装)

  • 安装命令 (默认安装目录是/usr/local/bin/)

# make install

[root@localhost redis-5.0.3]# make install
cd src && make install
make[1]: Entering directory `/root/redis-5.0.3/src'
    CC Makefile.dep
make[1]: Leaving directory `/root/redis-5.0.3/src'
make[1]: Entering directory `/root/redis-5.0.3/src'

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

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/root/redis-5.0.3/src'
[root@localhost redis-5.0.3]#

查看安装目录

# ll /usr/local/bin/redis-*

[root@localhost redis-5.0.3]# ll /usr/local/bin/redis-*
-rwxr-xr-x. 1 root root 4365320 Mar 25 18:32 /usr/local/bin/redis-benchmark
-rwxr-xr-x. 1 root root 8089534 Mar 25 18:32 /usr/local/bin/redis-check-aof
-rwxr-xr-x. 1 root root 8089534 Mar 25 18:32 /usr/local/bin/redis-check-rdb
-rwxr-xr-x. 1 root root 4800687 Mar 25 18:32 /usr/local/bin/redis-cli
lrwxrwxrwx. 1 root root      12 Mar 25 18:32 /usr/local/bin/redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 8089534 Mar 25 18:32 /usr/local/bin/redis-server
[root@localhost redis-5.0.3]#
  • 指定redis安装目录

# make install PREFIX=/usr/local/redis

配置文件

配置文件在redis-5.0.3目录下,文件名是 redis.conf

根据你的安装目录,将配置文件拷贝至对应的目录,比如拷贝到 /root/目录下,命令如下:

[root@localhost redis-5.0.3]# ls
00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README.md   runtest          runtest-sentinel  src    utils
BUGS             COPYING       INSTALL  MANIFESTO  redis.conf  runtest-cluster  sentinel.conf     tests
[root@localhost redis-5.0.3]#
[root@localhost redis-5.0.3]# cp redis.conf /root/
[root@localhost redis-5.0.3]#
[root@localhost redis-5.0.3]# cd
[root@localhost ~]#
[root@localhost ~]# ls
anaconda-ks.cfg  redis-5.0.3  redis-5.0.3.tar.gz  redis.conf
[root@localhost ~]#

三、正常启动

启动redis命令和效果如下,默认是前台启动,按 ctrl+c 停止

# redis-server /root/redis-5.0.3/redis.conf

[root@localhost ~]# redis-server /root/redis-5.0.3/redis.conf
6991:C 25 Mar 2019 18:56:14.612 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
6991:C 25 Mar 2019 18:56:14.612 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=6991, just started
6991:C 25 Mar 2019 18:56:14.612 # Configuration loaded
6991:M 25 Mar 2019 18:56:14.614 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 5.0.3 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 6991
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

6991:M 25 Mar 2019 18:56:14.617 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
6991:M 25 Mar 2019 18:56:14.617 # Server initialized
6991:M 25 Mar 2019 18:56:14.617 # 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.
6991:M 25 Mar 2019 18:56:14.617 # 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.
6991:M 25 Mar 2019 18:56:14.617 * Ready to accept connections

后台启动

后台启动需要修改配置文件 (大概在136行 ),将daemonize no 改为 daemonize yes

重启启动,效果如下

# redis-server /root/redis-5.0.3/redis.conf

[root@localhost ~]# redis-server /root/redis-5.0.3/redis.conf
7020:C 25 Mar 2019 19:01:35.264 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7020:C 25 Mar 2019 19:01:35.264 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=7020, just started
7020:C 25 Mar 2019 19:01:35.264 # Configuration loaded

 查看redis服务进程

# ps aux | grep redis

[root@localhost ~]# ps aux | grep redis
root       7021  0.2  0.4 153828  7700 ?        Ssl  19:01   0:00 redis-server 127.0.0.1:6379
root       7026  0.0  0.0 112644   952 pts/0    S+   19:03   0:00 grep --color=auto redis
[root@localhost ~]#

本地客户端交互

[root@localhost ~]# redis-cli
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> exit
[root@localhost ~]#

 远程客户端连接

直接使用客户端加参数 redis-cli -h <ip> 进行远程连接

[root@localhost ~]# redis-cli -h 192.168.2.88
Could not connect to Redis at 192.168.2.88:6379: Connection refused

默认配置会报错,连接被拒绝,需要修改配置文件 redis.conf

默认配置,69行默认绑定了本机地址,注释此配置或修改为自己的IP

# vi redis-5.0.3/redis.conf

redis-5.0.3 默认开启保护模式,protected-mode yes,修改为 protected-mode no

重新启动

# redis-server /root/redis-5.0.3/redis.conf

[root@localhost ~]# redis-server /root/redis-5.0.3/redis.conf
7133:C 25 Mar 2019 19:30:06.700 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7133:C 25 Mar 2019 19:30:06.700 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=7133, just started
7133:C 25 Mar 2019 19:30:06.700 # Configuration loaded
[root@localhost ~]#

 关闭redis服务

[root@localhost ~]# redis-cli shutdown
[root@localhost ~]#
[root@localhost ~]# ps aux | grep redis
root       7139  0.0  0.0 112644   952 pts/0    S+   19:32   0:00 grep --color=auto redis
[root@localhost ~]#

参考博客:

https://blog.csdn.net/weixin_39979119/article/details/86632582

https://blog.csdn.net/litte_frog/article/details/83278047

Redis配置文件详解

https://www.cnblogs.com/pqchao/p/6558688.html

end

猜你喜欢

转载自www.cnblogs.com/djlsunshine/p/10592174.html