环境依赖
gcc gcc-c++
[root@redis ~]# yum install gcc* -y
下载安装包
[root@redis ~]# wget https://download.redis.io/redis-stable.tar.gz
--2023-07-13 16:54:01-- https://download.redis.io/redis-stable.tar.gz
Resolving download.redis.io (download.redis.io)... 45.60.125.1
Connecting to download.redis.io (download.redis.io)|45.60.125.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3071850 (2.9M) [application/octet-stream]
Saving to: ‘redis-stable.tar.gz’
100%[======================================>] 3,071,850 29.8KB/s in 65s
2023-07-13 16:55:06 (46.3 KB/s) - ‘redis-stable.tar.gz’ saved [3071850/3071850]
[root@redis ~]# ll
total 3004
-rw-------. 1 root root 1294 Jul 13 11:32 anaconda-ks.cfg
-rw-r--r--. 1 root root 3071850 Jul 10 19:52 redis-stable.tar.gz
解压缩
[root@redis ~]# tar -zxf redis-stable.tar.gz
[root@redis ~]# ll -h redis-stable
total 272K
-rw-rw-r--. 1 1000 1000 45K Jul 10 19:39 00-RELEASENOTES
-rw-rw-r--. 1 1000 1000 51 Jul 10 19:39 BUGS
-rw-rw-r--. 1 1000 1000 5.0K Jul 10 19:39 CODE_OF_CONDUCT.md
-rw-rw-r--. 1 1000 1000 2.6K Jul 10 19:39 CONTRIBUTING.md
-rw-rw-r--. 1 1000 1000 1.5K Jul 10 19:39 COPYING
drwxrwxr-x. 7 1000 1000 119 Jul 10 19:39 deps
-rw-rw-r--. 1 1000 1000 11 Jul 10 19:39 INSTALL
-rw-rw-r--. 1 1000 1000 151 Jul 10 19:39 Makefile
-rw-rw-r--. 1 1000 1000 6.8K Jul 10 19:39 MANIFESTO
-rw-rw-r--. 1 1000 1000 22K Jul 10 19:39 README.md
-rw-rw-r--. 1 1000 1000 105K Jul 10 19:39 redis.conf
-rwxrwxr-x. 1 1000 1000 279 Jul 10 19:39 runtest
-rwxrwxr-x. 1 1000 1000 283 Jul 10 19:39 runtest-cluster
-rwxrwxr-x. 1 1000 1000 1.6K Jul 10 19:39 runtest-moduleapi
-rwxrwxr-x. 1 1000 1000 285 Jul 10 19:39 runtest-sentinel
-rw-rw-r--. 1 1000 1000 1.7K Jul 10 19:39 SECURITY.md
-rw-rw-r--. 1 1000 1000 14K Jul 10 19:39 sentinel.conf
drwxrwxr-x. 4 1000 1000 8.0K Jul 10 19:39 src
drwxrwxr-x. 11 1000 1000 199 Jul 10 19:39 tests
-rw-rw-r--. 1 1000 1000 3.0K Jul 10 19:39 TLS.md
drwxrwxr-x. 8 1000 1000 4.0K Jul 10 19:39 utils
编译安装
[root@redis redis-stable]# make
。。。
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/root/redis-stable/src'
[root@redis redis-stable]# make install
cd src && make install
which: no python3 in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
make[1]: Entering directory `/root/redis-stable/src'
CC Makefile.dep
make[1]: Leaving directory `/root/redis-stable/src'
which: no python3 in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
make[1]: Entering directory `/root/redis-stable/src'
Hint: It's a good idea to run 'make test' ;)
INSTALL redis-server
INSTALL redis-benchmark
INSTALL redis-cli
make[1]: Leaving directory `/root/redis-stable/src'
默认安装目录/usr/local/bin
[root@redis redis-stable]# ll -h /usr/local/bin/
total 22M
-rwxr-xr-x. 1 root root 5.0M Jul 13 17:30 redis-benchmark
lrwxrwxrwx. 1 root root 12 Jul 13 17:30 redis-check-aof -> redis-server
lrwxrwxrwx. 1 root root 12 Jul 13 17:30 redis-check-rdb -> redis-server
-rwxr-xr-x. 1 root root 5.2M Jul 13 17:30 redis-cli
lrwxrwxrwx. 1 root root 12 Jul 13 17:30 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 11M Jul 13 17:30 redis-server
修改配置文件
[root@redis redis-stable]# vim /redis/redis.conf
daemonize yes
protected-mode no
#bind 127.0.0.1 -::1
requirepass oracle
添加环境变量
[root@redis ~]# vim .bash_profile
export PATH=/usr/local/bin:$PATH
[root@redis ~]# source .bash_profile
启动服务
[root@redis ~]# redis-server /redis/redis.conf
[root@redis ~]# ps -ef |grep redis
root 6001 1 0 18:20 ? 00:00:00 redis-server *:6379
root 6007 1417 0 18:20 pts/0 00:00:00 grep --color=auto redis
[root@redis ~]# redis-server --help
Usage: ./redis-server [/path/to/redis.conf] [options] [-]
./redis-server - (read config from stdin)
./redis-server -v or --version
./redis-server -h or --help
./redis-server --test-memory <megabytes>
./redis-server --check-system
Examples:
./redis-server (run the server with default conf)
echo 'maxmemory 128mb' | ./redis-server -
./redis-server /etc/redis/6379.conf
./redis-server --port 7777
./redis-server --port 7777 --replicaof 127.0.0.1 8888
./redis-server /etc/myredis.conf --loglevel verbose -
./redis-server /etc/myredis.conf --loglevel verbose
Sentinel mode:
./redis-server /etc/sentinel.conf --sentinel
查看版本
[root@redis ~]# redis-server --version
Redis server v=7.0.12 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=3c6460644b75d16c
连接redis
[root@redis ~]# redis-cli -hlocalhost -p6379 --pass
Unrecognized option or bad number of args for: '-hlocalhost'
[root@redis ~]# redis-cli -h localhost -p 6379 --pass
Unrecognized option or bad number of args for: '--pass'
[root@redis ~]# redis-cli -h localhost -p 6379 -a
Unrecognized option or bad number of args for: '-a'
[root@redis ~]# redis-cli -h localhost -p 6379 -a oracle
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
localhost:6379>
[root@redis ~]# redis-cli -h localhost -p 6379 --pass oracle
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
localhost:6379>
[root@redis ~]# ps -ef |grep redis |grep -v grep
root 6001 1 0 18:20 ? 00:00:00 redis-server *:6379
root 6018 1417 0 18:27 pts/0 00:00:00 redis-cli -h localhost -p 6379 --pass oracle
localhost:6379> ping
PONG
localhost:6379> ping
PONG
localhost:6379> set key helloworld
OK
localhost:6379> get key
"helloworld"
关闭服务
1、在客户端里面关闭
localhost:6379> shutdown
not connected>
not connected> exit
[root@redis ~]# ps -ef |grep redis | grep -v grep
2、单实例关闭
redis-cli -a oracle shutdown
[root@redis ~]# redis-server /redis/redis.conf
[root@redis ~]# ps -ef |grep redis | grep -v grep
root 6067 1 0 18:43 ? 00:00:00 redis-server *:6379
3、多实例关闭
redis-cli -p 6379,6378,6377 shutdown