1.安装依赖

  1. yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

2. 使用wget下载压缩包安装

  1. wget http://download.redis.io/releases/redis-5.0.0.tar.gz

redis-5.0.0.tar.gz 👈 这里也有安装包

3.解压

  1. tar -zxvf redis-5.0.0.tar.gz

4.编译

  1. cd redis-5.0.0
  2. make

5.安装

  1. make install

6.启动服务

  1. [root@iZwz9g1c3fleilwng44esiZ redis-5.0.0]# cd src
  2. [root@iZwz9g1c3fleilwng44esiZ src]# ./redis-server
  3. 7121:C 16 Feb 2021 11:35:26.136 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
  4. 7121:C 16 Feb 2021 11:35:26.136 # Redis version=5.0.0, bits=64, commit=00000000, modified=0, pid=7121, just started
  5. 7121:C 16 Feb 2021 11:35:26.136 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
  6. _._
  7. _.-``__ ''-._
  8. _.-`` `. `_. ''-._ Redis 5.0.0 (00000000/0) 64 bit
  9. .-`` .-```. ```\/ _.,_ ''-._
  10. ( ' , .-` | `, ) Running in standalone mode
  11. |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
  12. | `-._ `._ / _.-' | PID: 7121
  13. `-._ `-._ `-./ _.-' _.-'
  14. |`-._`-._ `-.__.-' _.-'_.-'|
  15. | `-._`-._ _.-'_.-' | http://redis.io
  16. `-._ `-._`-.__.-'_.-' _.-'
  17. |`-._`-._ `-.__.-' _.-'_.-'|
  18. | `-._`-._ _.-'_.-' |
  19. `-._ `-._`-.__.-'_.-' _.-'
  20. `-._ `-.__.-' _.-'
  21. `-._ _.-'
  22. `-.__.-'

7.使用nohup来后台运行

  1. [root@iZwz9g1c3fleilwng44esiZ src]# nohup ./redis-server &
  2. [1] 13148

13148 是redis-server进程标识,可以使用kill -9 13148 来停止redis服务

8.使用systemd来开机自启

使用nohup可以后台运行,但是不能开机自启,所以使用systemd

  1. vim /etc/systemd/system/redis.service

ExecStart和ExecStop为redis目录

  1. #[Unit] 表示这是基础信息
  2. [Unit]
  3. #Description 是描述
  4. Description=Redis
  5. #After 是在那个服务后面启动,一般是网络服务启动后启动
  6. After=network.target
  7. ##[Service]服务运行参数的设置
  8. [Service]
  9. #ExecStart 是启动服务的命令
  10. # redis-server路径和配置文件
  11. ExecStart=/root/redis-5.0.0/src/redis-server /root/redis-5.0.0/redis.conf --daemonize no
  12. #ExecStop 是停止服务的指令
  13. # redis-cli
  14. ExecStop=/root/redis-5.0.0/src/redis-cli -h 127.0.0.1 -p 6379 shutdown
  15. #表示这是是安装相关信息
  16. [Install]
  17. #WantedBy 是以哪种方式启动:multi-user.target表明当系统以多用户方式
  18. WantedBy=multi-user.target

编辑完后保存

  1. systemctl daemon-reload #刷新配置文件
  2. systemctl enable redis #加入开机启动,先执行这个
  3. systemctl start redis #开启redis服务
  4. systemctl stop redis #停止redis服务
  5. systemctl status redis #查看redis运行状态

9.添加环境变量

如果觉得每次都要进入reids目录安装太麻烦,想在其它的目录也可以使用,则需要配置环境变量

  1. vim /etc/profile
  1. # 在/etc/profile中最底下添加下面两句话
  2. export REDIS_HOME=/root/redis-5.0.0/
  3. export PATH=$PATH:$REDIS_HOME/src
  1. #刷新配置文件使追加的生效
  2. source /etc/profile