温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CentOS 7.4如何安装redis 4.0

发布时间:2021-11-10 11:58:42 来源:亿速云 阅读:144 作者:小新 栏目:关系型数据库

这篇文章主要为大家展示了“CentOS 7.4如何安装redis 4.0”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“CentOS 7.4如何安装redis 4.0”这篇文章吧。

一、redis单实例安装


1、安装依赖包

[root@VM_2_13_centos redis]# yum install gcc*

2、获取安装文件

[root@VM_2_13_centos redis]# wget http://download.redis.io/releases/redis-4.0.9.tar.gz

3、解压文件

[root@VM_2_13_centos redis]# tar zxvf redis-4.0.9.tar.gz

[root@VM_2_13_centos redis]# ll

total 1708

drwxrwxr-x 6 root root    4096 Mar 27 00:04 redis-4.0.9

-rw-r--r-- 1 root root 1737022 Mar 27 00:04 redis-4.0.9.tar.gz

4、编译安装

[root@VM_2_13_centos redis-4.0.9]# make

[root@VM_2_13_centos redis-4.0.9]# make PREFIX=/usr/local/redis install

cd src && make install

make[1]: Entering directory `/usr/local/redis/redis-4.0.9/src'

    CC Makefile.dep

make[1]: Leaving directory `/usr/local/redis/redis-4.0.9/src'

make[1]: Entering directory `/usr/local/redis/redis-4.0.9/src'

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

    INSTALL install

    INSTALL install

    INSTALL install

    INSTALL install

    INSTALL install

5、查看redis的版本

[root@VM_2_13_centos ~]# redis-server --version

Redis server v=4.0.9 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=c97ec2b5e9b86914

6、启动redis

[root@VM_2_13_centos redis]# /usr/local/redis/bin/redis-server /etc/redis/redis.conf

[root@VM_2_13_centos redis]# netstat -tuplan | grep 6379

tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      5305/redis-server 1

[root@VM_2_13_centos redis]# ps -ef | grep redis

root      5305     1  0 21:38 ?        00:00:00 /usr/local/redis/bin/redis-server 127.0.0.1:6379

root      5356 30807  0 21:39 pts/1    00:00:00 grep --color=auto redis

7、通过客户端登录

[root@VM_2_13_centos ~]# redis-cli

127.0.0.1:6379>

备注:如果要卸载redis,把/usr/local/redis/bin/目录下的redis删除即可。为了卸载干净,你还可以把解压和编译的redis包及配置的redis.conf也删除。

二、安全配置

1、设置密码

redis的默认安装是不设置密码的,可以在redis.conf中进行配置

[root@VM_2_13_centos ~]# vim /etc/redis/redis.conf

requirepass qcloud@2018

或者通过命令配置

127.0.0.1:6379>CONFIG set requirepass qcloud@2018

由于Redis的性能极高,并且输入错误密码后Redis并不会进行主动延迟(考虑到Redis的单线程模型),所以攻击者可以通过穷举法破解Redis的密码(1秒内能够尝试十几万个密码),因此在设置时一定要选择复杂的密码,可以用随机密码生成器生成。

注意:配置Redis复制的时候如果主数据库设置了密码,需要在从数据库的配置文件中通过masterauth参数设置主数据库的密码,以使从数据库连接主数据库时自动使用AUTH命令认证。

验证密码是否有效,是否需要认证

[root@VM_2_13_centos ~]# redis-cli

127.0.0.1:6379>

127.0.0.1:6379> keys *

(error) NOAUTH Authentication required.

127.0.0.1:6379>

127.0.0.1:6379> auth qcloud@2018

OK

127.0.0.1:6379>

127.0.0.1:6379> keys *

(empty list or set)

2、禁用高危命令

目前该命令可以正常使用

127.0.0.1:6379> flushall

OK

关闭redis,但是由于上面设置了密码,必须要认证成功后才能关闭

[root@VM_2_13_centos ~]# redis-cli shutdown

(error) NOAUTH Authentication required.

[root@VM_2_13_centos ~]# redis-cli -a qcloud@2018 shutdown

[root@VM_2_13_centos ~]#

[root@VM_2_13_centos ~]# ps -ef | grep redis

root      6144  5406  0 21:54 pts/0    00:00:00 grep --color=auto redis

修改配置文件redis.conf,增加如下行:

[root@VM_2_13_centos ~]# vim /etc/redis/redis.conf

rename-command FLUSHALL ""

rename-command CONFIG   ""

rename-command EVAL     ""

重新启动redis

[root@VM_2_13_centos ~]# redis-server /etc/redis/redis.conf

[root@VM_2_13_centos ~]#

[root@VM_2_13_centos ~]# redis-cli

127.0.0.1:6379>

127.0.0.1:6379> keys *

(error) NOAUTH Authentication required.

127.0.0.1:6379>

127.0.0.1:6379> auth qcloud@2018

OK

127.0.0.1:6379>

127.0.0.1:6379> flushall

(error) ERR unknown command 'flushall'

127.0.0.1:6379>

127.0.0.1:6379> config

(error) ERR unknown command 'config'

127.0.0.1:6379>

127.0.0.1:6379> eval

(error) ERR unknown command 'eval'

通过上面的报错可以发现,在配置文件禁用的三个命令无法使用

3、绑定只能本机访问

[root@VM_2_13_centos ~]# vim /etc/redis/redis.conf

bind 127.0.0.1

4、设置redis开启自启动

[root@VM_2_13_centos ~]# vim /etc/rc.d/rc.local

/usr/local/redis/bin/redis-server /etc/redis/redis.conf &

以上是“CentOS 7.4如何安装redis 4.0”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI