一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Redis7.4.2单机环境配置步骤详解

时间:2026-05-27 13:30:02 编辑:袖梨 来源:一聚教程网

Redis作为高性能键值数据库,其源码编译安装过程需要遵循特定步骤。本文将详细介绍从解压到配置的全流程操作指南。 解压源码包 首先需要将获取的Redis源码压缩包上传至服务器指定位置。通过wget命令可直接下载最新稳定版到本地。 [root@hcss-ecs-2851 ~]# wget https://download.redis.io/redis-stable.tar.gz[root@hcss-ecs-2851 ~]# mv redis-stable.tar.gz /opt/soft/redis/[root@hcss-ecs-2851 ~]# cd /opt/soft/redis/[root@hcss-ecs-2851 redis]# lsredis-stable.tar.gz 执行解压命令后进入生成的目录,可以看到完整的源码文件结构。 [root@hcss-ecs-2851 redis]# tar -zxvf redis-stable.tar.gz[root@hcss-ecs-2851 redis]# lsredis-stable redis-stable.tar.gz[root@hcss-ecs-2851 redis]# cd redis-stable[root@hcss-ecs-2851 redis-stable]# ls00-RELEASENOTES CODE_OF_CONDUCT.md deps LICENSE.txt MANIFESTO redis.conf runtest runtest-moduleapi SECURITY.md src TLS.mdBUGS CONTRIBUTING.md INSTALL Makefile README.md REDISCONTRIBUTIONS.txt runtest-cluster runtest-sentinel sentinel.conf tests utils 安装gcc 编译Redis需要先安装gcc编译器组件,使用yum命令可快速完成环境准备。 [root@hcss-ecs-2851 redis-stable]# yum install -y gcc gcc-c++ 安装redis 通过make命令进行编译安装,完成后系统会将可执行文件部署到默认路径。 [root@hcss-ecs-2851 redis-stable]# makeroot@hcss-ecs-2851 redis-stable]# make install 简单测试是否安装成功 启动redis-server服务,观察控制台输出信息可验证安装结果。 [root@hcss-ecs-2851 redis-stable]# cd [root@hcss-ecs-2851 ~]# redis-server9193:C 24 Mar 2025 12:03:19.847 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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.9193:C 24 Mar 2025 12:03:19.847 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo9193:C 24 Mar 2025 12:03:19.847 * Redis version=7.4.2, bits=64, commit=00000000, modified=0, pid=9193, just started9193:C 24 Mar 2025 12:03:19.847 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf9193:M 24 Mar 2025 12:03:19.847 * monotonic clock: POSIX clock_gettime _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis Community Edition .-`` .-```. ```/ _.,_ ''-._ 7.4.2 (00000000/0) 64 bit ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 9193 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | https://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 9193:M 24 Mar 2025 12:03:19.848 * Server initialized9193:M 24 Mar 2025 12:03:19.848 * Ready to accept connections tcp 自定义设置 自定义目录 创建专用目录存放配置文件、日志等数据,便于后续维护管理。 [root@hcss-ecs-2851 ~]# cd /opt/soft/redis/[root@hcss-ecs-2851 redis]# mkdir {etc,lib,log}[root@hcss-ecs-2851 redis]# lsetc lib log redis-stable redis-stable.tar.gz[root@hcss-ecs-2851 redis]# cp redis-stable/redis.conf etc/[root@hcss-ecs-2851 redis]# ls etc/redis.conf 编辑redis.conf 修改核心配置文件参数,包括绑定地址、端口设置以及日志路径等关键选项。 bind 0.0.0.0 # 任意ip均可访问protected-mode noport 6379daemonize yes # 后台运行pidfile /var/run/redis.pid # 运行时进程idlogfile /opt/soft/redis/log/redis.log #日志文件dir /opt/soft/redis/lib/requirepass ********* # 设置密码 创建 systemd 服务文件 配置systemd服务实现开机自启,方便日常运维操作。 [root@hcss-ecs-2851 etc]# cd /etc/systemd/system/[root@hcss-ecs-2851 system]# vim redis.service [Unit]Description=Redis In-Memory Data StoreAfter=network.target[Service]Type=forkingUser=rootGroup=rootExecStart=/usr/local/bin/redis-server /opt/soft/redis/etc/redis.confExecStop=/usr/local/bin/redis-cli -p 6379 shutdownPIDFile=/var/run/redis.pidRestart=on-failure[Install]WantedBy=multi-user.target [root@hcss-ecs-2851 ~]# systemctl daemon-reload[root@hcss-ecs-2851 ~]# systemctl start redis[root@hcss-ecs-2851 ~]# systemctl status redis● redis.service - Redis In-Memory Data Store Loaded: loaded (/etc/systemd/system/redis.service; disabled; vendor preset: disabled) Active: active (running) since 一 2025-03-24 12:43:28 CST; 8s ago Process: 3340 ExecStart=/usr/local/bin/redis-server /opt/soft/redis/etc/redis.conf (code=exited, status=0/SUCCESS) Main PID: 3341 (redis-server) CGroup: /system.slice/redis.service └─3341 /usr/local/bin/redis-server 0.0.0.0:63793月 24 12:43:28 hcss-ecs-2851 systemd[1]: Starting Redis In-Memory Data Store...3月 24 12:43:28 hcss-ecs-2851 systemd[1]: Can't open PID file /var/run/

热门栏目