目录
一、环境准备
Linux环境安装Redis必须先具备gcc编译环境
# getconf LONG_BIT
64
# yum -y install gcc-c++
# gcc -v
二、Linux下安装
2.1、安装Redis
# tar xzvf redis-7.2.3.tar.gz
# cd redis-7.2.3
# make && make install
# ll /usr/local/bin/
-rwxr-xr-x 1 root root 6900144 Jan 24 16:55 redis-benchmark
lrwxrwxrwx 1 root root 12 Jan 24 16:55 redis-check-aof -> redis-server
lrwxrwxrwx 1 root root 12 Jan 24 16:55 redis-check-rdb -> redis-server
-rwxr-xr-x 1 root root 7620392 Jan 24 16:55 redis-cli
lrwxrwxrwx 1 root root 12 Jan 24 16:55 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 15415400 Jan 24 16:55 redis-server
说明:
- redis-benchmark:性能测试工具,服务启动后运行该命令
- redis-check-aof:修复有问题的AOF文件,rdb和aof后面讲
- redis-check-dump:修复有问题的dump.rdb文件
- redis-cli:客户端,操作入口
- redis-sentinel:redis集群使用
- redis-server:Redis服务器启动命令
2.2、配置Redis
# cp redis.conf /etc/
# vim /etc/redis.conf
1 默认daemonize no 改为 daemonize yes
2 默认protected-mode yes 改为 protected-mode no
3 默认bind 127.0.0.1 改为 直接注释掉(默认bind 127.0.0.1只能本机访问)或改成本机IP地址,否则影响远程IP连接
4 添加redis密码 改为 requirepass 你自己设置的密码
2.3、启动Redis
# redis-server /etc/redis.conf
# ps -ef |grep redis
root 98839 1 0 17:17 ? 00:00:00 redis-server *:6379
root 98879 6737 0 17:17 pts/1 00:00:00 grep --color=auto redis
# netstat -lnp |grep 6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 98839/redis-server
tcp6 0 0 :::6379 :::* LISTEN 98839/redis-server
2.4、连接Redis
# redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth Zqye@wid6
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> quit
# redis-cli -a Zqye@wid6
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set k1 hellword
OK
127.0.0.1:6379> get k1
"hellword"
2.5、关闭Redis
(1)单实例关闭
# redis-cli -a Zqye@wid6 shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
[root@localhost redis-7.2.3]# ps -ef |grep redis |grep -v grep
(2)多实例关闭
# redis-cli -a Zqye@wid6 -p 6379 shutdown
# ps -ef |grep redis |grep -v grep
2.6、卸载Redis
# redis-cli -a Zqye@wid6 shutdown
# ls -l /usr/local/bin/redis-*
# rm -rf /usr/local/bin/redis-*