Centos7 安装配置Reids

本文详细介绍如何下载并安装Redis,包括编译安装步骤、启动及后台运行的方法。此外,还介绍了如何配置Redis以设置密码保护、开启远程访问等功能。

下载redis安装包

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

[root@test bak]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz
--2018-07-06 10:37:12--  http://download.redis.io/releases/redis-4.0.10.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: 1738465 (1.7M) [application/x-gzip]
Saving to: ‘redis-4.0.10.tar.gz’
100%[==========================================================================>] 1,738,465   1.26MB/s   in 1.3s   
2018-07-06 10:37:13 (1.26 MB/s) - ‘redis-4.0.10.tar.gz’ saved [1738465/1738465]

解压

[root@test bak]# tar -zxvf redis-4.0.10.tar.gz 
[root@test bak]# cd redis-4.0.10
[root@test redis-4.0.10]# 

编译安装

make
[root@test redis-4.0.10]# make MALLOC=libc
新建/usr/local/redis目录,将当前src目录下面的文件复制到/usr/local/redis中

[root@test redis-4.0.6]# cd src && make install
    CC Makefile.dep 
Hint: It's a good idea to run 'make test' ;)
 
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install

启动redis

切找到/usr/local/redis目录下启动redis

[root@test redis]# ./redis-server 
10270:C 06 Jul 10:49:46.602 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
10270:C 06 Jul 10:49:46.603 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=10270, just started
10270:C 06 Jul 10:49:46.603 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.10 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 10270
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

10270:M 06 Jul 10:49:46.604 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
10270:M 06 Jul 10:49:46.604 # Server initialized
10270:M 06 Jul 10:49:46.604 # 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.
10270:M 06 Jul 10:49:46.604 # 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.
10270:M 06 Jul 10:49:46.604 * Ready to accept connections

后台启动redis

打开redis.conf,把daemonize设置为yes
daemonize yes

[root@test redis]# ./redis-server /usr/local/redis/redis.conf
10324:C 06 Jul 10:57:09.129 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
10324:C 06 Jul 10:57:09.129 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=10324, just started
10324:C 06 Jul 10:57:09.129 # Configuration loaded

今天发现无法后台启动,需要修改daemonize值为yes

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
# daemonize no
# 修改为yes值
# daemonize yes

##Redis可视化工具管理
Redis Desktop Manager 0.9.3 for mac可视化管理工具
https://download.youkuaiyun.com/download/xianglingchuan/10524408

设置访问密码

打开redis.conf配置文件,找到requirepass,然后修改如下:
requirepass yourpassword
重启redis生效

开启远程访问权限

解决办法:注释掉bind 127.0.0.1可以使所有的ip访问redis
若是想指定多个ip访问,但并不是全部的ip访问,可以bind

在redis3.2之后,redis增加了protected-mode,在这个模式下,即使注释掉了bind 127.0.0.1,再访问redisd时候还是报错,如下
修改办法:protected-mode no
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值