http://redis.io/download
解压包移到安装目录
tar xf redis-6.2.6.tar.gz
mv redis-6.2.6 soft/
cd soft/
cd redis-6.2.6/
make
启动服务
./redis-server
8063:C 19 Nov 2021 18:58:44.631 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8063:C 19 Nov 2021 18:58:44.631 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=8063, just started
8063:C 19 Nov 2021 18:58:44.631 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
8063:M 19 Nov 2021 18:58:44.632 * Increased maximum number of open files to 10032 (it was originally set to 1024).
8063:M 19 Nov 2021 18:58:44.632 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.6 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 8063
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
8063:M 19 Nov 2021 18:58:44.633 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
8063:M 19 Nov 2021 18:58:44.633 # Server initialized
8063:M 19 Nov 2021 18:58:44.633 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
8063:M 19 Nov 2021 18:58:44.633 * Ready to accept connections
修改配置文件,添加参数
[root@host1 src]# vi /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.core.somaxconn= 1024
vm.overcommit_memory=1
~
:x
[root@host1 src]# vi /etc/sysctl.conf
[root@host1 src]# sysctl -p
net.core.somaxconn = 1024
vm.overcommit_memory = 1
echo 511 > /proc/sys/net/core/somaxconn
echo 1 > /proc/sys/vm/overcommit_memory
再次启动(没有指定配置文件,警告)
[root@host1 src]# ./redis-server
8169:C 19 Nov 2021 19:07:32.062 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8169:C 19 Nov 2021 19:07:32.062 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=8169, just started
8169:C 19 Nov 2021 19:07:32.062 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
8169:M 19 Nov 2021 19:07:32.063 * Increased maximum number of open files to 10032 (it was originally set to 1024).
8169:M 19 Nov 2021 19:07:32.063 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.6 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 8169
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
8169:M 19 Nov 2021 19:07:32.064 # Server initialized
8169:M 19 Nov 2021 19:07:32.064 * Loading RDB produced by version 6.2.6
8169:M 19 Nov 2021 19:07:32.064 * RDB age 4 seconds
8169:M 19 Nov 2021 19:07:32.064 * RDB memory usage when created 0.77 Mb
8169:M 19 Nov 2021 19:07:32.064 # Done loading RDB, keys loaded: 0, keys expired: 0.
8169:M 19 Nov 2021 19:07:32.064 * DB loaded from disk: 0.000 seconds
8169:M 19 Nov 2021 19:07:32.064 * Ready to accept connections
退出,指定配置文件启动
[root@host1 src]# ./redis-server ../redis.conf
8226:C 19 Nov 2021 19:11:40.297 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8226:C 19 Nov 2021 19:11:40.297 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=8226, just started
8226:C 19 Nov 2021 19:11:40.297 # Configuration loaded
8226:M 19 Nov 2021 19:11:40.297 * Increased maximum number of open files to 10032 (it was originally set to 1024).
8226:M 19 Nov 2021 19:11:40.297 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.6 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 8226
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
8226:M 19 Nov 2021 19:11:40.299 # Server initialized
8226:M 19 Nov 2021 19:11:40.299 * Loading RDB produced by version 6.2.6
8226:M 19 Nov 2021 19:11:40.299 * RDB age 20 seconds
8226:M 19 Nov 2021 19:11:40.299 * RDB memory usage when created 0.77 Mb
8226:M 19 Nov 2021 19:11:40.299 # Done loading RDB, keys loaded: 0, keys expired: 0.
8226:M 19 Nov 2021 19:11:40.299 * DB loaded from disk: 0.000 seconds
8226:M 19 Nov 2021 19:11:40.299 * Ready to accept connections
[root@host1 src]# ./redis-cli
127.0.0.1:6379> set name 汤姆
OK
127.0.0.1:6379> get name
"\xe6\xb1\xa4\xe5\xa7\x86"
127.0.0.1:6379>
[root@host1 src]# ./redis-cli --raw
127.0.0.1:6379> get name
汤姆
127.0.0.1:6379>
Redis:Remote Dictionary Server(远程字典服务器) ,键值对存储非关系数据库。
非关系数据库类型:键值对存储(key-value),文档存储(document store),基于列的数据库(column-oriented),还有就是图形数据库(graph database)
redis.conf 是一个默认的配置文件。我们可以根据需要使用自己的配置文件。
cat …/redis.conf |grep -v “#”|grep -v "^$"
[root@host1 src]# cat ../redis.conf |grep -v "#"|grep -v "^$"
bind 127.0.0.1 -::1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes