注: Redis 是 C 语言开发,在安装 Redis 时须要先将官网下载的源码进行编译,而编译是依赖 gcc 环境的。若是没有 gcc 环境,须要先安装 gcc 。
gcc 安装命令:yum install gcc-c++
1.1 访问 Redis官网,下载 Redis 的压缩文件
linux
1.2 使用 rz
命令 Redis 的压缩文件放置当前自定义的目录下
c++
1.3 解压 Redis 压缩文件至同目录redis
tar -zxvf redis-4.0.10.tar.gz
注: 若是未安装gcc,执行如下编译操做时会出现错误提示。若是安装失败,须要删除整个解压文件,从新进行解压
进入 Redis解压目录,执行 make
命令进行编译
shell
3.1 安装可执行文件至指定目录vim
make PREFIX=/usr/local/redis install
可执行文件说明 | |
---|---|
redis-benchmark | 性能测试工具 |
redis-check-aof | AOF文件修复工具 |
redis-check-rdb | RDB文件检查工具(快照持久化文件) |
redis-cli | 命令行客户端 |
redis-server | redis服务器启动命令 |
3.2 拷贝配置文件至指定目录segmentfault
cp redis.conf /usr/local/redis/
修改 步骤3.2 中指定目录下的 redis.conf 配置文件服务器
vim redis.conf
修改项 | 原始值 | 修改值 | 修改说明 |
---|---|---|---|
bind | 127.0.0.1 | 0.0.0.0 | 开启远程访问 |
daemonize | no | yes | 以守护进程启动 |
appendonly | no | yes | 开启aof持久化 |
appendfsync | no | everysec | 每一秒写入aof文件,并完成磁盘同步 |
requirepass | - | (自定义) | 设置链接密码 |
5.1 在 步骤3.2 中指定目录下执行如下命令启动 redis 服务app
./bin/redis-server ./redis.conf
5.2 执行如下命令查看 redis 服务是否启动tcp
ps -ef | grep -i redis
5.3 如下两种方式都可以关闭 redis 服务工具
方式一: kill -9 11706(该进程号从 步骤5.2 中获取) 方式二: ./bin/redis-cli shutdown
至此,redis 的安装过程基本结束。
容许外部服务器远程访问该服务器的6379端口。
1 添加 iptables 规则
iptables -I INPUT -p tcp --dport 6379 -j ACCEPT
2 保存 iptables 规则
service iptables save
注: 执行以上命令时,有可能报如下错误:
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
遇到此问题是由于没有安装 iptables 服务,须要先安装 iptables 服务。
具体解决方案参考另外一篇博文 【Linux】执行 service iptables save 命令异常解决 。
3 若保存 iptables 规则后,远程仍没法访问,则执行如下命令
service iptables restart