CentOS 7.4如何安装redis 4.0

32次阅读
没有评论

共计 3315 个字符,预计需要花费 9 分钟才能阅读完成。

这篇文章主要为大家展示了“CentOS 7.4 如何安装 redis 4.0”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让丸趣 TV 小编带领大家一起研究并学习一下“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”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-24发表,共计3315字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)