环境阿里云ECS 腾讯云ECS // 两者相同配置, 均是centOS7 【7.5/7.8】
方式一:编译安装
1. 使用以下命令下载,提取和编译Redis$ wget http://download.redis.io/releases/redis-6.0.5.tar.gz $ tar xzf redis-6.0.5.tar.gz $ cd redis-6.0.5 $ make
Note: 这里进入/usr/local/bin 目录下 [只是推荐, 不是强制要求] 安装出现失败, 原因: gcc的版本低于5, 当前gcc版本为 4.8 解决办法: 先升级gcc版本 具体操作过程后补. 详见: http://www.redis.cn/download.html
升级步骤请先检查gcc的版本是否低于5,如果是请先升级,可以使用以下命令: sudo yum install centos-release-scl sudo yum install devtoolset-7-gcc* scl enable devtoolset-7 bash 下面已经升级到7.3
2.src 目录 中现在提供了已编译的二进制文件 // 上面编译后的产物,源文件中是没有的
使用以下命令运行Redis$ src/redis-server
3. 您可以使用内置客户端与Redis进行交互:$ src/redis-cli redis> set foo bar OK redis> get foo "bar"
4. 配置参见:下方 7.2 配置
官网提供了在线交互式教程。[Try Redis] 如下:
Note: 在腾讯云ECS配置下安装Redis, 下载压缩包速度明显慢.
方式二: yum 安装1. sudo yum install epel-release
2. sudo yum install redis
3. sudo systemctl start redis.service // 启动服务4. sudo systemctl enable redis // 开机启动服务
5. 查看redis进程ps -ef | grep redis
6. 命令行下交互测试redis-cli set name williamning get name
7.设置远程连接7.1 关闭防火墙 //关闭之前面, 查看防火墙服务状态systemctl status firewalld firewall-cmd --state
Note: 由上可知: 之前防火墙一直处于关闭状态,相当于所有端口都是开放状态,[即如: 80, 3306,6379 ] //这种操作相当危险, 很容易被攻击 打开防火墙之后, 查看80端口尚未开放,需要另外操作80端口, 3306端口开放.
打开防火墙,之后尚未开放80,3306端口的结果, 截图如下: 可以看到数据库可视化工具不能远程连接到数据库服务器,同时web页面也出现500报错。//这里都是因为3306端口尚未开放
解决办法: 开放3306端口即可,然后重启防火墙 firewall-cmd --permanent --add-port=3306/tcp service firewalld restart
结果如下:
但是: 如果远程连接访问redis server 需要开放6379与80端口
7.2 修改配置 //此时仍然不能远程连接redis server 因为配置文件中默认限制只有本机才可以访问redis7.2.1 vi /etc/redis.conf 进入编辑模式注释掉 bind 127.0.0.1 ,否则只有本机才能访问. 注释后: 7.2.2 保护模式修改为no 以及 端口修改[默认为6357 可不改]文档中原话://简单理解就是:一层保护层,防止被访问与利用 Protected mode is a layer of security protection, in order to avoid that Redis instances left open on the internet are accessed and exploited 修改后:
7.2.3 修改密码为 xxxxx //该密码为登陆redis所需要的密码,请记好, 另外请使用强密码Warning: since Redis is pretty fast an outside user can try up to # 150k passwords per second against a good box. This means that you should # use a very strong password otherwise it will be very easy to break.
警告:由于Redis是相当快的外部用户可以尝试 每秒150k个密码。 这意味着你应该 使用强密码,否则很容易被破解。
修改后: 省略.
补充://20200824 设置最大内存大小以及缓存淘汰策略
7.2.4 保存并退出编辑重启redissystemctl restart redis
7.2.5 重新检测是否能正常与Redis交互本机交互: redis-cli -h 127.0.0.1 -p 6379 -a password 简写: redis-cli -a xxx 回车即可 成功交互.
客户端远程连接 [redisClient]
成功连接.
后续补充 ... |