首次安装
[root@instance5 apps]# yum install -y gcc tcl make
[root@instance5 apps]# wget https://download.redis.io/releases/redis-5.0.7.tar.gz
[root@instance5 apps]# tar -zxvf redis-5.0.7.tar.gz -C /opt/
[root@instance5 apps]# cd /opt/redis-5.0.7
[root@instance5 apps]# mkdir /apps/redis -p
[root@instance5 apps]# make PREFIX=/apps/redis install
[root@instance5 apps]# echo 'PATH=/apps/redis/bin:$PATH' > /etc/profile.d/redis.sh
[root@instance5 apps]# source /etc/profile.d/redis.sh
[root@instance5 apps]# tree redis
redis
└── bin
├── redis-benchmark
├── redis-check-aof
├── redis-check-rdb
├── redis-cli
├── redis-sentinel -> redis-server
└── redis-server
1 directory, 6 files
[root@instance5 redis]# cp /opt/redis-5.0.7/redis.conf /apps/redis/etc/
[root@instance5 redis]# cd bin
[root@instance5 bin]# ls
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server
[root@instance5 bin]# pwd
/apps/redis/bin
[root@instance5 bin]# redis-server /apps/redis/etc/redis.conf
9967:C 20 Jun 2021 07:18:44.660 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9967:C 20 Jun 2021 07:18:44.660 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=9967, just started
9967:C 20 Jun 2021 07:18:44.660 # Configuration loaded
9967:M 20 Jun 2021 07:18:44.660 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.7 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 9967
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
9967:M 20 Jun 2021 07:18:44.662 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
9967:M 20 Jun 2021 07:18:44.662 # Server initialized
9967:M 20 Jun 2021 07:18:44.662 # 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.
9967:M 20 Jun 2021 07:18:44.662 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
9967:M 20 Jun 2021 07:18:44.662 * Ready to accept connections
解决启动问题
[root@instance5 ~]# vi /etc/sysctl.conf
net.core.somaxconn = 1024
vm.overcommit_memory = 1
[root@instance5 ~]# sysctl -p
net.core.somaxconn = 1024
vm.overcommit_memory = 1
[root@instance5 ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@instance5 ~]# echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.d/rc.local
再次启动
[root@instance5 bin]# redis-server /apps/redis/etc/redis.conf
10186:C 20 Jun 2021 07:32:49.232 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
10186:C 20 Jun 2021 07:32:49.232 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=10186, just started
10186:C 20 Jun 2021 07:32:49.232 # Configuration loaded
10186:M 20 Jun 2021 07:32:49.233 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.7 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 10186
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
10186:M 20 Jun 2021 07:32:49.233 # Server initialized
10186:M 20 Jun 2021 07:32:49.234 * DB loaded from disk: 0.000 seconds
10186:M 20 Jun 2021 07:32:49.234 * Ready to accept connections
创建用户和数据目录
[root@instance5 ~]# useradd -r -s /sbin/login redis
useradd: user 'redis' already exists
[root@instance5 ~]# chown -R redis.redis /apps/redis
创建服务启动文件
[root@instance5 system]# cp rpcbind.service redis.servive
[root@instance5 system]# vim redis.servive
[Unit]
Description=Redis Server
After=network.target
[Service]
ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis.conf --supervised systemd
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
[root@instance5 etc]# systemctl start redis
[root@instance5 etc]# systemctl status redis
● redis.service - Redis Server
Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2021-06-20 08:18:59 EDT; 36s ago
Main PID: 3505 (redis-server)
Tasks: 4 (limit: 24583)
Memory: 1.5M
CGroup: /system.slice/redis.service
└─3505 /apps/redis/bin/redis-server 127.0.0.1:6379
Jun 20 08:18:59 instance5 redis-server[3505]: `-._ `-._`-.__.-'_.-' _.-'
Jun 20 08:18:59 instance5 redis-server[3505]: |`-._`-._ `-.__.-' _.-'_.-'|
Jun 20 08:18:59 instance5 redis-server[3505]: | `-._`-._ _.-'_.-' |
Jun 20 08:18:59 instance5 redis-server[3505]: `-._ `-._`-.__.-'_.-' _.-'
Jun 20 08:18:59 instance5 redis-server[3505]: `-._ `-.__.-' _.-'
Jun 20 08:18:59 instance5 redis-server[3505]: `-._ _.-'
Jun 20 08:18:59 instance5 redis-server[3505]: `-.__.-'
Jun 20 08:18:59 instance5 redis-server[3505]: 3505:M 20 Jun 2021 08:18:59.726 # Server initialized
Jun 20 08:18:59 instance5 redis-server[3505]: 3505:M 20 Jun 2021 08:18:59.726 * Ready to accept connections
Jun 20 08:18:59 instance5 systemd[1]: Started Redis Server.
建立命令软链接
[root@instance5 etc]# ln -s /apps/redis/bin/redis-* /usr/bin/
基础配置
[root@instance5 etc]# redis-cli
127.0.0.1:6379> CONFIG SET requirepass 123456
OK
127.0.0.1:6379> CONFIG SET requirepass
(error) NOAUTH Authentication required.
127.0.0.1:6379> CONFIG GET requirepass
(error) NOAUTH Authentication required.
127.0.0.1:6379> AYTH 123456
(error) ERR unknown command `AYTH`, with args beginning with: `123456`,
127.0.0.1:6379> AUTH 123456
OK
127.0.0.1:6379> CONFIG GET requirepass
1) "requirepass"
2) "123456"
127.0.0.1:6379> CONFIG GET *
1) "dbfilename"
2) "dump.rdb"
3) "requirepass"
4) "123456"
5) "masterauth"
6) ""
7) "cluster-announce-ip"
8) ""
9) "unixsocket"
10) ""
11) "logfile"
12) ""
13) "pidfile"
14) "/var/run/redis_6379.pid"
15) "slave-announce-ip"
16) ""
17) "replica-announce-ip"
18) ""
19) "maxmemory"
20) "0"
21) "proto-max-bulk-len"
22) "536870912"
23) "client-query-buffer-limit"
24) "1073741824"
25) "maxmemory-samples"
26) "5"
27) "lfu-log-factor"
28) "10"
29) "lfu-decay-time"
30) "1"
31) "timeout"
32) "0"
33) "active-defrag-threshold-lower"
34) "10"
35) "active-defrag-threshold-upper"
36) "100"
37) "active-defrag-ignore-bytes"
38) "104857600"
39) "active-defrag-cycle-min"
40) "5"
41) "active-defrag-cycle-max"
42) "75"
43) "active-defrag-max-scan-fields"
44) "1000"
45) "auto-aof-rewrite-percentage"
46) "100"
47) "auto-aof-rewrite-min-size"
48) "67108864"
49) "hash-max-ziplist-entries"
50) "512"
51) "hash-max-ziplist-value"
52) "64"
53) "stream-node-max-bytes"
54) "4096"
55) "stream-node-max-entries"
56) "100"
57) "list-max-ziplist-size"
58) "-2"
59) "list-compress-depth"
60) "0"
61) "set-max-intset-entries"
62) "512"
63) "zset-max-ziplist-entries"
64) "128"
65) "zset-max-ziplist-value"
66) "64"
67) "hll-sparse-max-bytes"
68) "3000"
69) "lua-time-limit"
70) "5000"
71) "slowlog-log-slower-than"
72) "10000"
73) "latency-monitor-threshold"
74) "0"
75) "slowlog-max-len"
76) "128"
77) "port"
78) "6379"
79) "cluster-announce-port"
80) "0"
81) "cluster-announce-bus-port"
82) "0"
83) "tcp-backlog"
84) "511"
85) "databases"
86) "16"
87) "repl-ping-slave-period"
88) "10"
89) "repl-ping-replica-period"
90) "10"
91) "repl-timeout"
92) "60"
93) "repl-backlog-size"
94) "1048576"
95) "repl-backlog-ttl"
96) "3600"
97) "maxclients"
98) "10000"
99) "watchdog-period"
100) "0"
101) "slave-priority"
102) "100"
103) "replica-priority"
104) "100"
105) "slave-announce-port"
106) "0"
107) "replica-announce-port"
108) "0"
109) "min-slaves-to-write"
110) "0"
111) "min-replicas-to-write"
112) "0"
113) "min-slaves-max-lag"
114) "10"
115) "min-replicas-max-lag"
116) "10"
117) "hz"
118) "10"
119) "cluster-node-timeout"
120) "15000"
121) "cluster-migration-barrier"
122) "1"
123) "cluster-slave-validity-factor"
124) "10"
125) "cluster-replica-validity-factor"
126) "10"
127) "repl-diskless-sync-delay"
128) "5"
129) "tcp-keepalive"
130) "300"
131) "cluster-require-full-coverage"
132) "yes"
133) "cluster-slave-no-failover"
134) "no"
135) "cluster-replica-no-failover"
136) "no"
137) "no-appendfsync-on-rewrite"
138) "no"
139) "slave-serve-stale-data"
140) "yes"
141) "replica-serve-stale-data"
142) "yes"
143) "slave-read-only"
144) "yes"
145) "replica-read-only"
146) "yes"
147) "slave-ignore-maxmemory"
148) "yes"
149) "replica-ignore-maxmemory"
150) "yes"
151) "stop-writes-on-bgsave-error"
152) "yes"
153) "daemonize"
154) "no"
155) "rdbcompression"
156) "yes"
157) "rdbchecksum"
158) "yes"
159) "activerehashing"
160) "yes"
161) "activedefrag"
162) "no"
163) "protected-mode"
164) "yes"
165) "repl-disable-tcp-nodelay"
166) "no"
167) "repl-diskless-sync"
168) "no"
169) "aof-rewrite-incremental-fsync"
170) "yes"
171) "rdb-save-incremental-fsync"
172) "yes"
173) "aof-load-truncated"
174) "yes"
175) "aof-use-rdb-preamble"
176) "yes"
177) "lazyfree-lazy-eviction"
178) "no"
179) "lazyfree-lazy-expire"
180) "no"
181) "lazyfree-lazy-server-del"
182) "no"
183) "slave-lazy-flush"
184) "no"
185) "replica-lazy-flush"
186) "no"
187) "dynamic-hz"
188) "yes"
189) "maxmemory-policy"
190) "noeviction"
191) "loglevel"
192) "notice"
193) "supervised"
194) "systemd"
195) "appendfsync"
196) "everysec"
197) "syslog-facility"
198) "local0"
199) "appendonly"
200) "no"
201) "dir"
202) "/"
203) "save"
204) "900 1 300 10 60 10000"
205) "client-output-buffer-limit"
206) "normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60"
207) "unixsocketperm"
208) "0"
209) "slaveof"
210) ""
211) "notify-keyspace-events"
212) ""
213) "bind"
214) "127.0.0.1"