1. 使用tar.gz安装
-
下载并解压
$ wget http://download.redis.io/releases/redis-5.0.7.tar.gz $ tar xzf redis-5.0.7.tar.gz
-
切换到目录下安装
$ cd redis-5.0.7 $ make 编译 $ make PREFIX=/usr/local/redis install
-
启动
$ ./redis-server
-
测试运行,需要切换到另一个目录下
$./redis-cli redis> set foo bar OK redis> get foo "bar"
======================================================================
2. 使用yum安装
-
预处理
yum install epel-release yum-utils -y sudo yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm sudo yum --enablerepo=remi install redis -y
-
安装redis
yum install redis -y
-
设置开机自启动
systemctl start redis systemctl enable redis
-
检查启动状态
systemctl status redis
-
修改Redis的配置:
sudo vi /etc/redis/redis.conf 设置密码123456:#取消注释requirepass requirepass 123456 开启远程访问:#注释bind #bind 127.0.0.1 关闭保护模式:把 protected-mode yes 改为 protected-mode no 守护进程模式:把daemonize no 改为daemonize yes 重启服务: systemctl restart redis
-
开启防火墙设置
firewall-cmd --new-zone=redis --permanent firewall-cmd --zone=redis --add-port=6379/tcp --permanent firewall-cmd --zone=redis --add-source=192.168.121.0/24 --permanent firewall-cmd --reload