【注】如果正式服务器可以连接外网的话推荐使用 APT 在线安装。
通过APT命令安装
1. 执行安装命令
# 安装 Redis 服务 sudo apt-get install redis-server
2. 安装完成后,Redis 会自动启动,可通过命令查看 Redis 是否正在运行:
ps -e | grep redis # 出现以下代表 redis 运行成功 48441 ? 00:00:00 redis-server #或者是 service redis-server status # 可以看到 reids-server 正在运行 redis-server.service - Advanced key-value store Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor pre Active: active (running) since Fri 2020-02-14 09:43:09 UTC; 1min 49s ago Docs: http://redis.io/documentation, man:redis-server(1) Main PID: 48441 (redis-server) Tasks: 4 (limit: 2251) Memory: 1.9M CGroup: /system.slice/redis-server.service └─48441 /usr/bin/redis-server 127.0.0.1:6379 Feb 14 09:43:09 peng systemd[1]: Starting Advanced key-value store... Feb 14 09:43:09 peng systemd[1]: redis-server.service: Can't open PID file /run/ Feb 14 09:43:09 peng systemd[1]: Started Advanced key-value store.
通过源码安装
1. 安装编译环境
# 若有的话可以跳过
sudo apt install gcc make
2. 下载 Redis 并编译
建议在 /opt 目录下进行操作。
# 切换到 /opt 目录
cd /opt
# 下载 redis
sudo wget http://download.redis.io/releases/redis-5.0.7.tar.gz
# 解压 redis
sudo tar xzf redis-5.0.7.tar.gz
cd redis-5.0.7
# 直接编译
sudo make
安装完后,redis 会自动的启动。可通过命令查看 Redis 是否正在运行:
ps -e | grep redis # 出现以下代表 redis 运行成功 48441 ? 00:00:00 redis-server #或者是 service redis-server status # 可以看到 reids-server 正在运行 redis-server.service - Advanced key-value store Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor pre Active: active (running) since Fri 2020-02-14 09:43:09 UTC; 1min 49s ago Docs: http://redis.io/documentation, man:redis-server(1) Main PID: 48441 (redis-server) Tasks: 4 (limit: 2251) Memory: 1.9M CGroup: /system.slice/redis-server.service └─48441 /usr/bin/redis-server 127.0.0.1:6379 Feb 14 09:43:09 peng systemd[1]: Starting Advanced key-value store... Feb 14 09:43:09 peng systemd[1]: redis-server.service: Can't open PID file /run/ Feb 14 09:43:09 peng systemd[1]: Started Advanced key-value store.