一.写在前面
激动人心的Redis之旅开始了!
官方网址:https://redis.io/
Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.
二.安装(Linux)
具体步骤直接参考官方文档即可:https://redis.io/download
无奈Docker技术不是很熟,所以只能使用虚拟机了。
使用Oracle VM 创建了一个centos的最小系统;打算使用windows最新的Windows Terminal (Preview) 运行ssh工具连接虚拟机进行操作。
要想ssh虚拟机就得知道虚拟机分配的IP地址是多少才能连接!
当我像往常一样在shell里面输入:
[root@MiWiFi-R3-srv ~]# ifconfig
-bash: ifconfig: command not found
WTF?
问了一下度娘才知道改了,改成ip addr了
[root@MiWiFi-R3-srv ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:42:c5:33 brd ff:ff:ff:ff:ff:ff
inet 192.168.31.116/24 brd 192.168.31.255 scope global noprefixroute dynamic enp0s3
valid_lft 42645sec preferred_lft 42645sec
inet6 fe80::7170:ce54:9dc4:e0e/64 scope link noprefixroute
valid_lft forever preferred_lft forever
ok,拿到地址
因为我最后执行了
make && make install
所以redis最后安装在/usr/local/bin
此时我们还要把原来压缩包里面的配置文件移动过来(方便我们修改配置)
三.测试
1.先按照官方教程走一遍吧。
首先启动redis,直接在/usr/local/bin执行
[root@MiWiFi-R3-srv bin]# ./redis-server
2.此时我们发现redis的服务端默认启动方式非守护进程,我们可以另开一个terminal来启动客户端
[root@MiWiFi-R3-srv bin]# ./redis-cli
接下来就是跟着官方例子走呗
127.0.0.1:6379> SET foo bar
OK
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> exit
[root@MiWiFi-R3-srv bin]#
至此,redis安装基本没有问题!
四.配置文件
daemonize no
pidfile /var/run/redis.pid
port 6379
bind 127.0.0.1
timeout 300
loglevel verbose
logfile stdout
logfile stdout
save <seconds> <changes>
save 900 1
save 300 10
save 60 10000
分别表示900秒(15分钟)内有1个更改,300秒(5分钟)内有10个更改以及60秒内有10000个更改。
rdbcompression yes
dbfilename dump.rdb
dir ./
slaveof <masterip> <masterport>
masterauth <master-password>
requirepass foobared
maxclients 128
maxmemory <bytes>
appendonly no
appendfilename appendonly.aof
appendfsync everysec
vm-enabled no
vm-swap-file /tmp/redis.swap
vm-max-memory 0
vm-page-size 32
vm-pages 134217728
vm-max-threads 4
glueoutputbuf yes
hash-max-zipmap-entries 64
hash-max-zipmap-value 512
activerehashing yes
include /path/to/local.conf
五.自定义配置文件
主要改三个地方:
daemonize no 修改为 daemonize yes
bind 127.0.0.1 注释掉
requirepass 设置密码
六.启动和退出
1.Redis启动:
./bin/redis-server ./redis.conf
redis-cli -h host -p port -a password
2.Redis关闭
PID
ps -ef | grep -i redis
kill -9 PID
./bin/redis-cli shutdown