一、准备好 gcc 环境。
yum install gcc-c++
Loaded plugins: fastestmirror
Determining fastest mirrors
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
nginx | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/7): epel/x86_64/group_gz | 95 kB 00:00:00
(2/7): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(3/7): docker-ce-stable/x86_64/primary_db | 45 kB 00:00:00
(4/7): extras/7/x86_64/primary_db | 205 kB 00:00:00
(5/7): updates/7/x86_64/primary_db | 3.0 MB 00:00:00
(6/7): epel/x86_64/primary_db | 6.8 MB 00:00:00
(7/7): nginx/x86_64/primary_db | 55 kB 00:00:02
Package gcc-c++-4.8.5-39.el7.x86_64 already installed and latest version
Nothing to do
[root@root ~]#
二、下载并安装
[root@root /]# cd usr/java
[root@root java]# mkdir redis
[root@root java]# cd redis/
[root@root redis]# wget http://download.redis.io/releases/redis-5.0.7.tar.gz
[root@root redis]# tar -zxvf redis-5.0.7.tar.gz
[root@root redis]# cd redis-5.0.7
[root@root redis-5.0.7]# make
[root@root redis-5.0.7]# make install
三、启动
[root@root redis-5.0.7]# redis-server redis.conf
12513:C 10 Jul 2020 19:38:14.179 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12513:C 10 Jul 2020 19:38:14.179 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=12513, just started
12513:C 10 Jul 2020 19:38:14.179 # Configuration loaded
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.7 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 12513
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
12513:M 10 Jul 2020 19:38:14.181 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
12513:M 10 Jul 2020 19:38:14.181 # Server initialized
12513:M 10 Jul 2020 19:38:14.181 # 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.
12513:M 10 Jul 2020 19:38:14.181 # 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.
12513:M 10 Jul 2020 19:38:14.181 * Ready to accept connections
但是这样没有办法在这个tab页下做任何操作了,因为这个时候使用Ctrl+c之后,就变成了这个样子
^C13082:signal-handler (1594381754) Received SIGINT scheduling shutdown...
13082:M 10 Jul 2020 19:49:14.132 # User requested shutdown...
13082:M 10 Jul 2020 19:49:14.132 * Saving the final RDB snapshot before exiting.
13082:M 10 Jul 2020 19:49:14.135 * DB saved on disk
13082:M 10 Jul 2020 19:49:14.135 * Removing the pid file.
13082:M 10 Jul 2020 19:49:14.135 # Redis is now ready to exit, bye bye...
四、后台启动
[root@root redis-5.0.7]# vim redis.conf
#打开之后,在命令窗口按下/输入daem然后回车/daem

修改为yes
daemonize yes
再次启动
[root@root redis-5.0.7]# redis-server redis.conf
13352:C 10 Jul 2020 19:54:34.301 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
13352:C 10 Jul 2020 19:54:34.301 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=13352, just started
13352:C 10 Jul 2020 19:54:34.301 # Configuration loaded
五、连接Redis
[root@root redis-5.0.7]# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> config get requirepass
#查看密码
1) "requirepass"
2) ""
127.0.0.1:6379>
我们发现竟然不需要密码就可以进入redis。那怎么设置呢?
1、临时设置
config set requirepass 123456
2、永久设置
[root@root redis-5.0.7]# vim redis.conf


记住永久设置需要重启redis。
[root@root redis-5.0.7]# redis-server redis.conf
[root@root redis-5.0.7]# redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth xxx
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
可以看到第一次ping的时候提示我需要身份验证。auth xxx这是连接后输入密码。也可以在连接的时候输入:
[root@root redis-5.0.7]# redis-cli -p 6379 -a xxx
在线体验:https://try.redis.io/
以上所以只是均来自于大佬江南一点雨
。
个人博客:http://www.javaboy.org/
网友评论