CentOS7.4 Redis5.0.3配置

本文内容主要包括,以下两个方面:

  • redis的安装及配置
  • redis防入侵的保护措施
    • 禁止一些redis高危命令(config,flushall,flushdb,keys)
    • 为redis添加密码验证
    • 禁止外网访问redis
    • 为redis服务创建单独的用户和家目录,并配置禁止登录

安装redis

1# 下载并解压安装包 2[root@12 ~]# mkdir download 3[root@12 ~]# cd download/ 4[root@12 download]# wget http://download.redis.io/releases/redis-5.0.3.tar.gz 5[root@12 download]# tar -zxvf redis-5.0.3.tar.gz 6# 编译安装 7[root@12 download]# cd redis-5.0.3 8[root@12 redis-5.0.3]# make 9[root@12 redis-5.0.3]# make install PREFIX=/usr/local/redis

配置redis.conf

1# 从redis源码目录复制redis.conf到redis目录 2[root@12 redis-5.0.3]# cd /usr/local/redis/bin/ 3[root@12 bin]# cp /root/download/redis-5.0.3/redis.conf /usr/local/redis/bin/redis.conf 4[root@12 bin]# vim /usr/local/redis/bin/redis.conf

修改redis.conf中的以下内容:

1# 1.禁止redis高危命令 2rename-command CONFIG "" 3rename-command FLUSHALL "" 4rename-command FLUSHDB "" 5rename-command KEYS "" 6# 2.修改redis默认端口号 7port 16970 8# 3.打开保护模式,添加密码 9protected-mode yes 10requirepass xxxxxxx 11# 4.开启守护进程 12daemonize yes 13# 5.暂时将监听ip开放,后期改回127.0.0.1 14bind 0.0.0.0 15# 6.修改redis目录 16dir /home/redisuser/redis 17# 7.修改pid文件的位置 18pidfile /home/redisuser/run/redis.pid

为redis创建用户,并修改权限

1# 创建用户组 2[root@12 bin]# groupadd redis 3# 创建用户redisuser并加入redis组中 4[root@12 bin]# useradd redisuser -g redis 5# 锁定用户,禁止远程登录 6[root@12 bin]# usermod -L redisuser 7# 将redis配置文件移入redisuser家目录中 8[root@12 bin]# cp -rf /usr/local/redis/bin/redis.conf /home/redisuser/redis.conf 9# 创建所需目录 10[root@12 bin]# mkdir -p /home/redisuser/run 11[root@12 bin]# mkdir -p /home/redisuser/redis 12# 给redis目录修改权限 13[root@12 bin]# chown -R redisuser:redis /home/redisuser 14[root@12 bin]# chown -R redisuser:redis /user/local/redis

设置开机启动

1# 添加开机启动服务 2[root@12 bin]# vim /etc/systemd/system/redis.service

粘贴以下内容:

1[Unit] 2Description=redis-server 3After=network.target 4[Service] 5Type=forking 6ExecStart=/usr/local/redis/bin/redis-server /home/redisuser/redis.conf 7PrivateTmp=true 8[Install] 9WantedBy=multi-user.target 10 11 12[root@12 bin]# systemctl daemon-reload 13# 开启redis服务 14[root@12 bin]# systemctl start redis.service 15# 设置开机启动 16[root@12 bin]# systemctl enable redis.service

检查防火墙状态,开启redis对应端口

1# 查看防火墙状态 2[root@12 bin]# systemctl status firewalld 3# 开启防火墙 4[root@12 bin]# systemctl start firewalld 5# 开放16970端口 6[root@12 bin]# firewall-cmd --add-port=16970/tcp --permanent

创建软连接,添加别名

1# 创建软连接 2[root@12 bin]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis 3 4# 添加别名(--raw 防止中文乱码) 5[root@12 bin]# vi ~/.bashrc 6添加如下内容: 7alias redis='redis --raw' 8 9# 使.bashrc生效 10[root@12 bin]# source ~/.bashrc 11 12# 检查是否生效 13[root@12 bin]# redis -p 16970 14127.0.0.1:16970> # 表示生效
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )