记录下自己安装redis过程,算是个笔记吧,以后会用到。

准备条件

因为我虚拟机环境没有联网,所以需要提前准备好redis包。
一开始用的是redis 6+版本,安装后解压发现系统的gcc版本太低,无法编译。而没有联网,升级gcc版本太麻烦,之前系统装过rabbitmq,有4.8+版本的gcc,此版本适用于redis 5,于是就选择了redis-5.0.5的版本。
提前将压缩包通过XFTP导入系统内。

解压,编译

首先解压redis包

[root@zbh redis]# tar -zxvf redis-5.0.5.tar.gz

然后进入解压的redis文件夹,准备编译和安装

[root@zbh redis]# cd redis-5.0.5

编译

[root@zbh redis-5.0.5]# make

大概一分钟左右,编译完毕,生成了src目录。

    LINK redis-serverINSTALL redis-sentinelCC redis-cli.oLINK redis-cliCC redis-benchmark.oLINK redis-benchmarkINSTALL redis-check-rdbINSTALL redis-check-aofHint: It's a good idea to run 'make test' ;)make[1]: Leaving directory `/opt/redis/redis-5.0.5/src'

安装到常用包路径下

[root@zbh redis-5.0.5]# make install PREFIX=/usr/local/redis

这时候,其实就安装完成了,可以启动了。可以尝试去启动一次。

[root@zbh redis-5.0.5]# /usr/local/redis/bin/redis-server

启动成功

6556:C 12 Oct 2020 23:11:18.369 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
6556:C 12 Oct 2020 23:11:18.369 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=6556, just started
6556:C 12 Oct 2020 23:11:18.369 # Warning: no config file specified, using the default config. In order to specify a config file use /usr/local/redis/bin/redis-server /path/to/redis.conf
6556:M 12 Oct 2020 23:11:18.369 * Increased maximum number of open files to 10032 (it was originally set to 1024)._._                                                  _.-``__ ''-._                                             _.-``    `.  `_.  ''-._           Redis 5.0.5 (00000000/0) 64 bit.-`` .-```.  ```\/    _.,_ ''-._                                   (    '      ,       .-`  | `,    )     Running in standalone mode|`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379|    `-._   `._    /     _.-'    |     PID: 6556`-._    `-._  `-./  _.-'    _.-'                                   |`-._`-._    `-.__.-'    _.-'_.-'|                                  |    `-._`-._        _.-'_.-'    |           http://redis.io        `-._    `-._`-.__.-'_.-'    _.-'                                   |`-._`-._    `-.__.-'    _.-'_.-'|                                  |    `-._`-._        _.-'_.-'    |                                  `-._    `-._`-.__.-'_.-'    _.-'                                   `-._    `-.__.-'    _.-'                                       `-._        _.-'                                           `-.__.-'                                               6556:M 12 Oct 2020 23:11:18.371 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
6556:M 12 Oct 2020 23:11:18.371 # Server initialized
6556:M 12 Oct 2020 23:11:18.371 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
6556:M 12 Oct 2020 23:11:18.371 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
6556:M 12 Oct 2020 23:11:18.371 * Ready to accept connections

基础配置

这时候仅仅是能启动服务,但不是后台启动,且外部客户端无法连接到此redis,简单更改配置。
将原来文件夹的配置文件复制一份放到安装目录,然后修改配置。

[root@zbh redis-5.0.5]# cp redis.conf /usr/local/redis/bin/

进入安装目录,修改配置。

[root@zbh redis-5.0.5]# cd /usr/local/redis/bin
[root@zbh bin]# vi redis.conf

设置显示行号,方便修改

:set number

首先修改redis服务端监听请求的地址,注掉默认bind 127.0.0.1即可。此版本是在69行。

     48 # By default, if no "bind" configuration directive is specified, Redis listens49 # for connections from all the network interfaces available on the server.50 # It is possible to listen to just one or multiple selected interfaces using51 # the "bind" configuration directive, followed by one or more IP addresses.52 #53 # Examples:54 #55 # bind 192.168.1.100 10.0.0.156 # bind 127.0.0.1 ::157 #58 # ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the59 # internet, binding to all the interfaces is dangerous and will expose the60 # instance to everybody on the internet. So by default we uncomment the61 # following bind directive, that will force Redis to listen only into62 # the IPv4 loopback interface address (this means Redis will be able to63 # accept connections only from clients running into the same computer it64 # is running).65 #66 # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES67 # JUST COMMENT THE FOLLOWING LINE.68 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~69 # bind 127.0.0.1

然后关闭保护模式,默认开启yes,在88行。

     71 # Protected mode is a layer of security protection, in order to avoid that72 # Redis instances left open on the internet are accessed and exploited.73 #74 # When protected mode is on and if:75 #76 # 1) The server is not binding explicitly to a set of addresses using the77 #    "bind" directive.78 # 2) No password is configured.79 #80 # The server only accepts connections from clients connecting from the81 # IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain82 # sockets.83 #84 # By default protected mode is enabled. You should disable it only if85 # you are sure you want clients from other hosts to connect to Redis86 # even if no authentication is configured, nor a specific set of interfaces87 # are explicitly listed using the "bind" directive.88 protected-mode no

最后开启后台启动。

    134 # By default Redis does not run as a daemon. Use 'yes' if you need it.135 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.136 daemonize yes

OK,暂时就先配置这些。保存退出。
试试能不能启动。

[root@zbh bin]# ./redis-server redis.conf
6578:C 12 Oct 2020 23:27:23.510 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
6578:C 12 Oct 2020 23:27:23.510 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=6578, just started
6578:C 12 Oct 2020 23:27:23.510 # Configuration loaded

开机自启动

创建一个启动服务。

[root@zbh bin]# vi /etc/systemd/system/redis.service

添加启动服务内容

[Unit]
Description=redis-server
After=network.target[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true[Install]
WantedBy=multi-user.target

注意其中的 ExecStart项,是你redis编译安装指定的路径和所使用的配置文件的路径。

设置开机启动

[root@zbh bin]# systemctl daemon-reload
[root@zbh bin]# systemctl start redis.service
[root@zbh bin]# systemctl enable redis.service
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /etc/systemd/system/redis.service.

至此,就完成了开机启动。可以重启试一试。
查看进程。

[root@zbh ~]# ps -aux|grep redis
root       1584  0.1  0.7 154000  7624 ?        Rsl  00:04   0:00 /usr/local/redis/bin/redis-server *:6379
root       2243  0.0  0.0 112816   960 pts/0    R+   00:05   0:00 grep --color=auto redis

外部使用redis客户端连接试试。

OK,大功告成。开启redis之旅。

一般通过redis客户端命令行来输出redis命令。设置启动客户端软连接,生成一个redis命令,方便启动客户端。

[root@zbh ~]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis

试一试是否成功。

[root@zbh ~]# redis
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379>

至此,启动客户端就简单多了。
本人对redis及linux不熟悉,参考文章:https://www.cnblogs.com/heqiuyong/p/10463334.html

CentOS 7 完美安装redis-5.0.5相关推荐

  1. 腾讯云轻量服务器Centos 7.6安装redis 5.0.4教程

    1. 在Redis官网下载redis,下载完后上传到服务器上.下载地址:Index of /releases/ 2. 在/usr/local/目录下创建software文件夹,在software下创建 ...

  2. linux yum安装redis5.0,CentOS 7安装Redis 5.0.5并加入Systemd服务

    记录在CentOS 7下安装Redis 5.0.5并加入Systemd服务的步骤. 1. 安装gcc-c++, tcl yum install gcc-c++ tcl 2. 解压缩, 编译, 测试 t ...

  3. centos / Linux 服务环境下安装 Redis 5.0.3

    centos / Linux 服务环境下安装 Redis 5.0.3 原文:centos / Linux 服务环境下安装 Redis 5.0.3 1.首先进入你要安装的目录 cd /usr/local ...

  4. Linux/ubuntu 安装 redis 4.0报错解决:redis-server.service: Can't open PID file /var/run/redis/redis-server.

    此文首发于我的个人博客:Linux/ubuntu 安装 redis 4.0报错解决:redis-server.service: Can't open PID file /var/run/redis/r ...

  5. CentOS 6.5 安装 Redis 执行 make #error Newer version of jemalloc required

    为什么80%的码农都做不了架构师?>>>    CentOS 6.5 安装 Redis 执行 make #error "Newer version of jemalloc ...

  6. CentOS 7.5 安装Redis教程

    CentOS 7.5 安装Redis教程 这里写目录标题 CentOS 7.5 安装Redis教程 一.上传与解压 1.上传路径 2.解压缩 3.进入目录 二.编译与安装 1.安装流程 2.安装结果 ...

  7. CentOS 8.1安装MySQL 8.0详解

    CentOS 8.1安装MySQL 8.0详解 引言 一.YUM在线安装 0.删除已安装的MySQL 1.添加MySQL Yum Repository 2.选择MySQL版本 3.安装MySQL 4. ...

  8. 在CentOS 6.3 64bit上安装redis 3.0.3

    1.下载源码并安装 安装Unix的Tcl工具, 测试redis时需要用到 yum install tcl 去redis官网 http://redis.io/download/下载源码, 目前最新版本是 ...

  9. 运维Linux redis,系统运维|如何在 CentOS 7 上安装 Redis 服务器

    大家好,本文的主题是 Redis,我们将要在 CentOS 7 上安装它.编译源代码,安装二进制文件,创建.安装文件.在安装了它的组件之后,我们还会配置 redis ,就像配置操作系统参数一样,目标就 ...

最新文章

  1. 15个超实用的php正则表达式
  2. android5.0(Lollipop) BLE Peripheral牛刀小试
  3. PHP数组的排序函数
  4. React-引领未来的用户界面开发框架-读书笔记(三)
  5. linux多进程 段错误,关于段错误
  6. 活动目录管理中常用的脚本(一)
  7. vector的学习(系统的学习)
  8. Twisted入门教程(10)
  9. ASP.NET错误处理的方式(一)
  10. Jenkins自动化构建Gitee项目
  11. 数据库审计系统(启明设备)
  12. 笔记19-字节缓冲流字符流
  13. 《老师好》有感-学历迷思
  14. P1217 [USACO1.5]回文质数 Prime Palindromes(素数筛法/打表)
  15. win10如何隐藏任务栏
  16. Mars Crowdloan 空投领取及开放查询(内附领取操作)
  17. Redis集群系列一 —— AKF拆分原则
  18. 如何下载 TI 公司的官方例程以及为用户写好的标准头/源文件
  19. activiti 多实例任务
  20. Java import 和 import static

热门文章

  1. 粗糙集理解之一:基本概念
  2. 华为编程决赛后的感想
  3. 【云原生之kubernetes实战】在k8s环境下部署Snipe-IT固定资产管理平台
  4. 2023年,前端开发就业前景好吗?
  5. Linux基础知识命令总结1
  6. js 鼠标滑轮控制左右横向滚动
  7. 前端实现文件在线预览
  8. crc16-ccitt算法c语言,CRC-CCITT 标准CRC16(1021) 算法校验类
  9. 如何购买云服务器及其配置
  10. 适合开发人员看的鸿蒙OS介绍~