Redis安装在Mac,Linux,树莓派上并相互联通教程
1. 下载Redis
https://redis.io/download
2. Mac上安装Redis
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| $ brew install redis@5.0.5 #使用配置文件启动redis-server $ redis-server /usr/local/etc/redis.conf #停止redis服务 $ redis-cli shutdown #允许远程访问 $ nano /usr/local/etc/redis.conf #修改配置 bind 0.0.0.0 protected-mode no
$ brew services start redis $ brew services stop redis $ brew services restart redis
|
3. Linux上安装Redis
1 2 3 4 5 6 7 8
| [linux@localhost ~]$ su [linux@localhost ~]$ cd /home/linux/Desktop [linux@localhost ~]$ tar zxvf redis-5.0.5.tar.gz [linux@localhost ~]$ cp -r redis-5.0.5 /usr/local/redis [linux@localhost ~]$ cd /usr/local/redis [linux@localhost ~]$ make [linux@localhost ~]$ cd src [linux@localhost ~]$ ./redis-server
|
配置客户端
1 2
| [linux@localhost ~]$ ./redis-cli 127.0.0.1:6379>
|
3.1. 简单测试
设置 键 值 期望值 秒数
set a b EX 5
get a

4. 树莓派上安装redis
sudo apt-get install redis-server
端口 6379
配置文件在 /etc/redis/redis.conf
4.1. 启用/关闭命令
1 2 3
| /etc/init.d/redis-server start /etc/init.d/redis-server stop /etc/init.d/redis-server restart
|
4.2. 开启远程连接
4.2.1. 将配置文件中的 bind 改为 0.0.0.0
1
| root@pi:/# nano /etc/redis/redis.conf
|
4.2.2. 开启6379端口
1 2
| root@pi:/# iptables -I INPUT -i eth0 -p tcp --dport 6379 -j ACCEPT root@pi:/# iptables -I OUTPUT -o eth0 -p tcp --sport 6379 -j ACCEPT
|
4.2.3. 启动redis服务器
1
| root@pi:/# redis-server /etc/redis/redis.conf
|
4.2.4. 本地连接
1 2 3 4
| root@pi:/# redis-cli 127.0.0.1:6379> set msg hello OK 127.0.0.1:6379>
|
4.2.5. 远程连接-mac
1 2 3 4 5 6
| $ redis-cli -h 192.168.0.112 -p 6379 192.168.0.112:6379> keys * 1) "msg" 192.168.0.112:6379> get msg "hello" 192.168.0.112:6379>
|