1.1下载最新稳定版的redis:
wget https://download.redis.io/releases/redis-5.0.14.tar.gz
1.2安装依赖包:
yum install -y epel-release yum install -y gcc
2.1进入下载目录并解压:
cd /root tar -xzvf redis-5.0.14.tar.gz 2.2编译: cd redis-5.0.14 cd deps make jemalloc make hiredis make linenoise make lua cd .. make make install
3.1打开配置文件:
cd /root/redis-5.0.14 vi redis.conf
3.2修改允许远程访问:
bind 127.0.0.1 修改为 #bind 127.0.0.1
3.3设置密码:
# requirepass foobared 修改为 requirepass password(需要设置的密码)
3.4进程在后台运行:
daemonize no 修改为 daemonize yes
3.5日志输出文件等信息:
logfile "" 修改为指定的日志文件 logfile "/var/log/redis/6379.log"
4.1将第三步配置好的配置文件复制到指定目录
cp /root/redis-5.0.14/redis.conf /etc/redis/redis.conf
4.2设置启动服务脚本
cat > /usr/lib/systemd/system/redis.service <<-EOF [Unit] Description=Redis 6379 After=syslog.target network.target [Service] Type=forking PrivateTmp=yes Restart=always ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf ExecStop=/usr/local/bin/redis-cli -h 127.0.0.1 -p 6379 -a jcon shutdown User=root Group=root LimitCORE=infinity LimitNOFILE=100000 LimitNPROC=100000 [Install] WantedBy=multi-user.target EOF # 使服务自动运行 systemctl daemon-reload systemctl enable redis # 启动服务 systemctl restart redis systemctl status redis 参考https://segmentfault.com/a/1190000017780463