• 周五. 11 月 13th, 2026

Linux平台Redis源码安装

1. 下载Redis最新稳定版本

wget -c https://download.redis.io/redis-stable.tar.gz

2. 编译并安装

tar -zxvf redis-stable.tar.gz
cd redis-stable/
make
make install PREFIX=/usr/local/redis  #安装

3. 配置

编辑redis-stable/utils/install_server.sh文件,注释掉下边代码

#bail if this system is managed by systemd
#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
#        echo "This systems seems to use systemd."
#        echo "Please take a look at the provided example service unit files in this #directory, and adapt and install them. Sorry!"
#        exit 1
#fi
#unset _pid_1_exe

运行脚本redis-stable/utils/install_server.sh

[root@company utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/redis/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/redis/bin/redis-server
Cli Executable : /usr/local/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

4. 修改配置文件

根据上边的默认信息

vim /etc/redis/6379.conf

#bind 127.0.0.1 -::1
bind 192.168.177.100 127.0.0.1  #这里绑定一个IP与本机127.0.0.1使可远程访问

#后台运行模式
daemonize yes

#日志相关
loglevel notice


logfile /var/log/redis_6379.log

保存退出

5. 启动redis服务并验证

[root@company utils]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@company utils]# redis-cli
127.0.0.1:6379> set hello world
OK
127.0.0.1:6379> get hello
"world"
127.0.0.1:6379> 

至此安装成功

由 root