- 中文官网
- 安装依赖
yum -y install wget gcc-c++
- 安装目录
mkdir /opt/redis && cd /opt/redis
- 安装包下载
wget http://download.redis.io/releases/redis-7.0.5.tar.gz 注意:http://download.redis.io/releases获取最新版本下载链接并替换
- 安装包解压
tar -zxvf redis-7.0.5.tar.gz && rm -rf redis-7.0.5.tar.gz
- 编译安装
cd /opt/redis/redis-7.0.5 && # 进入目录 make && make PREFIX=/opt/redis/redis-7.0.5 install # 编译安装到指定目录
- 环境变量
echo "export REDIS_HOME=/opt/redis/redis-7.0.5" >> /etc/profile echo "export PATH=\$PATH:\$REDIS_HOME/bin" >> /etc/profile source /etc/profile
- Redis配置(redis.conf)
解除本机绑定:# bind 127.0.0.1 -::1 守护方式启动:daemonize yes 设置pid路径:pidfile /opt/redis/redis-7.0.5/redis_6379.pid 设置存储路径:dir /opt/redis/redis-7.0.5 设置连接密码:requirepass 123456 AOF方式持久化:appendonly yes AOF存储文件名:appendfilename "appendonly_6379.aof" AOF持久化策略:appendfsync always # appendfsync everysec 注意:不设置密码需要禁用保护模式protected-mode no
- Redis命令
启动服务:redis-server /opt/redis/redis-7.0.5/redis.conf 查看服务:ps -ef | grep -i redis 关闭服务:redis-cli -a 123456 shutdown 登录客户端:redis-cli 退出客户端:exit 端口权限:firewall-cmd --zone=public --add-port=6379/tcp --permanent && firewall-cmd --reload
- 开机启动
#---------------------------------------------------------- sudo tee /usr/bin/redis.sh <<-'EOF' #! /bin/bash /opt/redis/redis-7.0.5/bin/redis-server /opt/redis/redis-7.0.5/redis.conf EOF chmod +x /usr/bin/redis.sh #---------------------------------------------------------- sudo tee /etc/systemd/system/redis.service <<-'EOF' [Unit] Description=redis After=syslog.target network.target [Service] Type=oneshot RemainAfterExit=yes ExecStart=/usr/bin/redis.sh [Install] WantedBy=multi-user.target EOF #---------------------------------------------------------- systemctl enable redis #---------------------------------------------------------- reboot
Linux安装Redis(简洁版)
于 2022-12-11 15:52:54 首次发布