CentOS Stream 9 Redis 7.2.7 源码编译一键安装脚本 CentOS Stream 9 Redis 7.2.7 源码编译一键安装脚本自动编译、自动配置、自动 systemd 托管开启 AOF 持久化 密码 远程访问安装完直接可用#!/bin/bashset-euopipefail# 版本与路径REDIS_VERSION7.2.7INSTALL_DIR/usr/local/redisDATA_DIR/data/redisLOG_DIR/var/log/redisCONF_DIR${INSTALL_DIR}/confREDIS_PASS123456echo-e\033[32m 安装依赖 \033[0mdnfinstall-ygcc gcc-cmakeopenssl-develecho-e\033[32m 下载 Redis${REDIS_VERSION}\033[0mcd/usr/local/srcwget-Nhttps://download.redis.io/releases/redis-${REDIS_VERSION}.tar.gzecho-e\033[32m 解压 编译 \033[0mtarzxf redis-${REDIS_VERSION}.tar.gzcdredis-${REDIS_VERSION}make-j$(nproc)echo-e\033[32m 安装 \033[0mmakeinstallPREFIX${INSTALL_DIR}echo-e\033[32m 创建目录 \033[0mmkdir-p${CONF_DIR}${DATA_DIR}${LOG_DIR}echo-e\033[32m 复制配置文件 \033[0mcpredis.conf${CONF_DIR}/redis.confecho-e\033[32m 自动配置 redis.conf \033[0msed-is|^bind .*|bind 0.0.0.0|${CONF_DIR}/redis.confsed-is|^protected-mode .*|protected-mode no|${CONF_DIR}/redis.confsed-is|^port .*|port 6379|${CONF_DIR}/redis.confsed-is|^daemonize .*|daemonize no|${CONF_DIR}/redis.confsed-is|^logfile .*|logfile${LOG_DIR}/redis.log|${CONF_DIR}/redis.confsed-is|^dir .*|dir${DATA_DIR}|${CONF_DIR}/redis.confsed-is|^# requirepass .*|requirepass${REDIS_PASS}|${CONF_DIR}/redis.confsed-is|^appendonly .*|appendonly yes|${CONF_DIR}/redis.confecho-e\033[32m 创建 systemd 服务 \033[0mcat/usr/lib/systemd/system/redis.serviceEOF [Unit] DescriptionRedis Server Afternetwork.target [Service] Typesimple ExecStart${INSTALL_DIR}/bin/redis-server${CONF_DIR}/redis.conf ExecReload/bin/kill -USR2 \$MAINPIDRestarton-failure LimitNOFILE65535 [Install] WantedBymulti-user.target EOFecho-e\033[32m 启动并开机自启 \033[0msystemctl daemon-reload systemctlenable--nowredissleep2echo-e\033[32m 加入全局命令 \033[0mechoexport PATH\$PATH:${INSTALL_DIR}/bin/etc/profile.d/redis.shsource/etc/profile.d/redis.shecho-e\033[32m 安装完成\033[0mredis-server--versionredis-cli--versionechoecho安装目录${INSTALL_DIR}echo配置文件${CONF_DIR}/redis.confecho数据目录${DATA_DIR}echo密码${REDIS_PASS}echo测试redis-cli -a${REDIS_PASS}使用方法# 1. 创建脚本viminstall_redis727.sh# 2. 粘贴上面全部内容保存# 3. 加执行权限chmodx install_redis727.sh# 4. 运行./install_redis727.sh安装后信息端口6379密码123456开启 AOF 持久化允许远程访问开机自启命令全局可用测试redis-cli-a123456127.0.0.1:6379settestok127.0.0.1:6379gettest